Compare commits

..
18 Commits
Author SHA1 Message Date
saherelm c05a389a44 last ... 2026-11-11 12:31:38 +03:30
saherelm 185aaae19a apply fix on Create Conversation Validations ... 2026-11-11 11:56:33 +03:30
saherelm 4fe5d57d37 fix Create Conversation to Handle Default Project Id ... 2026-11-11 11:43:10 +03:30
saherelm 27b9f51dc9 apply fix on owner id validation ... 2026-11-11 10:31:47 +03:30
saherelm 08fd26ffac last ... 2026-11-10 17:30:10 +03:30
saherelm 476ace743d last ... 2026-11-08 18:06:27 +03:30
saherelm c53553e1cf add all requirements for implementing XAiMcpClient ... 2026-11-06 19:09:07 +03:30
saherelm 33dda6bee7 Handle Authentication and Authorization in xAiMcpServer ... 2026-11-05 20:08:43 +03:30
saherelm 7ba0916461 adding datetime zone library ... 2026-11-05 18:12:50 +03:30
saherelm 2d44ec8744 Adding Requirements for AiMcpServer Definition and Usage ... 2026-11-05 14:51:59 +03:30
saherelm 25534f0273 Add MCP Server Domain and Persistence Contracts
- افزودن XAiMcpServer و XAiMcpServerDto.
- افزودن قراردادها و providerهای repository، in-memory/EF/Mongo، key generator،
  seeder، enricher و service provider.
- افزودن Entity Framework configuration، mapper و GraphQL type/query/schema.
- افزودن XAiMcpServerUsageScope و XAiMcpToolDescriptor.
2026-11-04 17:50:51 +03:30
saherelm 9668f26ffe last ... 2026-11-03 18:56:52 +03:30
saherelm 62aa8d51e6 Implement XAiMcpServer Stuffs ... 2026-11-02 23:16:50 +03:30
saherelm 9e7710e345 Make projectId Nullable in Data Provider and Remove Api Configuration
- IXAiDataProvider.GetDefaultConversation: projectId changed from Guid to Guid?;
- XAiDataProvider.GetDefaultConversation / HasDefaultConversation /
  CreateDefaultConversation: adapt to Guid? (use !projectId.HasValue instead of
  projectId.IsNull(); resolve project via projectId.Value);
- XAiDataProvider: conversation lookup predicate fixed to
  x.ProjectId == project.Id (was x.ProjectId == projectId);
- XEmbeddingExtensions: add ToEmbedding(this ReadOnlyMemory<float>) to persist
  embeddings as JSON;
- XAiDataProvider: use item.Embedding.ToEmbedding() instead of ToJSON() when
  upserting vectors;
- XAiModelsExtensions: rename GetDafualtProject -> GetDafaultProject (typo fix);
- Remove Configurations/XAiApiConfiguration.cs and
  Extensions/XAiApiConfigurationExtensions.cs (Api configuration does not belong
  to the models module).
BREAKING: XAiApiConfiguration / XAiApiConfigurationExtensions removed from
          xAiModels; GetDafualtProject renamed to GetDafaultProject.
2026-11-02 16:37:27 +03:30
saherelm c4b7e86174 Try to Fix Embeding RAG Persisted Issues ... 2026-11-01 23:12:25 +03:30
saherelm 1b74f23a18 refactor person owner reader ... 2026-10-31 21:40:26 +03:30
saherelm 146137c908 last ... 2026-10-31 17:18:23 +03:30
saherelm 31a0d097c0 Make Project and Conversation Optional in XAiResponseRequest
- XAiResponseRequest: ProjectId / ConversationId changed from Guid to Guid?
  (omitted => default project / default conversation);
