Skip to content

Commit 6fc844e

Browse files
committed
Merge branch 'master' of https://github.com/SciSharp/BotSharp
2 parents 27d3027 + 9beea89 commit 6fc844e

File tree

20 files changed

+68
-428
lines changed

20 files changed

+68
-428
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@
111111
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
112112
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
113113
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
114-
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.2" />
114+
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.5" />
115+
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.1.0-preview.5" />
115116
</ItemGroup>
116117
<ItemGroup>
117118
<PackageVersion Include="BotSharp.Core" Version="$(BotSharpVersion)" />

src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ public class ElementLocatingArgs
3636
/// </summary>
3737
public bool Highlight { get; set; }
3838
public string HighlightColor { get; set; } = "red";
39+
[JsonPropertyName("is_read_content")]
40+
public bool IsReadContent { get;set; }
3941
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public class McpServerConfigModel
2424
/// </summary>
2525
public string? Location { get; set; }
2626

27-
/// <summary>
28-
/// Arguments (if any) to pass to the executable.
29-
/// </summary>
30-
public string[]? Arguments { get; set; }
31-
3227
/// <summary>
3328
/// Additional transport-specific configuration.
3429
/// </summary>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using BotSharp.Core.MCP.Functions;
2-
using BotSharp.Core.MCP.Settings;
32
using BotSharp.Core.MCP.Hooks;
3+
using BotSharp.Core.MCP.Managers;
4+
using BotSharp.Core.MCP.Services;
5+
using BotSharp.Core.MCP.Settings;
46
using Microsoft.Extensions.Configuration;
5-
using ModelContextProtocol.Configuration;
7+
using ModelContextProtocol;
68
using ModelContextProtocol.Client;
7-
using BotSharp.Core.MCP.Managers;
89

910
namespace BotSharp.Core.MCP;
1011

@@ -18,6 +19,7 @@ public static class BotSharpMcpExtensions
1819
/// <returns></returns>
1920
public static IServiceCollection AddBotSharpMCP(this IServiceCollection services, IConfiguration config)
2021
{
22+
services.AddScoped<IMcpService, McpService>();
2123
var settings = config.GetSection("MCP").Get<McpSettings>();
2224
services.AddScoped(provider => { return settings; });
2325

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Infrastructure/BotSharp.Core.MCP/Services/McpService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public IEnumerable<McpServerConfigModel> GetServerConfigs()
2626
Name = x.Name,
2727
TransportType = x.TransportType,
2828
TransportOptions = x.TransportOptions,
29-
Arguments = x.Arguments,
3029
Location = x.Location
3130
});
3231
}

src/Infrastructure/BotSharp.Core.MCP/Settings/MCPSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using ModelContextProtocol.Client;
2-
using ModelContextProtocol.Configuration;
2+
using ModelContextProtocol;
33

44
namespace BotSharp.Core.MCP.Settings;
55

src/Infrastructure/BotSharp.Core.Realtime/Hooks/RealtimeConversationHook.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BotSharp.Abstraction.Utilities;
2+
using BotSharp.Core.Infrastructures;
23

34
namespace BotSharp.Core.Realtime.Hooks;
45

@@ -29,6 +30,10 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
2930
{
3031
return;
3132
}
33+
34+
// Clear cache to force to rebuild the agent instruction
35+
Utilities.ClearCache();
36+
3237
var routing = _services.GetRequiredService<IRoutingService>();
3338

3439
message.Role = AgentRole.Function;

src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public async Task Listen(WebSocket userWebSocket,
4949
{
5050
await _completer.AppenAudioBuffer(_conn.Data);
5151
}
52+
else if (_conn.Event == "user_dtmf_receiving")
53+
{
54+
}
5255
else if (_conn.Event == "user_dtmf_received")
5356
{
5457
await HandleUserDtmfReceived();

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,28 @@ private async Task ReceiveMessage(RealtimeHubConnection conn,
144144
Action onUserInterrupted)
145145
{
146146
var buffer = new byte[1024 * 32];
147-
WebSocketReceiveResult result;
147+
// Model response timeout
148+
var timeout = 30;
149+
WebSocketReceiveResult? result = default;
148150

149151
do
150152
{
151153
Array.Clear(buffer, 0, buffer.Length);
152-
result = await _webSocket.ReceiveAsync(
153-
new ArraySegment<byte>(buffer), CancellationToken.None);
154+
155+
var taskWorker = _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
156+
var taskTimer = Task.Delay(1000 * timeout);
157+
var completedTask = await Task.WhenAny(taskWorker, taskTimer);
158+
159+
if (completedTask == taskWorker)
160+
{
161+
result = taskWorker.Result;
162+
}
163+
else
164+
{
165+
_logger.LogWarning($"Timeout {timeout} seconds waiting for Model response.");
166+
await TriggerModelInference("Response user immediately");
167+
continue;
168+
}
154169

155170
// Convert received data to text/audio (Twilio sends Base64-encoded audio)
156171
string receivedText = Encoding.UTF8.GetString(buffer, 0, result.Count);
@@ -164,6 +179,11 @@ private async Task ReceiveMessage(RealtimeHubConnection conn,
164179
if (response.Type == "error")
165180
{
166181
_logger.LogError($"{response.Type}: {receivedText}");
182+
var error = JsonSerializer.Deserialize<ServerEventErrorResponse>(receivedText);
183+
if (error?.Body.Type == "server_error")
184+
{
185+
break;
186+
}
167187
}
168188
else if (response.Type == "session.created")
169189
{
@@ -182,7 +202,6 @@ private async Task ReceiveMessage(RealtimeHubConnection conn,
182202
{
183203
_logger.LogInformation($"{response.Type}: {receivedText}");
184204
var data = JsonSerializer.Deserialize<ResponseAudioTranscript>(receivedText);
185-
await Task.Delay(1000);
186205
onModelAudioTranscriptDone(data.Transcript);
187206
}
188207
else if (response.Type == "response.audio.delta")

0 commit comments

Comments
 (0)