[Security Solution] Auto-bundle AI Assistant API OpenAPI specs (#188826)

**Addresses**: https://github.com/elastic/kibana/issues/184428

## Summary

This PR adds scripts for automatic bundling of AI Assistant API OpenAPI specs as a part of PR pipeline. Corresponding result bundles are automatically committed to the Assistant Common package `x-pack/packages/kbn-elastic-assistant-common` in the `docs/openapi/ess/` and `docs/openapi/serverless` folders (similar to https://github.com/elastic/kibana/pull/186384).
This commit is contained in:
Maxim Palenov 2024-07-24 22:46:06 +02:00 committed by GitHub
parent e67b9678b3
commit d7f62b63d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 2374 additions and 2369 deletions

View file

@ -6,16 +6,27 @@ source .buildkite/scripts/common/util.sh
echo --- Security Solution OpenAPI Bundling
(cd x-pack/plugins/security_solution && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true
echo -e "\n[Security Solution OpenAPI Bundling] Detections API\n"
(cd x-pack/plugins/security_solution && yarn openapi:bundle:detections)
check_for_changed_files "yarn openapi:bundle:detections" true
echo -e "\n[Security Solution OpenAPI Bundling] Entity Analytics API\n"
(cd x-pack/plugins/security_solution && yarn openapi:bundle:entity-analytics)
check_for_changed_files "yarn openapi:bundle:entity-analytics" true
echo -e "\n[Security Solution OpenAPI Bundling] Lists API\n"
(cd packages/kbn-securitysolution-lists-common && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true
echo -e "\n[Security Solution OpenAPI Bundling] Exceptions API\n"
(cd packages/kbn-securitysolution-exceptions-common && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true
echo -e "\n[Security Solution OpenAPI Bundling] Elastic Assistant API\n"
(cd x-pack/packages/kbn-elastic-assistant-common && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true

View file

@ -10,27 +10,43 @@ 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_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 =
`${ELASTIC_AI_ASSISTANT_URL}/current_user/conversations` as const;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID =
`${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/{id}` as const;
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_INTERNAL_CONVERSATIONS_URL =
`${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/current_user/conversations` as const;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID_MESSAGES =
`${ELASTIC_AI_ASSISTANT_INTERNAL_CONVERSATIONS_URL}/{id}/messages` as const;
export const ELASTIC_AI_ASSISTANT_CHAT_COMPLETE_URL = `${ELASTIC_AI_ASSISTANT_URL}/chat/complete`;
export const ELASTIC_AI_ASSISTANT_CHAT_COMPLETE_URL =
`${ELASTIC_AI_ASSISTANT_URL}/chat/complete` as const;
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_CONVERSATIONS_URL_BULK_ACTION =
`${ELASTIC_AI_ASSISTANT_INTERNAL_CONVERSATIONS_URL}/_bulk_action` as const;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_FIND =
`${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/_find` as const;
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_PROMPTS_URL = `${ELASTIC_AI_ASSISTANT_URL}/prompts` as const;
export const ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION =
`${ELASTIC_AI_ASSISTANT_PROMPTS_URL}/_bulk_action` as const;
export const ELASTIC_AI_ASSISTANT_PROMPTS_URL_FIND =
`${ELASTIC_AI_ASSISTANT_PROMPTS_URL}/_find` as const;
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`;
export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL =
`${ELASTIC_AI_ASSISTANT_URL}/anonymization_fields` as const;
export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION =
`${ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL}/_bulk_action` as const;
export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_FIND =
`${ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL}/_find` as const;
// TODO: Update existing 'status' endpoint to take resource as query param as to not conflict with 'entries'
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/knowledge_base/{resource?}`;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/knowledge_base/entries`;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND = `${ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL}/_find`;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION = `${ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL}/_bulk_action`;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL =
`${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/knowledge_base/{resource?}` as const;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL =
`${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/knowledge_base/entries` as const;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND =
`${ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL}/_find` as const;
export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION =
`${ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL}/_bulk_action` as const;

View file

@ -11,7 +11,7 @@
*
* info:
* title: Bulk Anonymization Fields Actions API endpoint
* version: 1
* version: 2023-10-31
*/
import { z } from 'zod';

View file

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Bulk Anonymization Fields Actions API endpoint
version: '1'
version: '2023-10-31'
paths:
/api/security_ai_assistant/anonymization_fields/_bulk_action:
post:
@ -195,7 +195,6 @@ components:
required:
- attributes
BulkActionBase:
x-inline: true
type: object

View file

@ -11,7 +11,7 @@
*
* info:
* title: Find AnonymizationFields API endpoint
* version: 1
* version: 2023-10-31
*/
import { z } from 'zod';

View file

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Find AnonymizationFields API endpoint
version: '1'
version: '2023-10-31'
paths:
/api/security_ai_assistant/anonymization_fields/_find:
get:

View file

@ -0,0 +1,44 @@
/*
* 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.
*/
/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Append Conversation API endpoint
* version: 1
*/
import { z } from 'zod';
import { NonEmptyString } from '../common_attributes.gen';
import { ConversationMessageCreateProps, ConversationResponse } from './common_attributes.gen';
export type AppendConversationMessageRequestParams = z.infer<
typeof AppendConversationMessageRequestParams
>;
export const AppendConversationMessageRequestParams = z.object({
/**
* The conversation's `id` value.
*/
id: NonEmptyString,
});
export type AppendConversationMessageRequestParamsInput = z.input<
typeof AppendConversationMessageRequestParams
>;
export type AppendConversationMessageRequestBody = z.infer<
typeof AppendConversationMessageRequestBody
>;
export const AppendConversationMessageRequestBody = ConversationMessageCreateProps;
export type AppendConversationMessageRequestBodyInput = z.input<
typeof AppendConversationMessageRequestBody
>;
export type AppendConversationMessageResponse = z.infer<typeof AppendConversationMessageResponse>;
export const AppendConversationMessageResponse = ConversationResponse;

View file

@ -0,0 +1,47 @@
openapi: 3.0.0
info:
title: Append Conversation API endpoint
version: '1'
paths:
/internal/elastic_assistant/current_user/conversations/{id}/messages:
post:
x-codegen-enabled: true
x-labels: [ess, serverless]
operationId: AppendConversationMessage
description: Append a message to the conversation
summary: Append a message to the conversation
tags:
- Conversation API
parameters:
- name: id
in: path
required: true
description: The conversation's `id` value.
schema:
$ref: '../common_attributes.schema.yaml#/components/schemas/NonEmptyString'
requestBody:
required: true
content:
application/json:
schema:
$ref: './common_attributes.schema.yaml#/components/schemas/ConversationMessageCreateProps'
responses:
200:
description: Indicates a successful call.
content:
application/json:
schema:
$ref: './common_attributes.schema.yaml#/components/schemas/ConversationResponse'
400:
description: Generic Error
content:
application/json:
schema:
type: object
properties:
statusCode:
type: number
error:
type: string
message:
type: string

View file

@ -11,7 +11,7 @@
*
* info:
* title: Create Conversation API endpoint
* version: 1
* version: 2023-10-31
*/
import { z } from 'zod';
@ -20,34 +20,9 @@ import {
ConversationCreateProps,
ConversationResponse,
ConversationUpdateProps,
ConversationMessageCreateProps,
} from './common_attributes.gen';
import { NonEmptyString } from '../common_attributes.gen';
export type AppendConversationMessageRequestParams = z.infer<
typeof AppendConversationMessageRequestParams
>;
export const AppendConversationMessageRequestParams = z.object({
/**
* The conversation's `id` value.
*/
id: NonEmptyString,
});
export type AppendConversationMessageRequestParamsInput = z.input<
typeof AppendConversationMessageRequestParams
>;
export type AppendConversationMessageRequestBody = z.infer<
typeof AppendConversationMessageRequestBody
>;
export const AppendConversationMessageRequestBody = ConversationMessageCreateProps;
export type AppendConversationMessageRequestBodyInput = z.input<
typeof AppendConversationMessageRequestBody
>;
export type AppendConversationMessageResponse = z.infer<typeof AppendConversationMessageResponse>;
export const AppendConversationMessageResponse = ConversationResponse;
export type CreateConversationRequestBody = z.infer<typeof CreateConversationRequestBody>;
export const CreateConversationRequestBody = ConversationCreateProps;
export type CreateConversationRequestBodyInput = z.input<typeof CreateConversationRequestBody>;

View file

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Create Conversation API endpoint
version: '1'
version: '2023-10-31'
paths:
/api/security_ai_assistant/current_user/conversations:
post:
@ -151,46 +151,3 @@ paths:
type: string
message:
type: string
/internal/elastic_assistant/current_user/conversations/{id}/messages:
post:
x-codegen-enabled: true
x-labels: [ess, serverless]
operationId: AppendConversationMessage
description: Append a message to the conversation
summary: Append a message to the conversation
tags:
- Conversation API
parameters:
- name: id
in: path
required: true
description: The conversation's `id` value.
schema:
$ref: '../common_attributes.schema.yaml#/components/schemas/NonEmptyString'
requestBody:
required: true
content:
application/json:
schema:
$ref: './common_attributes.schema.yaml#/components/schemas/ConversationMessageCreateProps'
responses:
200:
description: Indicates a successful call.
content:
application/json:
schema:
$ref: './common_attributes.schema.yaml#/components/schemas/ConversationResponse'
400:
description: Generic Error
content:
application/json:
schema:
type: object
properties:
statusCode:
type: number
error:
type: string
message:
type: string

View file

@ -11,7 +11,7 @@
*
* info:
* title: Find Conversations API endpoint
* version: 1
* version: 2023-10-31
*/
import { z } from 'zod';

View file

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Find Conversations API endpoint
version: '1'
version: '2023-10-31'
paths:
/api/security_ai_assistant/current_user/conversations/_find:
get:

View file

@ -13,7 +13,7 @@ export const API_VERSIONS = {
internal: {
v1: '1',
},
};
} as const;
export const PUBLIC_API_ACCESS = 'public';
export const INTERNAL_API_ACCESS = 'internal';
@ -38,6 +38,7 @@ export * from './evaluation/get_evaluate_route.gen';
export * from './capabilities/get_capabilities_route.gen';
// Conversations Schemas
export * from './conversations/append_message.gen';
export * from './conversations/bulk_crud_conversations_route.gen';
export * from './conversations/common_attributes.gen';
export * from './conversations/crud_conversation_route.gen';

View file

@ -11,7 +11,7 @@
*
* info:
* title: Bulk Prompts Actions API endpoint
* version: 1
* version: 2023-10-31
*/
import { z } from 'zod';

View file

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Bulk Prompts Actions API endpoint
version: '1'
version: '2023-10-31'
paths:
/api/security_ai_assistant/prompts/_bulk_action:
post:
@ -220,7 +220,6 @@ components:
required:
- attributes
BulkActionBase:
x-inline: true
type: object

View file

@ -11,7 +11,7 @@
*
* info:
* title: Find Prompts API endpoint
* version: 1
* version: 2023-10-31
*/
import { z } from 'zod';

View file

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Find Prompts API endpoint
version: '1'
version: '2023-10-31'
paths:
/api/security_ai_assistant/prompts/_find:
get:

View file

@ -30,7 +30,7 @@
"junit:transform": "node scripts/junit_transformer --pathPattern '../../../target/kibana-security-solution/cypress/results/*.xml' --rootDirectory ../../../ --reportName 'Security Solution Cypress' --writeInPlace",
"openapi:generate": "node scripts/openapi/generate",
"openapi:generate:debug": "node --inspect-brk scripts/openapi/generate",
"openapi:bundle": "node scripts/openapi/bundle",
"openapi:bundle:detections": "node scripts/openapi/bundle_detections",
"openapi:bundle:entity-analytics": "node scripts/openapi/bundle_entity_analytics"
}
}