From a1acd9f9cab0a3ea6717291696628da253e4f057 Mon Sep 17 00:00:00 2001 From: enisn Date: Fri, 23 Jan 2026 12:38:13 +0300 Subject: [PATCH] Add fallback to default chat client for unconfigured workspaces Updated ChatClientAccessor and TypedChatClient to fallback to the default chat client if a workspace-specific client is not configured. Adjusted tests to verify that the default chat client is resolved for non-configured workspaces. --- .../Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs | 8 ++++++++ .../src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs | 6 +++++- .../Volo/Abp/AI/ChatClientAccessor_Tests.cs | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs b/framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs index 247e6e354e..dfe79d7e01 100644 --- a/framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs +++ b/framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs @@ -29,5 +29,13 @@ public class ChatClientAccessor : IChatClientAccessor ChatClient = serviceProvider.GetKeyedService( AbpAIWorkspaceOptions.GetChatClientServiceKeyName( WorkspaceNameAttribute.GetWorkspaceName())); + + // Fallback to default chat client if not configured for the workspace. + if (ChatClient is null) + { + ChatClient = serviceProvider.GetKeyedService( + AbpAIWorkspaceOptions.GetChatClientServiceKeyName( + AbpAIModule.DefaultWorkspaceName)); + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs b/framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs index 72ccfdaf38..9a52f7edc9 100644 --- a/framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs +++ b/framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs @@ -9,9 +9,13 @@ public class TypedChatClient : DelegatingChatClient, IChatClient( + serviceProvider.GetKeyedService( AbpAIWorkspaceOptions.GetChatClientServiceKeyName( WorkspaceNameAttribute.GetWorkspaceName())) + ?? + serviceProvider.GetRequiredKeyedService( + AbpAIWorkspaceOptions.GetChatClientServiceKeyName( + AbpAIModule.DefaultWorkspaceName)) ) { } diff --git a/framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs b/framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs index 6cf352318a..f384bba591 100644 --- a/framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs +++ b/framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs @@ -31,14 +31,24 @@ public class ChatClientAccessor_Tests : AbpIntegratedTest } [Fact] - public void Should_Resolve_ChatClientAccessor_For_NonConfigured_Workspace() + public void Should_Resolve_Default_ChatClient_From_NonConfigured_Workspace_Accessor() { // Arrange & Act var chatClientAccessor = GetRequiredService>(); // Assert chatClientAccessor.ShouldNotBeNull(); - chatClientAccessor.ChatClient.ShouldBeNull(); + chatClientAccessor.ChatClient.ShouldNotBeNull(); + } + + [Fact] + public void Should_Resolve_Default_ChatClient_For_NonConfigured_Workspace() + { + // Arrange & Act + var chatClientAccessor = GetRequiredService>(); + + // Assert + chatClientAccessor.ShouldNotBeNull(); } public class NonConfiguredWorkspace