Move Knowledge Constants and Fix Inverted Ownership Filters
- Add XAiKnowledgeScope enum (Conversation=0, Project=1, Global=2, User=3) with StringValue prefixes; - Add Knowledge constants, scope prefixes, metadata keys and XAiErrorRoute to XAiModelsConstants; - Fix inverted ownerId condition in QueryProjects / QueryConversations / QueryMessages (ownership filter was skipped for real owners -> cross-user data exposure); - Fix inverted HasChild() validation in HasDefaultProject / HasDefaultConversation; - LoadConversations: ignore soft-deleted conversations; - CreateProject / CreateConversation: set isDefaultLanguageHandled = true; - GetDefaultConversation: use projectId instead of unloaded project.Id.
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
using xExceptions.Attributes;
|
||||||
|
|
||||||
|
namespace xAiModels.Constants
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Knowledge Base Scope (Where Ingested Vectors are Visible) ...
|
||||||
|
/// Identifier Layout: "{scopePrefix}/{scopeKey}/{fileName}#{chunkIndex}" (Global has no scopeKey) ...
|
||||||
|
/// </summary>
|
||||||
|
public enum XAiKnowledgeScope
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Visible only Inside a Conversation (Key = ConversationId) ...
|
||||||
|
/// </summary>
|
||||||
|
[StringValue(XAiModelsConstants.XAiKnowledgeConversationPrefix)]
|
||||||
|
Conversation = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Visible to all Conversations of a Project (Key = ProjectId) ...
|
||||||
|
/// </summary>
|
||||||
|
[StringValue(XAiModelsConstants.XAiKnowledgeProjectPrefix)]
|
||||||
|
Project = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Visible to Everyone (Write Requires Admin Role) ...
|
||||||
|
/// </summary>
|
||||||
|
[StringValue(XAiModelsConstants.XAiKnowledgeGlobalPrefix)]
|
||||||
|
Global = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Personal Knowledge Base of Owner (Key = UserId) ...
|
||||||
|
/// </summary>
|
||||||
|
[StringValue(XAiModelsConstants.XAiKnowledgeUserPrefix)]
|
||||||
|
User = 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,5 +60,28 @@ namespace xAiModels.Constants
|
|||||||
|
|
||||||
//
|
//
|
||||||
public const string XOpenAINoKey = "no-key-required";
|
public const string XOpenAINoKey = "no-key-required";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Knowledge (Persistent RAG) ...
|
||||||
|
public const string XAiDefaultKnowledgeType = "XAiKnowledge";
|
||||||
|
public const string XAiKnowledgeSeparator = "/";
|
||||||
|
public const string XAiKnowledgeOwnerSeparator = "/";
|
||||||
|
public const string XAiKnowledgeChunkSeparator = "#";
|
||||||
|
public const string XAiKnowledgeUserPrefix = "user";
|
||||||
|
public const string XAiKnowledgeGlobalPrefix = "global";
|
||||||
|
public const string XAiKnowledgeProjectPrefix = "project";
|
||||||
|
public const string XAiKnowledgeConversationPrefix = "conversation";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Error Handler Route (Production) ...
|
||||||
|
public const string XAiErrorRoute = "/error";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Knowledge Metadata Keys ...
|
||||||
|
public const string XAiKnowledgeMetadataType = "type";
|
||||||
|
public const string XAiKnowledgeMetadataScope = "scope";
|
||||||
|
public const string XAiKnowledgeMetadataScopeId = "scopeId";
|
||||||
|
public const string XAiKnowledgeMetadataOwnerId = "ownerId";
|
||||||
|
public const string XAiKnowledgeMetadataIngestedAtUtc = "ingestedAtUtc";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ namespace xAiModels.Extensions
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (source.HasChild() ||
|
if (!source.HasChild() ||
|
||||||
ownerId.IsNullOrEmpty())
|
ownerId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
@@ -306,7 +306,7 @@ namespace xAiModels.Extensions
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (source.HasChild() ||
|
if (!source.HasChild() ||
|
||||||
projectId.IsDefaultGuid())
|
projectId.IsDefaultGuid())
|
||||||
{
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ namespace xAiModels.Providers
|
|||||||
// Retrieve Conversation's List ...
|
// Retrieve Conversation's List ...
|
||||||
var result = await conversationRepositoryService.FindManyAsync(
|
var result = await conversationRepositoryService.FindManyAsync(
|
||||||
includeBuilder: null,
|
includeBuilder: null,
|
||||||
ignoreSoftDeleteds: false,
|
ignoreSoftDeleteds: true,
|
||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken,
|
||||||
predicate: x => x.ProjectId == projectId,
|
predicate: x => x.ProjectId == projectId,
|
||||||
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
|
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
|
||||||
@@ -490,7 +490,7 @@ namespace xAiModels.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
trl.Language = defaultLanguage;
|
trl.Language = defaultLanguage;
|
||||||
isDefaultLanguageHandled = false;
|
isDefaultLanguageHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -534,7 +534,7 @@ namespace xAiModels.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
trl.Language = defaultLanguage;
|
trl.Language = defaultLanguage;
|
||||||
isDefaultLanguageHandled = false;
|
isDefaultLanguageHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -742,7 +742,7 @@ namespace xAiModels.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
trl.Language = defaultLanguage;
|
trl.Language = defaultLanguage;
|
||||||
isDefaultLanguageHandled = false;
|
isDefaultLanguageHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -1039,7 +1039,7 @@ namespace xAiModels.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
project = await projectRepositoryService.GetAsync(
|
project = await projectRepositoryService.GetAsync(
|
||||||
id: project.Id,
|
id: projectId,
|
||||||
includeBuilder: null,
|
includeBuilder: null,
|
||||||
ignoreSoftDeleteds: true,
|
ignoreSoftDeleteds: true,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
@@ -1128,7 +1128,7 @@ namespace xAiModels.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
Expression<Func<XAiProject, bool>> predicate = null;
|
Expression<Func<XAiProject, bool>> predicate = null;
|
||||||
if (ownerId.IsNullOrEmpty())
|
if (!ownerId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
predicate = x => x.OwnerId == ownerId;
|
predicate = x => x.OwnerId == ownerId;
|
||||||
}
|
}
|
||||||
@@ -1196,7 +1196,7 @@ namespace xAiModels.Providers
|
|||||||
//
|
//
|
||||||
Expression<Func<XAiConversation, bool>> predicate = x =>
|
Expression<Func<XAiConversation, bool>> predicate = x =>
|
||||||
x.ProjectId == projectId;
|
x.ProjectId == projectId;
|
||||||
if (ownerId.IsNullOrEmpty())
|
if (!ownerId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
predicate = x =>
|
predicate = x =>
|
||||||
@@ -1266,7 +1266,7 @@ namespace xAiModels.Providers
|
|||||||
//
|
//
|
||||||
Expression<Func<XAiMessage, bool>> predicate = x =>
|
Expression<Func<XAiMessage, bool>> predicate = x =>
|
||||||
x.ConversationId == conversationId;
|
x.ConversationId == conversationId;
|
||||||
if (ownerId.IsNullOrEmpty())
|
if (!ownerId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
predicate = x =>
|
predicate = x =>
|
||||||
|
|||||||
Reference in New Issue
Block a user