diff --git a/modules/fundamental/src/ai/endpoints/mod.rs b/modules/fundamental/src/ai/endpoints/mod.rs index 5c2c6779f..1506db8d9 100644 --- a/modules/fundamental/src/ai/endpoints/mod.rs +++ b/modules/fundamental/src/ai/endpoints/mod.rs @@ -3,7 +3,7 @@ mod test; use crate::{ ai::{ - model::{AiFlags, AiTool, ChatState, Conversation, ConversationSummary}, + model::{AiFlags, AiTool, ChatMessage, ChatState, Conversation, ConversationSummary}, service::AiService, }, Error, @@ -13,15 +13,13 @@ use actix_web::{ http::header::{self, ETag, EntityTag, IfMatch}, post, put, web, HttpResponse, Responder, }; - -use crate::ai::model::ChatMessage; use itertools::Itertools; use time::OffsetDateTime; -use trustify_auth::authenticator::user::UserDetails; -use trustify_auth::{authorizer::Require, Ai}; -use trustify_common::db::query::Query; -use trustify_common::db::Database; -use trustify_common::model::{Paginated, PaginatedResults}; +use trustify_auth::{authenticator::user::UserDetails, authorizer::Require, Ai}; +use trustify_common::{ + db::{query::Query, Database}, + model::{Paginated, PaginatedResults}, +}; use uuid::Uuid; pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { @@ -149,7 +147,7 @@ pub async fn tool_call( (status = 404, description = "The AI service is not enabled") ) )] -#[post("/v1/ai/conversations")] +#[post("/v2/ai/conversations")] pub async fn create_conversation(_: Require) -> actix_web::Result { // generate an assistant response let uuid = Uuid::now_v7(); @@ -187,7 +185,7 @@ fn to_offset_date_time(uuid: Uuid) -> Result { (status = 404, description = "The AI service is not enabled or the conversation was not found") ) )] -#[put("/v1/ai/conversations/{id}")] +#[put("/v2/ai/conversations/{id}")] pub async fn update_conversation( service: web::Data, db: web::Data, @@ -232,7 +230,7 @@ pub async fn update_conversation( (status = 404, description = "The AI service is not enabled") ) )] -#[get("/v1/ai/conversations")] +#[get("/v2/ai/conversations")] // Gets the list of the user's previous conversations pub async fn list_conversations( service: web::Data, @@ -278,7 +276,7 @@ pub async fn list_conversations( (status = 404, description = "The AI service is not enabled") ) )] -#[get("/v1/ai/conversations/{id}")] +#[get("/v2/ai/conversations/{id}")] pub async fn get_conversation( service: web::Data, db: web::Data, @@ -338,7 +336,7 @@ pub async fn get_conversation( (status = 404, description = "The AI service is not enabled or the conversation was not found") ) )] -#[delete("/v1/ai/conversations/{id}")] +#[delete("/v2/ai/conversations/{id}")] pub async fn delete_conversation( service: web::Data, db: web::Data, diff --git a/openapi.yaml b/openapi.yaml index 7d14e31b0..2cae92b75 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -24,159 +24,6 @@ paths: type: object version: type: string - /api/v1/ai/conversations: - get: - tags: - - ai - operationId: listConversations - parameters: - - name: q - in: query - required: false - schema: - type: string - - name: sort - in: query - required: false - schema: - type: string - - name: offset - in: query - description: |- - The first item to return, skipping all that come before it. - - NOTE: The order of items is defined by the API being called. - required: false - schema: - type: integer - format: int64 - minimum: 0 - - name: limit - in: query - description: |- - The maximum number of entries to return. - - Zero means: no limit - required: false - schema: - type: integer - format: int64 - minimum: 0 - responses: - '200': - description: The resulting list of conversation summaries - content: - application/json: - schema: - $ref: '#/components/schemas/PaginatedResults_ConversationSummary' - '404': - description: The AI service is not enabled - post: - tags: - - ai - operationId: createConversation - responses: - '200': - description: The resulting conversation - content: - application/json: - schema: - $ref: '#/components/schemas/Conversation' - '400': - description: The request was invalid - '404': - description: The AI service is not enabled - /api/v1/ai/conversations/{id}: - get: - tags: - - ai - operationId: getConversation - parameters: - - name: id - in: path - description: Opaque ID of the conversation - required: true - schema: - type: string - format: uuid - responses: - '200': - description: The resulting conversation - headers: - etag: - schema: - type: string - description: Sequence ID - content: - application/json: - schema: - $ref: '#/components/schemas/Conversation' - '400': - description: The request was invalid - '404': - description: The AI service is not enabled - put: - tags: - - ai - operationId: updateConversation - parameters: - - name: id - in: path - description: Opaque ID of the conversation - required: true - schema: - type: string - format: uuid - - name: if-match - in: header - description: The revision to update - required: false - schema: - type: - - string - - 'null' - requestBody: - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/ChatMessage' - required: true - responses: - '200': - description: The resulting conversation - content: - application/json: - schema: - $ref: '#/components/schemas/Conversation' - '400': - description: The request was invalid - '404': - description: The AI service is not enabled or the conversation was not found - delete: - tags: - - ai - operationId: deleteConversation - parameters: - - name: id - in: path - description: Opaque ID of the conversation - required: true - schema: - type: string - format: uuid - responses: - '200': - description: The resulting conversation - content: - application/json: - schema: - $ref: '#/components/schemas/Conversation' - '400': - description: The request was invalid - '404': - description: The AI service is not enabled or the conversation was not found /api/v2/advisory: get: tags: @@ -401,6 +248,159 @@ paths: description: The request was invalid '404': description: The AI service is not enabled + /api/v2/ai/conversations: + get: + tags: + - ai + operationId: listConversations + parameters: + - name: q + in: query + required: false + schema: + type: string + - name: sort + in: query + required: false + schema: + type: string + - name: offset + in: query + description: |- + The first item to return, skipping all that come before it. + + NOTE: The order of items is defined by the API being called. + required: false + schema: + type: integer + format: int64 + minimum: 0 + - name: limit + in: query + description: |- + The maximum number of entries to return. + + Zero means: no limit + required: false + schema: + type: integer + format: int64 + minimum: 0 + responses: + '200': + description: The resulting list of conversation summaries + content: + application/json: + schema: + $ref: '#/components/schemas/PaginatedResults_ConversationSummary' + '404': + description: The AI service is not enabled + post: + tags: + - ai + operationId: createConversation + responses: + '200': + description: The resulting conversation + content: + application/json: + schema: + $ref: '#/components/schemas/Conversation' + '400': + description: The request was invalid + '404': + description: The AI service is not enabled + /api/v2/ai/conversations/{id}: + get: + tags: + - ai + operationId: getConversation + parameters: + - name: id + in: path + description: Opaque ID of the conversation + required: true + schema: + type: string + format: uuid + responses: + '200': + description: The resulting conversation + headers: + etag: + schema: + type: string + description: Sequence ID + content: + application/json: + schema: + $ref: '#/components/schemas/Conversation' + '400': + description: The request was invalid + '404': + description: The AI service is not enabled + put: + tags: + - ai + operationId: updateConversation + parameters: + - name: id + in: path + description: Opaque ID of the conversation + required: true + schema: + type: string + format: uuid + - name: if-match + in: header + description: The revision to update + required: false + schema: + type: + - string + - 'null' + requestBody: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/ChatMessage' + required: true + responses: + '200': + description: The resulting conversation + content: + application/json: + schema: + $ref: '#/components/schemas/Conversation' + '400': + description: The request was invalid + '404': + description: The AI service is not enabled or the conversation was not found + delete: + tags: + - ai + operationId: deleteConversation + parameters: + - name: id + in: path + description: Opaque ID of the conversation + required: true + schema: + type: string + format: uuid + responses: + '200': + description: The resulting conversation + content: + application/json: + schema: + $ref: '#/components/schemas/Conversation' + '400': + description: The request was invalid + '404': + description: The AI service is not enabled or the conversation was not found /api/v2/ai/flags: get: tags: