Skip to content

Commit c8a565f

Browse files
author
Haiping Chen
committed
Seperate realtime in a new project
1 parent 4dadd5c commit c8a565f

10 files changed

Lines changed: 71 additions & 24 deletions

File tree

BotSharp.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Rules", "src\
127127
EndProject
128128
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}"
129129
EndProject
130+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}"
131+
EndProject
130132
Global
131133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
132134
Debug|Any CPU = Debug|Any CPU
@@ -519,6 +521,14 @@ Global
519521
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU
520522
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU
521523
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = Release|Any CPU
524+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
525+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
526+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|x64.ActiveCfg = Debug|Any CPU
527+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|x64.Build.0 = Debug|Any CPU
528+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
529+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|Any CPU.Build.0 = Release|Any CPU
530+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|x64.ActiveCfg = Release|Any CPU
531+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|x64.Build.0 = Release|Any CPU
522532
EndGlobalSection
523533
GlobalSection(SolutionProperties) = preSolution
524534
HideSolutionNode = FALSE
@@ -580,6 +590,7 @@ Global
580590
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
581591
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
582592
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
593+
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
583594
EndGlobalSection
584595
GlobalSection(ExtensibilityGlobals) = postSolution
585596
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class RealtimeHubConnection
88
public string StreamId { get; set; } = null!;
99
public string? LastAssistantItemId { get; set; } = null!;
1010
public long LatestMediaTimestamp { get; set; }
11-
public long? ResponseStartTimestampTwilio { get; set; }
11+
public long? ResponseStartTimestamp { get; set; }
1212
public string KeypadInputBuffer { get; set; } = string.Empty;
1313
public ConcurrentQueue<string> MarkQueue { get; set; } = new();
1414
public string CurrentAgentId { get; set; } = null!;
@@ -23,12 +23,12 @@ public void ResetResponseState()
2323
{
2424
MarkQueue.Clear();
2525
LastAssistantItemId = null;
26-
ResponseStartTimestampTwilio = null;
26+
ResponseStartTimestamp = null;
2727
}
2828

2929
public void ResetStreamState()
3030
{
31-
ResponseStartTimestampTwilio = null;
31+
ResponseStartTimestamp = null;
3232
LatestMediaTimestamp = 0;
3333
}
3434
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using BotSharp.Abstraction.Plugins;
2+
using BotSharp.Core.Realtime.Services;
3+
using Microsoft.Extensions.Configuration;
4+
5+
namespace BotSharp.Core.Realtime;
6+
7+
public class RealtimePlugin : IBotSharpPlugin
8+
{
9+
public string Id => "68c1c737-5c21-49de-b141-cd5c8d9bf978";
10+
public string Name => "Realtime Hub";
11+
public string? IconUrl => "https://thumbs.dreamstime.com/b/microphone-icon-sound-waves-voice-command-recording-message-sign-349007898.jpg";
12+
public string Description => "Build low-latency, multi-modal experiences with the Realtime API.";
13+
14+
public void RegisterDI(IServiceCollection services, IConfiguration config)
15+
{
16+
services.AddScoped<IRealtimeHub, RealtimeHub>();
17+
}
18+
}

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
using BotSharp.Abstraction.Realtime;
2-
using System.Net.WebSockets;
3-
using BotSharp.Abstraction.Realtime.Models;
4-
using BotSharp.Abstraction.MLTasks;
5-
using BotSharp.Abstraction.Conversations.Enums;
6-
using BotSharp.Abstraction.Routing.Models;
7-
using NetTopologySuite.Index.HPRtree;
8-
using BotSharp.Abstraction.Agents.Models;
9-
using Microsoft.Identity.Client.Extensions.Msal;
10-
using Microsoft.AspNetCore.Cors.Infrastructure;
11-
12-
namespace BotSharp.Core.Realtime;
1+
namespace BotSharp.Core.Realtime.Services;
132

