diff --git a/oas_docs/output/kibana.serverless.yaml b/oas_docs/output/kibana.serverless.yaml index 6fd080c8c5f27..e113e20d474f3 100644 --- a/oas_docs/output/kibana.serverless.yaml +++ b/oas_docs/output/kibana.serverless.yaml @@ -37315,10 +37315,132 @@ paths: tags: - Security AI Assistant API x-beta: true - /api/security_ai_assistant/prompts/_bulk_action: + /api/security_ai_assistant/knowledge_base/{resource}: + get: + description: Read a single KB + operationId: ReadKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + elser_exists: + type: boolean + index_exists: + type: boolean + is_setup_available: + type: boolean + is_setup_in_progress: + type: boolean + pipeline_exists: + type: boolean + security_labs_exists: + type: boolean + user_data_exists: + type: boolean + description: Indicates a successful call. + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Read a KnowledgeBase + tags: + - Security AI Assistant API + x-beta: true post: - description: Apply a bulk action to multiple prompts. The bulk action is applied to all prompts that match the filter or to the list of prompts by their IDs. - operationId: PerformPromptsBulkAction + description: Create a KnowledgeBase + operationId: CreateKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + - description: Optional ELSER modelId to use when setting up the Knowledge Base + in: query + name: modelId + required: false + schema: + type: string + - description: Indicates whether we should or should not install Security Labs docs when setting up the Knowledge Base + in: query + name: ignoreSecurityLabs + required: false + schema: + default: false + type: boolean + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseResponse' + description: Indicates a successful call. + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Create a KnowledgeBase + tags: + - Security AI Assistant API + x-beta: true + /api/security_ai_assistant/knowledge_base/entries: + post: + description: Create a Knowledge Base Entry + operationId: CreateKnowledgeBaseEntry + requestBody: + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryCreateProps' + required: true + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + description: Successful request returning Knowledge Base Entries + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Create a Knowledge Base Entry + tags: + - Security AI Assistant API + x-beta: true + /api/security_ai_assistant/knowledge_base/entries/_bulk_action: + post: + description: The bulk action is applied to all Knowledge Base Entries that match the filter or to the list of Knowledge Base Entries by their IDs + operationId: PerformKnowledgeBaseEntryBulkAction requestBody: content: application/json; Elastic-Api-Version=2023-10-31: @@ -37327,52 +37449,45 @@ paths: properties: create: items: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptCreateProps' + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryCreateProps' type: array delete: type: object properties: ids: - description: Array of prompts IDs + description: Array of Knowledge base Entry IDs items: type: string minItems: 1 type: array query: - description: Query to filter promps + description: Query to filter Knowledge Base Entries type: string update: items: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptUpdateProps' + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryUpdateProps' type: array responses: '200': content: application/json; Elastic-Api-Version=2023-10-31: schema: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptsBulkCrudActionResponse' - description: Indicates a successful call. + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResponse' + description: Successful bulk operation request '400': content: application/json; Elastic-Api-Version=2023-10-31: schema: - type: object - properties: - error: - type: string - message: - type: string - statusCode: - type: number + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' description: Generic Error - summary: Apply a bulk action to prompts + summary: Applies a bulk action to multiple Knowledge Base Entries tags: - Security AI Assistant API x-beta: true - /api/security_ai_assistant/prompts/_find: + /api/security_ai_assistant/knowledge_base/entries/_find: get: - description: Get a list of all prompts. - operationId: FindPrompts + description: Finds Knowledge Base Entries that match the given query. + operationId: FindKnowledgeBaseEntries parameters: - in: query name: fields @@ -37392,7 +37507,7 @@ paths: name: sort_field required: false schema: - $ref: '#/components/schemas/Security_AI_Assistant_API_FindPromptsSortField' + $ref: '#/components/schemas/Security_AI_Assistant_API_FindKnowledgeBaseEntriesSortField' - description: Sort order in: query name: sort_order @@ -37407,7 +37522,7 @@ paths: default: 1 minimum: 1 type: integer - - description: Prompts per page + - description: Knowledge Base Entries per page in: query name: per_page required: false @@ -37424,7 +37539,7 @@ paths: properties: data: items: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptResponse' + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' type: array page: type: integer @@ -37451,126 +37566,354 @@ paths: statusCode: type: number description: Generic Error - summary: Get prompts + summary: Finds Knowledge Base Entries that match the given query. tags: - Security AI Assistant API x-beta: true - /api/security/role: - get: - operationId: get-security-role - parameters: - - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. - in: query - name: replaceDeprecatedPrivileges - required: false - schema: - type: boolean - responses: - '200': - description: Indicates a successful call. - summary: Get all roles - tags: - - roles - x-beta: true - /api/security/role/{name}: + /api/security_ai_assistant/knowledge_base/entries/{id}: delete: - operationId: delete-security-role-name + description: Deletes a single Knowledge Base Entry using the `id` field + operationId: DeleteKnowledgeBaseEntry parameters: - - description: A required header to protect against CSRF attacks - in: header - name: kbn-xsrf - required: true - schema: - example: 'true' - type: string - - in: path - name: name + - description: The Knowledge Base Entry's `id` value + in: path + name: id required: true schema: - minLength: 1 - type: string + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' responses: - '204': - description: Indicates a successful call. - summary: Delete a role + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_DeleteResponseFields' + description: Successful request returning the deleted Knowledge Base Entry's ID + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Deletes a single Knowledge Base Entry using the `id` field tags: - - roles + - Security AI Assistant API x-beta: true get: - operationId: get-security-role-name + description: Read a Knowledge Base Entry + operationId: ReadKnowledgeBaseEntry parameters: - - description: The role name. + - description: The Knowledge Base Entry's `id` value. in: path - name: name + name: id required: true schema: - minLength: 1 - type: string - - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. - in: query - name: replaceDeprecatedPrivileges - required: false - schema: - type: boolean + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' responses: '200': - description: Indicates a successful call. - summary: Get a role + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + description: Successful request returning a Knowledge Base Entry + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Read a Knowledge Base Entry tags: - - roles + - Security AI Assistant API x-beta: true put: - description: Create a new Kibana role or update the attributes of an existing role. Kibana roles are stored in the Elasticsearch native realm. - operationId: put-security-role-name + description: Update a Knowledge Base Entry + operationId: UpdateKnowledgeBaseEntry parameters: - - description: A required header to protect against CSRF attacks - in: header - name: kbn-xsrf - required: true - schema: - example: 'true' - type: string - - description: The role name. + - description: The Knowledge Base Entry's `id` value in: path - name: name + name: id required: true schema: - maxLength: 1024 - minLength: 1 - type: string - - description: When true, a role is not overwritten if it already exists. - in: query - name: createOnly - required: false - schema: - default: false - type: boolean + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + requestBody: + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryUpdateProps' + required: true + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + description: Successful request returning the updated Knowledge Base Entry + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Update a Knowledge Base Entry + tags: + - Security AI Assistant API + x-beta: true + /api/security_ai_assistant/prompts/_bulk_action: + post: + description: Apply a bulk action to multiple prompts. The bulk action is applied to all prompts that match the filter or to the list of prompts by their IDs. + operationId: PerformPromptsBulkAction requestBody: content: application/json; Elastic-Api-Version=2023-10-31: schema: - additionalProperties: false type: object properties: - description: - description: A description for the role. - maxLength: 2048 - type: string - elasticsearch: - additionalProperties: false + create: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptCreateProps' + type: array + delete: type: object properties: - cluster: + ids: + description: Array of prompts IDs items: - description: Cluster privileges that define the cluster level actions that users can perform. type: string + minItems: 1 type: array - indices: - items: - additionalProperties: false - type: object - properties: - allow_restricted_indices: + query: + description: Query to filter promps + type: string + update: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptUpdateProps' + type: array + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptsBulkCrudActionResponse' + description: Indicates a successful call. + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Apply a bulk action to prompts + tags: + - Security AI Assistant API + x-beta: true + /api/security_ai_assistant/prompts/_find: + get: + description: Get a list of all prompts. + operationId: FindPrompts + parameters: + - in: query + name: fields + required: false + schema: + items: + type: string + type: array + - description: Search query + in: query + name: filter + required: false + schema: + type: string + - description: Field to sort by + in: query + name: sort_field + required: false + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_FindPromptsSortField' + - description: Sort order + in: query + name: sort_order + required: false + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_SortOrder' + - description: Page number + in: query + name: page + required: false + schema: + default: 1 + minimum: 1 + type: integer + - description: Prompts per page + in: query + name: per_page + required: false + schema: + default: 20 + minimum: 0 + type: integer + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + data: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptResponse' + type: array + page: + type: integer + perPage: + type: integer + total: + type: integer + required: + - page + - perPage + - total + - data + description: Successful response + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Get prompts + tags: + - Security AI Assistant API + x-beta: true + /api/security/role: + get: + operationId: get-security-role + parameters: + - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. + in: query + name: replaceDeprecatedPrivileges + required: false + schema: + type: boolean + responses: + '200': + description: Indicates a successful call. + summary: Get all roles + tags: + - roles + x-beta: true + /api/security/role/{name}: + delete: + operationId: delete-security-role-name + parameters: + - description: A required header to protect against CSRF attacks + in: header + name: kbn-xsrf + required: true + schema: + example: 'true' + type: string + - in: path + name: name + required: true + schema: + minLength: 1 + type: string + responses: + '204': + description: Indicates a successful call. + summary: Delete a role + tags: + - roles + x-beta: true + get: + operationId: get-security-role-name + parameters: + - description: The role name. + in: path + name: name + required: true + schema: + minLength: 1 + type: string + - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. + in: query + name: replaceDeprecatedPrivileges + required: false + schema: + type: boolean + responses: + '200': + description: Indicates a successful call. + summary: Get a role + tags: + - roles + x-beta: true + put: + description: Create a new Kibana role or update the attributes of an existing role. Kibana roles are stored in the Elasticsearch native realm. + operationId: put-security-role-name + parameters: + - description: A required header to protect against CSRF attacks + in: header + name: kbn-xsrf + required: true + schema: + example: 'true' + type: string + - description: The role name. + in: path + name: name + required: true + schema: + maxLength: 1024 + minLength: 1 + type: string + - description: When true, a role is not overwritten if it already exists. + in: query + name: createOnly + required: false + schema: + default: false + type: boolean + requestBody: + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + additionalProperties: false + type: object + properties: + description: + description: A description for the role. + maxLength: 2048 + type: string + elasticsearch: + additionalProperties: false + type: object + properties: + cluster: + items: + description: Cluster privileges that define the cluster level actions that users can perform. + type: string + type: array + indices: + items: + additionalProperties: false + type: object + properties: + allow_restricted_indices: description: Restricted indices are a special category of indices that are used internally to store configuration data and should not be directly accessed. Only internal system roles should normally grant privileges over the restricted indices. Toggling this flag is very strongly discouraged because it could effectively grant unrestricted operations on critical data, making the entire system unstable or leaking sensitive information. If for administrative purposes you need to create a role with privileges covering restricted indices, however, you can set this property to true. In that case, the names field covers the restricted indices too. type: boolean field_security: @@ -43322,220 +43665,578 @@ components: - skipped - succeeded - total - Security_AI_Assistant_API_ChatCompleteProps: - type: object - properties: - connectorId: - type: string - conversationId: - type: string - isStream: - type: boolean - langSmithApiKey: - type: string - langSmithProject: - type: string - messages: - items: - $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessage' - type: array - model: - type: string - persist: - type: boolean - promptId: - type: string - responseLanguage: - type: string - required: - - messages - - persist - - connectorId - Security_AI_Assistant_API_ChatMessage: - description: AI assistant message. - type: object - properties: - content: - description: Message content. - type: string - data: - $ref: '#/components/schemas/Security_AI_Assistant_API_MessageData' - description: ECS object to attach to the context of the message. - fields_to_anonymize: - items: - type: string - type: array - role: - $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessageRole' - description: Message role. - required: - - role - Security_AI_Assistant_API_ChatMessageRole: - description: Message role. - enum: - - system - - user - - assistant - type: string - Security_AI_Assistant_API_ConversationCategory: - description: The conversation category. - enum: - - assistant - - insights - type: string - Security_AI_Assistant_API_ConversationConfidence: - description: The conversation confidence. - enum: - - low - - medium - - high - type: string - Security_AI_Assistant_API_ConversationCreateProps: + Security_AI_Assistant_API_ChatCompleteProps: + type: object + properties: + connectorId: + type: string + conversationId: + type: string + isStream: + type: boolean + langSmithApiKey: + type: string + langSmithProject: + type: string + messages: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessage' + type: array + model: + type: string + persist: + type: boolean + promptId: + type: string + responseLanguage: + type: string + required: + - messages + - persist + - connectorId + Security_AI_Assistant_API_ChatMessage: + description: AI assistant message. + type: object + properties: + content: + description: Message content. + type: string + data: + $ref: '#/components/schemas/Security_AI_Assistant_API_MessageData' + description: ECS object to attach to the context of the message. + fields_to_anonymize: + items: + type: string + type: array + role: + $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessageRole' + description: Message role. + required: + - role + Security_AI_Assistant_API_ChatMessageRole: + description: Message role. + enum: + - system + - user + - assistant + type: string + Security_AI_Assistant_API_ConversationCategory: + description: The conversation category. + enum: + - assistant + - insights + type: string + Security_AI_Assistant_API_ConversationConfidence: + description: The conversation confidence. + enum: + - low + - medium + - high + type: string + Security_AI_Assistant_API_ConversationCreateProps: + type: object + properties: + apiConfig: + $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' + description: LLM API configuration. + category: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' + description: The conversation category. + 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: + $ref: '#/components/schemas/Security_AI_Assistant_API_Message' + type: array + replacements: + $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' + title: + description: The conversation title. + type: string + required: + - title + Security_AI_Assistant_API_ConversationResponse: + type: object + properties: + apiConfig: + $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' + description: LLM API configuration. + category: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' + description: The conversation category. + createdAt: + description: The last time conversation was updated. + 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: + $ref: '#/components/schemas/Security_AI_Assistant_API_Message' + type: array + namespace: + description: Kibana space + type: string + replacements: + $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' + summary: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' + timestamp: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + title: + description: The conversation title. + type: string + updatedAt: + description: The last time conversation was updated. + type: string + users: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - id + - title + - createdAt + - users + - namespace + - category + Security_AI_Assistant_API_ConversationSummary: + type: object + properties: + confidence: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationConfidence' + description: How confident you are about this being a correct and useful learning. + content: + description: Summary text of the conversation over time. + type: string + public: + description: Define if summary is marked as publicly available. + type: boolean + timestamp: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + description: The timestamp summary was updated. + Security_AI_Assistant_API_ConversationUpdateProps: + type: object + properties: + apiConfig: + $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' + description: LLM API configuration. + category: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' + description: The conversation category. + excludeFromLastConversationStorage: + description: excludeFromLastConversationStorage. + type: boolean + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + messages: + description: The conversation messages. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_Message' + type: array + replacements: + $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' + summary: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' + title: + description: The conversation title. + type: string + required: + - id + Security_AI_Assistant_API_DeleteResponseFields: + type: object + properties: + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + required: + - id + Security_AI_Assistant_API_DocumentEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/Security_AI_Assistant_API_ResponseFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryResponseFields' + Security_AI_Assistant_API_DocumentEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryOptionalFields' + Security_AI_Assistant_API_DocumentEntryOptionalFields: + type: object + properties: + required: + description: Whether this resource should always be included, defaults to false + type: boolean + vector: + $ref: '#/components/schemas/Security_AI_Assistant_API_Vector' + Security_AI_Assistant_API_DocumentEntryRequiredFields: + type: object + properties: + kbResource: + description: Knowledge Base resource name for grouping entries, e.g. 'esql', 'lens-docs', etc + type: string + source: + description: Source document name or filepath + type: string + text: + description: Knowledge Base Entry content + type: string + type: + description: Entry type + enum: + - document + type: string + required: + - type + - kbResource + - source + - text + Security_AI_Assistant_API_DocumentEntryResponseFields: + allOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryOptionalFields' + Security_AI_Assistant_API_DocumentEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - id + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryCreateFields' + Security_AI_Assistant_API_FindAnonymizationFieldsSortField: + enum: + - created_at + - anonymized + - allowed + - field + - updated_at + type: string + Security_AI_Assistant_API_FindConversationsSortField: + enum: + - created_at + - is_default + - title + - updated_at + type: string + Security_AI_Assistant_API_FindKnowledgeBaseEntriesSortField: + enum: + - created_at + - is_default + - title + - updated_at + type: string + Security_AI_Assistant_API_FindPromptsSortField: + enum: + - created_at + - is_default + - name + - updated_at + type: string + Security_AI_Assistant_API_IndexEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/Security_AI_Assistant_API_ResponseFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryResponseFields' + Security_AI_Assistant_API_IndexEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryOptionalFields' + Security_AI_Assistant_API_IndexEntryOptionalFields: + type: object + properties: + inputSchema: + $ref: '#/components/schemas/Security_AI_Assistant_API_InputSchema' + outputFields: + description: Fields to extract from the query result, defaults to all fields if not provided or empty + items: + type: string + type: array + Security_AI_Assistant_API_IndexEntryRequiredFields: + type: object + properties: + description: + description: Description for when this index or data stream should be queried for Knowledge Base content. Passed to the LLM as a tool description + type: string + field: + description: Field to query for Knowledge Base content + type: string + index: + description: Index or Data Stream to query for Knowledge Base content + type: string + queryDescription: + description: Description of query field used to fetch Knowledge Base content. Passed to the LLM as part of the tool input schema + type: string + type: + description: Entry type + enum: + - index + type: string + required: + - type + - index + - field + - description + - queryDescription + Security_AI_Assistant_API_IndexEntryResponseFields: + allOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryOptionalFields' + Security_AI_Assistant_API_IndexEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - id + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryCreateFields' + Security_AI_Assistant_API_InputSchema: + description: Array of objects defining the input schema, allowing the LLM to extract structured data to be used in retrieval + items: + type: object + properties: + description: + description: Description of the field + type: string + fieldName: + description: Name of the field + type: string + fieldType: + description: Type of the field + type: string + required: + - fieldName + - fieldType + - description + type: array + Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipReason: + enum: + - KNOWLEDGE_BASE_ENTRY_NOT_MODIFIED + type: string + Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipResult: + type: object + properties: + id: + type: string + name: + type: string + skip_reason: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipReason' + required: + - id + - skip_reason + Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResponse: + type: object + properties: + attributes: + type: object + properties: + errors: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_NormalizedKnowledgeBaseEntryError' + type: array + results: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResults' + summary: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionSummary' + required: + - results + - summary + knowledgeBaseEntriesCount: + type: integer + message: + type: string + statusCode: + type: integer + success: + type: boolean + required: + - attributes + Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResults: + type: object + properties: + created: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + type: array + deleted: + items: + type: string + type: array + skipped: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipResult' + type: array + updated: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + type: array + required: + - updated + - created + - deleted + - skipped + Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionSummary: + type: object + properties: + failed: + type: integer + skipped: + type: integer + succeeded: + type: integer + total: + type: integer + required: + - failed + - skipped + - succeeded + - total + Security_AI_Assistant_API_KnowledgeBaseEntryCreateProps: + anyOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryCreateFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryCreateFields' + discriminator: + propertyName: type + Security_AI_Assistant_API_KnowledgeBaseEntryDetailsInError: type: object properties: - apiConfig: - $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' - description: LLM API configuration. - category: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' - description: The conversation category. - 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: - $ref: '#/components/schemas/Security_AI_Assistant_API_Message' - type: array - replacements: - $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' - title: - description: The conversation title. + name: type: string required: - - title - Security_AI_Assistant_API_ConversationResponse: + - id + Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema: + additionalProperties: false type: object properties: - apiConfig: - $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' - description: LLM API configuration. - category: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' - description: The conversation category. - createdAt: - description: The last time conversation was updated. - 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: - $ref: '#/components/schemas/Security_AI_Assistant_API_Message' - type: array - namespace: - description: Kibana space - type: string - replacements: - $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' - summary: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' - timestamp: - $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' - title: - description: The conversation title. + error: type: string - updatedAt: - description: The last time conversation was updated. + message: type: string - users: - items: - $ref: '#/components/schemas/Security_AI_Assistant_API_User' - type: array + statusCode: + type: number required: - - id - - title - - createdAt - - users - - namespace - - category - Security_AI_Assistant_API_ConversationSummary: - type: object - properties: - confidence: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationConfidence' - description: How confident you are about this being a correct and useful learning. - content: - description: Summary text of the conversation over time. - type: string - public: - description: Define if summary is marked as publicly available. - type: boolean - timestamp: - $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' - description: The timestamp summary was updated. - Security_AI_Assistant_API_ConversationUpdateProps: + - statusCode + - error + - message + Security_AI_Assistant_API_KnowledgeBaseEntryResponse: + anyOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntry' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntry' + discriminator: + propertyName: type + Security_AI_Assistant_API_KnowledgeBaseEntryUpdateProps: + anyOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryUpdateFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryUpdateFields' + discriminator: + propertyName: type + Security_AI_Assistant_API_KnowledgeBaseResponse: + description: AI assistant KnowledgeBase. type: object properties: - apiConfig: - $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' - description: LLM API configuration. - category: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' - description: The conversation category. - excludeFromLastConversationStorage: - description: excludeFromLastConversationStorage. + success: + description: Identify the success of the method execution. type: boolean - id: - $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' - messages: - description: The conversation messages. - items: - $ref: '#/components/schemas/Security_AI_Assistant_API_Message' - type: array - replacements: - $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' - summary: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' - title: - description: The conversation title. - type: string - required: - - id - Security_AI_Assistant_API_FindAnonymizationFieldsSortField: - enum: - - created_at - - anonymized - - allowed - - field - - updated_at - type: string - Security_AI_Assistant_API_FindConversationsSortField: - enum: - - created_at - - is_default - - title - - updated_at - type: string - Security_AI_Assistant_API_FindPromptsSortField: - enum: - - created_at - - is_default - - name - - updated_at - type: string Security_AI_Assistant_API_Message: description: AI assistant conversation message. type: object @@ -43594,6 +44295,23 @@ components: - message - status_code - anonymization_fields + Security_AI_Assistant_API_NormalizedKnowledgeBaseEntryError: + type: object + properties: + err_code: + type: string + knowledgeBaseEntries: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryDetailsInError' + type: array + message: + type: string + statusCode: + type: integer + required: + - message + - statusCode + - knowledgeBaseEntries Security_AI_Assistant_API_NormalizedPromptError: type: object properties: @@ -43799,6 +44517,29 @@ components: type: string description: Replacements object used to anonymize/deanomymize messsages type: object + Security_AI_Assistant_API_ResponseFields: + type: object + properties: + createdAt: + description: Time the Knowledge Base Entry was created + type: string + createdBy: + description: User who created the Knowledge Base Entry + type: string + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + updatedAt: + description: Time the Knowledge Base Entry was last updated + type: string + updatedBy: + description: User who last updated the Knowledge Base Entry + type: string + required: + - id + - createdAt + - createdBy + - updatedAt + - updatedBy Security_AI_Assistant_API_SortOrder: enum: - asc @@ -43824,6 +44565,21 @@ components: name: description: User name type: string + Security_AI_Assistant_API_Vector: + description: Object containing Knowledge Base Entry text embeddings and modelId used to create the embeddings + type: object + properties: + modelId: + description: ID of the model used to create the embeddings + type: string + tokens: + additionalProperties: + type: number + description: Tokens with their corresponding values + type: object + required: + - modelId + - tokens Security_Detections_API_AlertAssignees: type: object properties: diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml index 8c04df0345d9b..6912ecaa79fcd 100644 --- a/oas_docs/output/kibana.yaml +++ b/oas_docs/output/kibana.yaml @@ -39793,10 +39793,129 @@ paths: summary: Update a conversation tags: - Security AI Assistant API - /api/security_ai_assistant/prompts/_bulk_action: + /api/security_ai_assistant/knowledge_base/{resource}: + get: + description: Read a single KB + operationId: ReadKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + elser_exists: + type: boolean + index_exists: + type: boolean + is_setup_available: + type: boolean + is_setup_in_progress: + type: boolean + pipeline_exists: + type: boolean + security_labs_exists: + type: boolean + user_data_exists: + type: boolean + description: Indicates a successful call. + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Read a KnowledgeBase + tags: + - Security AI Assistant API post: - description: Apply a bulk action to multiple prompts. The bulk action is applied to all prompts that match the filter or to the list of prompts by their IDs. - operationId: PerformPromptsBulkAction + description: Create a KnowledgeBase + operationId: CreateKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + - description: Optional ELSER modelId to use when setting up the Knowledge Base + in: query + name: modelId + required: false + schema: + type: string + - description: Indicates whether we should or should not install Security Labs docs when setting up the Knowledge Base + in: query + name: ignoreSecurityLabs + required: false + schema: + default: false + type: boolean + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseResponse' + description: Indicates a successful call. + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Create a KnowledgeBase + tags: + - Security AI Assistant API + /api/security_ai_assistant/knowledge_base/entries: + post: + description: Create a Knowledge Base Entry + operationId: CreateKnowledgeBaseEntry + requestBody: + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryCreateProps' + required: true + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + description: Successful request returning Knowledge Base Entries + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Create a Knowledge Base Entry + tags: + - Security AI Assistant API + /api/security_ai_assistant/knowledge_base/entries/_bulk_action: + post: + description: The bulk action is applied to all Knowledge Base Entries that match the filter or to the list of Knowledge Base Entries by their IDs + operationId: PerformKnowledgeBaseEntryBulkAction requestBody: content: application/json; Elastic-Api-Version=2023-10-31: @@ -39805,51 +39924,44 @@ paths: properties: create: items: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptCreateProps' + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryCreateProps' type: array delete: type: object properties: ids: - description: Array of prompts IDs + description: Array of Knowledge base Entry IDs items: type: string minItems: 1 type: array query: - description: Query to filter promps + description: Query to filter Knowledge Base Entries type: string update: items: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptUpdateProps' + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryUpdateProps' type: array responses: '200': content: application/json; Elastic-Api-Version=2023-10-31: schema: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptsBulkCrudActionResponse' - description: Indicates a successful call. + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResponse' + description: Successful bulk operation request '400': content: application/json; Elastic-Api-Version=2023-10-31: schema: - type: object - properties: - error: - type: string - message: - type: string - statusCode: - type: number + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' description: Generic Error - summary: Apply a bulk action to prompts + summary: Applies a bulk action to multiple Knowledge Base Entries tags: - Security AI Assistant API - /api/security_ai_assistant/prompts/_find: + /api/security_ai_assistant/knowledge_base/entries/_find: get: - description: Get a list of all prompts. - operationId: FindPrompts + description: Finds Knowledge Base Entries that match the given query. + operationId: FindKnowledgeBaseEntries parameters: - in: query name: fields @@ -39869,7 +39981,7 @@ paths: name: sort_field required: false schema: - $ref: '#/components/schemas/Security_AI_Assistant_API_FindPromptsSortField' + $ref: '#/components/schemas/Security_AI_Assistant_API_FindKnowledgeBaseEntriesSortField' - description: Sort order in: query name: sort_order @@ -39884,7 +39996,7 @@ paths: default: 1 minimum: 1 type: integer - - description: Prompts per page + - description: Knowledge Base Entries per page in: query name: per_page required: false @@ -39901,7 +40013,7 @@ paths: properties: data: items: - $ref: '#/components/schemas/Security_AI_Assistant_API_PromptResponse' + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' type: array page: type: integer @@ -39928,133 +40040,356 @@ paths: statusCode: type: number description: Generic Error - summary: Get prompts + summary: Finds Knowledge Base Entries that match the given query. tags: - Security AI Assistant API - /api/security/role: - get: - operationId: get-security-role + /api/security_ai_assistant/knowledge_base/entries/{id}: + delete: + description: Deletes a single Knowledge Base Entry using the `id` field + operationId: DeleteKnowledgeBaseEntry parameters: - - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. - in: query - name: replaceDeprecatedPrivileges - required: false + - description: The Knowledge Base Entry's `id` value + in: path + name: id + required: true schema: - type: boolean + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' responses: '200': - description: Indicates a successful call. content: application/json; Elastic-Api-Version=2023-10-31: - examples: - getRolesResponse1: - $ref: '#/components/examples/get_roles_response1' - summary: Get all roles - tags: - - roles - /api/security/role/{name}: - delete: - operationId: delete-security-role-name - parameters: - - description: A required header to protect against CSRF attacks - in: header - name: kbn-xsrf - required: true - schema: - example: 'true' - type: string - - in: path - name: name - required: true - schema: - minLength: 1 - type: string - responses: - '204': - description: Indicates a successful call. - summary: Delete a role + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_DeleteResponseFields' + description: Successful request returning the deleted Knowledge Base Entry's ID + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Deletes a single Knowledge Base Entry using the `id` field tags: - - roles + - Security AI Assistant API get: - operationId: get-security-role-name + description: Read a Knowledge Base Entry + operationId: ReadKnowledgeBaseEntry parameters: - - description: The role name. + - description: The Knowledge Base Entry's `id` value. in: path - name: name + name: id required: true schema: - minLength: 1 - type: string - - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. - in: query - name: replaceDeprecatedPrivileges - required: false - schema: - type: boolean + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' responses: '200': - description: Indicates a successful call. content: application/json; Elastic-Api-Version=2023-10-31: - examples: - getRoleResponse1: - $ref: '#/components/examples/get_role_response1' - summary: Get a role + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + description: Successful request returning a Knowledge Base Entry + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Read a Knowledge Base Entry tags: - - roles + - Security AI Assistant API put: - description: Create a new Kibana role or update the attributes of an existing role. Kibana roles are stored in the Elasticsearch native realm. - operationId: put-security-role-name + description: Update a Knowledge Base Entry + operationId: UpdateKnowledgeBaseEntry parameters: - - description: A required header to protect against CSRF attacks - in: header - name: kbn-xsrf - required: true - schema: - example: 'true' - type: string - - description: The role name. + - description: The Knowledge Base Entry's `id` value in: path - name: name + name: id required: true schema: - maxLength: 1024 - minLength: 1 - type: string - - description: When true, a role is not overwritten if it already exists. - in: query - name: createOnly - required: false - schema: - default: false - type: boolean + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + requestBody: + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryUpdateProps' + required: true + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + description: Successful request returning the updated Knowledge Base Entry + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Update a Knowledge Base Entry + tags: + - Security AI Assistant API + /api/security_ai_assistant/prompts/_bulk_action: + post: + description: Apply a bulk action to multiple prompts. The bulk action is applied to all prompts that match the filter or to the list of prompts by their IDs. + operationId: PerformPromptsBulkAction requestBody: content: application/json; Elastic-Api-Version=2023-10-31: schema: - additionalProperties: false type: object properties: - description: - description: A description for the role. - maxLength: 2048 - type: string - elasticsearch: - additionalProperties: false + create: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptCreateProps' + type: array + delete: type: object properties: - cluster: + ids: + description: Array of prompts IDs items: - description: Cluster privileges that define the cluster level actions that users can perform. type: string + minItems: 1 type: array - indices: - items: - additionalProperties: false - type: object - properties: - allow_restricted_indices: - description: Restricted indices are a special category of indices that are used internally to store configuration data and should not be directly accessed. Only internal system roles should normally grant privileges over the restricted indices. Toggling this flag is very strongly discouraged because it could effectively grant unrestricted operations on critical data, making the entire system unstable or leaking sensitive information. If for administrative purposes you need to create a role with privileges covering restricted indices, however, you can set this property to true. In that case, the names field covers the restricted indices too. + query: + description: Query to filter promps + type: string + update: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptUpdateProps' + type: array + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptsBulkCrudActionResponse' + description: Indicates a successful call. + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Apply a bulk action to prompts + tags: + - Security AI Assistant API + /api/security_ai_assistant/prompts/_find: + get: + description: Get a list of all prompts. + operationId: FindPrompts + parameters: + - in: query + name: fields + required: false + schema: + items: + type: string + type: array + - description: Search query + in: query + name: filter + required: false + schema: + type: string + - description: Field to sort by + in: query + name: sort_field + required: false + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_FindPromptsSortField' + - description: Sort order + in: query + name: sort_order + required: false + schema: + $ref: '#/components/schemas/Security_AI_Assistant_API_SortOrder' + - description: Page number + in: query + name: page + required: false + schema: + default: 1 + minimum: 1 + type: integer + - description: Prompts per page + in: query + name: per_page + required: false + schema: + default: 20 + minimum: 0 + type: integer + responses: + '200': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + data: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_PromptResponse' + type: array + page: + type: integer + perPage: + type: integer + total: + type: integer + required: + - page + - perPage + - total + - data + description: Successful response + '400': + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Get prompts + tags: + - Security AI Assistant API + /api/security/role: + get: + operationId: get-security-role + parameters: + - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. + in: query + name: replaceDeprecatedPrivileges + required: false + schema: + type: boolean + responses: + '200': + description: Indicates a successful call. + content: + application/json; Elastic-Api-Version=2023-10-31: + examples: + getRolesResponse1: + $ref: '#/components/examples/get_roles_response1' + summary: Get all roles + tags: + - roles + /api/security/role/{name}: + delete: + operationId: delete-security-role-name + parameters: + - description: A required header to protect against CSRF attacks + in: header + name: kbn-xsrf + required: true + schema: + example: 'true' + type: string + - in: path + name: name + required: true + schema: + minLength: 1 + type: string + responses: + '204': + description: Indicates a successful call. + summary: Delete a role + tags: + - roles + get: + operationId: get-security-role-name + parameters: + - description: The role name. + in: path + name: name + required: true + schema: + minLength: 1 + type: string + - description: If `true` and the response contains any privileges that are associated with deprecated features, they are omitted in favor of details about the appropriate replacement feature privileges. + in: query + name: replaceDeprecatedPrivileges + required: false + schema: + type: boolean + responses: + '200': + description: Indicates a successful call. + content: + application/json; Elastic-Api-Version=2023-10-31: + examples: + getRoleResponse1: + $ref: '#/components/examples/get_role_response1' + summary: Get a role + tags: + - roles + put: + description: Create a new Kibana role or update the attributes of an existing role. Kibana roles are stored in the Elasticsearch native realm. + operationId: put-security-role-name + parameters: + - description: A required header to protect against CSRF attacks + in: header + name: kbn-xsrf + required: true + schema: + example: 'true' + type: string + - description: The role name. + in: path + name: name + required: true + schema: + maxLength: 1024 + minLength: 1 + type: string + - description: When true, a role is not overwritten if it already exists. + in: query + name: createOnly + required: false + schema: + default: false + type: boolean + requestBody: + content: + application/json; Elastic-Api-Version=2023-10-31: + schema: + additionalProperties: false + type: object + properties: + description: + description: A description for the role. + maxLength: 2048 + type: string + elasticsearch: + additionalProperties: false + type: object + properties: + cluster: + items: + description: Cluster privileges that define the cluster level actions that users can perform. + type: string + type: array + indices: + items: + additionalProperties: false + type: object + properties: + allow_restricted_indices: + description: Restricted indices are a special category of indices that are used internally to store configuration data and should not be directly accessed. Only internal system roles should normally grant privileges over the restricted indices. Toggling this flag is very strongly discouraged because it could effectively grant unrestricted operations on critical data, making the entire system unstable or leaking sensitive information. If for administrative purposes you need to create a role with privileges covering restricted indices, however, you can set this property to true. In that case, the names field covers the restricted indices too. type: boolean field_security: additionalProperties: @@ -49834,220 +50169,578 @@ components: - skipped - succeeded - total - Security_AI_Assistant_API_ChatCompleteProps: - type: object - properties: - connectorId: - type: string - conversationId: - type: string - isStream: - type: boolean - langSmithApiKey: - type: string - langSmithProject: - type: string - messages: - items: - $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessage' - type: array - model: - type: string - persist: - type: boolean - promptId: - type: string - responseLanguage: - type: string - required: - - messages - - persist - - connectorId - Security_AI_Assistant_API_ChatMessage: - description: AI assistant message. - type: object - properties: - content: - description: Message content. - type: string - data: - $ref: '#/components/schemas/Security_AI_Assistant_API_MessageData' - description: ECS object to attach to the context of the message. - fields_to_anonymize: - items: - type: string - type: array - role: - $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessageRole' - description: Message role. - required: - - role - Security_AI_Assistant_API_ChatMessageRole: - description: Message role. - enum: - - system - - user - - assistant - type: string - Security_AI_Assistant_API_ConversationCategory: - description: The conversation category. - enum: - - assistant - - insights - type: string - Security_AI_Assistant_API_ConversationConfidence: - description: The conversation confidence. - enum: - - low - - medium - - high - type: string - Security_AI_Assistant_API_ConversationCreateProps: + Security_AI_Assistant_API_ChatCompleteProps: + type: object + properties: + connectorId: + type: string + conversationId: + type: string + isStream: + type: boolean + langSmithApiKey: + type: string + langSmithProject: + type: string + messages: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessage' + type: array + model: + type: string + persist: + type: boolean + promptId: + type: string + responseLanguage: + type: string + required: + - messages + - persist + - connectorId + Security_AI_Assistant_API_ChatMessage: + description: AI assistant message. + type: object + properties: + content: + description: Message content. + type: string + data: + $ref: '#/components/schemas/Security_AI_Assistant_API_MessageData' + description: ECS object to attach to the context of the message. + fields_to_anonymize: + items: + type: string + type: array + role: + $ref: '#/components/schemas/Security_AI_Assistant_API_ChatMessageRole' + description: Message role. + required: + - role + Security_AI_Assistant_API_ChatMessageRole: + description: Message role. + enum: + - system + - user + - assistant + type: string + Security_AI_Assistant_API_ConversationCategory: + description: The conversation category. + enum: + - assistant + - insights + type: string + Security_AI_Assistant_API_ConversationConfidence: + description: The conversation confidence. + enum: + - low + - medium + - high + type: string + Security_AI_Assistant_API_ConversationCreateProps: + type: object + properties: + apiConfig: + $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' + description: LLM API configuration. + category: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' + description: The conversation category. + 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: + $ref: '#/components/schemas/Security_AI_Assistant_API_Message' + type: array + replacements: + $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' + title: + description: The conversation title. + type: string + required: + - title + Security_AI_Assistant_API_ConversationResponse: + type: object + properties: + apiConfig: + $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' + description: LLM API configuration. + category: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' + description: The conversation category. + createdAt: + description: The last time conversation was updated. + 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: + $ref: '#/components/schemas/Security_AI_Assistant_API_Message' + type: array + namespace: + description: Kibana space + type: string + replacements: + $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' + summary: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' + timestamp: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + title: + description: The conversation title. + type: string + updatedAt: + description: The last time conversation was updated. + type: string + users: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - id + - title + - createdAt + - users + - namespace + - category + Security_AI_Assistant_API_ConversationSummary: + type: object + properties: + confidence: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationConfidence' + description: How confident you are about this being a correct and useful learning. + content: + description: Summary text of the conversation over time. + type: string + public: + description: Define if summary is marked as publicly available. + type: boolean + timestamp: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + description: The timestamp summary was updated. + Security_AI_Assistant_API_ConversationUpdateProps: + type: object + properties: + apiConfig: + $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' + description: LLM API configuration. + category: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' + description: The conversation category. + excludeFromLastConversationStorage: + description: excludeFromLastConversationStorage. + type: boolean + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + messages: + description: The conversation messages. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_Message' + type: array + replacements: + $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' + summary: + $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' + title: + description: The conversation title. + type: string + required: + - id + Security_AI_Assistant_API_DeleteResponseFields: + type: object + properties: + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + required: + - id + Security_AI_Assistant_API_DocumentEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/Security_AI_Assistant_API_ResponseFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryResponseFields' + Security_AI_Assistant_API_DocumentEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryOptionalFields' + Security_AI_Assistant_API_DocumentEntryOptionalFields: + type: object + properties: + required: + description: Whether this resource should always be included, defaults to false + type: boolean + vector: + $ref: '#/components/schemas/Security_AI_Assistant_API_Vector' + Security_AI_Assistant_API_DocumentEntryRequiredFields: + type: object + properties: + kbResource: + description: Knowledge Base resource name for grouping entries, e.g. 'esql', 'lens-docs', etc + type: string + source: + description: Source document name or filepath + type: string + text: + description: Knowledge Base Entry content + type: string + type: + description: Entry type + enum: + - document + type: string + required: + - type + - kbResource + - source + - text + Security_AI_Assistant_API_DocumentEntryResponseFields: + allOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryOptionalFields' + Security_AI_Assistant_API_DocumentEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - id + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryCreateFields' + Security_AI_Assistant_API_FindAnonymizationFieldsSortField: + enum: + - created_at + - anonymized + - allowed + - field + - updated_at + type: string + Security_AI_Assistant_API_FindConversationsSortField: + enum: + - created_at + - is_default + - title + - updated_at + type: string + Security_AI_Assistant_API_FindKnowledgeBaseEntriesSortField: + enum: + - created_at + - is_default + - title + - updated_at + type: string + Security_AI_Assistant_API_FindPromptsSortField: + enum: + - created_at + - is_default + - name + - updated_at + type: string + Security_AI_Assistant_API_IndexEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/Security_AI_Assistant_API_ResponseFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryResponseFields' + Security_AI_Assistant_API_IndexEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - name + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryOptionalFields' + Security_AI_Assistant_API_IndexEntryOptionalFields: + type: object + properties: + inputSchema: + $ref: '#/components/schemas/Security_AI_Assistant_API_InputSchema' + outputFields: + description: Fields to extract from the query result, defaults to all fields if not provided or empty + items: + type: string + type: array + Security_AI_Assistant_API_IndexEntryRequiredFields: + type: object + properties: + description: + description: Description for when this index or data stream should be queried for Knowledge Base content. Passed to the LLM as a tool description + type: string + field: + description: Field to query for Knowledge Base content + type: string + index: + description: Index or Data Stream to query for Knowledge Base content + type: string + queryDescription: + description: Description of query field used to fetch Knowledge Base content. Passed to the LLM as part of the tool input schema + type: string + type: + description: Entry type + enum: + - index + type: string + required: + - type + - index + - field + - description + - queryDescription + Security_AI_Assistant_API_IndexEntryResponseFields: + allOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryRequiredFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryOptionalFields' + Security_AI_Assistant_API_IndexEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: Users who have access to the Knowledge Base Entry, defaults to current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_User' + type: array + required: + - id + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryCreateFields' + Security_AI_Assistant_API_InputSchema: + description: Array of objects defining the input schema, allowing the LLM to extract structured data to be used in retrieval + items: + type: object + properties: + description: + description: Description of the field + type: string + fieldName: + description: Name of the field + type: string + fieldType: + description: Type of the field + type: string + required: + - fieldName + - fieldType + - description + type: array + Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipReason: + enum: + - KNOWLEDGE_BASE_ENTRY_NOT_MODIFIED + type: string + Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipResult: + type: object + properties: + id: + type: string + name: + type: string + skip_reason: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipReason' + required: + - id + - skip_reason + Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResponse: + type: object + properties: + attributes: + type: object + properties: + errors: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_NormalizedKnowledgeBaseEntryError' + type: array + results: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResults' + summary: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionSummary' + required: + - results + - summary + knowledgeBaseEntriesCount: + type: integer + message: + type: string + statusCode: + type: integer + success: + type: boolean + required: + - attributes + Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionResults: + type: object + properties: + created: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + type: array + deleted: + items: + type: string + type: array + skipped: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryBulkActionSkipResult' + type: array + updated: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryResponse' + type: array + required: + - updated + - created + - deleted + - skipped + Security_AI_Assistant_API_KnowledgeBaseEntryBulkCrudActionSummary: + type: object + properties: + failed: + type: integer + skipped: + type: integer + succeeded: + type: integer + total: + type: integer + required: + - failed + - skipped + - succeeded + - total + Security_AI_Assistant_API_KnowledgeBaseEntryCreateProps: + anyOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryCreateFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryCreateFields' + discriminator: + propertyName: type + Security_AI_Assistant_API_KnowledgeBaseEntryDetailsInError: type: object properties: - apiConfig: - $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' - description: LLM API configuration. - category: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' - description: The conversation category. - 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: - $ref: '#/components/schemas/Security_AI_Assistant_API_Message' - type: array - replacements: - $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' - title: - description: The conversation title. + name: type: string required: - - title - Security_AI_Assistant_API_ConversationResponse: + - id + Security_AI_Assistant_API_KnowledgeBaseEntryErrorSchema: + additionalProperties: false type: object properties: - apiConfig: - $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' - description: LLM API configuration. - category: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' - description: The conversation category. - createdAt: - description: The last time conversation was updated. - 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: - $ref: '#/components/schemas/Security_AI_Assistant_API_Message' - type: array - namespace: - description: Kibana space - type: string - replacements: - $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' - summary: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' - timestamp: - $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' - title: - description: The conversation title. + error: type: string - updatedAt: - description: The last time conversation was updated. + message: type: string - users: - items: - $ref: '#/components/schemas/Security_AI_Assistant_API_User' - type: array + statusCode: + type: number required: - - id - - title - - createdAt - - users - - namespace - - category - Security_AI_Assistant_API_ConversationSummary: - type: object - properties: - confidence: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationConfidence' - description: How confident you are about this being a correct and useful learning. - content: - description: Summary text of the conversation over time. - type: string - public: - description: Define if summary is marked as publicly available. - type: boolean - timestamp: - $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' - description: The timestamp summary was updated. - Security_AI_Assistant_API_ConversationUpdateProps: + - statusCode + - error + - message + Security_AI_Assistant_API_KnowledgeBaseEntryResponse: + anyOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntry' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntry' + discriminator: + propertyName: type + Security_AI_Assistant_API_KnowledgeBaseEntryUpdateProps: + anyOf: + - $ref: '#/components/schemas/Security_AI_Assistant_API_DocumentEntryUpdateFields' + - $ref: '#/components/schemas/Security_AI_Assistant_API_IndexEntryUpdateFields' + discriminator: + propertyName: type + Security_AI_Assistant_API_KnowledgeBaseResponse: + description: AI assistant KnowledgeBase. type: object properties: - apiConfig: - $ref: '#/components/schemas/Security_AI_Assistant_API_ApiConfig' - description: LLM API configuration. - category: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory' - description: The conversation category. - excludeFromLastConversationStorage: - description: excludeFromLastConversationStorage. + success: + description: Identify the success of the method execution. type: boolean - id: - $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' - messages: - description: The conversation messages. - items: - $ref: '#/components/schemas/Security_AI_Assistant_API_Message' - type: array - replacements: - $ref: '#/components/schemas/Security_AI_Assistant_API_Replacements' - summary: - $ref: '#/components/schemas/Security_AI_Assistant_API_ConversationSummary' - title: - description: The conversation title. - type: string - required: - - id - Security_AI_Assistant_API_FindAnonymizationFieldsSortField: - enum: - - created_at - - anonymized - - allowed - - field - - updated_at - type: string - Security_AI_Assistant_API_FindConversationsSortField: - enum: - - created_at - - is_default - - title - - updated_at - type: string - Security_AI_Assistant_API_FindPromptsSortField: - enum: - - created_at - - is_default - - name - - updated_at - type: string Security_AI_Assistant_API_Message: description: AI assistant conversation message. type: object @@ -50106,6 +50799,23 @@ components: - message - status_code - anonymization_fields + Security_AI_Assistant_API_NormalizedKnowledgeBaseEntryError: + type: object + properties: + err_code: + type: string + knowledgeBaseEntries: + items: + $ref: '#/components/schemas/Security_AI_Assistant_API_KnowledgeBaseEntryDetailsInError' + type: array + message: + type: string + statusCode: + type: integer + required: + - message + - statusCode + - knowledgeBaseEntries Security_AI_Assistant_API_NormalizedPromptError: type: object properties: @@ -50311,6 +51021,29 @@ components: type: string description: Replacements object used to anonymize/deanomymize messsages type: object + Security_AI_Assistant_API_ResponseFields: + type: object + properties: + createdAt: + description: Time the Knowledge Base Entry was created + type: string + createdBy: + description: User who created the Knowledge Base Entry + type: string + id: + $ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString' + updatedAt: + description: Time the Knowledge Base Entry was last updated + type: string + updatedBy: + description: User who last updated the Knowledge Base Entry + type: string + required: + - id + - createdAt + - createdBy + - updatedAt + - updatedBy Security_AI_Assistant_API_SortOrder: enum: - asc @@ -50336,6 +51069,21 @@ components: name: description: User name type: string + Security_AI_Assistant_API_Vector: + description: Object containing Knowledge Base Entry text embeddings and modelId used to create the embeddings + type: object + properties: + modelId: + description: ID of the model used to create the embeddings + type: string + tokens: + additionalProperties: + type: number + description: Tokens with their corresponding values + type: object + required: + - modelId + - tokens Security_Detections_API_AlertAssignees: type: object properties: diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/constants.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/constants.ts index 7a884936d04e2..5042b66facd70 100755 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/constants.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/constants.ts @@ -5,8 +5,6 @@ * 2.0. */ -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'; @@ -43,16 +41,18 @@ export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_FIND = // 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?}` as const; + `${ELASTIC_AI_ASSISTANT_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; + `${ELASTIC_AI_ASSISTANT_URL}/knowledge_base/entries` as const; +export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID = + `${ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL}/{id}` 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; + export const ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_INDICES_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/knowledge_base/_indices` as const; - export const ELASTIC_AI_ASSISTANT_EVALUATE_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/evaluate` as const; diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml index 726f5faba2edb..1da2cb5ce57ee 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml @@ -418,6 +418,353 @@ paths: tags: - Security AI Assistant API - Conversation API + /api/security_ai_assistant/knowledge_base/{resource}: + get: + description: Read a single KB + operationId: ReadKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + properties: + elser_exists: + type: boolean + index_exists: + type: boolean + is_setup_available: + type: boolean + is_setup_in_progress: + type: boolean + pipeline_exists: + type: boolean + security_labs_exists: + type: boolean + user_data_exists: + type: boolean + description: Indicates a successful call. + '400': + content: + application/json: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Read a KnowledgeBase + tags: + - Security AI Assistant API + - KnowledgeBase API + post: + description: Create a KnowledgeBase + operationId: CreateKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + - description: Optional ELSER modelId to use when setting up the Knowledge Base + in: query + name: modelId + required: false + schema: + type: string + - description: >- + Indicates whether we should or should not install Security Labs docs + when setting up the Knowledge Base + in: query + name: ignoreSecurityLabs + required: false + schema: + default: false + type: boolean + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseResponse' + description: Indicates a successful call. + '400': + content: + application/json: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Create a KnowledgeBase + tags: + - Security AI Assistant API + - KnowledgeBase API + /api/security_ai_assistant/knowledge_base/entries: + post: + description: Create a Knowledge Base Entry + operationId: CreateKnowledgeBaseEntry + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryCreateProps' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + description: Successful request returning Knowledge Base Entries + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Create a Knowledge Base Entry + tags: + - Security AI Assistant API + - Knowledge Base Entries API + /api/security_ai_assistant/knowledge_base/entries/_bulk_action: + post: + description: >- + The bulk action is applied to all Knowledge Base Entries that match the + filter or to the list of Knowledge Base Entries by their IDs + operationId: PerformKnowledgeBaseEntryBulkAction + requestBody: + content: + application/json: + schema: + type: object + properties: + create: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryCreateProps' + type: array + delete: + type: object + properties: + ids: + description: Array of Knowledge base Entry IDs + items: + type: string + minItems: 1 + type: array + query: + description: Query to filter Knowledge Base Entries + type: string + update: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryUpdateProps' + type: array + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkCrudActionResponse' + description: Successful bulk operation request + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Applies a bulk action to multiple Knowledge Base Entries + tags: + - Security AI Assistant API + - Knowledge Base Entries Bulk API + /api/security_ai_assistant/knowledge_base/entries/_find: + get: + description: Finds Knowledge Base Entries that match the given query. + operationId: FindKnowledgeBaseEntries + parameters: + - in: query + name: fields + required: false + schema: + items: + type: string + type: array + - description: Search query + in: query + name: filter + required: false + schema: + type: string + - description: Field to sort by + in: query + name: sort_field + required: false + schema: + $ref: '#/components/schemas/FindKnowledgeBaseEntriesSortField' + - description: Sort order + in: query + name: sort_order + required: false + schema: + $ref: '#/components/schemas/SortOrder' + - description: Page number + in: query + name: page + required: false + schema: + default: 1 + minimum: 1 + type: integer + - description: Knowledge Base Entries per page + in: query + name: per_page + required: false + schema: + default: 20 + minimum: 0 + type: integer + responses: + '200': + content: + application/json: + schema: + type: object + properties: + data: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + type: array + page: + type: integer + perPage: + type: integer + total: + type: integer + required: + - page + - perPage + - total + - data + description: Successful response + '400': + content: + application/json: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Finds Knowledge Base Entries that match the given query. + tags: + - Security AI Assistant API + - Knowledge Base Entries API + /api/security_ai_assistant/knowledge_base/entries/{id}: + delete: + description: Deletes a single Knowledge Base Entry using the `id` field + operationId: DeleteKnowledgeBaseEntry + parameters: + - description: The Knowledge Base Entry's `id` value + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/NonEmptyString' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteResponseFields' + description: Successful request returning the deleted Knowledge Base Entry's ID + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Deletes a single Knowledge Base Entry using the `id` field + tags: + - Security AI Assistant API + - Knowledge Base Entries API + get: + description: Read a Knowledge Base Entry + operationId: ReadKnowledgeBaseEntry + parameters: + - description: The Knowledge Base Entry's `id` value. + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/NonEmptyString' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + description: Successful request returning a Knowledge Base Entry + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Read a Knowledge Base Entry + tags: + - Security AI Assistant API + - Knowledge Base Entries API + put: + description: Update a Knowledge Base Entry + operationId: UpdateKnowledgeBaseEntry + parameters: + - description: The Knowledge Base Entry's `id` value + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/NonEmptyString' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryUpdateProps' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + description: Successful request returning the updated Knowledge Base Entry + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Update a Knowledge Base Entry + tags: + - Security AI Assistant API + - Knowledge Base Entries API /api/security_ai_assistant/prompts/_bulk_action: post: description: >- @@ -919,6 +1266,115 @@ components: type: string required: - id + DeleteResponseFields: + type: object + properties: + id: + $ref: '#/components/schemas/NonEmptyString' + required: + - id + DocumentEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/ResponseFields' + - $ref: '#/components/schemas/DocumentEntryResponseFields' + DocumentEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - $ref: '#/components/schemas/DocumentEntryRequiredFields' + - $ref: '#/components/schemas/DocumentEntryOptionalFields' + DocumentEntryOptionalFields: + type: object + properties: + required: + description: Whether this resource should always be included, defaults to false + type: boolean + vector: + $ref: '#/components/schemas/Vector' + DocumentEntryRequiredFields: + type: object + properties: + kbResource: + description: >- + Knowledge Base resource name for grouping entries, e.g. 'esql', + 'lens-docs', etc + type: string + source: + description: Source document name or filepath + type: string + text: + description: Knowledge Base Entry content + type: string + type: + description: Entry type + enum: + - document + type: string + required: + - type + - kbResource + - source + - text + DocumentEntryResponseFields: + allOf: + - $ref: '#/components/schemas/DocumentEntryRequiredFields' + - $ref: '#/components/schemas/DocumentEntryOptionalFields' + DocumentEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - id + - $ref: '#/components/schemas/DocumentEntryCreateFields' FindAnonymizationFieldsSortField: enum: - created_at @@ -934,6 +1390,13 @@ components: - title - updated_at type: string + FindKnowledgeBaseEntriesSortField: + enum: + - created_at + - is_default + - title + - updated_at + type: string FindPromptsSortField: enum: - created_at @@ -941,6 +1404,270 @@ components: - name - updated_at type: string + IndexEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/ResponseFields' + - $ref: '#/components/schemas/IndexEntryResponseFields' + IndexEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - $ref: '#/components/schemas/IndexEntryRequiredFields' + - $ref: '#/components/schemas/IndexEntryOptionalFields' + IndexEntryOptionalFields: + type: object + properties: + inputSchema: + $ref: '#/components/schemas/InputSchema' + outputFields: + description: >- + Fields to extract from the query result, defaults to all fields if + not provided or empty + items: + type: string + type: array + IndexEntryRequiredFields: + type: object + properties: + description: + description: >- + Description for when this index or data stream should be queried for + Knowledge Base content. Passed to the LLM as a tool description + type: string + field: + description: Field to query for Knowledge Base content + type: string + index: + description: Index or Data Stream to query for Knowledge Base content + type: string + queryDescription: + description: >- + Description of query field used to fetch Knowledge Base content. + Passed to the LLM as part of the tool input schema + type: string + type: + description: Entry type + enum: + - index + type: string + required: + - type + - index + - field + - description + - queryDescription + IndexEntryResponseFields: + allOf: + - $ref: '#/components/schemas/IndexEntryRequiredFields' + - $ref: '#/components/schemas/IndexEntryOptionalFields' + IndexEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - id + - $ref: '#/components/schemas/IndexEntryCreateFields' + InputSchema: + description: >- + Array of objects defining the input schema, allowing the LLM to extract + structured data to be used in retrieval + items: + type: object + properties: + description: + description: Description of the field + type: string + fieldName: + description: Name of the field + type: string + fieldType: + description: Type of the field + type: string + required: + - fieldName + - fieldType + - description + type: array + KnowledgeBaseEntryBulkActionSkipReason: + enum: + - KNOWLEDGE_BASE_ENTRY_NOT_MODIFIED + type: string + KnowledgeBaseEntryBulkActionSkipResult: + type: object + properties: + id: + type: string + name: + type: string + skip_reason: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkActionSkipReason' + required: + - id + - skip_reason + KnowledgeBaseEntryBulkCrudActionResponse: + type: object + properties: + attributes: + type: object + properties: + errors: + items: + $ref: '#/components/schemas/NormalizedKnowledgeBaseEntryError' + type: array + results: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkCrudActionResults' + summary: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkCrudActionSummary' + required: + - results + - summary + knowledgeBaseEntriesCount: + type: integer + message: + type: string + statusCode: + type: integer + success: + type: boolean + required: + - attributes + KnowledgeBaseEntryBulkCrudActionResults: + type: object + properties: + created: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + type: array + deleted: + items: + type: string + type: array + skipped: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkActionSkipResult' + type: array + updated: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + type: array + required: + - updated + - created + - deleted + - skipped + KnowledgeBaseEntryBulkCrudActionSummary: + type: object + properties: + failed: + type: integer + skipped: + type: integer + succeeded: + type: integer + total: + type: integer + required: + - failed + - skipped + - succeeded + - total + KnowledgeBaseEntryCreateProps: + anyOf: + - $ref: '#/components/schemas/DocumentEntryCreateFields' + - $ref: '#/components/schemas/IndexEntryCreateFields' + discriminator: + propertyName: type + KnowledgeBaseEntryDetailsInError: + type: object + properties: + id: + type: string + name: + type: string + required: + - id + KnowledgeBaseEntryErrorSchema: + additionalProperties: false + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + required: + - statusCode + - error + - message + KnowledgeBaseEntryResponse: + anyOf: + - $ref: '#/components/schemas/DocumentEntry' + - $ref: '#/components/schemas/IndexEntry' + discriminator: + propertyName: type + KnowledgeBaseEntryUpdateProps: + anyOf: + - $ref: '#/components/schemas/DocumentEntryUpdateFields' + - $ref: '#/components/schemas/IndexEntryUpdateFields' + discriminator: + propertyName: type + KnowledgeBaseResponse: + description: AI assistant KnowledgeBase. + type: object + properties: + success: + description: Identify the success of the method execution. + type: boolean Message: description: AI assistant conversation message. type: object @@ -999,6 +1726,23 @@ components: - message - status_code - anonymization_fields + NormalizedKnowledgeBaseEntryError: + type: object + properties: + err_code: + type: string + knowledgeBaseEntries: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryDetailsInError' + type: array + message: + type: string + statusCode: + type: integer + required: + - message + - statusCode + - knowledgeBaseEntries NormalizedPromptError: type: object properties: @@ -1204,6 +1948,29 @@ components: type: string description: Replacements object used to anonymize/deanomymize messsages type: object + ResponseFields: + type: object + properties: + createdAt: + description: Time the Knowledge Base Entry was created + type: string + createdBy: + description: User who created the Knowledge Base Entry + type: string + id: + $ref: '#/components/schemas/NonEmptyString' + updatedAt: + description: Time the Knowledge Base Entry was last updated + type: string + updatedBy: + description: User who last updated the Knowledge Base Entry + type: string + required: + - id + - createdAt + - createdBy + - updatedAt + - updatedBy SortOrder: enum: - asc @@ -1229,6 +1996,23 @@ components: name: description: User name type: string + Vector: + description: >- + Object containing Knowledge Base Entry text embeddings and modelId used + to create the embeddings + type: object + properties: + modelId: + description: ID of the model used to create the embeddings + type: string + tokens: + additionalProperties: + type: number + description: Tokens with their corresponding values + type: object + required: + - modelId + - tokens securitySchemes: BasicAuth: scheme: basic diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml index 81112f1470547..be0c22efb99ab 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml @@ -418,6 +418,353 @@ paths: tags: - Security AI Assistant API - Conversation API + /api/security_ai_assistant/knowledge_base/{resource}: + get: + description: Read a single KB + operationId: ReadKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + properties: + elser_exists: + type: boolean + index_exists: + type: boolean + is_setup_available: + type: boolean + is_setup_in_progress: + type: boolean + pipeline_exists: + type: boolean + security_labs_exists: + type: boolean + user_data_exists: + type: boolean + description: Indicates a successful call. + '400': + content: + application/json: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Read a KnowledgeBase + tags: + - Security AI Assistant API + - KnowledgeBase API + post: + description: Create a KnowledgeBase + operationId: CreateKnowledgeBase + parameters: + - description: The KnowledgeBase `resource` value. + in: path + name: resource + schema: + type: string + - description: Optional ELSER modelId to use when setting up the Knowledge Base + in: query + name: modelId + required: false + schema: + type: string + - description: >- + Indicates whether we should or should not install Security Labs docs + when setting up the Knowledge Base + in: query + name: ignoreSecurityLabs + required: false + schema: + default: false + type: boolean + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseResponse' + description: Indicates a successful call. + '400': + content: + application/json: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Create a KnowledgeBase + tags: + - Security AI Assistant API + - KnowledgeBase API + /api/security_ai_assistant/knowledge_base/entries: + post: + description: Create a Knowledge Base Entry + operationId: CreateKnowledgeBaseEntry + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryCreateProps' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + description: Successful request returning Knowledge Base Entries + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Create a Knowledge Base Entry + tags: + - Security AI Assistant API + - Knowledge Base Entries API + /api/security_ai_assistant/knowledge_base/entries/_bulk_action: + post: + description: >- + The bulk action is applied to all Knowledge Base Entries that match the + filter or to the list of Knowledge Base Entries by their IDs + operationId: PerformKnowledgeBaseEntryBulkAction + requestBody: + content: + application/json: + schema: + type: object + properties: + create: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryCreateProps' + type: array + delete: + type: object + properties: + ids: + description: Array of Knowledge base Entry IDs + items: + type: string + minItems: 1 + type: array + query: + description: Query to filter Knowledge Base Entries + type: string + update: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryUpdateProps' + type: array + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkCrudActionResponse' + description: Successful bulk operation request + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Applies a bulk action to multiple Knowledge Base Entries + tags: + - Security AI Assistant API + - Knowledge Base Entries Bulk API + /api/security_ai_assistant/knowledge_base/entries/_find: + get: + description: Finds Knowledge Base Entries that match the given query. + operationId: FindKnowledgeBaseEntries + parameters: + - in: query + name: fields + required: false + schema: + items: + type: string + type: array + - description: Search query + in: query + name: filter + required: false + schema: + type: string + - description: Field to sort by + in: query + name: sort_field + required: false + schema: + $ref: '#/components/schemas/FindKnowledgeBaseEntriesSortField' + - description: Sort order + in: query + name: sort_order + required: false + schema: + $ref: '#/components/schemas/SortOrder' + - description: Page number + in: query + name: page + required: false + schema: + default: 1 + minimum: 1 + type: integer + - description: Knowledge Base Entries per page + in: query + name: per_page + required: false + schema: + default: 20 + minimum: 0 + type: integer + responses: + '200': + content: + application/json: + schema: + type: object + properties: + data: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + type: array + page: + type: integer + perPage: + type: integer + total: + type: integer + required: + - page + - perPage + - total + - data + description: Successful response + '400': + content: + application/json: + schema: + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + description: Generic Error + summary: Finds Knowledge Base Entries that match the given query. + tags: + - Security AI Assistant API + - Knowledge Base Entries API + /api/security_ai_assistant/knowledge_base/entries/{id}: + delete: + description: Deletes a single Knowledge Base Entry using the `id` field + operationId: DeleteKnowledgeBaseEntry + parameters: + - description: The Knowledge Base Entry's `id` value + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/NonEmptyString' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteResponseFields' + description: Successful request returning the deleted Knowledge Base Entry's ID + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Deletes a single Knowledge Base Entry using the `id` field + tags: + - Security AI Assistant API + - Knowledge Base Entries API + get: + description: Read a Knowledge Base Entry + operationId: ReadKnowledgeBaseEntry + parameters: + - description: The Knowledge Base Entry's `id` value. + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/NonEmptyString' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + description: Successful request returning a Knowledge Base Entry + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Read a Knowledge Base Entry + tags: + - Security AI Assistant API + - Knowledge Base Entries API + put: + description: Update a Knowledge Base Entry + operationId: UpdateKnowledgeBaseEntry + parameters: + - description: The Knowledge Base Entry's `id` value + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/NonEmptyString' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryUpdateProps' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + description: Successful request returning the updated Knowledge Base Entry + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/KnowledgeBaseEntryErrorSchema' + description: Generic Error + summary: Update a Knowledge Base Entry + tags: + - Security AI Assistant API + - Knowledge Base Entries API /api/security_ai_assistant/prompts/_bulk_action: post: description: >- @@ -919,6 +1266,115 @@ components: type: string required: - id + DeleteResponseFields: + type: object + properties: + id: + $ref: '#/components/schemas/NonEmptyString' + required: + - id + DocumentEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/ResponseFields' + - $ref: '#/components/schemas/DocumentEntryResponseFields' + DocumentEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - $ref: '#/components/schemas/DocumentEntryRequiredFields' + - $ref: '#/components/schemas/DocumentEntryOptionalFields' + DocumentEntryOptionalFields: + type: object + properties: + required: + description: Whether this resource should always be included, defaults to false + type: boolean + vector: + $ref: '#/components/schemas/Vector' + DocumentEntryRequiredFields: + type: object + properties: + kbResource: + description: >- + Knowledge Base resource name for grouping entries, e.g. 'esql', + 'lens-docs', etc + type: string + source: + description: Source document name or filepath + type: string + text: + description: Knowledge Base Entry content + type: string + type: + description: Entry type + enum: + - document + type: string + required: + - type + - kbResource + - source + - text + DocumentEntryResponseFields: + allOf: + - $ref: '#/components/schemas/DocumentEntryRequiredFields' + - $ref: '#/components/schemas/DocumentEntryOptionalFields' + DocumentEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - id + - $ref: '#/components/schemas/DocumentEntryCreateFields' FindAnonymizationFieldsSortField: enum: - created_at @@ -934,6 +1390,13 @@ components: - title - updated_at type: string + FindKnowledgeBaseEntriesSortField: + enum: + - created_at + - is_default + - title + - updated_at + type: string FindPromptsSortField: enum: - created_at @@ -941,6 +1404,270 @@ components: - name - updated_at type: string + IndexEntry: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - namespace + - users + - $ref: '#/components/schemas/ResponseFields' + - $ref: '#/components/schemas/IndexEntryResponseFields' + IndexEntryCreateFields: + allOf: + - type: object + properties: + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - name + - $ref: '#/components/schemas/IndexEntryRequiredFields' + - $ref: '#/components/schemas/IndexEntryOptionalFields' + IndexEntryOptionalFields: + type: object + properties: + inputSchema: + $ref: '#/components/schemas/InputSchema' + outputFields: + description: >- + Fields to extract from the query result, defaults to all fields if + not provided or empty + items: + type: string + type: array + IndexEntryRequiredFields: + type: object + properties: + description: + description: >- + Description for when this index or data stream should be queried for + Knowledge Base content. Passed to the LLM as a tool description + type: string + field: + description: Field to query for Knowledge Base content + type: string + index: + description: Index or Data Stream to query for Knowledge Base content + type: string + queryDescription: + description: >- + Description of query field used to fetch Knowledge Base content. + Passed to the LLM as part of the tool input schema + type: string + type: + description: Entry type + enum: + - index + type: string + required: + - type + - index + - field + - description + - queryDescription + IndexEntryResponseFields: + allOf: + - $ref: '#/components/schemas/IndexEntryRequiredFields' + - $ref: '#/components/schemas/IndexEntryOptionalFields' + IndexEntryUpdateFields: + allOf: + - type: object + properties: + id: + $ref: '#/components/schemas/NonEmptyString' + name: + description: Name of the Knowledge Base Entry + type: string + namespace: + description: Kibana Space, defaults to 'default' space + type: string + users: + description: >- + Users who have access to the Knowledge Base Entry, defaults to + current user. Empty array provides access to all users. + items: + $ref: '#/components/schemas/User' + type: array + required: + - id + - $ref: '#/components/schemas/IndexEntryCreateFields' + InputSchema: + description: >- + Array of objects defining the input schema, allowing the LLM to extract + structured data to be used in retrieval + items: + type: object + properties: + description: + description: Description of the field + type: string + fieldName: + description: Name of the field + type: string + fieldType: + description: Type of the field + type: string + required: + - fieldName + - fieldType + - description + type: array + KnowledgeBaseEntryBulkActionSkipReason: + enum: + - KNOWLEDGE_BASE_ENTRY_NOT_MODIFIED + type: string + KnowledgeBaseEntryBulkActionSkipResult: + type: object + properties: + id: + type: string + name: + type: string + skip_reason: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkActionSkipReason' + required: + - id + - skip_reason + KnowledgeBaseEntryBulkCrudActionResponse: + type: object + properties: + attributes: + type: object + properties: + errors: + items: + $ref: '#/components/schemas/NormalizedKnowledgeBaseEntryError' + type: array + results: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkCrudActionResults' + summary: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkCrudActionSummary' + required: + - results + - summary + knowledgeBaseEntriesCount: + type: integer + message: + type: string + statusCode: + type: integer + success: + type: boolean + required: + - attributes + KnowledgeBaseEntryBulkCrudActionResults: + type: object + properties: + created: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + type: array + deleted: + items: + type: string + type: array + skipped: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryBulkActionSkipResult' + type: array + updated: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryResponse' + type: array + required: + - updated + - created + - deleted + - skipped + KnowledgeBaseEntryBulkCrudActionSummary: + type: object + properties: + failed: + type: integer + skipped: + type: integer + succeeded: + type: integer + total: + type: integer + required: + - failed + - skipped + - succeeded + - total + KnowledgeBaseEntryCreateProps: + anyOf: + - $ref: '#/components/schemas/DocumentEntryCreateFields' + - $ref: '#/components/schemas/IndexEntryCreateFields' + discriminator: + propertyName: type + KnowledgeBaseEntryDetailsInError: + type: object + properties: + id: + type: string + name: + type: string + required: + - id + KnowledgeBaseEntryErrorSchema: + additionalProperties: false + type: object + properties: + error: + type: string + message: + type: string + statusCode: + type: number + required: + - statusCode + - error + - message + KnowledgeBaseEntryResponse: + anyOf: + - $ref: '#/components/schemas/DocumentEntry' + - $ref: '#/components/schemas/IndexEntry' + discriminator: + propertyName: type + KnowledgeBaseEntryUpdateProps: + anyOf: + - $ref: '#/components/schemas/DocumentEntryUpdateFields' + - $ref: '#/components/schemas/IndexEntryUpdateFields' + discriminator: + propertyName: type + KnowledgeBaseResponse: + description: AI assistant KnowledgeBase. + type: object + properties: + success: + description: Identify the success of the method execution. + type: boolean Message: description: AI assistant conversation message. type: object @@ -999,6 +1726,23 @@ components: - message - status_code - anonymization_fields + NormalizedKnowledgeBaseEntryError: + type: object + properties: + err_code: + type: string + knowledgeBaseEntries: + items: + $ref: '#/components/schemas/KnowledgeBaseEntryDetailsInError' + type: array + message: + type: string + statusCode: + type: integer + required: + - message + - statusCode + - knowledgeBaseEntries NormalizedPromptError: type: object properties: @@ -1204,6 +1948,29 @@ components: type: string description: Replacements object used to anonymize/deanomymize messsages type: object + ResponseFields: + type: object + properties: + createdAt: + description: Time the Knowledge Base Entry was created + type: string + createdBy: + description: User who created the Knowledge Base Entry + type: string + id: + $ref: '#/components/schemas/NonEmptyString' + updatedAt: + description: Time the Knowledge Base Entry was last updated + type: string + updatedBy: + description: User who last updated the Knowledge Base Entry + type: string + required: + - id + - createdAt + - createdBy + - updatedAt + - updatedBy SortOrder: enum: - asc @@ -1229,6 +1996,23 @@ components: name: description: User name type: string + Vector: + description: >- + Object containing Knowledge Base Entry text embeddings and modelId used + to create the embeddings + type: object + properties: + modelId: + description: ID of the model used to create the embeddings + type: string + tokens: + additionalProperties: + type: number + description: Tokens with their corresponding values + type: object + required: + - modelId + - tokens securitySchemes: BasicAuth: scheme: basic diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.gen.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.gen.ts index a4f38cafd460b..ce1865496cd35 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.gen.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.gen.ts @@ -11,7 +11,7 @@ * * info: * title: KnowledgeBase API endpoints - * version: 1 + * version: 2023-10-31 */ import { z } from '@kbn/zod'; diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.schema.yaml index 67193212abb49..90617149886f6 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/crud_kb_route.schema.yaml @@ -1,9 +1,9 @@ openapi: 3.0.0 info: title: KnowledgeBase API endpoints - version: '1' + version: '2023-10-31' paths: - /internal/elastic_assistant/knowledge_base/{resource}: + /api/security_ai_assistant/knowledge_base/{resource}: post: x-codegen-enabled: true x-labels: [ess, serverless] diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.gen.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.gen.ts index 44759badb7374..631b8c27a6387 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.gen.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.gen.ts @@ -11,7 +11,7 @@ * * info: * title: Bulk Knowledge Base Actions API endpoint - * version: 1 + * version: 2023-10-31 */ import { z } from '@kbn/zod'; diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.http b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.http index 873a7299820f0..b3ab8827086a1 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.http +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.http @@ -1,5 +1,5 @@ ### Empty Bulk Action -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries/_bulk_action +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries/_bulk_action kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.schema.yaml index db68416b14561..0688fc5d3faca 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/bulk_crud_knowledge_base_entries_route.schema.yaml @@ -1,13 +1,11 @@ openapi: 3.0.0 info: title: Bulk Knowledge Base Actions API endpoint - version: '1' + version: '2023-10-31' paths: - /internal/elastic_assistant/knowledge_base/entries/_bulk_action: + /api/security_ai_assistant/knowledge_base/entries/_bulk_action: post: x-codegen-enabled: true - # Targeted to update to public by 8.18 - x-internal: true x-labels: [ess, serverless] operationId: PerformKnowledgeBaseEntryBulkAction summary: Applies a bulk action to multiple Knowledge Base Entries diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.gen.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.gen.ts index c32517fec0860..8a9e4b89e971f 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.gen.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.gen.ts @@ -136,6 +136,11 @@ export const ResponseFields = z.object({ updatedBy: z.string(), }); +export type DeleteResponseFields = z.infer; +export const DeleteResponseFields = z.object({ + id: NonEmptyString, +}); + export type SharedResponseProps = z.infer; export const SharedResponseProps = BaseResponseProps.merge(ResponseFields); @@ -250,3 +255,6 @@ export const KnowledgeBaseEntryUpdateProps = z.discriminatedUnion('type', [ export type KnowledgeBaseEntryResponse = z.infer; export const KnowledgeBaseEntryResponse = z.discriminatedUnion('type', [DocumentEntry, IndexEntry]); + +export type KnowledgeBaseEntryDeleteResponse = z.infer; +export const KnowledgeBaseEntryDeleteResponse = DeleteResponseFields; diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.schema.yaml index af7f4dd8e4221..91b082e4aac44 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.schema.yaml @@ -150,6 +150,14 @@ components: - updatedAt - updatedBy + DeleteResponseFields: + type: object + properties: + id: + $ref: "../../common_attributes.schema.yaml#/components/schemas/NonEmptyString" + required: + - id + SharedResponseProps: x-inline: true allOf: @@ -306,3 +314,7 @@ components: anyOf: - $ref: "#/components/schemas/DocumentEntry" - $ref: "#/components/schemas/IndexEntry" + + KnowledgeBaseEntryDeleteResponse: + allOf: + - $ref: "#/components/schemas/DeleteResponseFields" diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.gen.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.gen.ts index 1650f4ddc3cc6..d47f90b2446df 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.gen.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.gen.ts @@ -11,7 +11,7 @@ * * info: * title: Manage Knowledge Base Entries API endpoint - * version: 1 + * version: 2023-10-31 */ import { z } from '@kbn/zod'; @@ -20,6 +20,7 @@ import { KnowledgeBaseEntryCreateProps, KnowledgeBaseEntryResponse, KnowledgeBaseEntryUpdateProps, + DeleteResponseFields, } from './common_attributes.gen'; import { NonEmptyString } from '../../common_attributes.gen'; @@ -48,7 +49,7 @@ export type DeleteKnowledgeBaseEntryRequestParamsInput = z.input< >; export type DeleteKnowledgeBaseEntryResponse = z.infer; -export const DeleteKnowledgeBaseEntryResponse = KnowledgeBaseEntryResponse; +export const DeleteKnowledgeBaseEntryResponse = DeleteResponseFields; export type ReadKnowledgeBaseEntryRequestParams = z.infer< typeof ReadKnowledgeBaseEntryRequestParams diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.http b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.http index 6bd8dc7ba288b..123e00f2dbc8f 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.http +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.http @@ -1,5 +1,5 @@ ### Create Document Entry [Admin] [Private] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -16,7 +16,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Document Entry [Admin] [Global] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -34,7 +34,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Document Entry [Assistant All] [Private] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -51,7 +51,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Document Entry [Assistant All] [Global] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -69,7 +69,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Index Entry [Admin] [Private] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -89,7 +89,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Index Entry [Admin] [Global] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -110,7 +110,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Index Entry [Assistant All] [Private] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} @@ -129,7 +129,7 @@ X-Kbn-Context: {{appContext.security}} } ### Create Index Entry [Assistant All] [Global] -POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries +POST http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries kbn-xsrf: "true" Content-Type: application/json Elastic-Api-Version: {{elasticApiVersion}} diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.schema.yaml index 10105ef7dce90..4c80999d2c926 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.schema.yaml @@ -1,13 +1,11 @@ openapi: 3.0.0 info: title: Manage Knowledge Base Entries API endpoint - version: '1' + version: '2023-10-31' paths: - /internal/elastic_assistant/knowledge_base/entries: + /api/security_ai_assistant/knowledge_base/entries: post: x-codegen-enabled: true - # Targeted to update to public by 8.18 - x-internal: true x-labels: [ess, serverless] operationId: CreateKnowledgeBaseEntry description: Create a Knowledge Base Entry @@ -34,11 +32,9 @@ paths: schema: $ref: './common_attributes.schema.yaml#/components/schemas/KnowledgeBaseEntryErrorSchema' - /internal/elastic_assistant/knowledge_base/entries/{id}: + /api/security_ai_assistant/knowledge_base/entries/{id}: get: x-codegen-enabled: true - # Targeted to update to public by 8.18 - x-internal: true x-labels: [ess, serverless] operationId: ReadKnowledgeBaseEntry description: Read a Knowledge Base Entry @@ -67,8 +63,6 @@ paths: $ref: './common_attributes.schema.yaml#/components/schemas/KnowledgeBaseEntryErrorSchema' put: x-codegen-enabled: true - # Targeted to update to public by 8.18 - x-internal: true x-labels: [ess, serverless] operationId: UpdateKnowledgeBaseEntry description: Update a Knowledge Base Entry @@ -103,8 +97,6 @@ paths: $ref: './common_attributes.schema.yaml#/components/schemas/KnowledgeBaseEntryErrorSchema' delete: x-codegen-enabled: true - # Targeted to update to public by 8.18 - x-internal: true x-labels: [ess, serverless] operationId: DeleteKnowledgeBaseEntry description: Deletes a single Knowledge Base Entry using the `id` field @@ -120,11 +112,11 @@ paths: $ref: '../../common_attributes.schema.yaml#/components/schemas/NonEmptyString' responses: 200: - description: Successful request returning the deleted Knowledge Base Entry + description: Successful request returning the deleted Knowledge Base Entry's ID content: application/json: schema: - $ref: './common_attributes.schema.yaml#/components/schemas/KnowledgeBaseEntryResponse' + $ref: './common_attributes.schema.yaml#/components/schemas/DeleteResponseFields' 400: description: Generic Error content: diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.gen.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.gen.ts index 81930d69bb265..b27e003b3681d 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.gen.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.gen.ts @@ -11,7 +11,7 @@ * * info: * title: Find Knowledge Base Entries API endpoint - * version: 1 + * version: 2023-10-31 */ import { z } from '@kbn/zod'; diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.http b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.http index 81733c62838a4..b68f37374c236 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.http +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.http @@ -1,5 +1,5 @@ ### Find all knowledge base entries -GET http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries/_find +GET http://{{host}}:{{port}}{{basePath}}/api/security_ai_assistant/knowledge_base/entries/_find Elastic-Api-Version: {{elasticApiVersion}} Authorization: Basic {{auth.admin.username}} {{auth.admin.password}} X-Kbn-Context: {{appContext.security}} diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.schema.yaml index 9b9696e8760fc..1b333d18a0d4a 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/entries/find_knowledge_base_entries_route.schema.yaml @@ -1,13 +1,11 @@ openapi: 3.0.0 info: title: Find Knowledge Base Entries API endpoint - version: '1' + version: '2023-10-31' paths: - /internal/elastic_assistant/knowledge_base/entries/_find: + /api/security_ai_assistant/knowledge_base/entries/_find: get: x-codegen-enabled: true - # Targeted to update to public by 8.18 - x-internal: true x-labels: [ess, serverless] operationId: FindKnowledgeBaseEntries description: Finds Knowledge Base Entries that match the given query. diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/get_knowledge_base_indices_route.schema.yaml b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/get_knowledge_base_indices_route.schema.yaml index 2dbbc7b5cb527..ca4da6082a37a 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/get_knowledge_base_indices_route.schema.yaml +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/knowledge_base/get_knowledge_base_indices_route.schema.yaml @@ -6,6 +6,7 @@ paths: /internal/elastic_assistant/knowledge_base/_indices: get: x-codegen-enabled: true + x-internal: true x-labels: [ess, serverless] operationId: GetKnowledgeBaseIndices description: Gets Knowledge Base indices that have fields of a `sematic_text` type. diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.test.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.test.tsx index 2a1ffc5072570..62413538666a0 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.test.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.test.tsx @@ -8,6 +8,7 @@ import { HttpSetup } from '@kbn/core-http-browser'; import { getKnowledgeBaseIndices, getKnowledgeBaseStatus, postKnowledgeBase } from './api'; +import { API_VERSIONS } from '@kbn/spaces-plugin/common'; jest.mock('@kbn/core-http-browser'); @@ -30,11 +31,11 @@ describe('API tests', () => { await getKnowledgeBaseStatus(knowledgeBaseArgs); expect(mockHttp.fetch).toHaveBeenCalledWith( - '/internal/elastic_assistant/knowledge_base/a-resource', + '/api/security_ai_assistant/knowledge_base/a-resource', { method: 'GET', signal: undefined, - version: '1', + version: API_VERSIONS.public.v1, } ); }); @@ -55,11 +56,11 @@ describe('API tests', () => { await postKnowledgeBase(knowledgeBaseArgs); expect(mockHttp.fetch).toHaveBeenCalledWith( - '/internal/elastic_assistant/knowledge_base/a-resource', + '/api/security_ai_assistant/knowledge_base/a-resource', { method: 'POST', signal: undefined, - version: '1', + version: API_VERSIONS.public.v1, } ); }); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.tsx index 00fe022ad9517..06a6a4535dc8f 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/api.tsx @@ -40,7 +40,7 @@ export const getKnowledgeBaseStatus = async ({ const response = await http.fetch(path, { method: 'GET', signal, - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, }); return response as ReadKnowledgeBaseResponse; @@ -71,7 +71,7 @@ export const postKnowledgeBase = async ({ const response = await http.fetch(path, { method: 'POST', signal, - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, }); return response as CreateKnowledgeBaseResponse; diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_create_knowledge_base_entry.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_create_knowledge_base_entry.tsx index f4edcb0d8d442..769c8e5e25aa9 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_create_knowledge_base_entry.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_create_knowledge_base_entry.tsx @@ -20,7 +20,7 @@ import { useInvalidateKnowledgeBaseEntries } from './use_knowledge_base_entries' const CREATE_KNOWLEDGE_BASE_ENTRY_MUTATION_KEY = [ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL, - API_VERSIONS.internal.v1, + API_VERSIONS.public.v1, ]; export interface UseCreateKnowledgeBaseEntryParams { @@ -54,7 +54,7 @@ export const useCreateKnowledgeBaseEntry = ({ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL, { body: JSON.stringify(entry), - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, signal, } ); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.test.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.test.tsx index 439460862e6d4..7af5e38fdb6a5 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.test.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.test.tsx @@ -11,6 +11,7 @@ import { UseDeleteKnowledgeEntriesParams, } from './use_delete_knowledge_base_entries'; import { useInvalidateKnowledgeBaseEntries } from './use_knowledge_base_entries'; +import { API_VERSIONS } from '@kbn/elastic-assistant-common'; jest.mock('./use_knowledge_base_entries', () => ({ useInvalidateKnowledgeBaseEntries: jest.fn(), @@ -66,7 +67,7 @@ describe('useDeleteKnowledgeBaseEntries', () => { expect.any(String), expect.objectContaining({ body: JSON.stringify({ delete: { query: '', ids: ['1'] } }), - version: '1', + version: API_VERSIONS.public.v1, }) ); expect(invalidateKnowledgeBaseEntries).toHaveBeenCalled(); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.tsx index 0cfce8f576b24..2e0961a078208 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries.tsx @@ -21,7 +21,7 @@ import { useInvalidateKnowledgeBaseEntries } from './use_knowledge_base_entries' const DELETE_KNOWLEDGE_BASE_ENTRIES_MUTATION_KEY = [ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, - API_VERSIONS.internal.v1, + API_VERSIONS.public.v1, ]; export interface UseDeleteKnowledgeEntriesParams { @@ -61,7 +61,7 @@ export const useDeleteKnowledgeBaseEntries = ({ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, { body: JSON.stringify(body), - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, signal, } ); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_knowledge_base_entries.ts b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_knowledge_base_entries.ts index 0775ed2d27a36..a654fc9fbe0cf 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_knowledge_base_entries.ts +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_knowledge_base_entries.ts @@ -36,7 +36,7 @@ export const KNOWLEDGE_BASE_ENTRY_QUERY_KEY = [ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND, defaultQuery.page, defaultQuery.per_page, - API_VERSIONS.internal.v1, + API_VERSIONS.public.v1, ]; /** @@ -66,7 +66,7 @@ export const useKnowledgeBaseEntries = ({ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND, { method: 'GET', - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, query, signal, } diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.test.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.test.tsx index 141ea5b47a8b1..20acd57b8745d 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.test.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.test.tsx @@ -11,6 +11,7 @@ import { UseUpdateKnowledgeBaseEntriesParams, } from './use_update_knowledge_base_entries'; import { useInvalidateKnowledgeBaseEntries } from './use_knowledge_base_entries'; +import { API_VERSIONS } from '@kbn/elastic-assistant-common'; jest.mock('./use_knowledge_base_entries', () => ({ useInvalidateKnowledgeBaseEntries: jest.fn(), @@ -67,7 +68,7 @@ describe('useUpdateKnowledgeBaseEntries', () => { expect.any(String), expect.objectContaining({ body: JSON.stringify({ update: defaultArgs }), - version: '1', + version: API_VERSIONS.public.v1, }) ); expect(invalidateKnowledgeBaseEntries).toHaveBeenCalled(); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.tsx index e717c6786cd25..95278f7382be8 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/entries/use_update_knowledge_base_entries.tsx @@ -20,7 +20,7 @@ import { useInvalidateKnowledgeBaseEntries } from './use_knowledge_base_entries' const BULK_UPDATE_KNOWLEDGE_BASE_ENTRY_MUTATION_KEY = [ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, - API_VERSIONS.internal.v1, + API_VERSIONS.public.v1, 'UPDATE', ]; @@ -58,7 +58,7 @@ export const useUpdateKnowledgeBaseEntries = ({ ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, { body: JSON.stringify(body), - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, signal, } ); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_knowledge_base_status.test.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_knowledge_base_status.test.tsx index 69fccba092ee9..a7d73c8b10a62 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_knowledge_base_status.test.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_knowledge_base_status.test.tsx @@ -8,6 +8,7 @@ import { waitFor, renderHook } from '@testing-library/react'; import { useKnowledgeBaseStatus, UseKnowledgeBaseStatusParams } from './use_knowledge_base_status'; import { getKnowledgeBaseStatus as _getKnowledgeBaseStatus } from './api'; +import { API_VERSIONS } from '@kbn/elastic-assistant-common'; const getKnowledgeBaseStatusMock = _getKnowledgeBaseStatus as jest.Mock; @@ -52,11 +53,11 @@ describe('useKnowledgeBaseStatus', () => { renderHook(() => useKnowledgeBaseStatus(defaultProps)); await waitFor(() => { expect(defaultProps.http.fetch).toHaveBeenCalledWith( - '/internal/elastic_assistant/knowledge_base/', + '/api/security_ai_assistant/knowledge_base/', { method: 'GET', signal: undefined, - version: '1', + version: API_VERSIONS.public.v1, } ); expect(toasts.addError).not.toHaveBeenCalled(); @@ -66,11 +67,11 @@ describe('useKnowledgeBaseStatus', () => { renderHook(() => useKnowledgeBaseStatus({ ...defaultProps, resource: 'something' })); await waitFor(() => expect(defaultProps.http.fetch).toHaveBeenCalledWith( - '/internal/elastic_assistant/knowledge_base/something', + '/api/security_ai_assistant/knowledge_base/something', { method: 'GET', signal: undefined, - version: '1', + version: API_VERSIONS.public.v1, } ) ); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_setup_knowledge_base.test.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_setup_knowledge_base.test.tsx index 802ddf74bdf72..f5ce14d9ab1b5 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_setup_knowledge_base.test.tsx +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/api/knowledge_base/use_setup_knowledge_base.test.tsx @@ -9,6 +9,7 @@ import { waitFor, renderHook } from '@testing-library/react'; import { useSetupKnowledgeBase, UseSetupKnowledgeBaseParams } from './use_setup_knowledge_base'; import { postKnowledgeBase as _postKnowledgeBase } from './api'; import { useMutation as _useMutation } from '@tanstack/react-query'; +import { API_VERSIONS } from '@kbn/elastic-assistant-common'; const postKnowledgeBaseMock = _postKnowledgeBase as jest.Mock; const useMutationMock = _useMutation as jest.Mock; @@ -53,10 +54,10 @@ describe('useSetupKnowledgeBase', () => { renderHook(() => useSetupKnowledgeBase(defaultProps)); await waitFor(() => { expect(defaultProps.http.fetch).toHaveBeenCalledWith( - '/internal/elastic_assistant/knowledge_base/', + '/api/security_ai_assistant/knowledge_base/', { method: 'POST', - version: '1', + version: API_VERSIONS.public.v1, } ); expect(toasts.addError).not.toHaveBeenCalled(); @@ -75,10 +76,10 @@ describe('useSetupKnowledgeBase', () => { renderHook(() => useSetupKnowledgeBase(defaultProps)); await waitFor(() => expect(defaultProps.http.fetch).toHaveBeenCalledWith( - '/internal/elastic_assistant/knowledge_base/something', + '/api/security_ai_assistant/knowledge_base/something', { method: 'POST', - version: '1', + version: API_VERSIONS.public.v1, } ) ); diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/tsconfig.json b/x-pack/platform/packages/shared/kbn-elastic-assistant/tsconfig.json index 0349d31758d0f..9e26a19706136 100644 --- a/x-pack/platform/packages/shared/kbn-elastic-assistant/tsconfig.json +++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/tsconfig.json @@ -39,5 +39,6 @@ "@kbn/core-chrome-browser", "@kbn/ai-assistant-icon", "@kbn/product-doc-base-plugin", + "@kbn/spaces-plugin", ] } diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/data_clients.mock.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/data_clients.mock.ts index 7c4abffff6520..42839280db520 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/data_clients.mock.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/data_clients.mock.ts @@ -60,6 +60,8 @@ const createKnowledgeBaseDataClientMock = () => { addKnowledgeBaseDocuments: jest.fn(), createInferenceEndpoint: jest.fn(), createKnowledgeBaseEntry: jest.fn(), + updateKnowledgeBaseEntry: jest.fn(), + deleteKnowledgeBaseEntry: jest.fn(), findDocuments: jest.fn(), getAssistantTools: jest.fn(), getKnowledgeBaseDocumentEntries: jest.fn(), diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/request.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/request.ts index 26db891242884..326b37ab219a3 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/request.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/__mocks__/request.ts @@ -14,6 +14,9 @@ import { import type { DefendInsightsGetRequestQuery, DefendInsightsPostRequestBody, + DeleteKnowledgeBaseEntryRequestParams, + KnowledgeBaseEntryUpdateProps, + UpdateKnowledgeBaseEntryRequestParams, } from '@kbn/elastic-assistant-common'; import { AttackDiscoveryPostRequestBody, @@ -31,6 +34,7 @@ import { ELASTIC_AI_ASSISTANT_EVALUATE_URL, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, + ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_INDICES_URL, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL, @@ -94,6 +98,27 @@ export const getBulkActionKnowledgeBaseEntryRequest = ( body, }); +export const getUpdateKnowledgeBaseEntryRequest = ({ + params, + body, +}: { + params: UpdateKnowledgeBaseEntryRequestParams; + body: KnowledgeBaseEntryUpdateProps; +}) => + requestMock.create({ + method: 'put', + path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, + params, + body, + }); + +export const getDeleteKnowledgeBaseEntryRequest = (params: DeleteKnowledgeBaseEntryRequestParams) => + requestMock.create({ + method: 'delete', + path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, + params, + }); + export const getGetCapabilitiesRequest = () => requestMock.create({ method: 'get', diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_data_clients/knowledge_base/index.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_data_clients/knowledge_base/index.ts index 854c83ac4f5a9..ab14236df5392 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_data_clients/knowledge_base/index.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_data_clients/knowledge_base/index.ts @@ -22,6 +22,7 @@ import { KnowledgeBaseEntryCreateProps, KnowledgeBaseEntryResponse, Metadata, + KnowledgeBaseEntryUpdateProps, } from '@kbn/elastic-assistant-common'; import pRetry from 'p-retry'; import { StructuredTool } from '@langchain/core/tools'; @@ -30,21 +31,36 @@ import { IndexPatternsFetcher } from '@kbn/data-views-plugin/server'; import { map } from 'lodash'; import { AIAssistantDataClient, AIAssistantDataClientParams } from '..'; import { GetElser } from '../../types'; -import { createKnowledgeBaseEntry, transformToCreateSchema } from './create_knowledge_base_entry'; -import { EsDocumentEntry, EsIndexEntry, EsKnowledgeBaseEntrySchema } from './types'; -import { transformESSearchToKnowledgeBaseEntry } from './transforms'; +import { + createKnowledgeBaseEntry, + getUpdateScript, + transformToCreateSchema, + transformToUpdateSchema, +} from './create_knowledge_base_entry'; +import { + EsDocumentEntry, + EsIndexEntry, + EsKnowledgeBaseEntrySchema, + UpdateKnowledgeBaseEntrySchema, +} from './types'; +import { transformESSearchToKnowledgeBaseEntry, transformESToKnowledgeBase } from './transforms'; import { SECURITY_LABS_RESOURCE, USER_RESOURCE } from '../../routes/knowledge_base/constants'; import { getKBVectorSearchQuery, getStructuredToolForIndexEntry, isModelAlreadyExistsError, } from './helpers'; -import { getKBUserFilter } from '../../routes/knowledge_base/entries/utils'; +import { + getKBUserFilter, + validateDocumentsModification, +} from '../../routes/knowledge_base/entries/utils'; import { loadSecurityLabs, getSecurityLabsDocsCount, } from '../../lib/langchain/content_loaders/security_labs_loader'; import { ASSISTANT_ELSER_INFERENCE_ID } from './field_maps_configuration'; +import { BulkOperationError } from '../../lib/data_stream/documents_data_writer'; +import { AUDIT_OUTCOME, KnowledgeBaseAuditAction, knowledgeBaseAuditEvent } from './audit_events'; /** * Params for when creating KbDataClient in Request Context Factory. Useful if needing to modify @@ -633,6 +649,118 @@ export class AIAssistantKnowledgeBaseDataClient extends AIAssistantDataClient { }); }; + /** + * Updates a Knowledge Base Entry. + * + * @param auditLogger + * @param knowledgeBaseEntryId + */ + public updateKnowledgeBaseEntry = async ({ + auditLogger, + knowledgeBaseEntry, + }: { + auditLogger?: AuditLogger; + knowledgeBaseEntry: KnowledgeBaseEntryUpdateProps; + }): Promise<{ + errors: BulkOperationError[]; + updatedEntry: KnowledgeBaseEntryResponse; + }> => { + const authenticatedUser = this.options.currentUser; + + if (authenticatedUser == null) { + throw new Error( + 'Authenticated user not found! Ensure kbDataClient was initialized from a request.' + ); + } + + await validateDocumentsModification(this, authenticatedUser, [knowledgeBaseEntry.id], 'update'); + + this.options.logger.debug( + () => `Updating Knowledge Base Entry:\n ${JSON.stringify(knowledgeBaseEntry, null, 2)}` + ); + this.options.logger.debug(`kbIndex: ${this.indexTemplateAndPattern.alias}`); + + const writer = await this.getWriter(); + const changedAt = new Date().toISOString(); + const { errors, docs_updated: docsUpdated } = await writer.bulk({ + documentsToUpdate: [ + transformToUpdateSchema({ + user: authenticatedUser, + updatedAt: changedAt, + entry: knowledgeBaseEntry, + global: knowledgeBaseEntry.users != null && knowledgeBaseEntry.users.length === 0, + }), + ], + getUpdateScript: (entry: UpdateKnowledgeBaseEntrySchema) => getUpdateScript({ entry }), + authenticatedUser, + }); + + // @ts-ignore-next-line TS2322 + const updatedEntry = transformESToKnowledgeBase(docsUpdated)?.[0]; + + if (updatedEntry) { + auditLogger?.log( + knowledgeBaseAuditEvent({ + action: KnowledgeBaseAuditAction.UPDATE, + id: updatedEntry.id, + name: updatedEntry.name, + outcome: AUDIT_OUTCOME.SUCCESS, + }) + ); + } + + return { errors, updatedEntry }; + }; + + /** + * Deletes a new Knowledge Base Entry. + * + * @param auditLogger + * @param knowledgeBaseEntryId + */ + public deleteKnowledgeBaseEntry = async ({ + auditLogger, + knowledgeBaseEntryId, + }: { + auditLogger?: AuditLogger; + knowledgeBaseEntryId: string; + }): Promise<{ errors: BulkOperationError[]; docsDeleted: string[] } | null> => { + const authenticatedUser = this.options.currentUser; + + if (authenticatedUser == null) { + throw new Error( + 'Authenticated user not found! Ensure kbDataClient was initialized from a request.' + ); + } + + await validateDocumentsModification(this, authenticatedUser, [knowledgeBaseEntryId], 'delete'); + + this.options.logger.debug( + () => `Deleting Knowledge Base Entry:\n ID: ${JSON.stringify(knowledgeBaseEntryId, null, 2)}` + ); + this.options.logger.debug(`kbIndex: ${this.indexTemplateAndPattern.alias}`); + + const writer = await this.getWriter(); + const { errors, docs_deleted: docsDeleted } = await writer.bulk({ + documentsToDelete: [knowledgeBaseEntryId], + authenticatedUser, + }); + + if (docsDeleted.length) { + docsDeleted.forEach((docsDeletedId) => { + auditLogger?.log( + knowledgeBaseAuditEvent({ + action: KnowledgeBaseAuditAction.DELETE, + id: docsDeletedId, + outcome: AUDIT_OUTCOME.SUCCESS, + }) + ); + }); + } + + return { errors, docsDeleted }; + }; + /** * Returns AssistantTools for any 'relevant' KB IndexEntries that exist in the knowledge base. * diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/attack_discovery/get/get_attack_discovery.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/attack_discovery/get/get_attack_discovery.ts index 9049c152183b0..cf6d07e4953cd 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/attack_discovery/get/get_attack_discovery.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/attack_discovery/get/get_attack_discovery.ts @@ -9,7 +9,7 @@ import { buildRouteValidationWithZod } from '@kbn/elastic-assistant-common/impl/ import { type IKibanaResponse, IRouter, Logger } from '@kbn/core/server'; import { AttackDiscoveryGetResponse, - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + API_VERSIONS, AttackDiscoveryGetRequestParams, } from '@kbn/elastic-assistant-common'; import { transformError } from '@kbn/securitysolution-es-utils'; @@ -32,7 +32,7 @@ export const getAttackDiscoveryRoute = (router: IRouter { router.versioned .post({ - access: 'internal', + access: 'public', path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, security: { authz: { @@ -182,7 +182,7 @@ export const bulkActionKnowledgeBaseEntriesRoute = (router: ElasticAssistantPlug }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: { body: buildRouteValidationWithZod(PerformKnowledgeBaseEntryBulkActionRequestBody), @@ -235,7 +235,6 @@ export const bulkActionKnowledgeBaseEntriesRoute = (router: ElasticAssistantPlug const kbDataClient = await ctx.elasticAssistant.getAIAssistantKnowledgeBaseDataClient(); const spaceId = ctx.elasticAssistant.getSpaceId(); const authenticatedUser = checkResponse.currentUser; - const userFilter = getKBUserFilter(authenticatedUser); const manageGlobalKnowledgeBaseAIAssistant = kbDataClient?.options.manageGlobalKnowledgeBaseAIAssistant; @@ -266,39 +265,15 @@ export const bulkActionKnowledgeBaseEntriesRoute = (router: ElasticAssistantPlug } } - const validateDocumentsModification = async ( - documentIds: string[], - operation: 'delete' | 'update' - ) => { - if (!documentIds.length) { - return; - } - const documentsFilter = documentIds.map((id) => `_id:${id}`).join(' OR '); - const entries = await kbDataClient?.findDocuments({ - page: 1, - perPage: 100, - filter: `${documentsFilter} AND ${userFilter}`, - }); - const availableEntries = entries - ? transformESSearchToKnowledgeBaseEntry(entries.data) - : []; - availableEntries.forEach((entry) => { - // RBAC validation - const isGlobal = entry.users != null && entry.users.length === 0; - if (isGlobal && !manageGlobalKnowledgeBaseAIAssistant) { - throw new Error( - `User lacks privileges to ${operation} global knowledge base entries` - ); - } - }); - const availableIds = availableEntries.map((doc) => doc.id); - const nonAvailableIds = documentIds.filter((id) => !availableIds.includes(id)); - if (nonAvailableIds.length > 0) { - throw new Error(`Could not find documents to ${operation}: ${nonAvailableIds}.`); - } - }; - await validateDocumentsModification(body.delete?.ids ?? [], 'delete'); await validateDocumentsModification( + kbDataClient, + authenticatedUser, + body.delete?.ids ?? [], + 'delete' + ); + await validateDocumentsModification( + kbDataClient, + authenticatedUser, body.update?.map((entry) => entry.id) ?? [], 'update' ); diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/create_route.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/create_route.ts index cd1216713e18a..5d3171f49533f 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/create_route.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/create_route.ts @@ -23,7 +23,7 @@ import { performChecks } from '../../helpers'; export const createKnowledgeBaseEntryRoute = (router: ElasticAssistantPluginRouter): void => { router.versioned .post({ - access: 'internal', + access: 'public', path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL, security: { @@ -34,7 +34,7 @@ export const createKnowledgeBaseEntryRoute = (router: ElasticAssistantPluginRout }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: { body: buildRouteValidationWithZod(KnowledgeBaseEntryCreateProps), diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/delete_route.test.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/delete_route.test.ts new file mode 100644 index 0000000000000..730807550545d --- /dev/null +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/delete_route.test.ts @@ -0,0 +1,92 @@ +/* + * 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. + */ + +import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; +import { requestContextMock } from '../../../__mocks__/request_context'; +import { serverMock } from '../../../__mocks__/server'; +import { deleteKnowledgeBaseEntryRoute } from './delete_route'; +import { getBasicEmptySearchResponse, getEmptyFindResult } from '../../../__mocks__/response'; +import { getDeleteKnowledgeBaseEntryRequest, requestMock } from '../../../__mocks__/request'; +import { authenticatedUser } from '../../../__mocks__/user'; +import { ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID } from '@kbn/elastic-assistant-common'; + +describe('Delete knowledge base entry route', () => { + let server: ReturnType; + let { clients, context } = requestContextMock.createTools(); + const mockUser1 = authenticatedUser; + + beforeEach(() => { + server = serverMock.create(); + ({ clients, context } = requestContextMock.createTools()); + + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.findDocuments.mockResolvedValue( + Promise.resolve(getEmptyFindResult()) + ); // no current conversations + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.deleteKnowledgeBaseEntry.mockResolvedValue( + { errors: [], docsDeleted: ['04128c15-0d1b-4716-a4c5-46997ac7f3bd'] } + ); // creation succeeds + + context.core.elasticsearch.client.asCurrentUser.search.mockResolvedValue( + elasticsearchClientMock.createSuccessTransportRequestPromise(getBasicEmptySearchResponse()) + ); + context.elasticAssistant.getCurrentUser.mockReturnValue(mockUser1); + deleteKnowledgeBaseEntryRoute(server.router); + }); + + describe('status codes', () => { + test('returns 200 with a conversation deleted via AIAssistantKnowledgeBaseDataClient', async () => { + const response = await server.inject( + getDeleteKnowledgeBaseEntryRequest({ id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd' }), + requestContextMock.convertContext(context) + ); + expect(response.status).toEqual(200); + }); + + test('returns 401 Unauthorized when request context getCurrentUser is not defined', async () => { + context.elasticAssistant.getCurrentUser.mockReturnValueOnce(null); + const response = await server.inject( + getDeleteKnowledgeBaseEntryRequest({ id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd' }), + requestContextMock.convertContext(context) + ); + expect(response.status).toEqual(401); + }); + }); + + describe('unhappy paths', () => { + test('catches error if deletion throws', async () => { + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.deleteKnowledgeBaseEntry.mockImplementation( + async () => { + throw new Error('Test error'); + } + ); + const response = await server.inject( + getDeleteKnowledgeBaseEntryRequest({ id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd' }), + requestContextMock.convertContext(context) + ); + expect(response.status).toEqual(500); + expect(response.body).toEqual({ + message: 'Test error', + status_code: 500, + }); + }); + }); + + describe('request validation', () => { + test('disallows wrong name type', async () => { + const request = requestMock.create({ + method: 'delete', + path: ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID, + params: { + id: '', + }, + }); + const result = server.validate(request); + + expect(result.badRequest).toHaveBeenCalled(); + }); + }); +}); diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/delete_route.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/delete_route.ts new file mode 100644 index 0000000000000..74ae67fdb17e5 --- /dev/null +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/delete_route.ts @@ -0,0 +1,93 @@ +/* + * 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. + */ + +import { IKibanaResponse } from '@kbn/core/server'; +import { transformError } from '@kbn/securitysolution-es-utils'; +import { + API_VERSIONS, + ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, +} from '@kbn/elastic-assistant-common'; +import { buildRouteValidationWithZod } from '@kbn/elastic-assistant-common/impl/schemas/common'; +import { + DeleteKnowledgeBaseEntryRequestParams, + DeleteKnowledgeBaseEntryResponse, +} from '@kbn/elastic-assistant-common/impl/schemas/knowledge_base/entries/crud_knowledge_base_entries_route.gen'; +import { ElasticAssistantPluginRouter } from '../../../types'; +import { buildResponse } from '../../utils'; +import { performChecks } from '../../helpers'; + +export const deleteKnowledgeBaseEntryRoute = (router: ElasticAssistantPluginRouter): void => { + router.versioned + .delete({ + access: 'public', + path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, + + security: { + authz: { + requiredPrivileges: ['elasticAssistant'], + }, + }, + }) + .addVersion( + { + version: API_VERSIONS.public.v1, + validate: { + request: { + params: buildRouteValidationWithZod(DeleteKnowledgeBaseEntryRequestParams), + }, + }, + }, + async ( + context, + request, + response + ): Promise> => { + const assistantResponse = buildResponse(response); + try { + const ctx = await context.resolve(['core', 'elasticAssistant', 'licensing']); + const logger = ctx.elasticAssistant.logger; + + // Perform license, authenticated user and FF checks + const checkResponse = performChecks({ + context: ctx, + request, + response, + }); + if (!checkResponse.isSuccess) { + return checkResponse.response; + } + + logger.debug(() => `Deleting KB Entry:\n${JSON.stringify(request.body)}`); + + const kbDataClient = await ctx.elasticAssistant.getAIAssistantKnowledgeBaseDataClient(); + const deleteResponse = await kbDataClient?.deleteKnowledgeBaseEntry({ + knowledgeBaseEntryId: request.params.id, + auditLogger: ctx.elasticAssistant.auditLogger, + }); + + if (deleteResponse?.docsDeleted) { + return response.ok({ + body: { + id: deleteResponse?.docsDeleted[0], + }, + }); + } + + return assistantResponse.error({ + body: deleteResponse?.errors?.[0].message ?? `Knowledge Base Entry was not deleted`, + statusCode: 400, + }); + } catch (err) { + const error = transformError(err as Error); + return assistantResponse.error({ + body: error.message, + statusCode: error.statusCode, + }); + } + } + ); +}; diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/find_route.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/find_route.ts index 6ed6001a59dbc..6823c8d346b87 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/find_route.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/find_route.ts @@ -31,7 +31,7 @@ import { SECURITY_LABS_RESOURCE } from '../constants'; export const findKnowledgeBaseEntriesRoute = (router: ElasticAssistantPluginRouter) => { router.versioned .get({ - access: 'internal', + access: 'public', path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND, security: { authz: { @@ -41,7 +41,7 @@ export const findKnowledgeBaseEntriesRoute = (router: ElasticAssistantPluginRout }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: { query: buildRouteValidationWithZod(FindKnowledgeBaseEntriesRequestQuery), diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/update_route.test.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/update_route.test.ts new file mode 100644 index 0000000000000..7f46434630172 --- /dev/null +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/update_route.test.ts @@ -0,0 +1,121 @@ +/* + * 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. + */ + +import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; +import { requestContextMock } from '../../../__mocks__/request_context'; +import { serverMock } from '../../../__mocks__/server'; +import { updateKnowledgeBaseEntryRoute } from './update_route'; +import { + getBasicEmptySearchResponse, + getEmptyFindResult, + getFindKnowledgeBaseEntriesResultWithSingleHit, +} from '../../../__mocks__/response'; +import { getUpdateKnowledgeBaseEntryRequest, requestMock } from '../../../__mocks__/request'; +import { + getKnowledgeBaseEntryMock, + getQueryKnowledgeBaseEntryParams, + getUpdateKnowledgeBaseEntrySchemaMock, +} from '../../../__mocks__/knowledge_base_entry_schema.mock'; +import { authenticatedUser } from '../../../__mocks__/user'; +import { ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL } from '@kbn/elastic-assistant-common'; + +describe('Update knowledge base entry route', () => { + let server: ReturnType; + let { clients, context } = requestContextMock.createTools(); + const mockUser1 = authenticatedUser; + + beforeEach(() => { + server = serverMock.create(); + ({ clients, context } = requestContextMock.createTools()); + + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.findDocuments.mockResolvedValue( + Promise.resolve(getEmptyFindResult()) + ); // no current conversations + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.updateKnowledgeBaseEntry.mockResolvedValue( + { + errors: [], + updatedEntry: getKnowledgeBaseEntryMock(getQueryKnowledgeBaseEntryParams(true)), + } + ); // creation succeeds + + context.core.elasticsearch.client.asCurrentUser.search.mockResolvedValue( + elasticsearchClientMock.createSuccessTransportRequestPromise(getBasicEmptySearchResponse()) + ); + context.elasticAssistant.getCurrentUser.mockReturnValue(mockUser1); + updateKnowledgeBaseEntryRoute(server.router); + }); + + describe('status codes', () => { + test('returns 200 with a conversation updated via AIAssistantKnowledgeBaseDataClient', async () => { + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.findDocuments.mockResolvedValue( + Promise.resolve(getFindKnowledgeBaseEntriesResultWithSingleHit()) + ); + + const response = await server.inject( + getUpdateKnowledgeBaseEntryRequest({ + params: { id: '1' }, + body: getKnowledgeBaseEntryMock(getQueryKnowledgeBaseEntryParams(true)), + }), + requestContextMock.convertContext(context) + ); + expect(response.status).toEqual(200); + }); + + test('returns 401 Unauthorized when request context getCurrentUser is not defined', async () => { + context.elasticAssistant.getCurrentUser.mockReturnValueOnce(null); + const response = await server.inject( + getUpdateKnowledgeBaseEntryRequest({ + params: { id: '1' }, + body: getKnowledgeBaseEntryMock(getQueryKnowledgeBaseEntryParams(true)), + }), + requestContextMock.convertContext(context) + ); + expect(response.status).toEqual(401); + }); + }); + + describe('unhappy paths', () => { + test('catches error if update throws', async () => { + clients.elasticAssistant.getAIAssistantKnowledgeBaseDataClient.updateKnowledgeBaseEntry.mockImplementation( + async () => { + throw new Error('Test error'); + } + ); + const response = await server.inject( + getUpdateKnowledgeBaseEntryRequest({ + params: { id: '1' }, + body: getKnowledgeBaseEntryMock(getQueryKnowledgeBaseEntryParams(true)), + }), + requestContextMock.convertContext(context) + ); + expect(response.status).toEqual(500); + expect(response.body).toEqual({ + message: 'Test error', + status_code: 500, + }); + }); + }); + + describe('request validation', () => { + test('disallows POST request', async () => { + const request = requestMock.create({ + method: 'put', + path: ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL, + params: { + id: '1', + }, + body: { + ...getUpdateKnowledgeBaseEntrySchemaMock(), + name: true, + }, + }); + const result = server.validate(request); + + expect(result.badRequest).toHaveBeenCalled(); + }); + }); +}); diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/update_route.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/update_route.ts new file mode 100644 index 0000000000000..4ef4cbeaaea50 --- /dev/null +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/update_route.ts @@ -0,0 +1,89 @@ +/* + * 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. + */ + +import { IKibanaResponse } from '@kbn/core/server'; +import { transformError } from '@kbn/securitysolution-es-utils'; +import { + API_VERSIONS, + ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, + UpdateKnowledgeBaseEntryRequestParams, +} from '@kbn/elastic-assistant-common'; +import { buildRouteValidationWithZod } from '@kbn/elastic-assistant-common/impl/schemas/common'; +import { + KnowledgeBaseEntryResponse, + KnowledgeBaseEntryUpdateProps, +} from '@kbn/elastic-assistant-common/impl/schemas/knowledge_base/entries/common_attributes.gen'; +import { ElasticAssistantPluginRouter } from '../../../types'; +import { buildResponse } from '../../utils'; +import { performChecks } from '../../helpers'; + +export const updateKnowledgeBaseEntryRoute = (router: ElasticAssistantPluginRouter): void => { + router.versioned + .put({ + access: 'public', + path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BY_ID, + + security: { + authz: { + requiredPrivileges: ['elasticAssistant'], + }, + }, + }) + .addVersion( + { + version: API_VERSIONS.public.v1, + validate: { + request: { + params: buildRouteValidationWithZod(UpdateKnowledgeBaseEntryRequestParams), + body: buildRouteValidationWithZod(KnowledgeBaseEntryUpdateProps), + }, + }, + }, + async (context, request, response): Promise> => { + const assistantResponse = buildResponse(response); + try { + const ctx = await context.resolve(['core', 'elasticAssistant', 'licensing']); + const logger = ctx.elasticAssistant.logger; + + // Perform license, authenticated user and FF checks + const checkResponse = performChecks({ + context: ctx, + request, + response, + }); + if (!checkResponse.isSuccess) { + return checkResponse.response; + } + + logger.debug(() => `Updating KB Entry:\n${JSON.stringify(request.body)}`); + + const kbDataClient = await ctx.elasticAssistant.getAIAssistantKnowledgeBaseDataClient(); + const updateResponse = await kbDataClient?.updateKnowledgeBaseEntry({ + knowledgeBaseEntry: { ...request.body, id: request.params.id }, + auditLogger: ctx.elasticAssistant.auditLogger, + }); + + if (updateResponse?.updatedEntry) { + return response.ok({ + body: updateResponse?.updatedEntry, + }); + } + + return assistantResponse.error({ + body: updateResponse?.errors?.[0].message ?? `Knowledge Base Entry was not created`, + statusCode: 400, + }); + } catch (err) { + const error = transformError(err as Error); + return assistantResponse.error({ + body: error.message, + statusCode: error.statusCode, + }); + } + } + ); +}; diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/utils.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/utils.ts index 0f5a0ab97fb29..38da2c733edc0 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/utils.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/entries/utils.ts @@ -6,6 +6,9 @@ */ import { AuthenticatedUser } from '@kbn/core-security-common'; +import { AIAssistantKnowledgeBaseDataClient } from '../../../ai_assistant_data_clients/knowledge_base'; +import { transformESSearchToKnowledgeBaseEntry } from '../../../ai_assistant_data_clients/knowledge_base/transforms'; +import { EsKnowledgeBaseEntrySchema } from '../../../ai_assistant_data_clients/knowledge_base/types'; export const getKBUserFilter = (user: AuthenticatedUser | null) => { // Only return the current users entries and all other global entries (where user[] is empty) @@ -24,3 +27,37 @@ export const getKBUserFilter = (user: AuthenticatedUser | null) => { return `(${globalFilter}${userFilter})`; }; + +export const validateDocumentsModification = async ( + kbDataClient: AIAssistantKnowledgeBaseDataClient | null, + authenticatedUser: AuthenticatedUser | null, + documentIds: string[], + operation: 'delete' | 'update' +) => { + if (!documentIds.length) { + return; + } + const manageGlobalKnowledgeBaseAIAssistant = + kbDataClient?.options?.manageGlobalKnowledgeBaseAIAssistant; + + const userFilter = getKBUserFilter(authenticatedUser); + const documentsFilter = documentIds.map((id) => `_id:${id}`).join(' OR '); + const entries = await kbDataClient?.findDocuments({ + page: 1, + perPage: 100, + filter: `${documentsFilter} AND ${userFilter}`, + }); + const availableEntries = entries ? transformESSearchToKnowledgeBaseEntry(entries.data) : []; + availableEntries.forEach((entry) => { + // RBAC validation + const isGlobal = entry.users != null && entry.users.length === 0; + if (isGlobal && !manageGlobalKnowledgeBaseAIAssistant) { + throw new Error(`User lacks privileges to ${operation} global knowledge base entries`); + } + }); + const availableIds = availableEntries.map((doc) => doc.id); + const nonAvailableIds = documentIds.filter((id) => !availableIds.includes(id)); + if (nonAvailableIds.length > 0) { + throw new Error(`Could not find documents to ${operation}: ${nonAvailableIds}.`); + } +}; diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts index b7da45f38b2aa..6eead8a0e317f 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts @@ -8,7 +8,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import { - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + API_VERSIONS, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_INDICES_URL, GetKnowledgeBaseIndicesResponse, } from '@kbn/elastic-assistant-common'; @@ -36,7 +36,7 @@ export const getKnowledgeBaseIndicesRoute = (router: ElasticAssistantPluginRoute }) .addVersion( { - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, validate: false, }, async (context, _, response): Promise> => { diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_status.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_status.ts index c782fc6dc7a15..88d2e118f8648 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_status.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_status.ts @@ -8,7 +8,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import { - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + API_VERSIONS, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL, ReadKnowledgeBaseRequestParams, ReadKnowledgeBaseResponse, @@ -26,7 +26,7 @@ import { ElasticAssistantPluginRouter } from '../../types'; export const getKnowledgeBaseStatusRoute = (router: ElasticAssistantPluginRouter) => { router.versioned .get({ - access: 'internal', + access: 'public', path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL, security: { authz: { @@ -36,7 +36,7 @@ export const getKnowledgeBaseStatusRoute = (router: ElasticAssistantPluginRouter }) .addVersion( { - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.public.v1, validate: { request: { params: buildRouteValidationWithZod(ReadKnowledgeBaseRequestParams), diff --git a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/post_knowledge_base.ts b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/post_knowledge_base.ts index b57e9832c126c..b29d00fae5d2d 100644 --- a/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/post_knowledge_base.ts +++ b/x-pack/solutions/security/plugins/elastic_assistant/server/routes/knowledge_base/post_knowledge_base.ts @@ -6,7 +6,7 @@ */ import { - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + API_VERSIONS, CreateKnowledgeBaseRequestParams, CreateKnowledgeBaseResponse, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL, @@ -28,7 +28,7 @@ const ROUTE_HANDLER_TIMEOUT = 10 * 60 * 1000; // 10 * 60 seconds = 10 minutes export const postKnowledgeBaseRoute = (router: ElasticAssistantPluginRouter) => { router.versioned .post({ - access: 'internal', + access: 'public', path: ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL, security: { authz: { @@ -43,7 +43,7 @@ export const postKnowledgeBaseRoute = (router: ElasticAssistantPluginRouter) => }) .addVersion( { - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.public.v1, validate: { request: { params: buildRouteValidationWithZod(CreateKnowledgeBaseRequestParams), diff --git a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/index.tsx b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/index.tsx index 3a3bc955cf66c..9cc7b7c475c09 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/index.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/index.tsx @@ -12,10 +12,7 @@ import type { GenerationInterval, AttackDiscoveryStats, } from '@kbn/elastic-assistant-common'; -import { - AttackDiscoveryPostResponse, - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, -} from '@kbn/elastic-assistant-common'; +import { AttackDiscoveryPostResponse, API_VERSIONS } from '@kbn/elastic-assistant-common'; import { isEmpty } from 'lodash/fp'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useFetchAnonymizationFields } from '@kbn/elastic-assistant/impl/assistant/api/anonymization_fields/use_fetch_anonymization_fields'; @@ -193,7 +190,7 @@ export const useAttackDiscovery = ({ // call the internal API to generate attack discoveries: const rawResponse = await http.post('/internal/elastic_assistant/attack_discovery', { body: JSON.stringify(bodyWithOverrides), - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, }); setIsLoadingPost(false); const parsedResponse = AttackDiscoveryPostResponse.safeParse(rawResponse); diff --git a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/use_poll_api/use_poll_api.tsx b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/use_poll_api/use_poll_api.tsx index 0b707349eb708..5910fb64705f1 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/use_poll_api/use_poll_api.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/use_attack_discovery/use_poll_api/use_poll_api.tsx @@ -15,7 +15,7 @@ import type { import { AttackDiscoveryCancelResponse, AttackDiscoveryGetResponse, - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + API_VERSIONS, } from '@kbn/elastic-assistant-common'; import type { HttpSetup } from '@kbn/core-http-browser'; import moment from 'moment'; @@ -126,7 +126,7 @@ export const usePollApi = ({ `/internal/elastic_assistant/attack_discovery/cancel/${connectorId}`, { method: 'POST', - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, } ); const parsedResponse = AttackDiscoveryCancelResponse.safeParse(rawResponse); @@ -159,7 +159,7 @@ export const usePollApi = ({ `/internal/elastic_assistant/attack_discovery/${connectorId}`, { method: 'GET', - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, } ); diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_insights.ts b/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_insights.ts index d4eee941200f4..fb030af078c8f 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_insights.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_insights.ts @@ -6,7 +6,7 @@ */ import { useQuery } from '@tanstack/react-query'; -import { ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION } from '@kbn/elastic-assistant-common'; +import { API_VERSIONS } from '@kbn/elastic-assistant-common'; import { WORKFLOW_INSIGHTS } from '../../translations'; import type { SecurityWorkflowInsight } from '../../../../../../../common/endpoint/types/workflow_insights'; import { ActionType } from '../../../../../../../common/endpoint/types/workflow_insights'; @@ -27,7 +27,7 @@ export const useFetchInsights = ({ endpointId, onSuccess }: UseFetchInsightsConf async () => { try { const result = await http.get(WORKFLOW_INSIGHTS_ROUTE, { - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, query: { actionTypes: JSON.stringify([ActionType.Refreshed]), targetIds: JSON.stringify([endpointId]), diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_ongoing_tasks.ts b/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_ongoing_tasks.ts index 6969ca0531f6c..b96e6d092a6c6 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_ongoing_tasks.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_fetch_ongoing_tasks.ts @@ -6,10 +6,10 @@ */ import { useQuery } from '@tanstack/react-query'; import { + API_VERSIONS, DEFEND_INSIGHTS, type DefendInsightsResponse, DefendInsightStatusEnum, - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, } from '@kbn/elastic-assistant-common'; import { useEffect, useRef } from 'react'; import { WORKFLOW_INSIGHTS } from '../../translations'; @@ -45,7 +45,7 @@ export const useFetchOngoingScans = ({ async () => { try { const response = await http.get<{ data: DefendInsightsResponse[] }>(DEFEND_INSIGHTS, { - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, query: { status: DefendInsightStatusEnum.running, endpoint_ids: [endpointId], diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_trigger_scan.ts b/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_trigger_scan.ts index efa5a937d442c..87ae37dd46063 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_trigger_scan.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/endpoint_hosts/view/hooks/insights/use_trigger_scan.ts @@ -8,9 +8,9 @@ import { useMutation } from '@tanstack/react-query'; import type { DefendInsightsResponse } from '@kbn/elastic-assistant-common'; import { + API_VERSIONS, DEFEND_INSIGHTS, DefendInsightTypeEnum, - ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, } from '@kbn/elastic-assistant-common'; import { useFetchAnonymizationFields } from '@kbn/elastic-assistant/impl/assistant/api/anonymization_fields/use_fetch_anonymization_fields'; import { useKibana, useToasts } from '../../../../../../common/lib/kibana'; @@ -36,7 +36,7 @@ export const useTriggerScan = ({ onMutate, onSuccess }: UseTriggerScanConfig) => return useMutation( ({ endpointId, connectorId, actionTypeId }: UseTriggerScanPayload) => http.post(DEFEND_INSIGHTS, { - version: ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION, + version: API_VERSIONS.internal.v1, body: JSON.stringify({ endpointIds: [endpointId], insightType: DefendInsightTypeEnum.incompatible_antivirus, diff --git a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/bulk_actions_entry.ts b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/bulk_actions_entry.ts index a709070d56fef..9b532b874e8ef 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/bulk_actions_entry.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/bulk_actions_entry.ts @@ -10,6 +10,7 @@ import type { ToolingLog } from '@kbn/tooling-log'; import type SuperTest from 'supertest'; import { ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_BULK_ACTION, + API_VERSIONS, KnowledgeBaseEntryCreateProps, KnowledgeBaseEntryUpdateProps, PerformKnowledgeBaseEntryBulkActionResponse, @@ -50,7 +51,7 @@ export const bulkActionKnowledgeBaseEntries = async ({ const response = await supertest .post(route) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(payload) .expect(expectedHttpCode); @@ -93,7 +94,7 @@ export const bulkActionKnowledgeBaseEntriesForUser = async ({ .post(route) .auth(user.username, user.password) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(payload) .expect(expectedHttpCode); diff --git a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/create_entry.ts b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/create_entry.ts index 3b4507d0c4ba0..5358a53013165 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/create_entry.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/create_entry.ts @@ -9,6 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import type { ToolingLog } from '@kbn/tooling-log'; import type SuperTest from 'supertest'; import { + API_VERSIONS, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL, KnowledgeBaseEntryCreateProps, KnowledgeBaseEntryResponse, @@ -42,7 +43,7 @@ export const createEntry = async ({ const response = await supertest .post(route) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(entry) .expect(expectedHttpCode); @@ -78,7 +79,7 @@ export const createEntryForUser = async ({ .post(route) .auth(user.username, user.password) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(entry) .expect(expectedHttpCode); diff --git a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/find_entry.ts b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/find_entry.ts index 23dbfafe8d56b..4b9b7cd37d4b7 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/find_entry.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/find_entry.ts @@ -12,6 +12,7 @@ import { FindKnowledgeBaseEntriesResponse, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_ENTRIES_URL_FIND, FindKnowledgeBaseEntriesRequestQuery, + API_VERSIONS, } from '@kbn/elastic-assistant-common'; import type { User } from './auth/types'; @@ -39,7 +40,7 @@ export const findEntries = async ({ const response = await supertest .get(route) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(); if (response.status !== 200) { throw new Error( @@ -78,7 +79,7 @@ export const findEntriesForUser = async ({ .get(route) .auth(user.username, user.password) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(); if (response.status !== 200) { throw new Error( diff --git a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/helpers.ts b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/helpers.ts index 36b2963f5b538..a118fd8c565c2 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/helpers.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/genai/knowledge_base/entries/utils/helpers.ts @@ -7,6 +7,7 @@ import { Client } from '@elastic/elasticsearch'; import { + API_VERSIONS, CreateKnowledgeBaseResponse, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_INDICES_URL, ELASTIC_AI_ASSISTANT_KNOWLEDGE_BASE_URL, @@ -73,7 +74,7 @@ export const setupKnowledgeBase = async ( const response = await supertest .post(route) .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .send(); if (response.status !== 200) { throw new Error(