Browse Source

fix: Check if the workspace is enabled

pull/1421/head
colin 2 weeks ago
parent
commit
19d8cb2694
  1. 19
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Agent/LINGYUN/Abp/AI/Agent/AgentFactory.cs
  2. 2
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientFactory.cs

19
aspnet-core/modules/ai/LINGYUN.Abp.AI.Agent/LINGYUN/Abp/AI/Agent/AgentFactory.cs

@ -5,7 +5,6 @@ using Microsoft.Extensions.Localization;
using System;
using System.Threading.Tasks;
using Volo.Abp.AI;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
using Volo.Abp.SimpleStateChecking;
@ -39,11 +38,6 @@ public class AgentFactory : IAgentFactory, IScopedDependency
var workspaceDefine = await WorkspaceDefinitionManager.GetOrNullAsync(workspace);
if (workspaceDefine != null)
{
await CheckWorkspaceStateAsync(workspaceDefine);
}
return await CreateAgentAsync(chatClient, workspaceDefine);
}
@ -51,8 +45,6 @@ public class AgentFactory : IAgentFactory, IScopedDependency
{
var workspaceDefine = await WorkspaceDefinitionManager.GetAsync(workspace);
await CheckWorkspaceStateAsync(workspaceDefine);
var chatClient = await ChatClientFactory.CreateAsync(workspace);
return await CreateAgentAsync(chatClient, workspaceDefine);
@ -96,15 +88,4 @@ public class AgentFactory : IAgentFactory, IScopedDependency
{
return Task.FromResult<AITool[]>([]);
}
protected async virtual Task CheckWorkspaceStateAsync(WorkspaceDefinition workspace)
{
if (!await StateCheckerManager.IsEnabledAsync(workspace))
{
throw new AbpAuthorizationException(
$"Workspace is not enabled: {workspace.Name}!",
AbpAIErrorCodes.WorkspaceIsNotEnabled)
.WithData("Workspace", workspace.Name);
}
}
}

2
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientFactory.cs

@ -70,7 +70,7 @@ public class ChatClientFactory : IChatClientFactory, IScopedDependency
protected async virtual Task CheckWorkspaceStateAsync(WorkspaceDefinition workspace)
{
if (!await StateCheckerManager.IsEnabledAsync(workspace))
if (!workspace.IsEnabled || !await StateCheckerManager.IsEnabledAsync(workspace))
{
throw new AbpAuthorizationException(
$"Workspace is not enabled: {workspace.Name}!",

Loading…
Cancel
Save