Compare commits
14
Commits
c4b7e86174
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c05a389a44 | ||
|
|
185aaae19a | ||
|
|
4fe5d57d37 | ||
|
|
27b9f51dc9 | ||
|
|
08fd26ffac | ||
|
|
476ace743d | ||
|
|
c53553e1cf | ||
|
|
33dda6bee7 | ||
|
|
7ba0916461 | ||
|
|
2d44ec8744 | ||
|
|
25534f0273 | ||
|
|
9668f26ffe | ||
|
|
62aa8d51e6 | ||
|
|
9e7710e345 |
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,10 @@ namespace xAiModels.Configurations
|
||||
// XAiProject ...
|
||||
CreateMap<XAiProject, XAiProjectDto>();
|
||||
|
||||
//
|
||||
CreateMap<XAiMcpServer, XAiMcpServerDto>();
|
||||
CreateMap<XAiMcpServerDto, XAiMcpServer>();
|
||||
|
||||
//
|
||||
// XAiConversation ...
|
||||
CreateMap<XAiConversation, XAiConversationDto>();
|
||||
|
||||
@@ -21,17 +21,6 @@ namespace xAiModels.Constants
|
||||
[StringValue("ProjectRemoved")]
|
||||
ProjectRemoved,
|
||||
|
||||
//
|
||||
// Conversation ...
|
||||
[StringValue("ConversationCreated")]
|
||||
ConversationCreated,
|
||||
|
||||
[StringValue("ConversationUpdated")]
|
||||
ConversationUpdated,
|
||||
|
||||
[StringValue("ConversationRemoved")]
|
||||
ConversationRemoved,
|
||||
|
||||
//
|
||||
// Message ...
|
||||
[StringValue("MessageCreated")]
|
||||
@@ -42,5 +31,27 @@ namespace xAiModels.Constants
|
||||
|
||||
[StringValue("MessageRemoved")]
|
||||
MessageRemoved,
|
||||
|
||||
//
|
||||
// MCPServer ...
|
||||
[StringValue("McpServerCreated")]
|
||||
McpServerCreated,
|
||||
|
||||
[StringValue("McpServerUpdated")]
|
||||
McpServerUpdated,
|
||||
|
||||
[StringValue("McpServerRemoved")]
|
||||
McpServerRemoved,
|
||||
|
||||
//
|
||||
// Conversation ...
|
||||
[StringValue("ConversationCreated")]
|
||||
ConversationCreated,
|
||||
|
||||
[StringValue("ConversationUpdated")]
|
||||
ConversationUpdated,
|
||||
|
||||
[StringValue("ConversationRemoved")]
|
||||
ConversationRemoved,
|
||||
}
|
||||
}
|
||||
@@ -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 = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using xExceptions.Attributes;
|
||||
|
||||
namespace xAiModels.Constants
|
||||
{
|
||||
public enum XAiMcpMethods
|
||||
{
|
||||
[StringValue("initialize")]
|
||||
Initialize,
|
||||
|
||||
[StringValue("tools/list")]
|
||||
ToolsList,
|
||||
|
||||
[StringValue("tools/call")]
|
||||
ToolsCall,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using xExceptions.Attributes;
|
||||
|
||||
namespace xAiModels.Constants
|
||||
{
|
||||
public enum XAiMcpServerUsageScope
|
||||
{
|
||||
[StringValue(XAiModelsConstants.XAiMcpServerUsageScopeAll)]
|
||||
All = 1,
|
||||
|
||||
[StringValue(XAiModelsConstants.XAiMcpServerUsageScopeOwner)]
|
||||
Owner = 2
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,27 @@ namespace xAiModels.Constants
|
||||
//
|
||||
// Service Extensions Log Tag ...
|
||||
public const string XAiModelsDILogTag = "XAiModels";
|
||||
|
||||
|
||||
//
|
||||
// Table Mapping Identifiers ...
|
||||
public const string XAiVectorTable = "AiVectors";
|
||||
public const string XAiMessageTable = "AiMessages";
|
||||
public const string XAiProjectTable = "AiProjects";
|
||||
public const string XAiMcpServerTable = "AiMcpServers";
|
||||
public const string XAiConversationTable = "AiConversations";
|
||||
|
||||
//
|
||||
// GraphQL Collection Mappings ...
|
||||
public const string XAiMessageSingleName = "aiMessage";
|
||||
public const string XAiProjectSingleName = "aiProject";
|
||||
public const string XAiMcpServerSingleName = "aiMcpServer";
|
||||
public const string XAiConversationSignleName = "aiConversation";
|
||||
|
||||
public const string XAiMessageCollectionName = "aiMessages";
|
||||
public const string XAiProjectCollectionName = "AiProjectsa";
|
||||
public const string XAiMcpServerCollectionName = "aiMcpServers";
|
||||
public const string XAiConversationCollectionName = "aiConversations";
|
||||
|
||||
|
||||
public const string XAiVectorSingleName = "aiVector";
|
||||
public const string XAiVectorCollectionName = "aiVectors";
|
||||
|
||||
@@ -34,6 +37,9 @@ namespace xAiModels.Constants
|
||||
public const string XAiProjectDtoHub = "aiProjectDto";
|
||||
public const string XAiProjectEntityHub = "aiProjectEntity";
|
||||
|
||||
public const string XAiMcpServerDtoHub = "aiMcpServerDto";
|
||||
public const string XAiMcpServerEntityHub = "aiMcpServerEntity";
|
||||
|
||||
public const string XAiConversationDtoHub = "aiConversationDto";
|
||||
public const string XAiConversationEntityHub = "aiConversationEntity";
|
||||
|
||||
@@ -48,18 +54,19 @@ namespace xAiModels.Constants
|
||||
|
||||
//
|
||||
// EF Repositories Helper Extensions ...
|
||||
public const string GetXAiVectorEFRepositoryDescriptor = "GetXAiVectorEFRepositoryDescriptor";
|
||||
public const string GetXAiMessageEFRepositoryDescriptor = "GetXAiMessageEFRepositoryDescriptor";
|
||||
public const string GetXAiProjectEFRepositoryDescriptor = "GetXAiProjectEFRepositoryDescriptor";
|
||||
public const string GetXAiMcpServerEFRepositoryDescriptor = "GetXAiMcpServerEFRepositoryDescriptor";
|
||||
public const string GetXAiConversationEFRepositoryDescriptor = "GetXAiConversationEFRepositoryDescriptor";
|
||||
public const string GetXAiVectorEFRepositoryDescriptor = "GetXAiVectorEFRepositoryDescriptor";
|
||||
|
||||
//
|
||||
public const string DefaultXAiProjectTitleResourceID = "XAiPrjT";
|
||||
public const string DefaultXAiConversationTitleResourceID = "XAiCnvT";
|
||||
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
|
||||
public const string DefaultXAiProjectTitleResourceID = "XAiPrjT";
|
||||
public const string DefaultXAiConversationTitleResourceID = "XAiCnvT";
|
||||
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
|
||||
|
||||
//
|
||||
public const string XOpenAINoKey = "no-key-required";
|
||||
public const string XOpenAINoKey = "no-key-required";
|
||||
|
||||
//
|
||||
// Knowledge (Persistent RAG) ...
|
||||
@@ -83,5 +90,11 @@ namespace xAiModels.Constants
|
||||
public const string XAiKnowledgeMetadataScopeId = "scopeId";
|
||||
public const string XAiKnowledgeMetadataOwnerId = "ownerId";
|
||||
public const string XAiKnowledgeMetadataIngestedAtUtc = "ingestedAtUtc";
|
||||
|
||||
//
|
||||
// Mcp Server ...
|
||||
public const int XAiMcpServerMinTimeoutSeconds = 30;
|
||||
public const string XAiMcpServerUsageScopeAll = "All";
|
||||
public const string XAiMcpServerUsageScopeOwner = "Owner";
|
||||
}
|
||||
}
|
||||
+63
-103
@@ -100,6 +100,11 @@ namespace xAiModels.DI
|
||||
pushHelper.AddHub<XAiProjectDtoHub>(XAiModelsConstants.XAiProjectDtoHub);
|
||||
pushHelper.AddHub<XAiProjectEntityHub>(XAiModelsConstants.XAiProjectEntityHub);
|
||||
|
||||
//
|
||||
// XAiMcpServer ...
|
||||
pushHelper.AddHub<XAiMcpServerDtoHub>(XAiModelsConstants.XAiMcpServerDtoHub);
|
||||
pushHelper.AddHub<XAiMcpServerEntityHub>(XAiModelsConstants.XAiMcpServerEntityHub);
|
||||
|
||||
//
|
||||
// XAiConversation ...
|
||||
pushHelper.AddHub<XAiConversationDtoHub>(XAiModelsConstants.XAiConversationDtoHub);
|
||||
@@ -143,109 +148,15 @@ namespace xAiModels.DI
|
||||
}
|
||||
|
||||
//
|
||||
// Create an Scope for Services Acces ...
|
||||
// Handle Seeding Category/SubCategory Resources ...
|
||||
// TODO: Enable Seeding if Required ...
|
||||
// using (var scope = app.ApplicationServices.CreateScope())
|
||||
// {
|
||||
// //
|
||||
// // Retrieve Configuratuions ...
|
||||
// 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 ...");
|
||||
// }
|
||||
// }
|
||||
// Using XAiMcpServer Repository Descriptor ...
|
||||
if (!aiMcpServerDescriptor.IsNull())
|
||||
{
|
||||
//
|
||||
app.UseXRepository(
|
||||
descriptor: aiMcpServerDescriptor,
|
||||
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -253,6 +164,7 @@ namespace xAiModels.DI
|
||||
private static XRepositoryDescriptor aiVectorDescriptor = null;
|
||||
private static XRepositoryDescriptor aiMessageDescriptor = null;
|
||||
private static XRepositoryDescriptor aiProjectDescriptor = null;
|
||||
private static XRepositoryDescriptor aiMcpServerDescriptor = null;
|
||||
private static XRepositoryDescriptor aiConversationDescriptor = null;
|
||||
|
||||
/// <summary>
|
||||
@@ -355,6 +267,15 @@ namespace xAiModels.DI
|
||||
methodName: XAiModelsConstants.GetXAiProjectEFRepositoryDescriptor
|
||||
);
|
||||
|
||||
//
|
||||
// XAiMcpServer ...
|
||||
aiMcpServerDescriptor = typeof(XAiModelsHelper)
|
||||
.InvokeGenericMethod<XRepositoryDescriptor>(
|
||||
args: null,
|
||||
runtimeType: contextType,
|
||||
methodName: XAiModelsConstants.GetXAiMcpServerEFRepositoryDescriptor
|
||||
);
|
||||
|
||||
//
|
||||
// XAiConversation ...
|
||||
aiConversationDescriptor = typeof(XAiModelsHelper)
|
||||
@@ -379,6 +300,10 @@ namespace xAiModels.DI
|
||||
// XAiProject ...
|
||||
aiProjectDescriptor = XAiModelsHelper.GetXAiProjectMongoRepositoryDescriptor();
|
||||
|
||||
//
|
||||
// XAiMcpServer ...
|
||||
aiMcpServerDescriptor = XAiModelsHelper.GetXAiMcpServerMongoRepositoryDescriptor();
|
||||
|
||||
//
|
||||
// XAiConversation ...
|
||||
aiConversationDescriptor = XAiModelsHelper.GetXAiConversationMongoRepositoryDescriptor();
|
||||
@@ -398,6 +323,10 @@ namespace xAiModels.DI
|
||||
// XAiProject ...
|
||||
aiProjectDescriptor = XAiModelsHelper.GetXAiProjectInMemoryRepositoryDescriptor();
|
||||
|
||||
//
|
||||
// XAiMcpServer ...
|
||||
aiMcpServerDescriptor = XAiModelsHelper.GetXAiMcpServerInMemoryRepositoryDescriptor();
|
||||
|
||||
//
|
||||
// XAiConversation ...
|
||||
aiConversationDescriptor = XAiModelsHelper.GetXAiConversationInMemoryRepositoryDescriptor();
|
||||
@@ -439,6 +368,17 @@ namespace xAiModels.DI
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// XAiMcpServer ...
|
||||
if (!aiMcpServerDescriptor.IsNull())
|
||||
{
|
||||
//
|
||||
services.AddXRepository(
|
||||
lifeTime: lifeTime,
|
||||
descriptor: aiMcpServerDescriptor
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// XAiConversation ...
|
||||
if (!aiConversationDescriptor.IsNull())
|
||||
@@ -522,6 +462,26 @@ namespace xAiModels.DI
|
||||
);
|
||||
#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 ...
|
||||
//
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace xAiModels.Extensions
|
||||
source is not null &&
|
||||
!source.IsNullOrDefault() &&
|
||||
!string.IsNullOrWhiteSpace(source.Text) &&
|
||||
source.FinishReason == ChatFinishReason.Stop;
|
||||
(source.FinishReason == ChatFinishReason.Stop ||
|
||||
source.FinishReason == ChatFinishReason.ToolCalls);
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,7 @@ namespace xAiModels.Extensions
|
||||
//
|
||||
var result =
|
||||
!source.IsNullOrDefault() &&
|
||||
!source.OwnerId.IsNullOrEmpty() &&
|
||||
!source.Prompt.IsNullOrEmpty();
|
||||
!source.OwnerId.IsNullOrEmpty();
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -40,8 +39,7 @@ namespace xAiModels.Extensions
|
||||
//
|
||||
var result =
|
||||
!source.IsNullOrDefault() &&
|
||||
!source.OwnerId.IsNullOrEmpty() &&
|
||||
!source.Prompt.IsNullOrEmpty();
|
||||
!source.OwnerId.IsNullOrEmpty();
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -57,9 +55,7 @@ namespace xAiModels.Extensions
|
||||
//
|
||||
var result =
|
||||
!source.IsNullOrDefault() &&
|
||||
!source.OwnerId.IsNullOrEmpty() &&
|
||||
!source.ProjectId.IsNull() &&
|
||||
!source.ProjectId.IsDefaultGuid();
|
||||
!source.OwnerId.IsNullOrEmpty();
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -69,9 +65,7 @@ namespace xAiModels.Extensions
|
||||
//
|
||||
var result =
|
||||
!source.IsNullOrDefault() &&
|
||||
!source.OwnerId.IsNullOrEmpty() &&
|
||||
!source.ProjectId.IsNull() &&
|
||||
!source.ProjectId.IsDefaultGuid();
|
||||
!source.OwnerId.IsNullOrEmpty();
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -111,6 +105,36 @@ namespace xAiModels.Extensions
|
||||
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>
|
||||
/// Validate a Model Descriptor ...
|
||||
/// </summary>
|
||||
@@ -339,7 +363,7 @@ namespace xAiModels.Extensions
|
||||
/// <param name="source"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <returns></returns>
|
||||
public static Guid GetDafualtProject(
|
||||
public static Guid GetDafaultProject(
|
||||
this IEnumerable<XAiProjectDto> source,
|
||||
string ownerId
|
||||
)
|
||||
@@ -494,5 +518,35 @@ namespace xAiModels.Extensions
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using xCommons.Extensions;
|
||||
|
||||
namespace xAiModels.Extensions
|
||||
@@ -13,7 +14,8 @@ namespace xAiModels.Extensions
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (source.IsNullOrEmpty()) {
|
||||
if (source.IsNullOrEmpty())
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -28,5 +30,25 @@ namespace xAiModels.Extensions
|
||||
//
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1079,5 +1079,272 @@ namespace xAiModels.Helpers
|
||||
}
|
||||
#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
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
{ }
|
||||
}
|
||||
@@ -66,12 +66,14 @@ namespace xAiModels.Interfaces
|
||||
/// Load List of Conversations for Specified Project ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string ownerId = null,
|
||||
bool fillMessages = false,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -81,10 +83,14 @@ namespace xAiModels.Interfaces
|
||||
/// Load Messages of Specified Conversation ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||
Guid conversationId,
|
||||
Guid? conversationId,
|
||||
string ownerId = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
@@ -197,7 +203,7 @@ namespace xAiModels.Interfaces
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> GetDefaultConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
@@ -231,7 +237,7 @@ namespace xAiModels.Interfaces
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> CreateConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
XAiConversationDto item = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,90 +100,6 @@ namespace xAiModels.Providers.Hubs
|
||||
}
|
||||
#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 ...
|
||||
/// <summary>
|
||||
@@ -267,5 +183,173 @@ namespace xAiModels.Providers.Hubs
|
||||
}
|
||||
}
|
||||
#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
|
||||
}
|
||||
}
|
||||
+428
-178
@@ -38,10 +38,13 @@ namespace xAiModels.Providers
|
||||
private readonly IXAiMessageEnricher messageEnricher;
|
||||
private readonly IXAiProjectEnricher projectEnricher;
|
||||
private readonly IXAiVectorRepository vectorRepository;
|
||||
private readonly IXAiMcpServerEnricher mcpServerEnricher;
|
||||
private readonly IXAiMcpServerRepository mcpServerRepository;
|
||||
private readonly IXAiConversationEnricher conversationEnricher;
|
||||
private readonly IXAiVectorRepositoryService vectorRepositoryService;
|
||||
private readonly IXAiMessageRepositoryService messageRepositoryService;
|
||||
private readonly IXAiProjectRepositoryService projectRepositoryService;
|
||||
private readonly IXAiMcpServerRepositoryService mcpServerRepositoryService;
|
||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
||||
private readonly IXAiConversationRepositoryService conversationRepositoryService;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
@@ -56,10 +59,13 @@ namespace xAiModels.Providers
|
||||
IXAiProjectEnricher projectEnricher,
|
||||
IXAiMessageEnricher messageEnricher,
|
||||
IXAiVectorRepository vectorRepository,
|
||||
IXAiMcpServerEnricher mcpServerEnricher,
|
||||
IXAiMcpServerRepository mcpServerRepository,
|
||||
IXAiConversationEnricher conversationEnricher,
|
||||
IXAiVectorRepositoryService vectorRepositoryService,
|
||||
IXAiMessageRepositoryService messageRepositoryService,
|
||||
IXAiProjectRepositoryService projectRepositoryService,
|
||||
IXAiMcpServerRepositoryService mcpServerRepositoryService,
|
||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||
IXAiConversationRepositoryService conversationRepositoryService,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
||||
@@ -73,10 +79,13 @@ namespace xAiModels.Providers
|
||||
this.messageEnricher = messageEnricher;
|
||||
this.appConfiguration = appConfiguration;
|
||||
this.vectorRepository = vectorRepository;
|
||||
this.mcpServerEnricher = mcpServerEnricher;
|
||||
this.mcpServerRepository = mcpServerRepository;
|
||||
this.conversationEnricher = conversationEnricher;
|
||||
this.vectorRepositoryService = vectorRepositoryService;
|
||||
this.messageRepositoryService = messageRepositoryService;
|
||||
this.projectRepositoryService = projectRepositoryService;
|
||||
this.mcpServerRepositoryService = mcpServerRepositoryService;
|
||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||
this.conversationRepositoryService = conversationRepositoryService;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
@@ -181,30 +190,51 @@ namespace xAiModels.Providers
|
||||
/// Load List of Conversations for Specified Project ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string ownerId = null,
|
||||
bool fillMessages = false,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (projectId.IsNull() ||
|
||||
projectId.IsDefaultGuid()
|
||||
)
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
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 ...
|
||||
var project = await projectRepositoryService.GetAsync(
|
||||
id: projectId,
|
||||
id: projectId.Value,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
@@ -262,26 +292,60 @@ namespace xAiModels.Providers
|
||||
/// Load Messages of Specified Conversation ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||
Guid conversationId,
|
||||
Guid? conversationId,
|
||||
string ownerId = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (conversationId.IsNull() ||
|
||||
conversationId.IsDefaultGuid()
|
||||
)
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
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(
|
||||
id: conversationId,
|
||||
includeBuilder: null,
|
||||
id: conversationId.Value,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -473,8 +537,12 @@ namespace xAiModels.Providers
|
||||
// Checking Resources ...
|
||||
|
||||
//
|
||||
// Titles ...
|
||||
#region Titles ...
|
||||
//
|
||||
var titleResource = string.Empty;
|
||||
|
||||
//
|
||||
// Provided in Locales ...
|
||||
if (!item.TitleResource.IsNullOrDefault() &&
|
||||
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;
|
||||
|
||||
//
|
||||
// Provided in Locales ...
|
||||
if (!item.DescriptionResource.IsNullOrDefault() &&
|
||||
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 ...
|
||||
result.Title = titleResource;
|
||||
@@ -654,7 +778,7 @@ namespace xAiModels.Providers
|
||||
/// <returns></returns>
|
||||
public async Task<XAiConversationDto> CreateConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
XAiConversationDto item = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -662,16 +786,34 @@ namespace xAiModels.Providers
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (projectId.IsNull() ||
|
||||
projectId.IsDefaultGuid())
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
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 ...
|
||||
XAiProjectDto project = await projectRepositoryService.GetAsync(
|
||||
id: projectId,
|
||||
id: projectId.Value,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
// fillConversations: false,
|
||||
@@ -725,8 +867,12 @@ namespace xAiModels.Providers
|
||||
// Checking Resources ...
|
||||
|
||||
//
|
||||
// Titles ...
|
||||
#region Titles ...
|
||||
//
|
||||
var titleResource = string.Empty;
|
||||
|
||||
//
|
||||
// Locales ...
|
||||
if (!item.TitleResource.IsNullOrDefault() &&
|
||||
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 ...
|
||||
result.Title = titleResource;
|
||||
@@ -802,7 +974,7 @@ namespace xAiModels.Providers
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
//`
|
||||
// Check Default Conversation ...
|
||||
else
|
||||
{
|
||||
@@ -1009,7 +1181,7 @@ namespace xAiModels.Providers
|
||||
/// <returns></returns>
|
||||
public async Task<XAiConversationDto> GetDefaultConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -1024,8 +1196,8 @@ namespace xAiModels.Providers
|
||||
//
|
||||
// Prepare Project ...
|
||||
XAiProjectDto project = null;
|
||||
if (projectId.IsNull() ||
|
||||
projectId.IsDefaultGuid()
|
||||
if (!projectId.HasValue ||
|
||||
projectId.Value.IsDefaultGuid()
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1039,7 +1211,7 @@ namespace xAiModels.Providers
|
||||
{
|
||||
//
|
||||
project = await projectRepositoryService.GetAsync(
|
||||
id: projectId,
|
||||
id: projectId.Value,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
@@ -1093,7 +1265,7 @@ namespace xAiModels.Providers
|
||||
var result = await conversationRepositoryService.FindOneAsync(
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x =>
|
||||
x.ProjectId == projectId &&
|
||||
x.ProjectId == project.Id &&
|
||||
x.Title == resource.ResourceTitle
|
||||
);
|
||||
|
||||
@@ -1149,6 +1321,111 @@ namespace xAiModels.Providers
|
||||
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>
|
||||
/// Query Conversations ...
|
||||
/// </summary>
|
||||
@@ -1218,75 +1495,6 @@ namespace xAiModels.Providers
|
||||
//
|
||||
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
|
||||
|
||||
//
|
||||
@@ -1533,7 +1741,7 @@ namespace xAiModels.Providers
|
||||
{
|
||||
//
|
||||
exists.Text = item.Text;
|
||||
exists.Embedding = item.Embedding.ToJSON();
|
||||
exists.Embedding = item.Embedding.ToEmbedding();
|
||||
exists.Type = item.Type.IsNullOrEmpty() ? exists.Type : item.Type;
|
||||
exists.Metadata = item.Metadata.IsNullOrDefault() ? exists.Metadata : item.Metadata.ToJSON();
|
||||
toUpdate.Add(exists);
|
||||
@@ -1547,7 +1755,7 @@ namespace xAiModels.Providers
|
||||
Type = item.Type,
|
||||
Identifier = item.Identifier,
|
||||
Metadata = item.Metadata.ToJSON(),
|
||||
Embedding = item.Embedding.ToJSON(),
|
||||
Embedding = item.Embedding.ToEmbedding(),
|
||||
Id = item.Id.IsDefaultGuid() ? Guid.NewGuid() : item.Id,
|
||||
});
|
||||
}
|
||||
@@ -1674,48 +1882,6 @@ namespace xAiModels.Providers
|
||||
|
||||
//
|
||||
#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>
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
@@ -1738,19 +1904,40 @@ namespace xAiModels.Providers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Items ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||
IEnumerable<XAiVectorDto> sources,
|
||||
public async Task<XAiVectorDto> Enrich(
|
||||
XAiVector source,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await vectorEnricher.EnrichRange(
|
||||
sources: sources,
|
||||
var result = await vectorEnricher.Enrich(
|
||||
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
|
||||
);
|
||||
|
||||
@@ -1786,26 +1973,20 @@ namespace xAiModels.Providers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Items ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XAiProjectDto>> EnrichRange(
|
||||
IEnumerable<XAiProjectDto> sources,
|
||||
bool fillConversations = false,
|
||||
bool fillConversationMessages = false,
|
||||
public async Task<XAiMcpServerDto> Enrich(
|
||||
XAiMcpServerDto source,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await projectEnricher.EnrichRange(
|
||||
sources: sources,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
var result = await mcpServerEnricher.Enrich(
|
||||
source: source,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
@@ -1840,19 +2021,16 @@ namespace xAiModels.Providers
|
||||
/// 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,
|
||||
public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||
IEnumerable<XAiVector> sources,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await conversationEnricher.EnrichRange(
|
||||
var result = await vectorEnricher.EnrichRange(
|
||||
sources: sources,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -1861,19 +2039,19 @@ namespace xAiModels.Providers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Item ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XAiMessageDto> Enrich(
|
||||
XAiMessageDto source,
|
||||
public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||
IEnumerable<XAiVectorDto> sources,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await messageEnricher.Enrich(
|
||||
source: source,
|
||||
var result = await vectorEnricher.EnrichRange(
|
||||
sources: sources,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -1881,6 +2059,33 @@ namespace xAiModels.Providers
|
||||
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>
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
@@ -1901,6 +2106,51 @@ namespace xAiModels.Providers
|
||||
//
|
||||
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
|
||||
|
||||
//
|
||||
@@ -2057,7 +2307,7 @@ namespace xAiModels.Providers
|
||||
/// <returns></returns>
|
||||
private async Task<bool> HasDefaultConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -2073,8 +2323,8 @@ namespace xAiModels.Providers
|
||||
//
|
||||
// Prepare Project ...
|
||||
XAiProjectDto project = null;
|
||||
if (projectId.IsNull() ||
|
||||
projectId.IsDefaultGuid()
|
||||
if (!projectId.HasValue ||
|
||||
projectId.Value.IsDefaultGuid()
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -2088,7 +2338,7 @@ namespace xAiModels.Providers
|
||||
{
|
||||
//
|
||||
project = await projectRepositoryService.GetAsync(
|
||||
id: projectId,
|
||||
id: projectId.Value,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
@@ -2124,7 +2374,7 @@ namespace xAiModels.Providers
|
||||
var defaultConversation = await conversationRepositoryService.FindOneAsync(
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x =>
|
||||
x.ProjectId == projectId &&
|
||||
x.ProjectId == project.Id &&
|
||||
x.Title == resource.ResourceTitle
|
||||
);
|
||||
result = !defaultConversation.IsNullOrDefault();
|
||||
@@ -2143,7 +2393,7 @@ namespace xAiModels.Providers
|
||||
/// <returns></returns>
|
||||
private async Task CreateDefaultConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -2162,8 +2412,8 @@ namespace xAiModels.Providers
|
||||
//
|
||||
// Prepare Project ...
|
||||
XAiProjectDto project = null;
|
||||
if (projectId.IsNull() ||
|
||||
projectId.IsDefaultGuid()
|
||||
if (!projectId.HasValue ||
|
||||
projectId.Value.IsDefaultGuid()
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -2177,7 +2427,7 @@ namespace xAiModels.Providers
|
||||
{
|
||||
//
|
||||
project = await projectRepositoryService.GetAsync(
|
||||
id: projectId,
|
||||
id: projectId.Value,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
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
@@ -25,7 +25,6 @@
|
||||
|
||||
<!-- Local Modules -->
|
||||
<ItemGroup>
|
||||
<!-- <PackageReference Include="xDashboard.xStringService" Version="1.0.0" /> -->
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Local Dependencies -->
|
||||
@@ -36,6 +35,7 @@
|
||||
<!-- Dependencies -->
|
||||
<ItemGroup>
|
||||
<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.OpenAI" Version="10.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user