Skip to content

Commit 3380cfb

Browse files
authored
Merge pull request #1271 from iceljc/master
refine and upgrade to net10
2 parents e02273d + 8259947 commit 3380cfb

File tree

15 files changed

+81
-59
lines changed

15 files changed

+81
-59
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net10.0</TargetFramework>
44
<LangVersion>12.0</LangVersion>
55
<BotSharpVersion>5.2.0</BotSharpVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

src/Infrastructure/BotSharp.Abstraction/MultiTenancy/Options/TenantConfiguration.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,24 @@ public TenantConfiguration()
2222
public TenantConfiguration(Guid id, [NotNull] string name)
2323
: this()
2424
{
25-
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Name cannot be null or whitespace.");
25+
if (string.IsNullOrWhiteSpace(name))
26+
{
27+
throw new ArgumentException("Name cannot be null or whitespace.");
28+
}
29+
2630
Id = id;
2731
Name = name;
28-
2932
ConnectionStrings = new ConnectionStrings();
3033
}
3134

3235
public TenantConfiguration(Guid id, [NotNull] string name, [NotNull] string normalizedName)
3336
: this(id, name)
3437
{
35-
if (string.IsNullOrWhiteSpace(normalizedName)) throw new ArgumentException("NormalizedName cannot be null or whitespace.");
38+
if (string.IsNullOrWhiteSpace(normalizedName))
39+
{
40+
throw new ArgumentException("NormalizedName cannot be null or whitespace.");
41+
}
42+
3643
NormalizedName = normalizedName;
3744
}
3845
}

src/Infrastructure/BotSharp.Core.A2A/Hooks/A2AAgentHook.cs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ public class A2AAgentHook : AgentHookBase
1313
{
1414
public override string SelfId => string.Empty;
1515

16-
private readonly A2ASettings _settings;
17-
private readonly IA2AService _iA2AService;
16+
private readonly A2ASettings _a2aSettings;
17+
private readonly IA2AService _a2aService;
1818

19-
public A2AAgentHook(IServiceProvider services, IA2AService a2AService, A2ASettings settings)
20-
: base(services, new AgentSettings())
19+
public A2AAgentHook(IServiceProvider services, IA2AService a2aService, A2ASettings a2aSettings, AgentSettings agentSettings)
20+
: base(services, agentSettings)
2121
{
22-
_iA2AService = a2AService;
23-
_settings = settings;
22+
_a2aService = a2aService;
23+
_a2aSettings = a2aSettings;
2424
}
2525

2626
public override bool OnAgentLoading(ref string id)
2727
{
2828
var agentId = id;
29-
var remoteConfig = _settings.Agents.FirstOrDefault(x => x.Id == agentId);
29+
var remoteConfig = _a2aSettings.Agents?.FirstOrDefault(x => x.Id == agentId);
3030
if (remoteConfig != null)
3131
{
3232
return true;
@@ -42,43 +42,46 @@ public override void OnAgentLoaded(Agent agent)
4242
return;
4343
}
4444

45-
var remoteConfig = _settings.Agents.FirstOrDefault(x => x.Id == agent.Id);
45+
var remoteConfig = _a2aSettings.Agents?.FirstOrDefault(x => x.Id == agent.Id);
4646
if (remoteConfig != null)
4747
{
48-
var agentCard = _iA2AService.GetCapabilitiesAsync(remoteConfig.Endpoint).GetAwaiter().GetResult();
49-
agent.Name = agentCard.Name;
50-
agent.Description = agentCard.Description;
51-
agent.Instruction = $"You are a proxy interface for an external intelligent service named '{agentCard.Name}'. " +
52-
$"Your ONLY goal is to forward the user's request verbatim to the external service. " +
53-
$"You must use the function 'delegate_to_a2a' to communicate with it. " +
54-
$"Do not attempt to answer the question yourself.";
55-
56-
var properties = new Dictionary<string, object>
48+
var agentCard = _a2aService.GetCapabilitiesAsync(remoteConfig.Endpoint).GetAwaiter().GetResult();
49+
if (agentCard != null)
5750
{
51+
agent.Name = agentCard.Name;
52+
agent.Description = agentCard.Description;
53+
agent.Instruction = $"You are a proxy interface for an external intelligent service named '{agentCard.Name}'. " +
54+
$"Your ONLY goal is to forward the user's request verbatim to the external service. " +
55+
$"You must use the function 'delegate_to_a2a' to communicate with it. " +
56+
$"Do not attempt to answer the question yourself.";
57+
58+
var properties = new Dictionary<string, object>
5859
{
59-
"user_query",
60-
new
6160
{
62-
type = "string",
63-
description = "The exact user request or task description to be forwarded."
61+
"user_query",
62+
new
63+
{
64+
type = "string",
65+
description = "The exact user request or task description to be forwarded."
66+
}
6467
}
65-
}
66-
};
68+
};
6769

68-
var propertiesJson = JsonSerializer.Serialize(properties);
69-
var propertiesDocument = JsonDocument.Parse(propertiesJson);
70+
var propertiesJson = JsonSerializer.Serialize(properties);
71+
var propertiesDocument = JsonDocument.Parse(propertiesJson);
7072

71-
agent.Functions.Add(new FunctionDef
72-
{
73-
Name = "delegate_to_a2a",
74-
Description = $"Delegates the task to the external {remoteConfig.Name} via A2A protocol.",
75-
Parameters = new FunctionParametersDef()
73+
agent.Functions.Add(new FunctionDef
7674
{
77-
Type = "object",
78-
Properties = propertiesDocument,
79-
Required = new List<string> { "user_query" }
80-
}
81-
});
75+
Name = "delegate_to_a2a",
76+
Description = $"Delegates the task to the external {remoteConfig.Name} via A2A protocol.",
77+
Parameters = new FunctionParametersDef()
78+
{
79+
Type = "object",
80+
Properties = propertiesDocument,
81+
Required = new List<string> { "user_query" }
82+
}
83+
});
84+
}
8285
}
8386
base.OnAgentLoaded(agent);
8487
}

