Skip to content

Commit 3dfb921

Browse files
authored
Merge pull request #1060 from iceljc/test/google-realtime
add session reconnect
2 parents 2ff2c30 + ba0b486 commit 3dfb921

52 files changed

Lines changed: 374 additions & 194 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public enum AgentField
88
IsPublic,
99
Disabled,
1010
Type,
11-
Mode,
11+
RoutingMode,
1212
InheritAgentId,
1313
Profile,
1414
Label,

src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Agent
99
public string Id { get; set; } = string.Empty;
1010
public string Name { get; set; } = string.Empty;
1111
public string Description { get; set; } = string.Empty;
12+
1213
/// <summary>
1314
/// Agent Type
1415
/// </summary>
@@ -17,7 +18,8 @@ public class Agent
1718
/// <summary>
1819
/// Routing Mode: lazy or eager
1920
/// </summary>
20-
public string Mode { get; set; } = "eager";
21+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
22+
public string? Mode { get; set; }
2123

2224
public DateTime CreatedDateTime { get; set; }
2325
public DateTime UpdatedDateTime { get; set; }
@@ -277,18 +279,18 @@ public Agent SetMergeUtility(bool merge)
277279
return this;
278280
}
279281

280-
public Agent SetAgentType(string type)
282+
public Agent SetType(string type)
281283
{
282284
Type = type;
283285
return this;
284286
}
285287

286288
/// <summary>
287-
/// Set agent mode: lazy or eager
289+
/// Set agent routing mode: lazy or eager
288290
/// </summary>
289291
/// <param name="mode"></param>
290292
/// <returns></returns>
291-
public Agent SetAgentMode(string mode)
293+
public Agent SetRoutingMode(string? mode)
292294
{
293295
Mode = mode;
294296
return this;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace BotSharp.Abstraction.Crontab.Settings;
2+
3+
public class CrontabSettings
4+
{
5+
public CrontabBaseSetting EventSubscriber { get; set; } = new();
6+
public CrontabBaseSetting Watcher { get; set; } = new();
7+
}
8+
9+
public class CrontabBaseSetting
10+
{
11+
public bool Enabled { get; set; } = true;
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using BotSharp.Abstraction.Users;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.Filters;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace BotSharp.Abstraction.Infrastructures.Attributes;
7+
8+
/// <summary>
9+
/// BotSharp authorization: check whether the request user is admin or root role.
10+
/// </summary>
11+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
12+
public class BotSharpAuthAttribute : Attribute, IAsyncAuthorizationFilter
13+
{
14+
public BotSharpAuthAttribute()
15+
{
16+
17+
}
18+
19+
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
20+
{
21+
var services = context.HttpContext.RequestServices;
22+
23+
var userIdentity = services.GetRequiredService<IUserIdentity>();
24+
var userService = services.GetRequiredService<IUserService>();
25+
26+
var (isAdmin, user) = await userService.IsAdminUser(userIdentity.Id);
27+
if (!isAdmin || user == null)
28+
{
29+
context.Result = new UnauthorizedResult();
30+
}
31+
}
32+
}

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Task Connect(
1919
Func<RoleDialogModel, Task> onInputAudioTranscriptionDone,
2020
Func<Task> onInterruptionDetected);
2121

22+
Task Reconnect(RealtimeHubConnection conn);
23+
2224
Task AppenAudioBuffer(string message);
2325
Task AppenAudioBuffer(ArraySegment<byte> data, int length);
2426

src/Infrastructure/BotSharp.Abstraction/Realtime/IRealtimeHook.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BotSharp.Abstraction.Hooks;
22
using BotSharp.Abstraction.MLTasks;
3+
using BotSharp.Abstraction.Realtime.Models;
34

45
namespace BotSharp.Abstraction.Realtime;
56

@@ -8,4 +9,5 @@ public interface IRealtimeHook : IHookBase
89
Task OnModelReady(Agent agent, IRealTimeCompletion completer);
910
string[] OnModelTranscriptPrompt(Agent agent);
1011
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data);
12+
Task<bool> ShouldReconnect(RealtimeHubConnection conn) => Task.FromResult(false);
1113
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using Microsoft.Extensions.Logging;
12
using System.Text.Json;
23

34
namespace BotSharp.Abstraction.Realtime.Models.Session;
45

56
public class ChatSessionOptions
67
{
8+
public string Provider { get; set; }
79
public int? BufferSize { get; set; }
810
public JsonSerializerOptions? JsonOptions { get; set; }
11+
public ILogger? Logger { get; set; }
912
}

src/Infrastructure/BotSharp.Abstraction/Repositories/BotSharpDatabaseSettings.cs renamed to src/Infrastructure/BotSharp.Abstraction/Repositories/Settings/BotSharpDatabaseSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace BotSharp.Abstraction.Repositories;
1+
namespace BotSharp.Abstraction.Repositories.Settings;
22

33
public class BotSharpDatabaseSettings : DatabaseBasicSettings
44
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Routing.Enums;
2+
3+
public class RoutingMode
4+
{
5+
public const string Eager = "eager";
6+
public const string Lazy = "lazy";
7+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace BotSharp.Abstraction.Utilities;
55

66
public static class StringExtensions
77
{
8-
public static string IfNullOrEmptyAs(this string str, string defaultValue)
8+
public static string IfNullOrEmptyAs(this string? str, string defaultValue)
99
=> string.IsNullOrEmpty(str) ? defaultValue : str;
1010

1111
public static string SubstringMax(this string str, int maxLength)

0 commit comments

Comments
 (0)