Skip to content

Commit 7ea6a62

Browse files
authored
Merge pull request #1010 from iceljc/test/realtime-test
Test/realtime test
2 parents 0c551b1 + 98e0142 commit 7ea6a62

File tree

35 files changed

+523
-204
lines changed

35 files changed

+523
-204
lines changed

Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@
111111
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
112112
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
113113
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
114-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
114+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
115115
<PackageVersion Include="Shouldly" Version="4.3.0" />
116-
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.5" />
117-
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.1.0-preview.5" />
116+
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.8" />
117+
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.1.0-preview.8" />
118118
</ItemGroup>
119119
<ItemGroup>
120120
<PackageVersion Include="BotSharp.Core" Version="$(BotSharpVersion)" />

src/Infrastructure/BotSharp.Abstraction/Functions/IFunctionCallback.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace BotSharp.Abstraction.Functions;
22

33
public interface IFunctionCallback
44
{
5+
string Provider => "Botsharp";
56
string Name { get; }
67

78
/// <summary>

src/Infrastructure/BotSharp.Abstraction/MCP/Models/McpServerConfigModel.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ public class McpServerConfigModel
1212
/// </summary>
1313
public string Name { get; set; } = null!;
1414

15-
/// <summary>
16-
/// The type of transport to use.
17-
/// </summary>
18-
[JsonPropertyName("transport_type")]
19-
public string TransportType { get; set; } = null!;
20-
21-
/// <summary>
22-
/// For stdio transport: path to the executable
23-
/// For HTTP transport: base URL of the server
24-
/// </summary>
25-
public string? Location { get; set; }
15+
public McpSseServerConfig? SseConfig { get; set; }
16+
public McpStdioServerConfig? StdioConfig { get; set; }
17+
}
2618

27-
/// <summary>
28-
/// Additional transport-specific configuration.
29-
/// </summary>
30-
[JsonPropertyName("transport_options")]
31-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
32-
public Dictionary<string, string>? TransportOptions { get; set; }
19+
public class McpSseServerConfig
20+
{
21+
public string EndPoint { get; set; } = null!;
22+
public TimeSpan ConnectionTimeout { get; init; } = TimeSpan.FromSeconds(30);
23+
public Dictionary<string, string>? AdditionalHeaders { get; set; }
3324
}
25+
26+
public class McpStdioServerConfig
27+
{
28+
public string Command { get; set; } = null!;
29+
public IList<string>? Arguments { get; set; }
30+
public Dictionary<string, string>? EnvironmentVariables { get; set; }
31+
public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5);
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace BotSharp.Abstraction.MCP.Models;
2+
3+
public class McpServerOptionModel : IdName
4+
{
5+
public IEnumerable<string> Tools { get; set; } = [];
6+
7+
public McpServerOptionModel() : base()
8+
{
9+
10+
}
11+
12+
public McpServerOptionModel(
13+
string id,
14+
string name,
15+
IEnumerable<string> tools) : base(id, name)
16+
{
17+
Tools = tools ?? [];
18+
}
19+
}

src/Infrastructure/BotSharp.Abstraction/MCP/Services/IMcpService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace BotSharp.Abstraction.MCP.Services;
22

33
public interface IMcpService
44
{
5-
IEnumerable<McpServerConfigModel> GetServerConfigs() => [];
5+
IEnumerable<McpServerOptionModel> GetServerConfigs() => [];
66
}

src/Infrastructure/BotSharp.Abstraction/Models/IdName.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public class IdName
88
[JsonPropertyName("name")]
99
public string Name { get; set; } = default!;
1010

11+
public IdName()
12+
{
13+
14+
}
15+
1116
public IdName(string id, string name)
1217
{
1318
Id = id;

src/Infrastructure/BotSharp.Abstraction/Models/MessageState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace BotSharp.Abstraction.Models;
33
public class MessageState
44
{
55
public string Key { get; set; }
6-
public string Value { get; set; }
6+
public object Value { get; set; }
77

88
[JsonPropertyName("active_rounds")]
99
public int ActiveRounds { get; set; } = -1;
@@ -13,7 +13,7 @@ public MessageState()
1313

1414
}
1515

16-
public MessageState(string key, string value, int activeRounds = -1)
16+
public MessageState(string key, object value, int activeRounds = -1)
1717
{
1818
Key = key;
1919
Value = value;

src/Infrastructure/BotSharp.Abstraction/Realtime/Models/RealtimeHubConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class RealtimeHubConnection
1313
public Func<string, string> OnModelMessageReceived { get; set; } = null!;
1414
public Func<string> OnModelAudioResponseDone { get; set; } = null!;
1515
public Func<string> OnModelUserInterrupted { get; set; } = null!;
16+
public Func<string> OnUserSpeechDetected { get; set; } = () => string.Empty;
1617

1718
public void ResetResponseState()
1819
{

src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,27 @@ public static bool IsPrimitiveValue(this string value)
108108
uint.TryParse(value, out _) ||
109109
ulong.TryParse(value, out _);
110110
}
111+
112+
113+
public static string ConvertToString<T>(this T? value, JsonSerializerOptions? jsonOptions = null)
114+
{
115+
if (value == null)
116+
{
117+
return string.Empty;
118+
}
119+
120+
if (value is string s)
121+
{
122+
return s;
123+
}
124+
125+
if (value is JsonElement elem
126+
&& elem.ValueKind == JsonValueKind.String)
127+
{
128+
return elem.ToString();
129+
}
130+
131+
var str = JsonSerializer.Serialize(value, jsonOptions);
132+
return str;
133+
}
111134
}

src/Infrastructure/BotSharp.Core.MCP/BotSharpMCPExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using BotSharp.Core.MCP.Services;
55
using BotSharp.Core.MCP.Settings;
66
using Microsoft.Extensions.Configuration;
7-
using ModelContextProtocol;
87
using ModelContextProtocol.Client;
98

109
namespace BotSharp.Core.MCP;
@@ -21,7 +20,7 @@ public static IServiceCollection AddBotSharpMCP(this IServiceCollection services
2120
{
2221
services.AddScoped<IMcpService, McpService>();
2322
var settings = config.GetSection("MCP").Get<McpSettings>();
24-
services.AddScoped(provider => { return settings; });
23+
services.AddScoped(provider => settings);
2524

2625
if (settings != null && settings.Enabled && !settings.McpServerConfigs.IsNullOrEmpty())
2726
{
@@ -42,18 +41,18 @@ public static IServiceCollection AddBotSharpMCP(this IServiceCollection services
4241
return services;
4342
}
4443

45-
private static async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server, McpClientManager clientManager)
44+
private static async Task RegisterFunctionCall(IServiceCollection services, McpServerConfigModel server, McpClientManager clientManager)
4645
{
4746
var client = await clientManager.GetMcpClientAsync(server.Id);
4847
var tools = await client.ListToolsAsync();
4948

5049
foreach (var tool in tools)
5150
{
52-
services.AddScoped(provider => { return tool; });
51+
services.AddScoped(provider => tool);
5352

5453
services.AddScoped<IFunctionCallback>(provider =>
5554
{
56-
var funcTool = new McpToolAdapter(provider, tool, clientManager);
55+
var funcTool = new McpToolAdapter(provider, server.Name, tool, clientManager);
5756
return funcTool;
5857
});
5958
}

0 commit comments

Comments
 (0)