Compare commits
14
Commits
5307fe4d2f
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a228439a5 | ||
|
|
13cd0745c6 | ||
|
|
5bccce3475 | ||
|
|
cddf2650f5 | ||
|
|
fba69b274c | ||
|
|
0077008105 | ||
|
|
3dc54332c2 | ||
|
|
dab384ea37 | ||
|
|
f6a916fa83 | ||
|
|
5656ec07d5 | ||
|
|
c24c14eb74 | ||
|
|
b58f1dd736 | ||
|
|
31add513bc | ||
|
|
16fb715926 |
@@ -1,6 +1,7 @@
|
|||||||
#
|
#
|
||||||
bin/*
|
bin/*
|
||||||
obj/*
|
obj/*
|
||||||
|
Logs
|
||||||
|
|
||||||
#
|
#
|
||||||
Db/*
|
Db/*
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace xAiApi.Constants
|
|||||||
public const string XAiApiContentExtractionPromptName = "ContentExtraction";
|
public const string XAiApiContentExtractionPromptName = "ContentExtraction";
|
||||||
|
|
||||||
//
|
//
|
||||||
public const string XAiDefaultModelName = "Gemma";
|
public const string XAiDefaultModelName = "Arion";
|
||||||
public const string XAiEmbeddingModelName = "Embed";
|
public const string XAiEmbeddingModelName = "Embed";
|
||||||
public const string XAiDefaultVisionModelName = "Qwen";
|
public const string XAiDefaultVisionModelName = "Qwen";
|
||||||
public const string XAiDefaultThinkingModelName = "Qwen";
|
public const string XAiDefaultThinkingModelName = "Qwen";
|
||||||
|
|||||||
@@ -536,6 +536,8 @@ namespace xAiApi.Controllers
|
|||||||
prompt: request.Prompt,
|
prompt: request.Prompt,
|
||||||
minScore: request.MinScore,
|
minScore: request.MinScore,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
|
extractFileContents: false,
|
||||||
|
addFilesToKnowledge: false,
|
||||||
projectId: request.ProjectId,
|
projectId: request.ProjectId,
|
||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken,
|
||||||
conversationId: request.ConversationId
|
conversationId: request.ConversationId
|
||||||
@@ -634,7 +636,7 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
[HttpGet("Projects/{projectId}/Conversations")]
|
[HttpGet("Projects/{projectId}/Conversations")]
|
||||||
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
||||||
[FromRoute] Guid projectId,
|
[FromRoute] Guid? projectId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -642,12 +644,44 @@ namespace xAiApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
var userInfo = await GetUserInfo();
|
||||||
if (projectId.IsDefaultGuid())
|
var connectionId = GetConnectionId();
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.LoadConversations(
|
||||||
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Specified AI Project's Conversations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
[HttpGet("Projects/Conversations")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadProjectConversations(
|
||||||
|
[FromQuery] Guid? projectId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var userInfo = await GetUserInfo();
|
var userInfo = await GetUserInfo();
|
||||||
var connectionId = GetConnectionId();
|
var connectionId = GetConnectionId();
|
||||||
@@ -655,6 +689,7 @@ namespace xAiApi.Controllers
|
|||||||
//
|
//
|
||||||
var result = await aiService.LoadConversations(
|
var result = await aiService.LoadConversations(
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -679,7 +714,7 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
[HttpGet("Conversations/{conversationId}/Messages")]
|
[HttpGet("Conversations/{conversationId}/Messages")]
|
||||||
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
||||||
[FromRoute] Guid conversationId,
|
[FromRoute] Guid? conversationId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -687,14 +722,52 @@ namespace xAiApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
var userInfo = await GetUserInfo();
|
||||||
if (conversationId.IsDefaultGuid())
|
var connectionId = GetConnectionId();
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await aiService.LoadMessages(
|
var result = await aiService.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
conversationId: conversationId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Specified AI Conversation's Messages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
[HttpGet("Conversations/Messages")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadConversationMessages(
|
||||||
|
[FromQuery] Guid? conversationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -949,6 +1022,63 @@ namespace xAiApi.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create an AI Conversation ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
[HttpPost("Projects/Conversations")]
|
||||||
|
public async Task<ActionResult<XAiConversationDto>> CreateProjectConversation(
|
||||||
|
[FromQuery] Guid? projectId,
|
||||||
|
[FromBody] XAiConversationDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (item.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update Required Params ...
|
||||||
|
item.OwnerId = userInfo.UserId;
|
||||||
|
if (!item.IsValidForAddOrUpdate())
|
||||||
|
{
|
||||||
|
XException.InvalidData.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.CreateConversation(
|
||||||
|
item: item,
|
||||||
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -325,5 +325,27 @@ namespace xAiApi.Extensions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ using System.Linq.Expressions;
|
|||||||
using xAiModels.Models.Entities;
|
using xAiModels.Models.Entities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using ModelContextProtocol.Client;
|
using ModelContextProtocol.Client;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
|
|
||||||
namespace xAiApi.Interfaces
|
namespace xAiApi.Interfaces
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,7 @@ namespace xAiApi.Interfaces
|
|||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IList<McpClientTool>> GetAvailableToolsAsync(
|
Task<IList<AITool>> GetAvailableToolsAsync(
|
||||||
bool forceOwner = false,
|
bool forceOwner = false,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -35,10 +36,14 @@ namespace xAiApi.Interfaces
|
|||||||
/// Test Specified Mcp Server ...
|
/// Test Specified Mcp Server ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server"></param>
|
/// <param name="server"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<string> TestServerAsync(
|
Task<string> TestServerAsync(
|
||||||
XAiMcpServerDto server,
|
XAiMcpServerDto server,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ namespace xAiApi.Interfaces
|
|||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="extractFileContents"></param>
|
||||||
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -144,6 +146,8 @@ namespace xAiApi.Interfaces
|
|||||||
Guid? projectId = null,
|
Guid? projectId = null,
|
||||||
Guid? conversationId = null,
|
Guid? conversationId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
|
bool extractFileContents = false,
|
||||||
|
bool addFilesToKnowledge = true,
|
||||||
IFormFileCollection files = null,
|
IFormFileCollection files = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -159,6 +163,8 @@ namespace xAiApi.Interfaces
|
|||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="extractFileContents"></param>
|
||||||
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -171,6 +177,8 @@ namespace xAiApi.Interfaces
|
|||||||
Guid? projectId = null,
|
Guid? projectId = null,
|
||||||
Guid? conversationId = null,
|
Guid? conversationId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
|
bool extractFileContents = false,
|
||||||
|
bool addFilesToKnowledge = true,
|
||||||
IFormFileCollection files = null,
|
IFormFileCollection files = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -198,11 +206,13 @@ namespace xAiApi.Interfaces
|
|||||||
/// Load Conversations of Specified AI Project ...
|
/// Load Conversations of Specified AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
|
string ownerId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -211,10 +221,14 @@ namespace xAiApi.Interfaces
|
|||||||
/// Load Messages of Specified Conversation ...
|
/// Load Messages of Specified Conversation ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||||
Guid conversationId,
|
Guid? conversationId,
|
||||||
|
string ownerId = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
@@ -293,7 +307,7 @@ namespace xAiApi.Interfaces
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XAiConversationDto> CreateConversation(
|
Task<XAiConversationDto> CreateConversation(
|
||||||
string ownerId,
|
string ownerId,
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
XAiConversationDto item,
|
XAiConversationDto item,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
|
|||||||
+5
-1
@@ -1,4 +1,5 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
using xLoggingService.DI;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
@@ -19,10 +20,13 @@ namespace xAiApi
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = Host.CreateDefaultBuilder(args)
|
var result = Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureLogging(logging =>
|
||||||
|
logging.AddXTelemetryLogger())
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
{
|
{
|
||||||
webBuilder.UseStartup<Startup>();
|
webBuilder.UseStartup<Startup>();
|
||||||
});
|
})
|
||||||
|
.AddXTelemetry();
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "weatherforecast",
|
"launchUrl": "weatherforecast",
|
||||||
"applicationUrl": "https://localhost:6001;http://localhost:6000",
|
"applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|||||||
+103
-26
@@ -27,6 +27,7 @@ using System.Collections.Generic;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using xAiApi.Interfaces.Extractors;
|
using xAiApi.Interfaces.Extractors;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using MongoDB.Driver.Core.Connections;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
@@ -129,7 +130,7 @@ namespace xAiApi.Providers
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
Options.Tools = [.. availableTools.Cast<AITool>()];
|
Options.Tools = [.. availableTools];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -389,7 +390,10 @@ namespace xAiApi.Providers
|
|||||||
connectionId: null,
|
connectionId: null,
|
||||||
conversationId: null,
|
conversationId: null,
|
||||||
persistPrompt: false,
|
persistPrompt: false,
|
||||||
|
additionalContents: null,
|
||||||
|
addFilesToKnowledge: false,
|
||||||
resolveConversation: false,
|
resolveConversation: false,
|
||||||
|
extractFileContents: false,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -470,7 +474,10 @@ namespace xAiApi.Providers
|
|||||||
connectionId: null,
|
connectionId: null,
|
||||||
conversationId: null,
|
conversationId: null,
|
||||||
persistPrompt: false,
|
persistPrompt: false,
|
||||||
|
additionalContents: null,
|
||||||
resolveConversation: false,
|
resolveConversation: false,
|
||||||
|
addFilesToKnowledge: false,
|
||||||
|
extractFileContents: false,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -522,6 +529,8 @@ namespace xAiApi.Providers
|
|||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="extractFileContents"></param>
|
||||||
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -534,6 +543,8 @@ namespace xAiApi.Providers
|
|||||||
Guid? projectId = null,
|
Guid? projectId = null,
|
||||||
Guid? conversationId = null,
|
Guid? conversationId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
|
bool extractFileContents = false,
|
||||||
|
bool addFilesToKnowledge = true,
|
||||||
IFormFileCollection files = null,
|
IFormFileCollection files = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -558,10 +569,13 @@ namespace xAiApi.Providers
|
|||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
persistPrompt: true,
|
persistPrompt: true,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
additionalContents: null,
|
||||||
resolveConversation: true,
|
resolveConversation: true,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken,
|
||||||
|
extractFileContents: extractFileContents,
|
||||||
|
addFilesToKnowledge: addFilesToKnowledge
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -625,6 +639,8 @@ namespace xAiApi.Providers
|
|||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="extractFileContents"></param>
|
||||||
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -637,6 +653,8 @@ namespace xAiApi.Providers
|
|||||||
Guid? projectId = null,
|
Guid? projectId = null,
|
||||||
Guid? conversationId = null,
|
Guid? conversationId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
|
bool extractFileContents = false,
|
||||||
|
bool addFilesToKnowledge = true,
|
||||||
IFormFileCollection files = null,
|
IFormFileCollection files = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
[EnumeratorCancellation]
|
[EnumeratorCancellation]
|
||||||
@@ -662,10 +680,13 @@ namespace xAiApi.Providers
|
|||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
persistPrompt: true,
|
persistPrompt: true,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
additionalContents: null,
|
||||||
resolveConversation: true,
|
resolveConversation: true,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken,
|
||||||
|
extractFileContents: extractFileContents,
|
||||||
|
addFilesToKnowledge: addFilesToKnowledge
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -816,24 +837,20 @@ namespace xAiApi.Providers
|
|||||||
/// Load Conversations of Specified AI Project ...
|
/// Load Conversations of Specified AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
public virtual async Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
|
string ownerId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (projectId.IsDefaultGuid())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await dataProvider.LoadConversations(
|
var result = await dataProvider.LoadConversations(
|
||||||
|
ownerId: ownerId,
|
||||||
fillMessages: false,
|
fillMessages: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
@@ -848,22 +865,21 @@ namespace xAiApi.Providers
|
|||||||
/// Load Messages of Specified Conversation ...
|
/// Load Messages of Specified Conversation ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
public virtual async Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||||
Guid conversationId,
|
Guid? conversationId,
|
||||||
|
string ownerId = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (conversationId.IsDefaultGuid())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await dataProvider.LoadMessages(
|
var result = await dataProvider.LoadMessages(
|
||||||
|
ownerId: ownerId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -1056,7 +1072,7 @@ namespace xAiApi.Providers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<XAiConversationDto> CreateConversation(
|
public virtual async Task<XAiConversationDto> CreateConversation(
|
||||||
string ownerId,
|
string ownerId,
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
XAiConversationDto item,
|
XAiConversationDto item,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -1465,17 +1481,20 @@ namespace xAiApi.Providers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve Prepared Chat Context ...
|
/// Retrieve Prepared Chat Context ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
/// <param name="topK"></param>
|
/// <param name="topK"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
/// <param name="minScore"></param>
|
/// <param name="minScore"></param>
|
||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="persistPrompt"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="resolveConversation"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="resolveConversation"></param>
|
/// <param name="extractFileContents"></param>
|
||||||
/// <param name="persistPrompt"></param>
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
|
/// <param name="additionalContents"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<XPreparedChatContext> PrepareChatRequirementsAsync(
|
private async Task<XPreparedChatContext> PrepareChatRequirementsAsync(
|
||||||
@@ -1490,6 +1509,8 @@ namespace xAiApi.Providers
|
|||||||
bool resolveConversation,
|
bool resolveConversation,
|
||||||
IFormFileCollection files,
|
IFormFileCollection files,
|
||||||
XUserClaimsInfoDto userInfo,
|
XUserClaimsInfoDto userInfo,
|
||||||
|
bool extractFileContents = true,
|
||||||
|
bool addFilesToKnowledge = false,
|
||||||
IList<AIContent> additionalContents = null,
|
IList<AIContent> additionalContents = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -1580,7 +1601,8 @@ namespace xAiApi.Providers
|
|||||||
// Ingest Files if Provided and also Resolve Conversation Flagged ...
|
// Ingest Files if Provided and also Resolve Conversation Flagged ...
|
||||||
if (
|
if (
|
||||||
files.HasChild() &&
|
files.HasChild() &&
|
||||||
resolveConversation
|
resolveConversation &&
|
||||||
|
addFilesToKnowledge
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1623,6 +1645,59 @@ namespace xAiApi.Providers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If there isn't Files need to add Files to Knowledge ...
|
||||||
|
if (files.HasChild() &&
|
||||||
|
!addFilesToKnowledge
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Extract File Content and add them to Additional Contents ...
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var mimeType = file.ContentType?.ToLowerInvariant() ?? string.Empty;
|
||||||
|
if (mimeType.IsNullOrEmpty() ||
|
||||||
|
!fileContentExtractor.CanExtract(mimeType))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
using var stream = file.OpenReadStream();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Extract File Content if necessary ...
|
||||||
|
if (extractFileContents)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var content = await fileContentExtractor.ExtractAsync(
|
||||||
|
fileStream: stream,
|
||||||
|
mimeType: mimeType,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (!content.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var fileContent = new TextContent($"File:{Environment.NewLine}{file.FileName}{Environment.NewLine}{content}");
|
||||||
|
additionalContents = [.. additionalContents, fileContent];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var fileContent = await DataContent.LoadFromAsync(stream, mimeType, cancellationToken);
|
||||||
|
if (additionalContents.IsNull())
|
||||||
|
{
|
||||||
|
additionalContents = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
additionalContents = [.. additionalContents, fileContent];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Request Knowledge ...
|
// Request Knowledge ...
|
||||||
var knowledgeRequest = new XAiKnowledgeAskRequest
|
var knowledgeRequest = new XAiKnowledgeAskRequest
|
||||||
@@ -1653,6 +1728,8 @@ namespace xAiApi.Providers
|
|||||||
// Retrieve Conversation Message ...
|
// Retrieve Conversation Message ...
|
||||||
var messages = await dataProvider
|
var messages = await dataProvider
|
||||||
.LoadMessages(
|
.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId.Value,
|
conversationId: conversationId.Value,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|||||||
+298
-113
@@ -7,22 +7,26 @@ using xAiApi.Interfaces;
|
|||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xAiModels.Constants;
|
using xAiModels.Constants;
|
||||||
|
using xAiService.Services;
|
||||||
using xAiModels.Extensions;
|
using xAiModels.Extensions;
|
||||||
|
using xAiService.Extensions;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xAiModels.Models.Dtos;
|
using xAiModels.Models.Dtos;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
using xAiModels.Providers.Hubs;
|
using xAiModels.Providers.Hubs;
|
||||||
using xAiModels.Models.Entities;
|
using xAiModels.Models.Entities;
|
||||||
using xAiModels.Interfaces.Dtos;
|
using xAiModels.Interfaces.Dtos;
|
||||||
using xIdentityHelper.Extensions;
|
using xIdentityHelper.Extensions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using ModelContextProtocol.Client;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using xAiModels.Interfaces.Entities;
|
using xAiModels.Interfaces.Entities;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using xAiModels.Interfaces.Enrichers;
|
using xAiModels.Interfaces.Enrichers;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
@@ -32,6 +36,12 @@ namespace xAiApi.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class XAiMcpServerProvider : IXAiMcpServerProvider, IAsyncDisposable
|
public class XAiMcpServerProvider : IXAiMcpServerProvider, IAsyncDisposable
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
private readonly XAiMcpSessionStore sessionStore;
|
||||||
|
private readonly XAiMcpHttpTransport mcpTransport;
|
||||||
|
|
||||||
|
//
|
||||||
|
private readonly XAppConfiguration configuration;
|
||||||
private readonly IHubContext<XAiDataProviderHub> hub;
|
private readonly IHubContext<XAiDataProviderHub> hub;
|
||||||
private readonly IXIdentityProvider identityProvider;
|
private readonly IXIdentityProvider identityProvider;
|
||||||
private readonly ILogger<XAiMcpServerProvider> logger;
|
private readonly ILogger<XAiMcpServerProvider> logger;
|
||||||
@@ -40,13 +50,20 @@ namespace xAiApi.Providers
|
|||||||
private readonly IXAiMcpServerServiceProvider mcpServerServiceProvider;
|
private readonly IXAiMcpServerServiceProvider mcpServerServiceProvider;
|
||||||
private readonly IXAiMcpServerRepositoryProvider mcpServerRepositoryProvider;
|
private readonly IXAiMcpServerRepositoryProvider mcpServerRepositoryProvider;
|
||||||
|
|
||||||
private readonly Dictionary<Guid, McpClient> clients = [];
|
//
|
||||||
private readonly Dictionary<Guid, XAiMcpServerDto> mcpServers = [];
|
private readonly ConcurrentDictionary<Guid, XAiMcpServerDto> mcpServers = [];
|
||||||
private readonly Dictionary<Guid, IList<McpClientTool>> tools = [];
|
private readonly ConcurrentDictionary<(Guid, string), DateTime> clientExpirations = new();
|
||||||
private readonly SemaphoreSlim initLock = new(1, 1);
|
private readonly ConcurrentDictionary<(Guid ServerId, string UserId), XAiMcpClient> clients = new();
|
||||||
|
private readonly ConcurrentDictionary<(Guid ServerId, string UserId), IList<AITool>> tools = new();
|
||||||
|
|
||||||
|
//
|
||||||
private bool isInitialized = false;
|
private bool isInitialized = false;
|
||||||
|
private readonly SemaphoreSlim initLock = new(1, 1);
|
||||||
|
|
||||||
public XAiMcpServerProvider(
|
public XAiMcpServerProvider(
|
||||||
|
XAiMcpSessionStore sessionStore,
|
||||||
|
XAppConfiguration configuration,
|
||||||
|
XAiMcpHttpTransport mcpTransport,
|
||||||
IHubContext<XAiDataProviderHub> hub,
|
IHubContext<XAiDataProviderHub> hub,
|
||||||
IXIdentityProvider identityProvider,
|
IXIdentityProvider identityProvider,
|
||||||
ILogger<XAiMcpServerProvider> logger,
|
ILogger<XAiMcpServerProvider> logger,
|
||||||
@@ -56,9 +73,12 @@ namespace xAiApi.Providers
|
|||||||
IXAiMcpServerRepositoryProvider mcpServerRepositoryProvider
|
IXAiMcpServerRepositoryProvider mcpServerRepositoryProvider
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
this.configuration = configuration;
|
||||||
//
|
//
|
||||||
this.hub = hub;
|
this.hub = hub;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.sessionStore = sessionStore;
|
||||||
|
this.mcpTransport = mcpTransport;
|
||||||
this.identityProvider = identityProvider;
|
this.identityProvider = identityProvider;
|
||||||
this.mcpServerEnricher = mcpServerEnricher;
|
this.mcpServerEnricher = mcpServerEnricher;
|
||||||
this.validationProvider = validationProvider;
|
this.validationProvider = validationProvider;
|
||||||
@@ -89,7 +109,7 @@ namespace xAiApi.Providers
|
|||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IList<McpClientTool>> GetAvailableToolsAsync(
|
public async Task<IList<AITool>> GetAvailableToolsAsync(
|
||||||
bool forceOwner = false,
|
bool forceOwner = false,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -110,78 +130,97 @@ namespace xAiApi.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check Initialization ...
|
// Load Servers Metadata ...
|
||||||
if (isInitialized)
|
await EnsureServersLoadedAsync(cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Extract Accessible Mcp Servers ...
|
||||||
|
var accessibleServers = mcpServers.Values
|
||||||
|
.Where(s => s.OwnerId == userInfo.UserId ||
|
||||||
|
s.Scope == XAiMcpServerUsageScope.All)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create User Speciic Client Connection ...
|
||||||
|
foreach (var server in accessibleServers)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var selectedServers = mcpServers
|
// Create User Specific Client Key ...
|
||||||
.Where(s =>
|
var key = (server.Id, userInfo.UserId);
|
||||||
s.Value.OwnerId == userInfo.UserId ||
|
|
||||||
s.Value.Scope == XAiMcpServerUsageScope.All
|
//
|
||||||
)
|
// Check Expiration ...
|
||||||
.Select(s => s.Key);
|
if (clients.ContainsKey(key) &&
|
||||||
var result = tools
|
clientExpirations.TryGetValue(key, out var exp) &&
|
||||||
.Where(c => selectedServers.Contains(c.Key))
|
exp < DateTime.UtcNow)
|
||||||
.SelectMany(c => c.Value);
|
{
|
||||||
return [.. result];
|
//
|
||||||
|
// Remove Expired Client and Tools ...
|
||||||
|
if (clients.TryRemove(key, out var old))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await old.DisposeAsync();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
tools.TryRemove(key, out _);
|
||||||
|
clientExpirations.TryRemove(key, out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (clients.ContainsKey(key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (!clients.ContainsKey(key))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await ConnectAndValidateAsync(
|
||||||
|
descriptor: server,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
await initLock.WaitAsync(cancellationToken);
|
// Extract User Specified Mcp Client Tools ...
|
||||||
try
|
var result = tools
|
||||||
{
|
.Where(kv => kv.Key.UserId == userInfo.UserId)
|
||||||
//
|
.SelectMany(kv => kv.Value)
|
||||||
if (isInitialized)
|
.ToList();
|
||||||
{
|
|
||||||
//
|
|
||||||
var selectedServers = mcpServers
|
|
||||||
.Where(s =>
|
|
||||||
s.Value.OwnerId == userInfo.UserId ||
|
|
||||||
s.Value.Scope == XAiMcpServerUsageScope.All
|
|
||||||
)
|
|
||||||
.Select(s => s.Key);
|
|
||||||
var result = tools
|
|
||||||
.Where(c => selectedServers.Contains(c.Key))
|
|
||||||
.SelectMany(c => c.Value);
|
|
||||||
return [.. result];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var servers = await mcpServerServiceProvider
|
return result;
|
||||||
.FindManyAsync(
|
|
||||||
orderBuilder: null,
|
|
||||||
includeBuilder: null,
|
|
||||||
ignoreSoftDeleteds: true,
|
|
||||||
predicate: x => x.Enabled,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
if (servers.HasChild())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var tasks = servers
|
|
||||||
.Select(s =>
|
|
||||||
ConnectAndValidateAsync(s, userInfo, cancellationToken));
|
|
||||||
await Task.WhenAll(tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
isInitialized = true;
|
|
||||||
return [.. tools.Values.SelectMany(t => t)];
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
initLock.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test Specified Mcp Server ...
|
/// Test Specified Mcp Server ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server"></param>
|
/// <param name="server"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<string> TestServerAsync(
|
public async Task<string> TestServerAsync(
|
||||||
XAiMcpServerDto server,
|
XAiMcpServerDto server,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -193,8 +232,8 @@ namespace xAiApi.Providers
|
|||||||
cts.CancelAfter(TimeSpan.FromSeconds(server.TimeoutSeconds));
|
cts.CancelAfter(TimeSpan.FromSeconds(server.TimeoutSeconds));
|
||||||
|
|
||||||
//
|
//
|
||||||
var client = await CreateClientAsync(server, cts.Token);
|
var client = CreateClientAsync(server, connectionId, userInfo);
|
||||||
await client.PingAsync(cancellationToken: cts.Token);
|
// await client.PingAsync(cancellationToken: cts.Token);
|
||||||
var serverTools = await client.ListToolsAsync(cancellationToken: cts.Token);
|
var serverTools = await client.ListToolsAsync(cancellationToken: cts.Token);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -220,7 +259,8 @@ namespace xAiApi.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (!userInfo.IsAdmin()) {
|
if (!userInfo.IsAdmin())
|
||||||
|
{
|
||||||
XException.NotAllowed.Throw();
|
XException.NotAllowed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +370,9 @@ namespace xAiApi.Providers
|
|||||||
await initLock.WaitAsync(cancellationToken);
|
await initLock.WaitAsync(cancellationToken);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ConnectAndValidateAsync(result, userInfo, cancellationToken);
|
//
|
||||||
|
mcpServers[result.Id] = result;
|
||||||
|
await ConnectAndValidateAsync(result, connectionId, userInfo);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -490,14 +532,30 @@ namespace xAiApi.Providers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Remove Exists ...
|
mcpServers[result.Id] = result;
|
||||||
tools.Remove(result.Id);
|
|
||||||
clients.Remove(result.Id);
|
|
||||||
mcpServers.Remove(result.Id);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Update ...
|
// Remove Exists ...
|
||||||
await ConnectAndValidateAsync(result, userInfo, cancellationToken);
|
var keysToRemove = clients.Keys
|
||||||
|
.Where(k => k.ServerId == result.Id)
|
||||||
|
.ToList();
|
||||||
|
foreach (var key in keysToRemove)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (clients.TryRemove(key, out var old))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await old.DisposeAsync();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
tools.TryRemove(key, out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reconnect ...
|
||||||
|
await ConnectAndValidateAsync(result, connectionId, userInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -587,10 +645,30 @@ namespace xAiApi.Providers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Remove Exists ...
|
// Remove Server Descriptor ...
|
||||||
tools.Remove(result.Id);
|
mcpServers.TryRemove(result.Id, out _);
|
||||||
clients.Remove(result.Id);
|
|
||||||
mcpServers.Remove(result.Id);
|
//
|
||||||
|
// Disconnect all Connections ...
|
||||||
|
var keysToRemove = clients.Keys
|
||||||
|
.Where(k => k.ServerId == result.Id)
|
||||||
|
.ToList();
|
||||||
|
foreach (var key in keysToRemove)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (clients.TryRemove(key, out var c))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await c.DisposeAsync();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
tools.TryRemove(key, out _);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -681,10 +759,30 @@ namespace xAiApi.Providers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Remove Exists ...
|
// Remove Server Descriptor ...
|
||||||
tools.Remove(exists.Id);
|
mcpServers.TryRemove(exists.Id, out _);
|
||||||
clients.Remove(exists.Id);
|
|
||||||
mcpServers.Remove(exists.Id);
|
//
|
||||||
|
// Disconnect all Connections ...
|
||||||
|
var keysToRemove = clients.Keys
|
||||||
|
.Where(k => k.ServerId == exists.Id)
|
||||||
|
.ToList();
|
||||||
|
foreach (var key in keysToRemove)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (clients.TryRemove(key, out var c))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await c.DisposeAsync();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
tools.TryRemove(key, out _);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -774,7 +872,9 @@ namespace xAiApi.Providers
|
|||||||
await initLock.WaitAsync(cancellationToken);
|
await initLock.WaitAsync(cancellationToken);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ConnectAndValidateAsync(exists, userInfo, cancellationToken);
|
//
|
||||||
|
mcpServers[exists.Id] = exists;
|
||||||
|
await ConnectAndValidateAsync(exists, connectionId, userInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -860,17 +960,40 @@ namespace xAiApi.Providers
|
|||||||
await initLock.WaitAsync(cancellationToken);
|
await initLock.WaitAsync(cancellationToken);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//
|
||||||
if (exists.Enabled)
|
if (exists.Enabled)
|
||||||
{
|
{
|
||||||
await ConnectAndValidateAsync(exists, userInfo, cancellationToken);
|
//
|
||||||
|
mcpServers[exists.Id] = exists;
|
||||||
|
await ConnectAndValidateAsync(exists, connectionId, userInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Remove Exists ...
|
// Remove Server Descriptor ...
|
||||||
tools.Remove(exists.Id);
|
mcpServers.TryRemove(exists.Id, out _);
|
||||||
clients.Remove(exists.Id);
|
|
||||||
mcpServers.Remove(exists.Id);
|
//
|
||||||
|
// Disconnect all Connections ...
|
||||||
|
var keysToRemove = clients.Keys
|
||||||
|
.Where(k => k.ServerId == exists.Id)
|
||||||
|
.ToList();
|
||||||
|
foreach (var key in keysToRemove)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (clients.TryRemove(key, out var c))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await c.DisposeAsync();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
tools.TryRemove(key, out _);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -1178,29 +1301,31 @@ namespace xAiApi.Providers
|
|||||||
=> json.IsNullOrEmpty() ? null
|
=> json.IsNullOrEmpty() ? null
|
||||||
: JsonSerializer.Deserialize<List<string>>(json);
|
: JsonSerializer.Deserialize<List<string>>(json);
|
||||||
|
|
||||||
private static async Task<McpClient> CreateClientAsync(
|
private XAiMcpClient CreateClientAsync(
|
||||||
XAiMcpServerDto s,
|
XAiMcpServerDto descriptor,
|
||||||
CancellationToken cancellationToken
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
IClientTransport transport = new HttpClientTransport(new HttpClientTransportOptions
|
var result = new XAiMcpClient(
|
||||||
{
|
logger: logger,
|
||||||
Endpoint = new Uri(s.Endpoint!),
|
userInfo: userInfo,
|
||||||
AdditionalHeaders = ParseJsonDict(s.Headers),
|
transport: mcpTransport,
|
||||||
TransportMode = HttpTransportMode.AutoDetect
|
serverId: descriptor.Id,
|
||||||
});
|
sessionStore: sessionStore,
|
||||||
|
connectionId: connectionId,
|
||||||
|
appConfiguration: configuration,
|
||||||
|
endpoint: new Uri(descriptor.Endpoint)
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return await McpClient
|
return result;
|
||||||
.CreateAsync(
|
|
||||||
transport,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ConnectAndValidateAsync(
|
private async Task ConnectAndValidateAsync(
|
||||||
XAiMcpServerDto descriptor,
|
XAiMcpServerDto descriptor,
|
||||||
|
string connectionId = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -1209,30 +1334,43 @@ namespace xAiApi.Providers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
// Create Specified Cancellation Token ...
|
||||||
|
using var cts = CancellationTokenSource
|
||||||
|
.CreateLinkedTokenSource(cancellationToken);
|
||||||
cts.CancelAfter(TimeSpan.FromSeconds(descriptor.TimeoutSeconds));
|
cts.CancelAfter(TimeSpan.FromSeconds(descriptor.TimeoutSeconds));
|
||||||
|
|
||||||
//
|
//
|
||||||
var client = await CreateClientAsync(descriptor, cts.Token);
|
var client = CreateClientAsync(
|
||||||
await client.PingAsync(cancellationToken: cts.Token);
|
userInfo: userInfo,
|
||||||
var serverTools = await client
|
descriptor: descriptor,
|
||||||
.ListToolsAsync(
|
connectionId: connectionId
|
||||||
cancellationToken: cts.Token
|
);
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
clients[descriptor.Id] = client;
|
await client.InitializeAsync(cts.Token);
|
||||||
tools[descriptor.Id] = serverTools;
|
|
||||||
|
//
|
||||||
|
var clientTools = await client.ListToolsAsync(cts.Token);
|
||||||
|
var aiTools = clientTools.ToAITools(client);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Key for Cache ...
|
||||||
|
var key = (descriptor.Id, userInfo.UserId);
|
||||||
|
|
||||||
|
//
|
||||||
|
tools[key] = aiTools;
|
||||||
|
clients[key] = client;
|
||||||
mcpServers[descriptor.Id] = descriptor;
|
mcpServers[descriptor.Id] = descriptor;
|
||||||
|
clientExpirations[key] = DateTime.UtcNow.AddMinutes(15);
|
||||||
|
|
||||||
//
|
//
|
||||||
logger.LogInformation(
|
logger.LogInformation(
|
||||||
"MCP '{Name}': {Count} Tools Detected ...",
|
"MCP '{Name}': {Count} Tools Detected for {UserId} ...",
|
||||||
descriptor.Name,
|
descriptor.Name,
|
||||||
serverTools.Count
|
aiTools.Count,
|
||||||
|
userInfo.UserId
|
||||||
);
|
);
|
||||||
}
|
} catch(Exception ex)
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
logger.LogWarning(ex,
|
logger.LogWarning(ex,
|
||||||
@@ -1241,6 +1379,53 @@ namespace xAiApi.Providers
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task EnsureServersLoadedAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (isInitialized)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (isInitialized)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var servers = await mcpServerServiceProvider.FindManyAsync(
|
||||||
|
orderBuilder: null,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
predicate: x => x.Enabled,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (servers.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
foreach (var s in servers)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
mcpServers[s.Id] = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
isInitialized = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
+28
-1
@@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using xAiApi.DI;
|
using xAiApi.DI;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using xAiModels.DI;
|
using xAiModels.DI;
|
||||||
|
using xAiService.DI;
|
||||||
using xTagService.DI;
|
using xTagService.DI;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using xAiApi.Database;
|
using xAiApi.Database;
|
||||||
@@ -14,6 +15,7 @@ using Newtonsoft.Json;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using xStringService.DI;
|
using xStringService.DI;
|
||||||
|
using xLoggingService.DI;
|
||||||
using xStorageService.DI;
|
using xStorageService.DI;
|
||||||
using xIdentityService.DI;
|
using xIdentityService.DI;
|
||||||
using xDataService.Models;
|
using xDataService.Models;
|
||||||
@@ -69,6 +71,10 @@ namespace xAiApi
|
|||||||
services.AddXAppConfiguration(Configuration);
|
services.AddXAppConfiguration(Configuration);
|
||||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Logging Service ...
|
||||||
|
services.AddXLoggingService(Configuration);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register Allowed Origins ...
|
// Register Allowed Origins ...
|
||||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
services.AddXCors(appConfiguration.AllowedOrigins);
|
||||||
@@ -200,6 +206,10 @@ namespace xAiApi
|
|||||||
// Register Chat With Documents Services (Text Chunker + In-Memory Vector Store) ...
|
// Register Chat With Documents Services (Text Chunker + In-Memory Vector Store) ...
|
||||||
services.AddXAiChatWithDocuments();
|
services.AddXAiChatWithDocuments();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register XAiMcpClient ...
|
||||||
|
services.AddXAiMcpClient();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Persistent RAG (Knowledge over XAiVector Table) ...
|
// Persistent RAG (Knowledge over XAiVector Table) ...
|
||||||
services.AddXRagService();
|
services.AddXRagService();
|
||||||
@@ -209,7 +219,10 @@ namespace xAiApi
|
|||||||
services.AddXAiServices();
|
services.AddXAiServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(
|
||||||
|
IApplicationBuilder app,
|
||||||
|
IWebHostEnvironment env
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -226,6 +239,10 @@ namespace xAiApi
|
|||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Environment in App Confiuration ...
|
||||||
|
app.AddEnvironmentToXAppConfiguration(env.EnvironmentName);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Force Https Redirection ...
|
// Force Https Redirection ...
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
@@ -254,6 +271,13 @@ namespace xAiApi
|
|||||||
// Using Routing ...
|
// Using Routing ...
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Using Request Logging ...
|
||||||
|
if (!isDevelopmentEnvironment)
|
||||||
|
{
|
||||||
|
app.UseXRequestLogger();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use xIdentityService (Authentication) ...
|
// Use xIdentityService (Authentication) ...
|
||||||
app.UseXIdentityService();
|
app.UseXIdentityService();
|
||||||
@@ -310,3 +334,6 @@ namespace xAiApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
{
|
{
|
||||||
"AllowedOrigins": [
|
"AllowedOrigins": [
|
||||||
|
"http://127.0.0.1:5500",
|
||||||
"http://localhost:5000",
|
"http://localhost:5000",
|
||||||
"https://localhost:5001",
|
"https://localhost:5001",
|
||||||
"http://api.saherelm.ir",
|
"http://api.saherelm.ir",
|
||||||
"https://api.saherelm.ir",
|
"https://api.saherelm.ir",
|
||||||
"http://api.saherelmhub.ir",
|
"http://api.saherelmhub.ir",
|
||||||
|
"http://192.168.11.29:5173",
|
||||||
|
"http://192.168.11.29:5174",
|
||||||
"https://api.saherelmhub.ir"
|
"https://api.saherelmhub.ir"
|
||||||
],
|
],
|
||||||
"IdentityServiceConfiguration": {
|
"IdentityServiceConfiguration": {
|
||||||
@@ -37,9 +40,16 @@
|
|||||||
},
|
},
|
||||||
"AiApiConfiguration": {
|
"AiApiConfiguration": {
|
||||||
"Models": [
|
"Models": [
|
||||||
|
{
|
||||||
|
"Name": "Arion",
|
||||||
|
"Provider": "OpenAI",
|
||||||
|
"LLM": "claude-fable-5-1",
|
||||||
|
"Url": "https://arionhub.pro/v1",
|
||||||
|
"ApiKey": "sk-AKJGD8J9gOCrQgc5oWPGtRGUo25PnnQGnMoipzdliYHa3otZ"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ApiKey": "",
|
"ApiKey": "",
|
||||||
"Name": "Gemma",
|
"Name": "Gemma_BKP",
|
||||||
"LLM": "gemma3:1b",
|
"LLM": "gemma3:1b",
|
||||||
"Provider": "OpenAI",
|
"Provider": "OpenAI",
|
||||||
"Url": "http://178.131.88.93:1112/v1"
|
"Url": "http://178.131.88.93:1112/v1"
|
||||||
|
|||||||
+33
-1
@@ -4,6 +4,7 @@
|
|||||||
"DefaultLanguage": "fa-IR",
|
"DefaultLanguage": "fa-IR",
|
||||||
"XPoweredValue": "SaherElmITCenter",
|
"XPoweredValue": "SaherElmITCenter",
|
||||||
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
||||||
|
"DefaultCacheTtlMinutes": 10,
|
||||||
"AllowedOrigins": [
|
"AllowedOrigins": [
|
||||||
"http://api.saherelm.ir",
|
"http://api.saherelm.ir",
|
||||||
"https://api.saherelm.ir",
|
"https://api.saherelm.ir",
|
||||||
@@ -22,7 +23,6 @@
|
|||||||
"DefaultValues": {
|
"DefaultValues": {
|
||||||
"version": "1.0"
|
"version": "1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"HttpServiceConfiguration": {
|
"HttpServiceConfiguration": {
|
||||||
"DisableSSLCheck": true,
|
"DisableSSLCheck": true,
|
||||||
@@ -52,6 +52,38 @@
|
|||||||
"BaseRoute": "hubs",
|
"BaseRoute": "hubs",
|
||||||
"AddSupportMessageProtocol": true
|
"AddSupportMessageProtocol": true
|
||||||
},
|
},
|
||||||
|
"LoggingServiceConfiguration": {
|
||||||
|
"Enabled": true,
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"Queue": {
|
||||||
|
"Enabled": true,
|
||||||
|
"Capacity": 10000,
|
||||||
|
"ShutdownTimeoutSeconds": 10
|
||||||
|
},
|
||||||
|
"File": {
|
||||||
|
"Enabled": true,
|
||||||
|
"Directory": "./Logs",
|
||||||
|
"FileName": "xAiApi-.log",
|
||||||
|
"Format": "Json",
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"RetainedFileCountLimit": 30
|
||||||
|
},
|
||||||
|
"Database": {
|
||||||
|
"Enabled": false,
|
||||||
|
"TableName": "XLogs",
|
||||||
|
"AutoCreateTable": true,
|
||||||
|
"MinimumLevel": "Warning",
|
||||||
|
"Provider": "Microsoft.Data.Sqlite",
|
||||||
|
"ConnectionString": "Filename=./Db/XLogs.db"
|
||||||
|
},
|
||||||
|
"Event": {
|
||||||
|
"Enabled": false,
|
||||||
|
"Sender": "xAiApi",
|
||||||
|
"MinimumLevel": "Error",
|
||||||
|
"Topic": "application-logs",
|
||||||
|
"Action": "ApplicationLogCreated"
|
||||||
|
}
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
+2
-1
@@ -17,8 +17,8 @@
|
|||||||
<PackageIcon>icon.png</PackageIcon>
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
|
||||||
<!-- Fix Duplicate TargetFramework Issue -->
|
<!-- Fix Duplicate TargetFramework Issue -->
|
||||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- Icon Handling -->
|
<!-- Icon Handling -->
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
<ProjectReference Include="../Modules/xHttpService/xHttpService.csproj" />
|
<ProjectReference Include="../Modules/xHttpService/xHttpService.csproj" />
|
||||||
<ProjectReference Include="../Modules/xFileService/xFileService.csproj" />
|
<ProjectReference Include="../Modules/xFileService/xFileService.csproj" />
|
||||||
<ProjectReference Include="../Modules/xStorageService/xStorageService.csproj" />
|
<ProjectReference Include="../Modules/xStorageService/xStorageService.csproj" />
|
||||||
|
<ProjectReference Include="..\Modules\xLoggingService\xLoggingService.csproj" />
|
||||||
<ProjectReference Include="../Modules/xIdentityHelper/xIdentityHelper.csproj" />
|
<ProjectReference Include="../Modules/xIdentityHelper/xIdentityHelper.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user