This commit is contained in:
2026-09-29 17:41:17 +03:30
parent 5d3601ba44
commit f48b9257a3
3 changed files with 265 additions and 29 deletions
+10 -12
View File
@@ -28,7 +28,6 @@ namespace xAiModels.Extensions
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty() &&
!source.Title.IsNullOrEmpty() &&
!source.Prompt.IsNullOrEmpty(); !source.Prompt.IsNullOrEmpty();
// //
@@ -40,7 +39,6 @@ namespace xAiModels.Extensions
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty() &&
!source.Title.IsNullOrEmpty() &&
!source.Prompt.IsNullOrEmpty(); !source.Prompt.IsNullOrEmpty();
// //
@@ -58,7 +56,6 @@ namespace xAiModels.Extensions
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty() &&
!source.Title.IsNullOrEmpty() &&
!source.ProjectId.IsNull() && !source.ProjectId.IsNull() &&
!source.ProjectId.IsDefaultGuid(); !source.ProjectId.IsDefaultGuid();
@@ -71,7 +68,6 @@ namespace xAiModels.Extensions
var result = var result =
!source.IsNullOrDefault() && !source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() && !source.OwnerId.IsNullOrEmpty() &&
!source.Title.IsNullOrEmpty() &&
!source.ProjectId.IsNull() && !source.ProjectId.IsNull() &&
!source.ProjectId.IsDefaultGuid(); !source.ProjectId.IsDefaultGuid();
@@ -222,7 +218,7 @@ namespace xAiModels.Extensions
.Contains(ownerId.ToNormalString()) && .Contains(ownerId.ToNormalString()) &&
x.Title x.Title
.ToNormalString() .ToNormalString()
.Contains(XAiModelsConstants.DefaultXAiProjectDescriptionResourceID) .Contains(XAiModelsConstants.DefaultXAiProjectDescriptionResourceID.ToNormalString())
); );
// //
@@ -287,7 +283,7 @@ namespace xAiModels.Extensions
{ {
// //
// Validate Args ... // Validate Args ...
if (source.HasChild() || if (!source.HasChild() ||
ownerId.IsNullOrEmpty()) ownerId.IsNullOrEmpty())
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
@@ -301,7 +297,7 @@ namespace xAiModels.Extensions
.Contains(ownerId.ToNormalString()) && .Contains(ownerId.ToNormalString()) &&
x.Title x.Title
.ToNormalString() .ToNormalString()
.Contains(XAiModelsConstants.DefaultXAiProjectDescriptionResourceID) .Contains(XAiModelsConstants.XAiProjectTitleIdentifier.ToNormalString())
); );
if (item.IsNullOrDefault()) if (item.IsNullOrDefault())
{ {
@@ -327,7 +323,8 @@ namespace xAiModels.Extensions
{ {
// //
// Validate Args ... // Validate Args ...
if (source.HasChild() || if (!source.HasChild() ||
ownerId.IsNullOrEmpty() ||
projectId.IsDefaultGuid()) projectId.IsDefaultGuid())
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
@@ -341,11 +338,12 @@ namespace xAiModels.Extensions
.Contains(ownerId.ToNormalString()) && .Contains(ownerId.ToNormalString()) &&
x.Title x.Title
.ToNormalString() .ToNormalString()
.Contains(projectId.ToString().ToNormalString()) && .Contains(XAiModelsConstants.XAiConversationTitleIdentifier.ToNormalString())
x.Title
.ToNormalString()
.Contains(XAiModelsConstants.DefaultXAiConversationTitleResourceID)
); );
if (item.IsNullOrDefault())
{
XException.NotFound.Throw();
}
// //
var result = item.Id; var result = item.Id;
+2
View File
@@ -222,12 +222,14 @@ namespace xAiModels.Interfaces
/// <summary> /// <summary>
/// Create Conversation ... /// Create Conversation ...
/// </summary> /// </summary>
/// <param name="ownerId"></param>
/// <param name="projectId"></param> /// <param name="projectId"></param>
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
Task<XAiConversationDto> CreateConversation( Task<XAiConversationDto> CreateConversation(
string ownerId,
Guid projectId, Guid projectId,
XAiConversationDto item = null, XAiConversationDto item = null,
string connectionId = null, string connectionId = null,
+252 -16
View File
@@ -397,6 +397,14 @@ namespace xAiModels.Providers
// //
#region Creator/Adders ... #region Creator/Adders ...
/// <summary>
/// Create Project ...
/// </summary>
/// <param name="ownerId"></param>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XAiProjectDto> CreateProject( public async Task<XAiProjectDto> CreateProject(
string ownerId, string ownerId,
XAiProjectDto item = null, XAiProjectDto item = null,
@@ -420,6 +428,7 @@ namespace xAiModels.Providers
if (hasProject) if (hasProject)
{ {
// //
item.OwnerId = ownerId;
item.CreatedOn = DateTime.UtcNow; item.CreatedOn = DateTime.UtcNow;
// //
@@ -432,18 +441,132 @@ namespace xAiModels.Providers
// //
XAiProjectDto result = null; XAiProjectDto result = null;
var defaultLanguage = appConfiguration.DefaultLanguage;
// //
// Create Provided Project ... // Create Provided Project ...
if (hasProject) if (hasProject)
{ {
// //
// Add Item for ID Gneneration ...
result = await projectRepositoryService.AddAsync( result = await projectRepositoryService.AddAsync(
item: item, item: item,
saveChanges: true, saveChanges: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
//
// Checking Resources ...
//
// Titles ...
var titleResource = string.Empty;
if (!item.TitleResource.IsNullOrDefault() &&
item.TitleResource.Locales.HasChild())
{
//
// Adding Title Resource Locales ...
var isDefaultLanguageHandled = false;
foreach (var trl in item.TitleResource.Locales)
{
//
// Attaching Default Language ...
if (!isDefaultLanguageHandled &&
trl.Language.IsNullOrEmpty())
{
//
trl.Language = defaultLanguage;
isDefaultLanguageHandled = false;
}
//
// Check Value Exists ...
if (trl.Value.IsNullOrEmpty())
{
continue;
}
//
var resource = await projectTitleResourceProvider.AddOrUpdateLocale(
locale: trl,
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
titleResource.IsNullOrEmpty())
{
titleResource = resource.Resource;
}
}
}
//
// Descriptions ...
var descriptionResource = string.Empty;
if (!item.DescriptionResource.IsNullOrDefault() &&
item.DescriptionResource.Locales.HasChild())
{
//
// Adding Description Resource Locales ....
var isDefaultLanguageHandled = false;
foreach (var trl in item.DescriptionResource.Locales)
{
//
// Attaching Default Language ...
if (!isDefaultLanguageHandled &&
trl.Language.IsNullOrEmpty())
{
//
trl.Language = defaultLanguage;
isDefaultLanguageHandled = false;
}
//
// Check Value Exists ...
if (trl.Value.IsNullOrEmpty())
{
continue;
}
//
var resource = await projectDescriptionResourceProvider.AddOrUpdateLocale(
locale: trl,
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
descriptionResource.IsNullOrEmpty())
{
descriptionResource = resource.Resource;
}
}
}
//
// Update Data ...
result.Title = titleResource;
result.Description = descriptionResource;
result = await projectRepositoryService.UpdateAsync(
item: result,
id: result.Id,
saveChanges: true,
cancellationToken: cancellationToken
);
if (!result.IsNullOrDefault())
{
//
result = await projectEnricher.Enrich(
source: result,
fillConversations: false,
fillConversationMessages: false,
cancellationToken: cancellationToken
);
}
// //
// Handling Send Push Notification ... // Handling Send Push Notification ...
if (!result.IsNullOrDefault() && if (!result.IsNullOrDefault() &&
@@ -493,11 +616,30 @@ namespace xAiModels.Providers
XException.ActionFailed.Throw(); XException.ActionFailed.Throw();
} }
//
// Handle Enrichment ...
result = await Enrich(
source: result,
fillConversations: false,
fillConversationMessages: false,
cancellationToken: cancellationToken
);
// //
return result; return result;
} }
/// <summary>
/// Create an AI Conversation ...
/// </summary>
/// <param name="ownerId"></param>
/// <param name="projectId"></param>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XAiConversationDto> CreateConversation( public async Task<XAiConversationDto> CreateConversation(
string ownerId,
Guid projectId, Guid projectId,
XAiConversationDto item = null, XAiConversationDto item = null,
string connectionId = null, string connectionId = null,
@@ -536,6 +678,7 @@ namespace xAiModels.Providers
if (hasConversation) if (hasConversation)
{ {
// //
item.OwnerId = ownerId;
item.ProjectId = project.Id; item.ProjectId = project.Id;
item.CreatedOn = DateTime.UtcNow; item.CreatedOn = DateTime.UtcNow;
@@ -549,12 +692,14 @@ namespace xAiModels.Providers
// //
XAiConversationDto result = null; XAiConversationDto result = null;
var defaultLanguage = appConfiguration.DefaultLanguage;
// //
// Create Provided Conversation ... // Create Provided Conversation ...
if (hasConversation) if (hasConversation)
{ {
// //
// Add Item for ID Gneneration ...
result = await conversationRepositoryService.AddAsync( result = await conversationRepositoryService.AddAsync(
item: item, item: item,
saveChanges: true, saveChanges: true,
@@ -562,6 +707,72 @@ namespace xAiModels.Providers
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
//
// Checking Resources ...
//
// Titles ...
var titleResource = string.Empty;
if (!item.TitleResource.IsNullOrDefault() &&
item.TitleResource.Locales.HasChild())
{
//
// Adding Title Resource Locales ...
var isDefaultLanguageHandled = false;
foreach (var trl in item.TitleResource.Locales)
{
//
// Attaching Default Language ...
if (!isDefaultLanguageHandled &&
trl.Language.IsNullOrEmpty())
{
//
trl.Language = defaultLanguage;
isDefaultLanguageHandled = false;
}
//
// Check Value Exists ...
if (trl.Value.IsNullOrEmpty())
{
continue;
}
//
var resource = await conversationTitleResourceProvider.AddOrUpdateLocale(
locale: trl,
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
titleResource.IsNullOrEmpty())
{
titleResource = resource.Resource;
}
}
}
//
// Update Data ...
result.Title = titleResource;
result = await conversationRepositoryService.UpdateAsync(
item: result,
id: result.Id,
saveChanges: true,
cancellationToken: cancellationToken
);
if (!result.IsNullOrDefault())
{
//
result = await conversationEnricher.Enrich(
source: result,
fillMessages: false,
cancellationToken: cancellationToken
);
}
// //
// Handling Send Push Notification ... // Handling Send Push Notification ...
if (!result.IsNullOrDefault() && if (!result.IsNullOrDefault() &&
@@ -613,10 +824,26 @@ namespace xAiModels.Providers
XException.ActionFailed.Throw(); XException.ActionFailed.Throw();
} }
//
// Handle Enrichment ...
result = await Enrich(
source: result,
fillMessages: false,
cancellationToken: cancellationToken
);
// //
return result; return result;
} }
/// <summary>
/// Add Message ...
/// </summary>
/// <param name="conversationId"></param>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XAiMessageDto> AddMessage( public async Task<XAiMessageDto> AddMessage(
Guid conversationId, Guid conversationId,
XAiMessageDto item, XAiMessageDto item,
@@ -653,6 +880,17 @@ namespace xAiModels.Providers
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
//
// Handle Enrichment ...
if (!result.IsNullOrDefault())
{
//
result = await Enrich(
source: result,
cancellationToken: cancellationToken
);
}
// //
// Handling Send Push Notification ... // Handling Send Push Notification ...
if (!result.IsNullOrDefault() && if (!result.IsNullOrDefault() &&
@@ -714,15 +952,14 @@ namespace xAiModels.Providers
cancellationToken: cancellationToken, cancellationToken: cancellationToken,
predicate: x => predicate: x =>
x.ResourceTitle x.ResourceTitle
// .ToNormalString() .ToNormalString()
.Contains(ownerId.ToNormalString()) && .Contains(ownerId.ToNormalString()) &&
x.ResourceTitle x.ResourceTitle
// .ToNormalString() .ToNormalString()
// .ToNormalString() .Contains(XAiModelsConstants.XAiProjectTitleIdentifier.ToNormalString()) &&
.Contains(XAiModelsConstants.XAiProjectTitleIdentifier) &&
x.TranslatedValue x.TranslatedValue
// .ToNormalString() .ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiProjectSuffix) .Contains(XAiDataProviderConstants.XDefaultAiProjectSuffix.ToNormalString())
); );
if (resource.IsNullOrDefault()) if (resource.IsNullOrDefault())
{ {
@@ -1101,7 +1338,7 @@ namespace xAiModels.Providers
// Prepare Tile and Description Resource Ids ... // Prepare Tile and Description Resource Ids ...
var titleResource = await projectTitleResourceProvider.AddOrUpdateLocale( var titleResource = await projectTitleResourceProvider.AddOrUpdateLocale(
owner: ownerId, owner: ownerId,
identifier: item.Id, // $"{XAiDataProviderConstants.XDefaultAiProjectSuffix}_{item.Id}", identifier: item.Id,
locale: new XLocaleResourceDto locale: new XLocaleResourceDto
{ {
Language = defaultLang, Language = defaultLang,
@@ -1111,7 +1348,7 @@ namespace xAiModels.Providers
); );
var descriptionResource = await projectDescriptionResourceProvider.AddOrUpdateLocale( var descriptionResource = await projectDescriptionResourceProvider.AddOrUpdateLocale(
owner: ownerId, owner: ownerId,
identifier: item.Id, // $"{XAiDataProviderConstants.XDefaultAiProjectSuffix}_{item.Id}", identifier: item.Id,
new XLocaleResourceDto new XLocaleResourceDto
{ {
Language = defaultLang, Language = defaultLang,
@@ -1209,15 +1446,14 @@ namespace xAiModels.Providers
cancellationToken: cancellationToken, cancellationToken: cancellationToken,
predicate: x => predicate: x =>
x.ResourceTitle x.ResourceTitle
// .ToNormalString() .ToNormalString()
// .ToNormalString() .Contains(ownerId.ToString().ToNormalString()) &&
.Contains(projectId.ToString()) &&
x.ResourceTitle x.ResourceTitle
// .ToNormalString() .ToNormalString()
.Contains(XAiModelsConstants.XAiConversationTitleIdentifier) && .Contains(XAiModelsConstants.XAiConversationTitleIdentifier.ToNormalString()) &&
x.TranslatedValue x.TranslatedValue
// .ToNormalString() .ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiConversationSuffix) .Contains(XAiDataProviderConstants.XDefaultAiConversationSuffix.ToNormalString())
); );
result = !resource.IsNullOrDefault(); result = !resource.IsNullOrDefault();
if (!result) if (!result)
@@ -1324,7 +1560,7 @@ namespace xAiModels.Providers
// Prepare Title Resource Ids ... // Prepare Title Resource Ids ...
var titleResource = await conversationTitleResourceProvider.AddOrUpdateLocale( var titleResource = await conversationTitleResourceProvider.AddOrUpdateLocale(
owner: ownerId, owner: ownerId,
identifier: item.Id, // $"{XAiDataProviderConstants.XDefaultAiConversationSuffix}_{item.Id}", identifier: item.Id,
locale: new XLocaleResourceDto locale: new XLocaleResourceDto
{ {
Language = defaultLang, Language = defaultLang,