143
public class RealtimeHub : IRealtimeHub
154
{
@@ -127,10 +116,10 @@ await completer.Connect(conn,
127116
await SendEventToUser(userWebSocket, data);
128117

129118
// If this is the first delta of a new response, set the start timestamp
130-
if (!conn.ResponseStartTimestampTwilio.HasValue)
119+
if (!conn.ResponseStartTimestamp.HasValue)
131120
{
132-
conn.ResponseStartTimestampTwilio = conn.LatestMediaTimestamp;
133-
_logger.LogDebug($"Setting start timestamp for new response: {conn.ResponseStartTimestampTwilio}ms");
121+
conn.ResponseStartTimestamp = conn.LatestMediaTimestamp;
122+
_logger.LogDebug($"Setting start timestamp for new response: {conn.ResponseStartTimestamp}ms");
134123
}
135124
// Record last assistant item ID for interruption handling
136125
if (!string.IsNullOrEmpty(itemId))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
global using Microsoft.Extensions.Logging;
2+
global using Microsoft.Extensions.DependencyInjection;
3+
4+
global using System.Net.WebSockets;
5+
global using System.Text;
6+
global using System.Text.Json;
7+
8+
global using BotSharp.Abstraction.Realtime;
9+
global using BotSharp.Abstraction.Realtime.Models;
10+
global using BotSharp.Abstraction.MLTasks;
11+
global using BotSharp.Abstraction.Conversations.Enums;
12+
global using BotSharp.Abstraction.Routing.Models;
13+
global using BotSharp.Abstraction.Conversations;
14+
global using BotSharp.Abstraction.Agents;
15+
global using BotSharp.Abstraction.Routing;
16+
global using BotSharp.Abstraction.Agents.Enums;
17+
global using BotSharp.Abstraction.Conversations.Models;

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using BotSharp.Core.Templating;
1717
using BotSharp.Abstraction.Infrastructures.Enums;
1818
using BotSharp.Abstraction.Realtime;
19-
using BotSharp.Core.Realtime;
2019

2120
namespace BotSharp.Core;
2221

@@ -173,7 +172,5 @@ public static void RegisterPlugins(IServiceCollection services, IConfiguration c
173172
});
174173

175174
services.AddSingleton(loader);
176-
177-
services.AddScoped<IRealtimeHub, RealtimeHub>();
178175
}
179176
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ private async Task ReceiveMessage(RealtimeHubConnection conn,
207207
else if (response.Type == "input_audio_buffer.speech_started")
208208
{
209209
// Handle user interuption
210-
if (conn.MarkQueue.Count > 0 && conn.ResponseStartTimestampTwilio != null)
210+
if (conn.MarkQueue.Count > 0 && conn.ResponseStartTimestamp != null)
211211
{
212-
var elapsedTime = conn.LatestMediaTimestamp - conn.ResponseStartTimestampTwilio;
212+
var elapsedTime = conn.LatestMediaTimestamp - conn.ResponseStartTimestamp;
213213

214214
if (!string.IsNullOrEmpty(conn.LastAssistantItemId))
215215
{

src/WebStarter/WebStarter.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>$(TargetFramework)</TargetFramework>
@@ -36,6 +36,7 @@
3636
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Rules\BotSharp.Core.Rules.csproj" />
3737
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Crontab\BotSharp.Core.Crontab.csproj" />
3838
<ProjectReference Include="..\Infrastructure\BotSharp.Core.SideCar\BotSharp.Core.SideCar.csproj" />
39+
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
3940
<ProjectReference Include="..\Infrastructure\BotSharp.Logger\BotSharp.Logger.csproj" />
4041
<ProjectReference Include="..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
4142
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />

src/WebStarter/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
"BotSharp.Core",
392392
"BotSharp.Core.SideCar",
393393
"BotSharp.Core.Crontab",
394+
"BotSharp.Core.Realtime",
394395
"BotSharp.Logger",
395396
"BotSharp.Plugin.MongoStorage",
396397
"BotSharp.Plugin.Dashboard",

0 commit comments

Comments
 (0)