From cddf2650f5412a8c8a94bec7d2f09daaed44ac62 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 11 Nov 2026 11:42:55 +0330 Subject: [PATCH] fix Create Conversation to Handle Default Project Id ... --- Controllers/XAiServiceControllerBase.cs | 60 +++++++++++++++++++++++++ Interfaces/IXAiServiceBase.cs | 2 +- Providers/XAIServiceBase.cs | 2 +- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Controllers/XAiServiceControllerBase.cs b/Controllers/XAiServiceControllerBase.cs index 2acd9e9..9e59c0c 100644 --- a/Controllers/XAiServiceControllerBase.cs +++ b/Controllers/XAiServiceControllerBase.cs @@ -1022,6 +1022,66 @@ namespace xAiApi.Controllers return result; } } + + /// + /// Create an AI Conversation ... + /// + /// + /// + /// + /// + [Authorize(Policy = XPolicies.EnabledUser)] + [HttpPost("Projects/Conversations")] + public async Task> CreateProjectConversation( + [FromQuery] Guid? projectId, + [FromBody] XAiConversationDto item, + CancellationToken cancellationToken = default + ) + { + // + try + { + // + // Validate ... + if (projectId.IsNull() || + !projectId.HasValue || + item.IsNullOrDefault() || + projectId.Value.IsDefaultGuid()) + { + XException.InvalidArgs.Throw(); + } + + // + var userInfo = await GetUserInfo(); + var connectionId = GetConnectionId(); + + // + // Update Required Params ... + item.OwnerId = userInfo.UserId; + if (!item.IsValidForAddOrUpdate()) + { + XException.InvalidData.Throw(); + } + + // + var result = await aiService.CreateConversation( + item: item, + projectId: projectId, + ownerId: userInfo.UserId, + connectionId: connectionId, + cancellationToken: cancellationToken + ); + + // + return Ok(result); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } #endregion // diff --git a/Interfaces/IXAiServiceBase.cs b/Interfaces/IXAiServiceBase.cs index 6b54fad..6c446b0 100644 --- a/Interfaces/IXAiServiceBase.cs +++ b/Interfaces/IXAiServiceBase.cs @@ -307,7 +307,7 @@ namespace xAiApi.Interfaces /// Task CreateConversation( string ownerId, - Guid projectId, + Guid? projectId, XAiConversationDto item, string connectionId = null, CancellationToken cancellationToken = default diff --git a/Providers/XAIServiceBase.cs b/Providers/XAIServiceBase.cs index cd5d1ab..5decac2 100644 --- a/Providers/XAIServiceBase.cs +++ b/Providers/XAIServiceBase.cs @@ -1072,7 +1072,7 @@ namespace xAiApi.Providers /// public virtual async Task CreateConversation( string ownerId, - Guid projectId, + Guid? projectId, XAiConversationDto item, string connectionId = null, CancellationToken cancellationToken = default