src/Infrastructure/BotSharp.Core.A2A/Services/A2AService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class A2AService : IA2AService
1313

1414
private readonly Dictionary<string, A2AClient> _clientCache = new Dictionary<string, A2AClient>();
1515

16-
public A2AService(IHttpClientFactory httpClientFactory, IServiceProvider serviceProvider, ILogger<A2AService> logger)
16+
public A2AService(IHttpClientFactory httpClientFactory, IServiceProvider services, ILogger<A2AService> logger)
1717
{
1818
_httpClientFactory = httpClientFactory;
19-
_services = serviceProvider;
19+
_services = services;
2020
_logger = logger;
2121
}
2222

src/Infrastructure/BotSharp.Core.A2A/Settings/A2ASettings.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
71
namespace BotSharp.Core.A2A.Settings;
82

93
public class A2ASettings

src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
3838
if (provider != null)
3939
{
4040
var cs = provider.GetConnectionString("BotSharpMongoDb");
41-
if (!string.IsNullOrWhiteSpace(cs)) dbSettings.BotSharpMongoDb = cs;
41+
if (!string.IsNullOrWhiteSpace(cs))
42+
{
43+
dbSettings.BotSharpMongoDb = cs;
44+
}
4245
}
4346
}
4447

src/Plugins/BotSharp.Plugin.MultiTenancy/Extensions/MultiTenancyServiceCollectionExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using BotSharp.Abstraction.MultiTenancy;
22
using BotSharp.Abstraction.MultiTenancy.Options;
3+
using BotSharp.Plugin.MultiTenancy.Interfaces;
34
using BotSharp.Plugin.MultiTenancy.Models;
45
using BotSharp.Plugin.MultiTenancy.MultiTenancy;
6+
using BotSharp.Plugin.MultiTenancy.MultiTenancy.Providers;
57
using BotSharp.Plugin.MultiTenancy.MultiTenancy.Resolvers;
8+
using BotSharp.Plugin.MultiTenancy.MultiTenancy.Tenant;
69
using Microsoft.Extensions.Configuration;
710
using Microsoft.Extensions.DependencyInjection;
811
using Microsoft.Extensions.DependencyInjection.Extensions;

src/Plugins/BotSharp.Plugin.MultiTenancy/MultiTenancy/ICurrentTenantAccessor.cs renamed to src/Plugins/BotSharp.Plugin.MultiTenancy/Interfaces/ICurrentTenantAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BotSharp.Plugin.MultiTenancy.Models;
22

3-
namespace BotSharp.Plugin.MultiTenancy.MultiTenancy;
3+
namespace BotSharp.Plugin.MultiTenancy.Interfaces;
44

55
public interface ICurrentTenantAccessor
66
{

src/Plugins/BotSharp.Plugin.MultiTenancy/MultiTenancy/ConfigTenantOptionProvider.cs renamed to src/Plugins/BotSharp.Plugin.MultiTenancy/MultiTenancy/Providers/ConfigTenantOptionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Linq;
88
using System.Threading.Tasks;
99

10-
namespace BotSharp.Plugin.MultiTenancy.MultiTenancy;
10+
namespace BotSharp.Plugin.MultiTenancy.MultiTenancy.Providers;
1111

1212
public class ConfigTenantOptionProvider : ITenantOptionProvider
1313
{

src/Plugins/BotSharp.Plugin.MultiTenancy/MultiTenancy/DefaultConnectionStringResolver.cs renamed to src/Plugins/BotSharp.Plugin.MultiTenancy/MultiTenancy/Providers/DefaultConnectionStringResolver.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66

7-
namespace BotSharp.Plugin.MultiTenancy.MultiTenancy
7+
namespace BotSharp.Plugin.MultiTenancy.MultiTenancy.Providers
88
{
99
public class DefaultConnectionStringResolver : IConnectionStringResolver
1010
{
@@ -19,7 +19,11 @@ public DefaultConnectionStringResolver(IOptionsMonitor<TenantStoreOptions> tenan
1919

2020
public string? GetConnectionString(string connectionStringName)
2121
{
22-
if (!_tenantStoreOptions.Enabled || !_tenantStoreOptions.Tenants.Any()) return null;
22+
if (!_tenantStoreOptions.Enabled || !_tenantStoreOptions.Tenants.Any())
23+
{
24+
return null;
25+
}
26+
2327
if (_currentTenant.Id.HasValue)
2428
{
2529
var tenant = _tenantStoreOptions.Tenants.FirstOrDefault(t => t.Id == _currentTenant.Id.Value);

0 commit comments

Comments
 (0)