- XAiModelsExtensions: fix indentation of ToChatMessages signature.
2026-10-30 19:45:57 +03:30
61 changed files with 2174 additions and 507 deletions
+40
View File
@@ -0,0 +1,40 @@
using System;
namespace xAiModels.Attributes
{
/// <summary>
/// Decorate and Describe Specified MCP Tool to LLM ...
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class XAiMcpToolAttribute : Attribute
{
/// <summary>
/// Tools Unique Name (Default: Method Name) ...
/// </summary>
/// <value></value>
public string Name { get; }
/// <summary>
/// Tools Description for LLM ...
/// </summary>
/// <value></value>
public string Description { get; set; }
/// <summary>
/// Specify it's Required to Authenticated or not ...
/// </summary>
/// <value></value>
public bool RequiresAuthentication { get; set; } = false;
/// <summary>
/// Authorization and Policiy ...
/// </summary>
/// <value></value>
public string RequiredPolicy { get; set; } = string.Empty;
public XAiMcpToolAttribute(string name = null)
{
Name = name;
}
}
}
+34
View File
@@ -0,0 +1,34 @@
using System;
namespace xAiModels.Attributes
{
/// <summary>
/// Describe Specific Tools Parameter Metadata ...
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public sealed class XAiMcpToolParamAttribute : Attribute
{
/// <summary>
/// Parameter Name in JSON (Default Parameter Name) ...
/// </summary>
/// <value></value>
public string Name { get; }
/// <summary>
/// Describe Parameter to LLM ...
/// </summary>
/// <value></value>
public string Description { get; set; }
/// <summary>
/// Specified this Parameter is Required or not (Default is true) ...
/// </summary>
/// <value></value>
public bool Required { get; set; } = true;
public XAiMcpToolParamAttribute(string name = null)
{
Name = name;
}
}
}
+10
View File
@@ -0,0 +1,10 @@
using System;
namespace xAiModels.Attributes
{
/// <summary>
/// Decorate Tools Classes ...
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class XAiMcpToolTypeAttribute : Attribute { }
}
@@ -0,0 +1,17 @@
using System;
using xAiModels.Constants;
using xDataService.Providers;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace xAiModels.Configurations.Entities
{
public class XAiMcpServerEntityConfiguration : XBaseEntityTypeConfiguration<XAiMcpServer, Guid>
{
public override void Configure(EntityTypeBuilder<XAiMcpServer> builder)
{
builder.ToTable(XAiModelsConstants.XAiMcpServerTable);
}
}
}
-28
View File
@@ -1,28 +0,0 @@
using xAiModels.Models;
using xAiModels.Constants;
namespace xAiModels.Configurations
{
public class XAiApiConfiguration
{
/// <summary>
/// Model Providers ...
/// </summary>
public XAiModelDescriptor[] Models { get; set; } = [];
/// <summary>
/// Each User must Has a Default Project, this is Title Resource Identifier ...
/// </summary>
public string DefaultProjectTitleResource { get; set; } = XAiModelsConstants.DefaultXAiProjectTitleResourceID;
/// <summary>
/// Each User must Has a Default Project, this is Description Resource Identifier ...
/// </summary>
public string DefaultProjectDescriptionResource { get; set; } = XAiModelsConstants.DefaultXAiProjectDescriptionResourceID;
/// <summary>
/// Each User must Has a Default Conversation, this is Title Resource Identifier ... ...
/// </summary>
public string DefaultConversationTitleResource { get; set; } = XAiModelsConstants.DefaultXAiConversationTitleResourceID;
}
}
+4
View File
@@ -25,6 +25,10 @@ namespace xAiModels.Configurations
// XAiProject ... // XAiProject ...
CreateMap<XAiProject, XAiProjectDto>(); CreateMap<XAiProject, XAiProjectDto>();
//
CreateMap<XAiMcpServer, XAiMcpServerDto>();
CreateMap<XAiMcpServerDto, XAiMcpServer>();
// //
// XAiConversation ... // XAiConversation ...
CreateMap<XAiConversation, XAiConversationDto>(); CreateMap<XAiConversation, XAiConversationDto>();
+22 -11
View File
@@ -21,17 +21,6 @@ namespace xAiModels.Constants
[StringValue("ProjectRemoved")] [StringValue("ProjectRemoved")]
ProjectRemoved, ProjectRemoved,
//
// Conversation ...
[StringValue("ConversationCreated")]
ConversationCreated,
[StringValue("ConversationUpdated")]
ConversationUpdated,
[StringValue("ConversationRemoved")]
ConversationRemoved,
// //
// Message ... // Message ...
[StringValue("MessageCreated")] [StringValue("MessageCreated")]
@@ -42,5 +31,27 @@ namespace xAiModels.Constants
[StringValue("MessageRemoved")] [StringValue("MessageRemoved")]
MessageRemoved, MessageRemoved,
//
// MCPServer ...
[StringValue("McpServerCreated")]
McpServerCreated,
[StringValue("McpServerUpdated")]
McpServerUpdated,
[StringValue("McpServerRemoved")]
McpServerRemoved,
//
// Conversation ...
[StringValue("ConversationCreated")]
ConversationCreated,
[StringValue("ConversationUpdated")]
ConversationUpdated,
[StringValue("ConversationRemoved")]
ConversationRemoved,
} }
} }
+23
View File
@@ -0,0 +1,23 @@
namespace xAiModels.Constants
{
public struct XAiMcpConstants
{
//
public const string XAiMcpProtocol = "2024-11-05";
public const string XAiMcpClientName = "XAiMcpClient";
public const string XAiMcpSessionIdentifier = "Mcp-Session-Id";
public const string XAiMcpProtocolIdentifier = "MCP-Protocol-Version";
//
public const string TextKey = "text";
public const string ContentKey = "content";
public const string ServerInfoNameKey = "name";
public const string ServerInfoKey = "serverInfo";
public const string ServerInfoVersionKey = "version";
public const string ProtocolVersionKey = "protocolVersion";
//
public const string serverInfoNameValue = "xAiApi";
public const string serverInfoVersionValue = "";
}
}
+16
View File
@@ -0,0 +1,16 @@
using xExceptions.Attributes;
namespace xAiModels.Constants
{
public enum XAiMcpMethods
{
[StringValue("initialize")]
Initialize,
[StringValue("tools/list")]
ToolsList,
[StringValue("tools/call")]
ToolsCall,
}
}
+13
View File
@@ -0,0 +1,13 @@
using xExceptions.Attributes;
namespace xAiModels.Constants
{
public enum XAiMcpServerUsageScope
{
[StringValue(XAiModelsConstants.XAiMcpServerUsageScopeAll)]
All = 1,
[StringValue(XAiModelsConstants.XAiMcpServerUsageScopeOwner)]
Owner = 2
}
}
+20 -7
View File
@@ -5,24 +5,27 @@ namespace xAiModels.Constants
// //
// Service Extensions Log Tag ... // Service Extensions Log Tag ...
public const string XAiModelsDILogTag = "XAiModels"; public const string XAiModelsDILogTag = "XAiModels";
// //
// Table Mapping Identifiers ... // Table Mapping Identifiers ...
public const string XAiVectorTable = "AiVectors"; public const string XAiVectorTable = "AiVectors";
public const string XAiMessageTable = "AiMessages"; public const string XAiMessageTable = "AiMessages";
public const string XAiProjectTable = "AiProjects"; public const string XAiProjectTable = "AiProjects";
public const string XAiMcpServerTable = "AiMcpServers";
public const string XAiConversationTable = "AiConversations"; public const string XAiConversationTable = "AiConversations";
// //
// GraphQL Collection Mappings ... // GraphQL Collection Mappings ...
public const string XAiMessageSingleName = "aiMessage"; public const string XAiMessageSingleName = "aiMessage";
public const string XAiProjectSingleName = "aiProject"; public const string XAiProjectSingleName = "aiProject";
public const string XAiMcpServerSingleName = "aiMcpServer";
public const string XAiConversationSignleName = "aiConversation"; public const string XAiConversationSignleName = "aiConversation";
public const string XAiMessageCollectionName = "aiMessages"; public const string XAiMessageCollectionName = "aiMessages";
public const string XAiProjectCollectionName = "AiProjectsa"; public const string XAiProjectCollectionName = "AiProjectsa";
public const string XAiMcpServerCollectionName = "aiMcpServers";
public const string XAiConversationCollectionName = "aiConversations"; public const string XAiConversationCollectionName = "aiConversations";
public const string XAiVectorSingleName = "aiVector"; public const string XAiVectorSingleName = "aiVector";
public const string XAiVectorCollectionName = "aiVectors"; public const string XAiVectorCollectionName = "aiVectors";
@@ -34,6 +37,9 @@ namespace xAiModels.Constants
public const string XAiProjectDtoHub = "aiProjectDto"; public const string XAiProjectDtoHub = "aiProjectDto";
public const string XAiProjectEntityHub = "aiProjectEntity"; public const string XAiProjectEntityHub = "aiProjectEntity";
public const string XAiMcpServerDtoHub = "aiMcpServerDto";
public const string XAiMcpServerEntityHub = "aiMcpServerEntity";
public const string XAiConversationDtoHub = "aiConversationDto"; public const string XAiConversationDtoHub = "aiConversationDto";
public const string XAiConversationEntityHub = "aiConversationEntity"; public const string XAiConversationEntityHub = "aiConversationEntity";
@@ -48,18 +54,19 @@ namespace xAiModels.Constants
// //
// EF Repositories Helper Extensions ... // EF Repositories Helper Extensions ...
public const string GetXAiVectorEFRepositoryDescriptor = "GetXAiVectorEFRepositoryDescriptor";
public const string GetXAiMessageEFRepositoryDescriptor = "GetXAiMessageEFRepositoryDescriptor"; public const string GetXAiMessageEFRepositoryDescriptor = "GetXAiMessageEFRepositoryDescriptor";
public const string GetXAiProjectEFRepositoryDescriptor = "GetXAiProjectEFRepositoryDescriptor"; public const string GetXAiProjectEFRepositoryDescriptor = "GetXAiProjectEFRepositoryDescriptor";
public const string GetXAiMcpServerEFRepositoryDescriptor = "GetXAiMcpServerEFRepositoryDescriptor";
public const string GetXAiConversationEFRepositoryDescriptor = "GetXAiConversationEFRepositoryDescriptor"; public const string GetXAiConversationEFRepositoryDescriptor = "GetXAiConversationEFRepositoryDescriptor";
public const string GetXAiVectorEFRepositoryDescriptor = "GetXAiVectorEFRepositoryDescriptor";
// //
public const string DefaultXAiProjectTitleResourceID = "XAiPrjT"; public const string DefaultXAiProjectTitleResourceID = "XAiPrjT";
public const string DefaultXAiConversationTitleResourceID = "XAiCnvT"; public const string DefaultXAiConversationTitleResourceID = "XAiCnvT";
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD"; public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
// //
public const string XOpenAINoKey = "no-key-required"; public const string XOpenAINoKey = "no-key-required";
// //
// Knowledge (Persistent RAG) ... // Knowledge (Persistent RAG) ...
@@ -83,5 +90,11 @@ namespace xAiModels.Constants
public const string XAiKnowledgeMetadataScopeId = "scopeId"; public const string XAiKnowledgeMetadataScopeId = "scopeId";
public const string XAiKnowledgeMetadataOwnerId = "ownerId"; public const string XAiKnowledgeMetadataOwnerId = "ownerId";
public const string XAiKnowledgeMetadataIngestedAtUtc = "ingestedAtUtc"; public const string XAiKnowledgeMetadataIngestedAtUtc = "ingestedAtUtc";
//
// Mcp Server ...
public const int XAiMcpServerMinTimeoutSeconds = 30;
public const string XAiMcpServerUsageScopeAll = "All";
public const string XAiMcpServerUsageScopeOwner = "Owner";
} }
} }
+63 -103
View File
@@ -100,6 +100,11 @@ namespace xAiModels.DI
pushHelper.AddHub<XAiProjectDtoHub>(XAiModelsConstants.XAiProjectDtoHub); pushHelper.AddHub<XAiProjectDtoHub>(XAiModelsConstants.XAiProjectDtoHub);
pushHelper.AddHub<XAiProjectEntityHub>(XAiModelsConstants.XAiProjectEntityHub); pushHelper.AddHub<XAiProjectEntityHub>(XAiModelsConstants.XAiProjectEntityHub);
//
// XAiMcpServer ...
pushHelper.AddHub<XAiMcpServerDtoHub>(XAiModelsConstants.XAiMcpServerDtoHub);
pushHelper.AddHub<XAiMcpServerEntityHub>(XAiModelsConstants.XAiMcpServerEntityHub);
// //
// XAiConversation ... // XAiConversation ...
pushHelper.AddHub<XAiConversationDtoHub>(XAiModelsConstants.XAiConversationDtoHub); pushHelper.AddHub<XAiConversationDtoHub>(XAiModelsConstants.XAiConversationDtoHub);
@@ -143,109 +148,15 @@ namespace xAiModels.DI
} }
// //
// Create an Scope for Services Acces ... // Using XAiMcpServer Repository Descriptor ...
// Handle Seeding Category/SubCategory Resources ... if (!aiMcpServerDescriptor.IsNull())
// TODO: Enable Seeding if Required ... {
// using (var scope = app.ApplicationServices.CreateScope()) //
// { app.UseXRepository(
// // descriptor: aiMcpServerDescriptor,
// // Retrieve Configuratuions ... isDevelopmentEnvironment: isDevelopmentEnvironment
// var aiMessageProvider = scope.ServiceProvider.GetService<IXAiMessageServiceProvider>(); );
// var aiProjectProvider = scope.ServiceProvider.GetService<IXAiProjectServiceProvider>(); }
// var aiConversationProvider = scope.ServiceProvider.GetService<IXAiConversationServiceProvider>();
// var configuration = scope.ServiceProvider.GetService<XAiDataServiceServiceConfiguration>();
// if (!configuration.IsNullOrDefault() &&
// !categoryProvider.IsNullOrDefault() &&
// !subaiConversationDescriptor.IsNullOrDefault()
// )
// {
// //
// // Logging ...
// Log("Start Seeding ...");
// //
// // Count Data in Category ...
// var hasCategory = (categoryProvider.Count().GetAwaiter().GetResult()) > 0;
// var hasSubCategory = (subCategoryProvider.Count().GetAwaiter().GetResult()) > 0;
// //
// // Seed Category Resources ...
// var canSeed =
// !hasCategory &&
// configuration.Categories.HasChild();
// if (canSeed)
// {
// //
// // Loop through Provided items ...
// foreach (var cat in configuration.Categories)
// {
// //
// try
// {
// //
// Log($"Start Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} ...");
// //
// categoryProvider.Refresh(
// resource: cat,
// userInfo: null,
// connectionId: null,
// cancellationToken: default
// )
// .GetAwaiter()
// .GetResult();
// //
// Log($"Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} Finished Successfully ...");
// }
// catch (Exception ex)
// {
// Log($"Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} Failed due: {ex.Message} ...");
// }
// }
// }
// //
// // Seed SubCategory Resources ...
// canSeed =
// !hasSubCategory &&
// configuration.SubCategories.HasChild();
// if (canSeed)
// {
// //
// // Loop through Provided items ...
// foreach (var subcat in configuration.SubCategories)
// {
// //
// try
// {
// //
// Log($"Start Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} ...");
// //
// subCategoryProvider.Refresh(
// userInfo: null,
// resource: subcat,
// connectionId: null,
// cancellationToken: default
// )
// .GetAwaiter()
// .GetResult();
// //
// Log($"Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} Finished Successfully ...");
// }
// catch (Exception ex)
// {
// Log($"Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} Failed due: {ex.Message} ...");
// }
// }
// }
// //
// Log("Finish Seeding ...");
// }
// }
} }
// //
@@ -253,6 +164,7 @@ namespace xAiModels.DI
private static XRepositoryDescriptor aiVectorDescriptor = null; private static XRepositoryDescriptor aiVectorDescriptor = null;
private static XRepositoryDescriptor aiMessageDescriptor = null; private static XRepositoryDescriptor aiMessageDescriptor = null;
private static XRepositoryDescriptor aiProjectDescriptor = null; private static XRepositoryDescriptor aiProjectDescriptor = null;
private static XRepositoryDescriptor aiMcpServerDescriptor = null;
private static XRepositoryDescriptor aiConversationDescriptor = null; private static XRepositoryDescriptor aiConversationDescriptor = null;
/// <summary> /// <summary>
@@ -355,6 +267,15 @@ namespace xAiModels.DI
methodName: XAiModelsConstants.GetXAiProjectEFRepositoryDescriptor methodName: XAiModelsConstants.GetXAiProjectEFRepositoryDescriptor
); );
//
// XAiMcpServer ...
aiMcpServerDescriptor = typeof(XAiModelsHelper)
.InvokeGenericMethod<XRepositoryDescriptor>(
args: null,
runtimeType: contextType,
methodName: XAiModelsConstants.GetXAiMcpServerEFRepositoryDescriptor
);
// //
// XAiConversation ... // XAiConversation ...
aiConversationDescriptor = typeof(XAiModelsHelper) aiConversationDescriptor = typeof(XAiModelsHelper)
@@ -379,6 +300,10 @@ namespace xAiModels.DI
// XAiProject ... // XAiProject ...
aiProjectDescriptor = XAiModelsHelper.GetXAiProjectMongoRepositoryDescriptor(); aiProjectDescriptor = XAiModelsHelper.GetXAiProjectMongoRepositoryDescriptor();
//
// XAiMcpServer ...
aiMcpServerDescriptor = XAiModelsHelper.GetXAiMcpServerMongoRepositoryDescriptor();
// //
// XAiConversation ... // XAiConversation ...
aiConversationDescriptor = XAiModelsHelper.GetXAiConversationMongoRepositoryDescriptor(); aiConversationDescriptor = XAiModelsHelper.GetXAiConversationMongoRepositoryDescriptor();
@@ -398,6 +323,10 @@ namespace xAiModels.DI
// XAiProject ... // XAiProject ...
aiProjectDescriptor = XAiModelsHelper.GetXAiProjectInMemoryRepositoryDescriptor(); aiProjectDescriptor = XAiModelsHelper.GetXAiProjectInMemoryRepositoryDescriptor();
//
// XAiMcpServer ...
aiMcpServerDescriptor = XAiModelsHelper.GetXAiMcpServerInMemoryRepositoryDescriptor();
// //
// XAiConversation ... // XAiConversation ...
aiConversationDescriptor = XAiModelsHelper.GetXAiConversationInMemoryRepositoryDescriptor(); aiConversationDescriptor = XAiModelsHelper.GetXAiConversationInMemoryRepositoryDescriptor();
@@ -439,6 +368,17 @@ namespace xAiModels.DI
); );
} }
//
// XAiMcpServer ...
if (!aiMcpServerDescriptor.IsNull())
{
//
services.AddXRepository(
lifeTime: lifeTime,
descriptor: aiMcpServerDescriptor
);
}
// //
// XAiConversation ... // XAiConversation ...
if (!aiConversationDescriptor.IsNull()) if (!aiConversationDescriptor.IsNull())
@@ -522,6 +462,26 @@ namespace xAiModels.DI
); );
#endregion #endregion
//
#region AiMcpServer ...
//
services.Add(
new ServiceDescriptor(typeof(IXAiMcpServerServiceProvider), typeof(XAiMcpServerServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiMcpServerRepositoryService), typeof(XAiMcpServerRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiMcpServerRepositoryProvider), typeof(XAiMcpServerRepositoryProvider), lifeTime)
);
//
// Enrichers ...
services.Add(
new ServiceDescriptor(typeof(IXAiMcpServerEnricher), typeof(XAiMcpServerEnricher), lifeTime)
);
#endregion
// //
#region AiConversation ... #region AiConversation ...
// //
+2 -1
View File
@@ -17,7 +17,8 @@ namespace xAiModels.Extensions
source is not null && source is not null &&
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!string.IsNullOrWhiteSpace(source.Text) && !string.IsNullOrWhiteSpace(source.Text) &&
source.FinishReason == ChatFinishReason.Stop; (source.FinishReason == ChatFinishReason.Stop ||
source.FinishReason == ChatFinishReason.ToolCalls);
// //
return result; return result;
@@ -1,42 +0,0 @@
using System.Linq;
using xAiModels.Models;
using xCommons.Extensions;
using xAiModels.Configurations;
namespace xAiModels.Extensions
{
public static class XAiApiConfigurationExtensions
{
/// <summary>
/// Validate Api Configuration ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XAiApiConfiguration source)
{
return
!source.IsNullOrDefault() &&
source.Models.HasChild();
}
/// <summary>
/// Retrieve Default Model Descriptor ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XAiModelDescriptor GetDefaultModel(this XAiApiConfiguration source)
{
//
XAiModelDescriptor result = null;
//
if (source.IsValid())
{
result = source.Models.First();
}
//
return result;
}
}
}
+66 -12
View File
@@ -29,8 +29,7 @@ namespace xAiModels.Extensions
// //
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty();
!source.Prompt.IsNullOrEmpty();
// //
return result; return result;
@@ -40,8 +39,7 @@ namespace xAiModels.Extensions
// //
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty();
!source.Prompt.IsNullOrEmpty();
// //
return result; return result;
@@ -57,9 +55,7 @@ namespace xAiModels.Extensions
// //
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty();
!source.ProjectId.IsNull() &&
!source.ProjectId.IsDefaultGuid();
// //
return result; return result;
@@ -69,9 +65,7 @@ namespace xAiModels.Extensions
// //
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty();
!source.ProjectId.IsNull() &&
!source.ProjectId.IsDefaultGuid();
// //
return result; return result;
@@ -111,6 +105,36 @@ namespace xAiModels.Extensions
return result; return result;
} }
/// <summary>
/// Validate a McpServer for Add Or Update ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValidForAddOrUpdate(this XAiMcpServer source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty() &&
!source.OwnerId.IsNullOrEmpty() &&
!source.Endpoint.IsNullOrEmpty();
//
return result;
}
public static bool IsValidForAddOrUpdate(this XAiMcpServerDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty() &&
!source.OwnerId.IsNullOrEmpty() &&
!source.Endpoint.IsNullOrEmpty();
//
return result;
}
/// <summary> /// <summary>
/// Validate a Model Descriptor ... /// Validate a Model Descriptor ...
/// </summary> /// </summary>
@@ -339,7 +363,7 @@ namespace xAiModels.Extensions
/// <param name="source"></param> /// <param name="source"></param>
/// <param name="ownerId"></param> /// <param name="ownerId"></param>
/// <returns></returns> /// <returns></returns>
public static Guid GetDafualtProject( public static Guid GetDafaultProject(
this IEnumerable<XAiProjectDto> source, this IEnumerable<XAiProjectDto> source,
string ownerId string ownerId
) )
@@ -423,7 +447,7 @@ namespace xAiModels.Extensions
/// <returns></returns> /// <returns></returns>
public static ChatMessage ToChatMessages( public static ChatMessage ToChatMessages(
this XAiMessageDto source, this XAiMessageDto source,
IList<AIContent> additionalContents = null IList<AIContent> additionalContents = null
) )
{ {
// //
@@ -494,5 +518,35 @@ namespace xAiModels.Extensions
value: $"{XAuthorization.TokenIdentifier} {apiKey}" value: $"{XAuthorization.TokenIdentifier} {apiKey}"
); );
} }
/// <summary>
/// Converts To AITools ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IList<AITool> ToAITools(
this IList<XAiMcpToolDefinition> source
)
{
//
var result = new List<AITool>();
//
foreach (var tool in source)
{
//
var declaration = AIFunctionFactory.CreateDeclaration(
name: tool.Name,
jsonSchema: tool.InputSchema,
description: tool.Description
);
//
result.Add(declaration);
}
//
return result;
}
} }
} }
+23 -2
View File
@@ -1,5 +1,5 @@
using System;
using xCommons.Extensions; using xCommons.Extensions;
using System.Collections.Generic;
namespace xAiModels.Extensions namespace xAiModels.Extensions
{ {
@@ -14,7 +14,8 @@ namespace xAiModels.Extensions
{ {
// //
// Validate ... // Validate ...
if (source.IsNullOrEmpty()) { if (source.IsNullOrEmpty())
{
return []; return [];
} }
@@ -29,5 +30,25 @@ namespace xAiModels.Extensions
// //
return result; return result;
} }
/// <summary>
/// Converts ReadOnly Memory to Embedding Representation ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string ToEmbedding(this ReadOnlyMemory<float> source)
{
//
var result = string.Empty;
//
if (!source.IsNull() && !source.IsEmpty)
{
result = source.ToArray().ToJSON();
}
//
return result;
}
} }
} }
+74
View File
@@ -0,0 +1,74 @@
using xCommons.Constants;
using xCommons.Extensions;
using xAiModels.Constants;
using xIdentityModels.Models;
using xCommons.Configurations;
using System.Collections.Generic;
using xIdentityService.Constants;
namespace xAiModels.Helpers
{
/// <summary>
/// a Helper Class for Prepare Headers of MCP Client ...
/// </summary>
public static class XAiMcpHeaderBuilder
{
/// <summary>
/// Build Headers for MCP Client Connection ...
/// </summary>
/// <param name="appConfiguration"></param>
/// <param name="sessionId"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <param name="protocolVersion"></param>
/// <returns></returns>
public static Dictionary<string, string> Build(
XAppConfiguration appConfiguration,
string sessionId = null,
string connectionId = null,
XUserClaimsInfoDto userInfo = null,
string protocolVersion = XAiMcpConstants.XAiMcpProtocol
)
{
//
var headers = new Dictionary<string, string>
{
//
["Accept"] = "application/json, text/event-stream",
["Content-Type"] = "application/json",
[XAiMcpConstants.XAiMcpProtocolIdentifier] = protocolVersion,
[XAuthorization.XPoweredBy] = appConfiguration.XPoweredValue ?? "xAiApi"
};
//
// Adding Authorization Headers ...
if (!userInfo.IsNullOrDefault() && !userInfo.AccessToken.IsNullOrEmpty())
{
//
headers[XAuthorization.Header] = $"{XAuthorization.TokenIdentifier} {userInfo.AccessToken}";
headers[XAuthorization.ExpiresAt] = userInfo.ExpiresAt.ToString();
//
if (!userInfo.RefreshToken.IsNullOrEmpty())
{
headers[XAuthorization.RefreshToken] = userInfo.RefreshToken;
}
}
//
// شناسه اتصال (برای Push Notification ها)
if (!connectionId.IsNullOrEmpty()) {
headers[XHeader.ConnectionId.GetStringValue()] = connectionId;
}
//
// Session Id ...
if (!sessionId.IsNullOrEmpty()) {
headers[XAiMcpConstants.XAiMcpSessionIdentifier] = sessionId;
}
//
return headers;
}
}
}
+86
View File
@@ -0,0 +1,86 @@
using System;
using System.IO;
using System.Text;
using System.Threading;
using xCommons.Extensions;
using xHttpService.Constants;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace xAiModels.Helpers
{
public static class XAiMcpSseReader
{
/// <summary>
/// Read an SSE Event ...
/// </summary>
/// <param name="stream"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async IAsyncEnumerable<string> ReadAsync(
Stream stream,
[EnumeratorCancellation]
CancellationToken cancellationToken = default
)
{
//
using var reader = new StreamReader(stream, Encoding.UTF8);
var dataBuffer = new StringBuilder();
while (!reader.EndOfStream)
{
//
var line = await reader.ReadLineAsync();
if (line is null)
{
break;
}
//
if (cancellationToken.IsCancellationRequested)
{
yield break;
}
//
// Empty Line equals End of an Event ...
if (line.IsNullOrEmpty())
{
//
if (dataBuffer.Length > 0)
{
//
yield return dataBuffer.ToString();
dataBuffer.Clear();
}
//
continue;
}
//
if (line.StartsWith(XSSEConstants.DataIdentifier, StringComparison.OrdinalIgnoreCase))
{
//
var data = line
.Substring(XSSEConstants.DataIdentifier.Length)
.TrimStart();
//
if (dataBuffer.Length > 0)
{
dataBuffer.Append('\n');
}
//
dataBuffer.Append(data);
}
}
//
if (dataBuffer.Length > 0)
{
yield return dataBuffer.ToString();
}
}
}
}
+267
View File
@@ -1079,5 +1079,272 @@ namespace xAiModels.Helpers
} }
#endregion #endregion
#endregion #endregion
//
#region XAiMcpServer ...
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerEFRepository<TContext>,
TContext
> GetXAiMcpServerEFRepositoryDescriptor<TContext>()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerEFRepository<TContext>,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerEFRepository<TContext>,
TContext,
IXAiMcpServerSeeder,
TSeederImplementation
> GetXAiMcpServerEFRepositoryDescriptor<TContext, TSeederImplementation>()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder<XAiMcpServer, Guid>
{
//
var result = new XEFRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerEFRepository<TContext>,
TContext,
IXAiMcpServerSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerMongoRepository
> GetXAiMcpServerMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerMongoRepository,
IXAiMcpServerSeeder,
TSeederImplementation
> GetXAiMcpServerMongoRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XAiMcpServer, Guid>
{
//
var result = new XMongoRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerMongoRepository,
IXAiMcpServerSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerInMemoryRepository
> GetXAiMcpServerInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerInMemoryRepository,
IXAiMcpServerSeeder,
TSeederImplementation
> GetXAiMcpServerInMemoryRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XAiMcpServer, Guid>
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiMcpServer,
Guid,
IXAiMcpServerKeyGenerator,
XAiMcpServerKeyGenerator,
IXAiMcpServerRepositoryEvents,
XAiMcpServerRepositoryEvents,
XAiMcpServerGraphType,
GuidGraphType,
XAiMcpServerGraphQuery,
IXAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphQLTypeHelper,
XAiMcpServerGraphSchema,
IXAiMcpServerRepository,
XAiMcpServerInMemoryRepository,
IXAiMcpServerSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
#endregion
} }
} }
+10
View File
@@ -0,0 +1,10 @@
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiMcpServerDtoHub : IXBaseDtoHub<XAiMcpServer, XAiMcpServerDto, Guid>
{ }
}
@@ -0,0 +1,10 @@
using System;
using xAiModels.Models.Dtos;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiMcpServerRepositoryService : IXBaseRepositoryService<XAiMcpServer, XAiMcpServerDto, Guid>
{ }
}
@@ -0,0 +1,11 @@
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Providers.Dtos;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiMcpServerServiceProvider : IXBaseDtoProvider<XAiMcpServer, XAiMcpServerDto, Guid, XAiMcpServerDtoHub>
{ }
}
@@ -0,0 +1,31 @@
using System.Threading;
using System.Threading.Tasks;
using xAiModels.Models.Dtos;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Enrichers
{
public interface IXAiMcpServerEnricher
{
Task<XAiMcpServerDto> Enrich(
XAiMcpServer source,
CancellationToken cancellationToken = default
);
Task<XAiMcpServerDto> Enrich(
XAiMcpServerDto source,
CancellationToken cancellationToken = default
);
Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
IEnumerable<XAiMcpServer> sources,
CancellationToken cancellationToken = default
);
Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
IEnumerable<XAiMcpServerDto> sources,
CancellationToken cancellationToken = default
);
}
}
@@ -0,0 +1,9 @@
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerEntityHub : IXBaseEntityHub<XAiMcpServer, Guid>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XAiMcpServer, Guid>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerKeyGenerator : IXKeyGenerator<XAiMcpServer, Guid>
{ }
}
@@ -0,0 +1,8 @@
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerRepository : IXBaseRepository<XAiMcpServer, Guid> { }
}
@@ -0,0 +1,8 @@
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerRepositoryEvents : IXBaseRepositoryEvents<XAiMcpServer>
{ }
}
@@ -0,0 +1,10 @@
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
using xAiModels.Providers.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerRepositoryProvider : IXBaseEntityProvider<XAiMcpServer, Guid, XAiMcpServerEntityHub>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMcpServerSeeder : IXBaseDbSeeder<XAiMcpServer, Guid>
{ }
}
+10 -4
View File
@@ -66,12 +66,14 @@ namespace xAiModels.Interfaces
/// Load List of Conversations for Specified Project ... /// Load List of Conversations for Specified Project ...
/// </summary> /// </summary>
/// <param name="projectId"></param> /// <param name="projectId"></param>
/// <param name="ownerId"></param>
/// <param name="fillMessages"></param> /// <param name="fillMessages"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<XAiConversationDto>> LoadConversations( Task<IEnumerable<XAiConversationDto>> LoadConversations(
Guid projectId, Guid? projectId,
string ownerId = null,
bool fillMessages = false, bool fillMessages = false,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
@@ -81,10 +83,14 @@ namespace xAiModels.Interfaces
/// Load Messages of Specified Conversation ... /// Load Messages of Specified Conversation ...
/// </summary> /// </summary>
/// <param name="conversationId"></param> /// <param name="conversationId"></param>
/// <param name="ownerId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<XAiMessageDto>> LoadMessages( Task<IEnumerable<XAiMessageDto>> LoadMessages(
Guid conversationId, Guid? conversationId,
string ownerId = null,
string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
#endregion #endregion
@@ -197,7 +203,7 @@ namespace xAiModels.Interfaces
/// <returns></returns> /// <returns></returns>
Task<XAiConversationDto> GetDefaultConversation( Task<XAiConversationDto> GetDefaultConversation(
string ownerId, string ownerId,
Guid projectId, Guid? projectId,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
@@ -231,7 +237,7 @@ namespace xAiModels.Interfaces
/// <returns></returns> /// <returns></returns>
Task<XAiConversationDto> CreateConversation( Task<XAiConversationDto> CreateConversation(
string ownerId, string ownerId,
Guid projectId, Guid? projectId,
XAiConversationDto item = null, XAiConversationDto item = null,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
+59
View File
@@ -0,0 +1,59 @@
using System;
using xModels.Base;
using xModels.Dtos;
using xAiModels.Constants;
namespace xAiModels.Models.Dtos
{
public class XAiMcpServerDto : XBaseGuidIDEntityDto
{
/// <summary>
/// Owner ...
/// </summary>
public string OwnerId { get; set; }
public virtual XPersonDto Owner { get; set; }
/// <summary>
/// Specified Which Scope can Use MCP Server ...
/// </summary>
public XAiMcpServerUsageScope Scope { get; set; } = XAiMcpServerUsageScope.Owner;
/// <summary>
/// MCP Server Name ...
/// </summary>
public string Name { get; set; }
/// <summary>
/// Description ...
/// </summary>
public string Description { get; set; }
/// <summary>
/// Enabled or Disabled ...
/// </summary>
public bool Enabled { get; set; } = true;
/// <summary>
/// Environment Variables as JSON Object ...
/// </summary>
public string EnvironmentVariables { get; set; }
/// <summary>
/// Endpoint to Connect ...
/// </summary>
public string Endpoint { get; set; }
/// <summary>
/// Headers List as Json Object ...
/// </summary>
public string Headers { get; set; }
/// <summary>
/// Timout Secconds ...
/// </summary>
public int TimeoutSeconds { get; set; } = 30;
public DateTime CreatedOn { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
+67
View File
@@ -0,0 +1,67 @@
using System;
using xModels.Base;
using xAiModels.Constants;
using System.ComponentModel.DataAnnotations;
namespace xAiModels.Models.Entities
{
/// <summary>
/// An MCP Server Descriptor for Adding Tools to XAI ...
/// </summary>
public class XAiMcpServer : XBaseGuidIDEntity
{
/// <summary>
/// Owner ...
/// </summary>
[Required]
[StringLength(255)]
public string OwnerId { get; set; }
/// <summary>
/// Specified Which Scope can Use MCP Server ...
/// </summary>
public XAiMcpServerUsageScope Scope { get; set; } = XAiMcpServerUsageScope.Owner;
/// <summary>
/// MCP Server Name ...
/// </summary>
[Required]
[StringLength(255)]
public string Name { get; set; }
/// <summary>
/// Description ...
/// </summary>
[StringLength(1000)]
public string Description { get; set; }
/// <summary>
/// Enabled or Disabled ...
/// </summary>
public bool Enabled { get; set; } = true;
/// <summary>
/// Environment Variables as JSON Object ...
/// </summary>
public string EnvironmentVariables { get; set; }
/// <summary>
/// Endpoint to Connect ...
/// </summary>
[StringLength(1000)]
public string Endpoint { get; set; }
/// <summary>
/// Headers List as Json Object ...
/// </summary>
public string Headers { get; set; }
/// <summary>
/// Timout Secconds ...
/// </summary>
public int TimeoutSeconds { get; set; } = 30;
public DateTime CreatedOn { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
+17
View File
@@ -0,0 +1,17 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace xAiModels.Models
{
public class XAiMcpJsonRpcError
{
[JsonPropertyName("code")]
public int Code { get; set; }
[JsonPropertyName("message")]
public string Message { get; set; }
[JsonPropertyName("data")]
public JsonElement? Data { get; set; }
}
}
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Text.Json.Serialization;
namespace xAiModels.Models
{
public class XAiMcpJsonRpcRequest
{
[JsonPropertyName("jsonrpc")]
public string JsonRpc { get; set; } = "2.0";
[JsonPropertyName("id")]
public string Id { get; set; } = Guid.NewGuid().ToString("N");
[JsonPropertyName("method")]
public string Method { get; set; }
[JsonPropertyName("params")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object Params { get; set; }
}
}
+25
View File
@@ -0,0 +1,25 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace xAiModels.Models
{
public class XAiMcpJsonRpcResponse
{
[JsonPropertyName("jsonrpc")]
public string JsonRpc { get; set; }
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("result")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public JsonElement? Result { get; set; }
[JsonPropertyName("error")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public XAiMcpJsonRpcError Error { get; set; }
[JsonIgnore]
public bool IsSuccess => Error is null;
}
}
+17
View File
@@ -0,0 +1,17 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace xAiModels.Models
{
public class XAiMcpToolDefinition
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("inputSchema")]
public JsonElement InputSchema { get; set; }
}
}
+17
View File
@@ -0,0 +1,17 @@
using System;
using System.Threading;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
namespace xAiModels.Models
{
public class XAiMcpToolDescriptor
{
public string Name { get; set; }
public string Description { get; set; }
public JObject InputSchema { get; set; }
public string RequiredPolicy { get; set; }
public bool RequiresAuthentication { get; set; } = false;
public Func<JObject, CancellationToken, Task<string>> Execute { get; set; }
}
}
+18 -2
View File
@@ -1,4 +1,5 @@
using System; using System;
using xAiModels.Constants;
namespace xAiModels.Models namespace xAiModels.Models
{ {
@@ -12,14 +13,29 @@ namespace xAiModels.Models
/// </summary> /// </summary>
public string Prompt { get; set; } public string Prompt { get; set; }
/// <summary>
/// Knowledge Type ...
/// </summary>
public string Type { get; set; } = XAiModelsConstants.XAiDefaultKnowledgeType;
/// <summary>
/// Provided TopK in Vector Searchs ...
/// </summary>
public int? TopK { get; set; }
/// <summary>
/// Min Score for Vector Searchs ...
/// </summary>
public float? MinScore { get; set; }
/// <summary> /// <summary>
/// Specified Project Id ... /// Specified Project Id ...
/// </summary> /// </summary>
public Guid ProjectId { get; set; } public Guid? ProjectId { get; set; }
/// <summary> /// <summary>
/// Specified Conversation Id ... /// Specified Conversation Id ...
/// </summary> /// </summary>
public Guid ConversationId { get; set; } public Guid? ConversationId { get; set; }
} }
} }
+17
View File
@@ -0,0 +1,17 @@
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using Microsoft.Extensions.Logging;
namespace xAiModels.Providers.Dtos
{
public class XAiMcpServerDtoHub : XBaseDtoHub<XAiMcpServer, XAiMcpServerDto, Guid>, IXAiMcpServerDtoHub
{
public XAiMcpServerDtoHub(
ILogger<XAiMcpServerDtoHub> logger
) : base(logger)
{ }
}
}
@@ -0,0 +1,26 @@
using System;
using xAiModels.Models.Dtos;
using xDataService.Providers;
using xAiModels.Configurations;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using xAiModels.Interfaces.Entities;
using xAiModels.Interfaces.Enrichers;
namespace xAiModels.Providers.Dtos
{
public class XAiMcpServerRepositoryService : XBaseRepositoryService<XAiMcpServer, XAiMcpServerDto, Guid>, IXAiMcpServerRepositoryService
{
private readonly IXAiMcpServerEnricher enricher;
private readonly IXAiMcpServerRepository repository;
public XAiMcpServerRepositoryService(
IXAiMcpServerRepository repository,
IXAiMcpServerEnricher enricher
) : base(repository, mapperProfiles: [new XAiModelMappersProfile()])
{
this.enricher = enricher;
this.repository = repository;
}
}
}
@@ -0,0 +1,22 @@
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
namespace xAiModels.Providers.Dtos
{
public class XAiMcpServerServiceProvider : XBaseDtoProvider<XAiMcpServer, XAiMcpServerDto, Guid, XAiMcpServerDtoHub>, IXAiMcpServerServiceProvider
{
public XAiMcpServerServiceProvider(
IHubContext<XAiMcpServerDtoHub> hub,
XDataServiceConfiguration dataConfiguration,
IXAiMcpServerRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(hub, dataConfiguration, service, identityProvider)
{ }
}
}
@@ -0,0 +1,79 @@
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xAiModels.Interfaces.Enrichers;
namespace xAiModels.Providers.Enrichers
{
public class XAiMcpServerEnricher : IXAiMcpServerEnricher
{
private readonly IXPersonService personService;
public XAiMcpServerEnricher(
IXPersonService personService
)
{
this.personService = personService;
}
public virtual async Task<XAiMcpServerDto> Enrich(
XAiMcpServer source,
CancellationToken cancellationToken = default
)
{
//
var result = source.MapConvert<XAiMcpServerDto, XAiMcpServer>();
result = await Enrich(
source: result,
cancellationToken: cancellationToken
);
//
return result;
}
public virtual async Task<XAiMcpServerDto> Enrich(
XAiMcpServerDto source,
CancellationToken cancellationToken = default
)
{
//
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
owner = await personService.GetPerson(source.OwnerId);
}
//
var result = source.MapConvert<XAiMcpServerDto, XAiMcpServerDto>();
result.Owner = owner;
//
return result;
}
public virtual async Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
IEnumerable<XAiMcpServer> sources,
CancellationToken cancellationToken = default
)
{
var tasks = sources.Select(x => Enrich(x, cancellationToken));
return await Task.WhenAll(tasks);
}
public virtual async Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
IEnumerable<XAiMcpServerDto> sources,
CancellationToken cancellationToken = default
)
{
var tasks = sources.Select(x => Enrich(x, cancellationToken));
return await Task.WhenAll(tasks);
}
}
}
+4 -8
View File
@@ -15,14 +15,17 @@ namespace xAiModels.Providers.Enrichers
{ {
public class XAiMessageEnricher : IXAiMessageEnricher public class XAiMessageEnricher : IXAiMessageEnricher
{ {
private readonly IXPersonService personService;
private readonly IXIdentityProvider identityProvider; private readonly IXIdentityProvider identityProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider; private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
public XAiMessageEnricher( public XAiMessageEnricher(
IXPersonService personService,
IXIdentityProvider identityProvider, IXIdentityProvider identityProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider IXAiConversationTitleResourceProvider conversationTitleResourceProvider
) )
{ {
this.personService = personService;
this.identityProvider = identityProvider; this.identityProvider = identityProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider; this.conversationTitleResourceProvider = conversationTitleResourceProvider;
} }
@@ -68,14 +71,7 @@ namespace xAiModels.Providers.Enrichers
XPersonDto owner = null; XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty()) if (!source.OwnerId.IsNullOrEmpty())
{ {
// owner = await personService.GetPerson(source.OwnerId);
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
} }
// //
+4 -9
View File
@@ -8,7 +8,6 @@ using System.Threading.Tasks;
using xAiModels.Models.Entities; using xAiModels.Models.Entities;
using System.Collections.Generic; using System.Collections.Generic;
using xIdentityService.Interfaces; using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Entities; using xAiModels.Interfaces.Entities;
using xAiModels.Interfaces.Enrichers; using xAiModels.Interfaces.Enrichers;
@@ -16,6 +15,7 @@ namespace xAiModels.Providers.Enrichers
{ {
public class XAiProjectEnricher : IXAiProjectEnricher public class XAiProjectEnricher : IXAiProjectEnricher
{ {
private readonly IXPersonService personService;
private readonly IXIdentityProvider identityProvider; private readonly IXIdentityProvider identityProvider;
private readonly IXAiMessageRepository messageRepository; private readonly IXAiMessageRepository messageRepository;
private readonly IXAiConversationRepository conversationRepository; private readonly IXAiConversationRepository conversationRepository;
@@ -24,6 +24,7 @@ namespace xAiModels.Providers.Enrichers
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider; private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
public XAiProjectEnricher( public XAiProjectEnricher(
IXPersonService personService,
IXIdentityProvider identityProvider, IXIdentityProvider identityProvider,
IXAiMessageRepository messageRepository, IXAiMessageRepository messageRepository,
IXAiConversationRepository conversationRepository, IXAiConversationRepository conversationRepository,
@@ -33,6 +34,7 @@ namespace xAiModels.Providers.Enrichers
) )
{ {
// //
this.personService = personService;
this.identityProvider = identityProvider; this.identityProvider = identityProvider;
this.messageRepository = messageRepository; this.messageRepository = messageRepository;
this.conversationRepository = conversationRepository; this.conversationRepository = conversationRepository;
@@ -92,14 +94,7 @@ namespace xAiModels.Providers.Enrichers
XPersonDto owner = null; XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty()) if (!source.OwnerId.IsNullOrEmpty())
{ {
// owner = await personService.GetPerson(source.OwnerId);
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
} }
// //
@@ -0,0 +1,22 @@
using System;
using xDataService.Db;
using xDataService.Providers;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerEFRepository<TContext> : XBaseEFRepository<XAiMcpServer, Guid, TContext>, IXAiMcpServerRepository
where TContext : XDbContext
{
public XAiMcpServerEFRepository(
IXUnitOfWorks<TContext> unitOfWorks,
XDataServiceConfiguration configuration,
IXAiMcpServerKeyGenerator keyGenerator = null,
IXAiMcpServerRepositoryEvents baseRepositoryEvents = null
) : base(unitOfWorks, configuration, keyGenerator, baseRepositoryEvents)
{ }
}
}
@@ -0,0 +1,16 @@
using System;
using xPushService.Base;
using xAiModels.Models.Entities;
using Microsoft.Extensions.Logging;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerEntityHub : XBaseEntityHub<XAiMcpServer, Guid>, IXAiMcpServerEntityHub
{
public XAiMcpServerEntityHub(
ILogger<XAiMcpServerEntityHub> logger
) : base(logger)
{ }
}
}
@@ -0,0 +1,18 @@
using System;
using xDataService.Providers;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerInMemoryRepository : XBaseInMemoryRepository<XAiMcpServer, Guid>, IXAiMcpServerRepository
{
public XAiMcpServerInMemoryRepository(
XDataServiceConfiguration configuration,
IXAiMcpServerKeyGenerator keyGenerator = null,
IXAiMcpServerRepositoryEvents baseRepositoryEvents = null
) : base(configuration, keyGenerator, baseRepositoryEvents)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xAiModels.Models.Entities;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerKeyGenerator : XGuidKeyGenerator<XAiMcpServer>, IXAiMcpServerKeyGenerator
{ }
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using xAiModels.Interfaces.Entities;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xDataService.Providers;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerMongoRepository : XBaseMongoRepository<XAiMcpServer, Guid>, IXAiMcpServerRepository
{
public XAiMcpServerMongoRepository(
XDataBaseConfiguration dbConfiguration,
XDataServiceConfiguration configuration,
string collectionName = null,
IXAiMcpServerKeyGenerator keyGenerator = null,
IXAiMcpServerRepositoryEvents baseRepositoryEvents = null
) : base(dbConfiguration, configuration, collectionName, keyGenerator, baseRepositoryEvents)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xAiModels.Models.Entities;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerRepositoryEvents : XBaseRepositoryEvents<XAiMcpServer>, IXAiMcpServerRepositoryEvents
{ }
}
@@ -0,0 +1,21 @@
using System;
using xPushService.Base;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public class XAiMcpServerRepositoryProvider : XBaseEntityProvider<XAiMcpServer, Guid, XAiMcpServerEntityHub>, IXAiMcpServerRepositoryProvider
{
public XAiMcpServerRepositoryProvider(
IHubContext<XAiMcpServerEntityHub> hub,
IXAiMcpServerRepository repository,
XDataServiceConfiguration dataConfiguration,
IXIdentityProvider identityProvider = null
) : base(hub, repository, dataConfiguration, identityProvider)
{ }
}
}
@@ -0,0 +1,24 @@
using System;
using xDataService.Providers;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Entities
{
public abstract class XAiMcpServerSeederBase : XBaseDbSeeder<XAiMcpServer, Guid>, IXAiMcpServerSeeder
{
protected XAiMcpServerSeederBase(
string entity,
string database,
IXAiMcpServerRepository repository,
XDataServiceConfiguration dataServiceConfiguration
) : base(
entity,
database,
repository,
dataServiceConfiguration
)
{ }
}
}
@@ -0,0 +1,21 @@
using System;
using xAiModels.Constants;
using xDataService.GraphQL;
using xAiModels.Models.Entities;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.GraphQL
{
public class XAiMcpServerGraphQLTypeHelper : XBaseGraphQLTypeHelper<XAiMcpServer, Guid>, IXAiMcpServerGraphQLTypeHelper
{
public override string GetInQueryCollectionName()
{
return XAiModelsConstants.XAiMcpServerCollectionName;
}
public override string GetInQuerySingleName()
{
return XAiModelsConstants.XAiMcpServerSingleName;
}
}
}
@@ -0,0 +1,23 @@
using System;
using GraphQL.Types;
using xDataService.GraphQL;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.GraphQL
{
public class XAiMcpServerGraphQuery : XBaseGraphQLQuery<XAiMcpServer, Guid, XAiMcpServerGraphType, GuidGraphType>
{
public XAiMcpServerGraphQuery(
XDataServiceConfiguration configuration,
IXAiMcpServerRepository repository,
IXAiMcpServerGraphQLTypeHelper helper
) : base(
configuration,
repository,
helper
)
{ }
}
}
@@ -0,0 +1,13 @@
using System;
using GraphQL.Types;
namespace xAiModels.Providers.GraphQL
{
public class XAiMcpServerGraphSchema : Schema
{
public XAiMcpServerGraphSchema(IServiceProvider services) : base(services)
{
Query = (XAiMcpServerGraphQuery)services.GetService(typeof(XAiMcpServerGraphQuery));
}
}
}
@@ -0,0 +1,23 @@
using System;
using xDataService.GraphQL;
using xAiModels.Models.Entities;
namespace xAiModels.Providers.GraphQL
{
public class XAiMcpServerGraphType: XBaseGraphObjectType<XAiMcpServer, Guid>
{
public XAiMcpServerGraphType() : base()
{
Field(x => x.Name);
Field(x => x.Enabled);
Field(x => x.OwnerId);
Field(x => x.Headers);
Field(x => x.Endpoint);
Field(x => x.CreatedOn);
Field(x => x.UpdatedAt);
Field(x => x.Description);
Field(x => x.TimeoutSeconds);
Field(x => x.EnvironmentVariables);
}
}
}
+168 -84
View File
@@ -100,90 +100,6 @@ namespace xAiModels.Providers.Hubs
} }
#endregion #endregion
//
#region XAiConversation ...
/// <summary>
/// Notify a New Item Created ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task ConversationCreated(
XAiProjectDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.ConversationCreated.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
/// <summary>
/// Notify an Item Removed ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task ConversationRemoved(
XAiProjectDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.ConversationRemoved.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
/// <summary>
/// Notify an Item Updated ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task ConversationUpdated(
XAiProjectDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.ConversationUpdated.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
#endregion
// //
#region XAiMessage ... #region XAiMessage ...
/// <summary> /// <summary>
@@ -267,5 +183,173 @@ namespace xAiModels.Providers.Hubs
} }
} }
#endregion #endregion
//
#region XAiMcpServer ...
/// <summary>
/// Notify a New Item Created ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task McpServerCreated(
XAiMcpServerDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.McpServerCreated.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
/// <summary>
/// Notify an Item Removed ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task McpServerRemoved(
XAiMcpServerDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.McpServerRemoved.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
/// <summary>
/// Notify an Item Updated ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task McpServerUpdated(
XAiMcpServerDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.McpServerUpdated.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
#endregion
//
#region XAiConversation ...
/// <summary>
/// Notify a New Item Created ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task ConversationCreated(
XAiProjectDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.ConversationCreated.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
/// <summary>
/// Notify an Item Removed ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task ConversationRemoved(
XAiProjectDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.ConversationRemoved.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
/// <summary>
/// Notify an Item Updated ...
/// </summary>
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task ConversationUpdated(
XAiProjectDto item,
CancellationToken cancellationToken = default
)
{
//
var connectionId = Context.ConnectionId;
if (!connectionId.IsNullOrEmpty())
{
//
await Clients
.AllExcept(connectionId)
.SendAsync(
XAiDataProviderHubActions.ConversationUpdated.GetStringValue(),
item.ToJSON(camelCase: true),
connectionId,
cancellationToken
);
}
}
#endregion
} }
} }
+441 -193
View File
@@ -38,10 +38,13 @@ namespace xAiModels.Providers
private readonly IXAiMessageEnricher messageEnricher; private readonly IXAiMessageEnricher messageEnricher;
private readonly IXAiProjectEnricher projectEnricher; private readonly IXAiProjectEnricher projectEnricher;
private readonly IXAiVectorRepository vectorRepository; private readonly IXAiVectorRepository vectorRepository;
private readonly IXAiMcpServerEnricher mcpServerEnricher;
private readonly IXAiMcpServerRepository mcpServerRepository;
private readonly IXAiConversationEnricher conversationEnricher; private readonly IXAiConversationEnricher conversationEnricher;
private readonly IXAiVectorRepositoryService vectorRepositoryService; private readonly IXAiVectorRepositoryService vectorRepositoryService;
private readonly IXAiMessageRepositoryService messageRepositoryService; private readonly IXAiMessageRepositoryService messageRepositoryService;
private readonly IXAiProjectRepositoryService projectRepositoryService; private readonly IXAiProjectRepositoryService projectRepositoryService;
private readonly IXAiMcpServerRepositoryService mcpServerRepositoryService;
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider; private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
private readonly IXAiConversationRepositoryService conversationRepositoryService; private readonly IXAiConversationRepositoryService conversationRepositoryService;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider; private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
@@ -56,10 +59,13 @@ namespace xAiModels.Providers
IXAiProjectEnricher projectEnricher, IXAiProjectEnricher projectEnricher,
IXAiMessageEnricher messageEnricher, IXAiMessageEnricher messageEnricher,
IXAiVectorRepository vectorRepository, IXAiVectorRepository vectorRepository,
IXAiMcpServerEnricher mcpServerEnricher,
IXAiMcpServerRepository mcpServerRepository,
IXAiConversationEnricher conversationEnricher, IXAiConversationEnricher conversationEnricher,
IXAiVectorRepositoryService vectorRepositoryService, IXAiVectorRepositoryService vectorRepositoryService,
IXAiMessageRepositoryService messageRepositoryService, IXAiMessageRepositoryService messageRepositoryService,
IXAiProjectRepositoryService projectRepositoryService, IXAiProjectRepositoryService projectRepositoryService,
IXAiMcpServerRepositoryService mcpServerRepositoryService,
IXAiProjectTitleResourceProvider projectTitleResourceProvider, IXAiProjectTitleResourceProvider projectTitleResourceProvider,
IXAiConversationRepositoryService conversationRepositoryService, IXAiConversationRepositoryService conversationRepositoryService,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider, IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
@@ -73,10 +79,13 @@ namespace xAiModels.Providers
this.messageEnricher = messageEnricher; this.messageEnricher = messageEnricher;
this.appConfiguration = appConfiguration; this.appConfiguration = appConfiguration;
this.vectorRepository = vectorRepository; this.vectorRepository = vectorRepository;
this.mcpServerEnricher = mcpServerEnricher;
this.mcpServerRepository = mcpServerRepository;
this.conversationEnricher = conversationEnricher; this.conversationEnricher = conversationEnricher;
this.vectorRepositoryService = vectorRepositoryService; this.vectorRepositoryService = vectorRepositoryService;
this.messageRepositoryService = messageRepositoryService; this.messageRepositoryService = messageRepositoryService;
this.projectRepositoryService = projectRepositoryService; this.projectRepositoryService = projectRepositoryService;
this.mcpServerRepositoryService = mcpServerRepositoryService;
this.projectTitleResourceProvider = projectTitleResourceProvider; this.projectTitleResourceProvider = projectTitleResourceProvider;
this.conversationRepositoryService = conversationRepositoryService; this.conversationRepositoryService = conversationRepositoryService;
this.conversationTitleResourceProvider = conversationTitleResourceProvider; this.conversationTitleResourceProvider = conversationTitleResourceProvider;
@@ -181,30 +190,51 @@ namespace xAiModels.Providers
/// Load List of Conversations for Specified Project ... /// Load List of Conversations for Specified Project ...
/// </summary> /// </summary>
/// <param name="projectId"></param> /// <param name="projectId"></param>
/// <param name="connectionId"></param> /// <param name="ownerId"></param>
/// <param name="fillMessages"></param> /// <param name="fillMessages"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<XAiConversationDto>> LoadConversations( public async Task<IEnumerable<XAiConversationDto>> LoadConversations(
Guid projectId, Guid? projectId,
string ownerId = null,
bool fillMessages = false, bool fillMessages = false,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
// //
// Validate Args ... // Validate ...
if (projectId.IsNull() || if (ownerId.IsNullOrEmpty())
projectId.IsDefaultGuid()
)
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
//
// Normalize ...
if (projectId.IsNull() ||
!projectId.HasValue
)
{
//
var defaultProject = await GetDefaultProject(
ownerId: ownerId,
connectionId: null,
cancellationToken: cancellationToken
);
if (defaultProject.IsNullOrDefault())
{
XException.InvalidData.Throw();
}
//
projectId = defaultProject.Id;
}
// //
// Retrieve Project ... // Retrieve Project ...
var project = await projectRepositoryService.GetAsync( var project = await projectRepositoryService.GetAsync(
id: projectId, id: projectId.Value,
includeBuilder: null, includeBuilder: null,
ignoreSoftDeleteds: true, ignoreSoftDeleteds: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
@@ -262,26 +292,60 @@ namespace xAiModels.Providers
/// Load Messages of Specified Conversation ... /// Load Messages of Specified Conversation ...
/// </summary> /// </summary>
/// <param name="conversationId"></param> /// <param name="conversationId"></param>
/// <param name="ownerId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<XAiMessageDto>> LoadMessages( public async Task<IEnumerable<XAiMessageDto>> LoadMessages(
Guid conversationId, Guid? conversationId,
string ownerId = null,
string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
// //
// Validate Args ... // Validate Args ...
if (conversationId.IsNull() || if (ownerId.IsNullOrEmpty())
conversationId.IsDefaultGuid()
)
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
//
// Normalize Conversation id ...
if (conversationId.IsNull() ||
!conversationId.HasValue)
{
//
var defaultProject = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (defaultProject.IsNullOrDefault())
{
XException.InvalidData.Throw();
}
//
var defaultConversation = await GetDefaultConversation(
ownerId: ownerId,
connectionId: connectionId,
projectId: defaultProject.Id,
cancellationToken: cancellationToken
);
if (defaultConversation.IsNullOrDefault())
{
XException.InvalidData.Throw();
}
//
conversationId = defaultConversation.Id;
}
// //
var conversation = await conversationRepositoryService.GetAsync( var conversation = await conversationRepositoryService.GetAsync(
id: conversationId,
includeBuilder: null, includeBuilder: null,
id: conversationId.Value,
ignoreSoftDeleteds: true, ignoreSoftDeleteds: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
@@ -473,8 +537,12 @@ namespace xAiModels.Providers
// Checking Resources ... // Checking Resources ...
// //
// Titles ... #region Titles ...
//
var titleResource = string.Empty; var titleResource = string.Empty;
//
// Provided in Locales ...
if (!item.TitleResource.IsNullOrDefault() && if (!item.TitleResource.IsNullOrDefault() &&
item.TitleResource.Locales.HasChild()) item.TitleResource.Locales.HasChild())
{ {
@@ -517,8 +585,38 @@ namespace xAiModels.Providers
} }
// //
// Descriptions ... // Provided in Title (defaultLanguage) ...
if (!item.Title.IsNullOrEmpty() &&
titleResource.IsNullOrEmpty() &&
item.TitleResource.IsNullOrDefault())
{
//
var resource = await projectTitleResourceProvider.AddOrUpdateLocale(
locale: new XLocaleResourceDto
{
Value = item.Title,
Language = defaultLanguage,
},
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
titleResource.IsNullOrEmpty())
{
titleResource = resource.Resource;
}
}
#endregion
//
#region Descriptions ...
//
var descriptionResource = string.Empty; var descriptionResource = string.Empty;
//
// Provided in Locales ...
if (!item.DescriptionResource.IsNullOrDefault() && if (!item.DescriptionResource.IsNullOrDefault() &&
item.DescriptionResource.Locales.HasChild()) item.DescriptionResource.Locales.HasChild())
{ {
@@ -560,6 +658,32 @@ namespace xAiModels.Providers
} }
} }
//
// Provided in Description (defaultLanguage) ...
if (!item.Description.IsNullOrEmpty() &&
descriptionResource.IsNullOrEmpty() &&
item.DescriptionResource.IsNullOrDefault())
{
//
var resource = await projectDescriptionResourceProvider.AddOrUpdateLocale(
locale: new XLocaleResourceDto
{
Value = item.Description,
Language = defaultLanguage,
},
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
descriptionResource.IsNullOrEmpty())
{
descriptionResource = resource.Resource;
}
}
#endregion
// //
// Update Data ... // Update Data ...
result.Title = titleResource; result.Title = titleResource;
@@ -654,7 +778,7 @@ namespace xAiModels.Providers
/// <returns></returns> /// <returns></returns>
public async Task<XAiConversationDto> CreateConversation( public async Task<XAiConversationDto> CreateConversation(
string ownerId, string ownerId,
Guid projectId, Guid? projectId,
XAiConversationDto item = null, XAiConversationDto item = null,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
@@ -662,16 +786,34 @@ namespace xAiModels.Providers
{ {
// //
// Validate Args ... // Validate Args ...
if (projectId.IsNull() || if (ownerId.IsNullOrEmpty())
projectId.IsDefaultGuid())
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
//
if (!projectId.HasValue ||
projectId.Value.IsDefaultGuid())
{
//
var defaultProject = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (defaultProject.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
projectId = defaultProject.Id;
}
// //
// Handle Proejct ... // Handle Proejct ...
XAiProjectDto project = await projectRepositoryService.GetAsync( XAiProjectDto project = await projectRepositoryService.GetAsync(
id: projectId, id: projectId.Value,
includeBuilder: null, includeBuilder: null,
ignoreSoftDeleteds: true, ignoreSoftDeleteds: true,
// fillConversations: false, // fillConversations: false,
@@ -725,8 +867,12 @@ namespace xAiModels.Providers
// Checking Resources ... // Checking Resources ...
// //
// Titles ... #region Titles ...
//
var titleResource = string.Empty; var titleResource = string.Empty;
//
// Locales ...
if (!item.TitleResource.IsNullOrDefault() && if (!item.TitleResource.IsNullOrDefault() &&
item.TitleResource.Locales.HasChild()) item.TitleResource.Locales.HasChild())
{ {
@@ -768,6 +914,32 @@ namespace xAiModels.Providers
} }
} }
//
// Title ...
if (!item.Title.IsNullOrEmpty() &&
titleResource.IsNullOrEmpty() &&
item.TitleResource.IsNullOrDefault())
{
//
var resource = await conversationTitleResourceProvider.AddOrUpdateLocale(
locale: new XLocaleResourceDto
{
Value = item.Title,
Language = defaultLanguage,
},
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
titleResource.IsNullOrEmpty())
{
titleResource = resource.Resource;
}
}
#endregion
// //
// Update Data ... // Update Data ...
result.Title = titleResource; result.Title = titleResource;
@@ -802,7 +974,7 @@ namespace xAiModels.Providers
); );
} }
} }
// //`
// Check Default Conversation ... // Check Default Conversation ...
else else
{ {
@@ -1009,7 +1181,7 @@ namespace xAiModels.Providers
/// <returns></returns> /// <returns></returns>
public async Task<XAiConversationDto> GetDefaultConversation( public async Task<XAiConversationDto> GetDefaultConversation(
string ownerId, string ownerId,
Guid projectId, Guid? projectId,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
@@ -1024,8 +1196,8 @@ namespace xAiModels.Providers
// //
// Prepare Project ... // Prepare Project ...
XAiProjectDto project = null; XAiProjectDto project = null;
if (projectId.IsNull() || if (!projectId.HasValue ||
projectId.IsDefaultGuid() projectId.Value.IsDefaultGuid()
) )
{ {
// //
@@ -1039,7 +1211,7 @@ namespace xAiModels.Providers
{ {
// //
project = await projectRepositoryService.GetAsync( project = await projectRepositoryService.GetAsync(
id: projectId, id: projectId.Value,
includeBuilder: null, includeBuilder: null,
ignoreSoftDeleteds: true, ignoreSoftDeleteds: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
@@ -1070,20 +1242,19 @@ namespace xAiModels.Providers
} }
// //
// Detect Conversation Resource ... // Check Default Owner Exists or not ...
var resource = await stringProvider.FindOne( var resource = await stringProvider.FindOne(
cancellationToken: cancellationToken, cancellationToken: cancellationToken,
predicate: x => predicate: x =>
x.ResourceTitle x.ResourceTitle
.ToNormalString() .ToNormalString()
.Contains(ownerId.ToNormalString()) && .Contains(ownerId.ToString().ToNormalString()) &&
x.ResourceTitle x.ResourceTitle
.ToNormalString() .ToNormalString()
.Contains(XAiModelsConstants.XAiProjectTitleIdentifier .Contains(XAiModelsConstants.XAiConversationTitleIdentifier.ToNormalString()) &&
.ToNormalString()) &&
x.TranslatedValue x.TranslatedValue
.ToNormalString() .ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiProjectSuffix) .Contains(XAiDataProviderConstants.XDefaultAiConversationSuffix.ToNormalString())
); );
if (resource.IsNullOrDefault()) if (resource.IsNullOrDefault())
{ {
@@ -1091,20 +1262,12 @@ namespace xAiModels.Providers
} }
// //
// Find Default Conversation ...
var result = await conversationRepositoryService.FindOneAsync( var result = await conversationRepositoryService.FindOneAsync(
cancellationToken: cancellationToken, cancellationToken: cancellationToken,
predicate: x => x.Title predicate: x =>
.Equals( x.ProjectId == project.Id &&
resource.ResourceTitle, x.Title == resource.ResourceTitle
StringComparison.InvariantCultureIgnoreCase
) &&
x.ProjectId == project.Id
); );
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
// //
return result; return result;
@@ -1158,6 +1321,111 @@ namespace xAiModels.Providers
return result; return result;
} }
/// <summary>
/// Query Messages ...
/// </summary>
/// <param name="ownerId"></param>
/// <param name="conversationId"></param>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<XAiMessageDto>> QueryMessages(
string ownerId,
Guid conversationId,
XQuery query,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (conversationId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
// Retrieve Conversation ...
var conversation = await conversationRepositoryService.GetAsync(
id: conversationId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (conversation.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
Expression<Func<XAiMessage, bool>> predicate = x =>
x.ConversationId == conversationId;
if (!ownerId.IsNullOrEmpty())
{
//
predicate = x =>
x.OwnerId == ownerId &&
x.ConversationId == conversationId;
}
//
var result = await messageRepositoryService.QueryAsync(
query: query,
predicate: predicate,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
if (!result.IsNullOrDefault() &&
result.Items.HasChild())
{
//
result.Items = [..await EnrichRange(
sources: result.Items,
cancellationToken: cancellationToken
)];
}
//
return result;
}
/// <summary>
/// Query McpServers ...
/// </summary>
/// <param name="query"></param>
/// <param name="predicate"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<XAiMcpServerDto>> QueryMcpServers(
XQuery query,
Expression<Func<XAiMcpServer, bool>> predicate = null,
CancellationToken cancellationToken = default
)
{
//
var result = await mcpServerRepositoryService.QueryAsync(
query: query,
predicate: predicate,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
if (!result.IsNullOrDefault() &&
result.Items.HasChild())
{
//
result.Items = [..await EnrichRange(
sources: result.Items,
cancellationToken: cancellationToken
)];
}
//
return result;
}
/// <summary> /// <summary>
/// Query Conversations ... /// Query Conversations ...
/// </summary> /// </summary>
@@ -1227,75 +1495,6 @@ namespace xAiModels.Providers
// //
return result; return result;
} }
/// <summary>
/// Query Messages ...
/// </summary>
/// <param name="ownerId"></param>
/// <param name="conversationId"></param>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<XAiMessageDto>> QueryMessages(
string ownerId,
Guid conversationId,
XQuery query,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (conversationId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
// Retrieve Conversation ...
var conversation = await conversationRepositoryService.GetAsync(
id: conversationId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (conversation.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
Expression<Func<XAiMessage, bool>> predicate = x =>
x.ConversationId == conversationId;
if (!ownerId.IsNullOrEmpty())
{
//
predicate = x =>
x.OwnerId == ownerId &&
x.ConversationId == conversationId;
}
//
var result = await messageRepositoryService.QueryAsync(
query: query,
predicate: predicate,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
if (!result.IsNullOrDefault() &&
result.Items.HasChild())
{
//
result.Items = [..await EnrichRange(
sources: result.Items,
cancellationToken: cancellationToken
)];
}
//
return result;
}
#endregion #endregion
// //
@@ -1396,6 +1595,13 @@ namespace xAiModels.Providers
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
//
// Normalize ...
if (type.IsNullOrEmpty())
{
type = XAiModelsConstants.XAiDefaultKnowledgeType;
}
// //
// Converts Question Vector to Vector Array ... // Converts Question Vector to Vector Array ...
var queryVector = queryEmbedding.ToArray(); var queryVector = queryEmbedding.ToArray();
@@ -1535,7 +1741,7 @@ namespace xAiModels.Providers
{ {
// //
exists.Text = item.Text; exists.Text = item.Text;
exists.Embedding = item.Embedding.ToJSON(); exists.Embedding = item.Embedding.ToEmbedding();
exists.Type = item.Type.IsNullOrEmpty() ? exists.Type : item.Type; exists.Type = item.Type.IsNullOrEmpty() ? exists.Type : item.Type;
exists.Metadata = item.Metadata.IsNullOrDefault() ? exists.Metadata : item.Metadata.ToJSON(); exists.Metadata = item.Metadata.IsNullOrDefault() ? exists.Metadata : item.Metadata.ToJSON();
toUpdate.Add(exists); toUpdate.Add(exists);
@@ -1549,7 +1755,7 @@ namespace xAiModels.Providers
Type = item.Type, Type = item.Type,
Identifier = item.Identifier, Identifier = item.Identifier,
Metadata = item.Metadata.ToJSON(), Metadata = item.Metadata.ToJSON(),
Embedding = item.Embedding.ToJSON(), Embedding = item.Embedding.ToEmbedding(),
Id = item.Id.IsDefaultGuid() ? Guid.NewGuid() : item.Id, Id = item.Id.IsDefaultGuid() ? Guid.NewGuid() : item.Id,
}); });
} }
@@ -1676,48 +1882,6 @@ namespace xAiModels.Providers
// //
#region Enrichers ... #region Enrichers ...
/// <summary>
/// Enrich Specified Item ...
/// </summary>
/// <param name="source"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XAiVectorDto> Enrich(
XAiVector source,
CancellationToken cancellationToken = default
)
{
//
var result = await vectorEnricher.Enrich(
source: source,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
IEnumerable<XAiVector> sources,
CancellationToken cancellationToken = default
)
{
//
var result = await vectorEnricher.EnrichRange(
sources: sources,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary> /// <summary>
/// Enrich Specified Item ... /// Enrich Specified Item ...
/// </summary> /// </summary>
@@ -1740,19 +1904,40 @@ namespace xAiModels.Providers
} }
/// <summary> /// <summary>
/// Enrich Specified Items ... /// Enrich Specified Item ...
/// </summary> /// </summary>
/// <param name="sources"></param> /// <param name="source"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<XAiVectorDto>> EnrichRange( public async Task<XAiVectorDto> Enrich(
IEnumerable<XAiVectorDto> sources, XAiVector source,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
// //
var result = await vectorEnricher.EnrichRange( var result = await vectorEnricher.Enrich(
sources: sources, source: source,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Enrich Specified Item ...
/// </summary>
/// <param name="source"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XAiMessageDto> Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
)
{
//
var result = await messageEnricher.Enrich(
source: source,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
@@ -1788,26 +1973,20 @@ namespace xAiModels.Providers
} }
/// <summary> /// <summary>
/// Enrich Specified Items ... /// Enrich Specified Item ...
/// </summary> /// </summary>
/// <param name="sources"></param> /// <param name="source"></param>
/// <param name="fillConversations"></param>
/// <param name="fillConversationMessages"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<XAiProjectDto>> EnrichRange( public async Task<XAiMcpServerDto> Enrich(
IEnumerable<XAiProjectDto> sources, XAiMcpServerDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
// //
var result = await projectEnricher.EnrichRange( var result = await mcpServerEnricher.Enrich(
sources: sources, source: source,
fillConversations: fillConversations, cancellationToken: cancellationToken
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
); );
// //
@@ -1842,19 +2021,16 @@ namespace xAiModels.Providers
/// Enrich Specified Items ... /// Enrich Specified Items ...
/// </summary> /// </summary>
/// <param name="sources"></param> /// <param name="sources"></param>
/// <param name="fillMessages"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<XAiConversationDto>> EnrichRange( public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
IEnumerable<XAiConversationDto> sources, IEnumerable<XAiVector> sources,
bool fillMessages = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
// //
var result = await conversationEnricher.EnrichRange( var result = await vectorEnricher.EnrichRange(
sources: sources, sources: sources,
fillMessages: fillMessages,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
@@ -1863,19 +2039,19 @@ namespace xAiModels.Providers
} }
/// <summary> /// <summary>
/// Enrich Specified Item ... /// Enrich Specified Items ...
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="sources"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<XAiMessageDto> Enrich( public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
XAiMessageDto source, IEnumerable<XAiVectorDto> sources,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
// //
var result = await messageEnricher.Enrich( var result = await vectorEnricher.EnrichRange(
source: source, sources: sources,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
@@ -1883,6 +2059,33 @@ namespace xAiModels.Providers
return result; return result;
} }
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="fillConversations"></param>
/// <param name="fillConversationMessages"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XAiProjectDto>> EnrichRange(
IEnumerable<XAiProjectDto> sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
var result = await projectEnricher.EnrichRange(
sources: sources,
fillConversations: fillConversations,
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
);
//
return result;
}
/// <summary> /// <summary>
/// Enrich Specified Items ... /// Enrich Specified Items ...
/// </summary> /// </summary>
@@ -1903,6 +2106,51 @@ namespace xAiModels.Providers
// //
return result; return result;
} }
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
IEnumerable<XAiMcpServerDto> sources,
CancellationToken cancellationToken = default
)
{
//
var result = await mcpServerEnricher.EnrichRange(
sources: sources,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="fillMessages"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XAiConversationDto>> EnrichRange(
IEnumerable<XAiConversationDto> sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var result = await conversationEnricher.EnrichRange(
sources: sources,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
//
return result;
}
#endregion #endregion
// //
@@ -2059,7 +2307,7 @@ namespace xAiModels.Providers
/// <returns></returns> /// <returns></returns>
private async Task<bool> HasDefaultConversation( private async Task<bool> HasDefaultConversation(
string ownerId, string ownerId,
Guid projectId, Guid? projectId,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
@@ -2075,8 +2323,8 @@ namespace xAiModels.Providers
// //
// Prepare Project ... // Prepare Project ...
XAiProjectDto project = null; XAiProjectDto project = null;
if (projectId.IsNull() || if (!projectId.HasValue ||
projectId.IsDefaultGuid() projectId.Value.IsDefaultGuid()
) )
{ {
// //
@@ -2090,7 +2338,7 @@ namespace xAiModels.Providers
{ {
// //
project = await projectRepositoryService.GetAsync( project = await projectRepositoryService.GetAsync(
id: projectId, id: projectId.Value,
includeBuilder: null, includeBuilder: null,
ignoreSoftDeleteds: true, ignoreSoftDeleteds: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
@@ -2126,7 +2374,7 @@ namespace xAiModels.Providers
var defaultConversation = await conversationRepositoryService.FindOneAsync( var defaultConversation = await conversationRepositoryService.FindOneAsync(
cancellationToken: cancellationToken, cancellationToken: cancellationToken,
predicate: x => predicate: x =>
x.ProjectId == projectId && x.ProjectId == project.Id &&
x.Title == resource.ResourceTitle x.Title == resource.ResourceTitle
); );
result = !defaultConversation.IsNullOrDefault(); result = !defaultConversation.IsNullOrDefault();
@@ -2145,7 +2393,7 @@ namespace xAiModels.Providers
/// <returns></returns> /// <returns></returns>
private async Task CreateDefaultConversation( private async Task CreateDefaultConversation(
string ownerId, string ownerId,
Guid projectId, Guid? projectId,
string connectionId = null, string connectionId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
@@ -2164,8 +2412,8 @@ namespace xAiModels.Providers
// //
// Prepare Project ... // Prepare Project ...
XAiProjectDto project = null; XAiProjectDto project = null;
if (projectId.IsNull() || if (!projectId.HasValue ||
projectId.IsDefaultGuid() projectId.Value.IsDefaultGuid()
) )
{ {
// //
@@ -2179,7 +2427,7 @@ namespace xAiModels.Providers
{ {
// //
project = await projectRepositoryService.GetAsync( project = await projectRepositoryService.GetAsync(
id: projectId, id: projectId.Value,
includeBuilder: null, includeBuilder: null,
ignoreSoftDeleteds: true, ignoreSoftDeleteds: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
@@ -0,0 +1,35 @@
using System;
using xDataService.Providers;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using xAiModels.Configurations.Entities;
namespace xAiModels.Providers
{
public class XAiMcpServerEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XAiMcpServerEntityRegisterar()
: base(nameof(XAiMcpServerEntityRegisterar))
{
//
// Add Entity ...
AddEntity<XAiMcpServer, Guid>();
}
/// <summary>
/// Configure Entities ...
/// </summary>
/// <param name="modelBuilder"></param>
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
//
// Configure Entity Using Provided ...
modelBuilder
.ApplyConfigurationsFromAssembly(typeof(XAiMcpServerEntityConfiguration).Assembly);
//
base.ConfigureEntities(modelBuilder);
}
}
}
+1 -1
View File
@@ -25,7 +25,6 @@
<!-- Local Modules --> <!-- Local Modules -->
<ItemGroup> <ItemGroup>
<!-- <PackageReference Include="xDashboard.xStringService" Version="1.0.0" /> -->
</ItemGroup> </ItemGroup>
<!-- Local Dependencies --> <!-- Local Dependencies -->
@@ -36,6 +35,7 @@
<!-- Dependencies --> <!-- Dependencies -->
<ItemGroup> <ItemGroup>
<PackageReference Include="OpenAI" Version="2.14.0" /> <PackageReference Include="OpenAI" Version="2.14.0" />
<PackageReference Include="TimeZoneConverter" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.AI" Version="10.4.1" /> <PackageReference Include="Microsoft.Extensions.AI" Version="10.4.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.10.0" /> <PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.10.0" />
</ItemGroup> </ItemGroup>