This commit is contained in:
Jicheng Lu 2025-05-07 16:34:39 -05:00
parent 8a6eb7d2ef
commit e35fbc7439
47 changed files with 279 additions and 233 deletions

View file

@ -0,0 +1,40 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Instructs.Models;
using BotSharp.Abstraction.Messaging;
using BotSharp.Abstraction.Messaging.Models.RichContent;
using BotSharp.Abstraction.Users.Dtos;
namespace BotSharp.Abstraction.Conversations.Dtos;
public class ChatResponseDto : InstructResult
{
[JsonPropertyName("conversation_id")]
public string ConversationId { get; set; } = string.Empty;
public UserDto Sender { get; set; } = new UserDto();
public string? Function { get; set; }
/// <summary>
/// Planner instruction
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FunctionCallFromLlm? Instruction { get; set; }
/// <summary>
/// Rich message for UI rendering
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("rich_content")]
public RichContent<IRichMessage>? RichContent { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("payload")]
public string? Payload { get; set; }
[JsonPropertyName("has_message_files")]
public bool HasMessageFiles { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}

View file

@ -0,0 +1,64 @@
using BotSharp.Abstraction.Conversations.Enums;
using BotSharp.Abstraction.Users.Dtos;
namespace BotSharp.Abstraction.Conversations.Dtos;
public class ConversationDto
{
public string Id { get; set; }
[JsonPropertyName("agent_id")]
public string AgentId { get; set; }
[JsonPropertyName("agent_name")]
public string AgentName { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; } = string.Empty;
[JsonPropertyName("title_alias")]
public string TitleAlias { get; set; } = string.Empty;
public UserDto User { get; set; } = new UserDto();
public string Channel { get; set; } = ConversationChannel.OpenAPI;
/// <summary>
/// Agent task id
/// </summary>
[JsonPropertyName("task_id")]
public string? TaskId { get; set; }
public string Status { get; set; }
public Dictionary<string, string> States { get; set; } = [];
public List<string> Tags { get; set; } = new();
[JsonPropertyName("updated_time")]
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
[JsonPropertyName("created_time")]
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
public static ConversationDto FromSession(Conversation sess)
{
return new ConversationDto
{
Id = sess.Id,
User = new UserDto
{
Id = sess.UserId
},
AgentId = sess.AgentId,
Title = sess.Title,
TitleAlias = sess.TitleAlias,
Channel = sess.Channel,
Status = sess.Status,
TaskId = sess.TaskId,
Tags = sess.Tags ?? [],
States = sess.States ?? [],
CreatedTime = sess.CreatedTime,
UpdatedTime = sess.UpdatedTime
};
}
}

View file

@ -1,4 +1,4 @@
namespace BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Abstraction.Crontab;
public interface ICrontabHook
{

View file

@ -1,4 +1,4 @@
namespace BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Abstraction.Crontab;
public interface ICrontabService
{

View file

@ -1,4 +1,4 @@
namespace BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Abstraction.Crontab;
/// <summary>
/// Provide a cron source for the crontab service.

View file

@ -1,4 +1,6 @@
namespace BotSharp.Core.Realtime.Models.Options;
using System.Text.Json;
namespace BotSharp.Abstraction.Realtime.Models.Session;
public class ChatSessionOptions
{

View file

@ -1,4 +1,4 @@
namespace BotSharp.Core.Realtime.Models.Chat;
namespace BotSharp.Abstraction.Realtime.Models.Session;
public class ChatSessionUpdate
{

View file

@ -0,0 +1,73 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
namespace BotSharp.Abstraction.Users.Dtos;
public class UserDto
{
public string Id { get; set; } = string.Empty;
[JsonPropertyName("user_name")]
public string UserName { get; set; } = string.Empty;
[JsonPropertyName("first_name")]
public string FirstName { get; set; } = string.Empty;
[JsonPropertyName("last_name")]
public string? LastName { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
[JsonPropertyName("full_name")]
public string FullName => $"{FirstName} {LastName}".Trim();
public string? Source { get; set; }
[JsonPropertyName("external_id")]
public string? ExternalId { get; set; }
public string Avatar { get; set; } = "/user/avatar";
public IEnumerable<string> Permissions { get; set; } = [];
[JsonPropertyName("create_date")]
public DateTime CreateDate { get; set; }
[JsonPropertyName("update_date")]
public DateTime UpdateDate { get; set; }
public string RegionCode { get; set; } = "CN";
public static UserDto FromUser(User user)
{
if (user == null)
{
return new UserDto
{
FirstName = "Unknown",
LastName = "Anonymous",
Type = UserType.Client,
Role = AgentRole.User
};
}
return new UserDto
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", string.Empty) : user.Phone,
Type = user.Type,
Role = user.Role,
Source = user.Source,
ExternalId = user.ExternalId,
Permissions = user.Permissions,
CreateDate = user.CreatedTime,
UpdateDate = user.UpdatedTime,
Avatar = "/user/avatar",
RegionCode = string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode
};
}
}

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(TargetFramework)</TargetFramework>
@ -10,6 +10,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Models\**" />
<EmbeddedResource Remove="Models\**" />
<None Remove="Models\**" />
</ItemGroup>
<ItemGroup>
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-crontab-schedule_task.json" />
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-crontab-schedule_task.fn.liquid" />
@ -35,8 +41,4 @@
<PackageReference Include="NCrontab" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project>

View file

@ -1,11 +1,5 @@
using BotSharp.Core.Crontab.Hooks;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace BotSharp.Core.Crontab.Functions;

View file

@ -4,10 +4,10 @@ global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using BotSharp.Abstraction.Agents.Enums;
global using BotSharp.Abstraction.Crontab;
global using BotSharp.Abstraction.Crontab.Models;
global using BotSharp.Abstraction.Agents;
global using BotSharp.Abstraction.Plugins;
global using BotSharp.Abstraction.Conversations.Models;
global using BotSharp.Abstraction.Functions;
global using BotSharp.Core.Crontab.Services;
global using BotSharp.Core.Crontab.Abstraction;
global using BotSharp.Core.Crontab.Services;

View file

@ -28,13 +28,7 @@ public class McpToolAgentHook : AgentHookBase
agent.SecondaryFunctions ??= [];
var functions = GetMcpContent(agent).Result;
foreach (var fn in functions)
{
if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase)))
{
agent.SecondaryFunctions.Add(fn);
}
}
agent.SecondaryFunctions = agent.SecondaryFunctions.Concat(functions).DistinctBy(x => x.Name).ToList();
}
private async Task<IEnumerable<FunctionDef>> GetMcpContent(Agent agent)

View file

@ -12,11 +12,9 @@
<ItemGroup>
<PackageReference Include="NAudio" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>

View file

@ -1,7 +1,6 @@
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.DependencyInjection;
global using System.Net.WebSockets;
global using System.Text;
global using System.Text.Json;
@ -15,7 +14,3 @@ global using BotSharp.Abstraction.Agents;
global using BotSharp.Abstraction.Routing;
global using BotSharp.Abstraction.Agents.Enums;
global using BotSharp.Abstraction.Conversations.Models;
global using BotSharp.Core.Realtime.Models.Chat;
global using BotSharp.Core.Realtime.Models.Options;
global using BotSharp.Core.Realtime.Websocket.Chat;

View file

@ -25,18 +25,8 @@ public class BasicAgentHook : AgentHookBase
var (functions, templates) = GetUtilityContent(agent);
foreach (var fn in functions)
{
if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase)))
{
agent.SecondaryFunctions.Add(fn);
}
}
foreach (var prompt in templates)
{
agent.SecondaryInstructions.Add(prompt);
}
agent.SecondaryFunctions = agent.SecondaryFunctions.Concat(functions).DistinctBy(x => x.Name).ToList();
agent.SecondaryInstructions = agent.SecondaryInstructions.Concat(templates).Distinct().ToList();
}

View file

@ -221,6 +221,7 @@
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="Nanoid" />
<PackageReference Include="Rougamo.Fody" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>
<ItemGroup>

View file

@ -1,7 +1,8 @@
using BotSharp.Core.Realtime.Models.Options;
using BotSharp.Abstraction.Realtime.Models.Session;
using System.ClientModel;
using System.Net.WebSockets;
namespace BotSharp.Core.Realtime.Websocket.Common;
namespace BotSharp.Core.Infrastructures.Websocket;
internal class AsyncWebsocketDataCollectionResult : AsyncCollectionResult<ClientResult>
{

View file

@ -1,8 +1,9 @@
using BotSharp.Core.Realtime.Models.Options;
using BotSharp.Abstraction.Realtime.Models.Session;
using System.Buffers;
using System.ClientModel;
using System.Net.WebSockets;
namespace BotSharp.Core.Realtime.Websocket.Common;
namespace BotSharp.Core.Infrastructures.Websocket;
internal class AsyncWebsocketDataResultEnumerator : IAsyncEnumerator<ClientResult>
{

View file

@ -1,7 +1,9 @@
using System.ClientModel.Primitives;
using System.IO;
using System.Net;
using System.Net.WebSockets;
namespace BotSharp.Core.Realtime.Websocket.Common;
namespace BotSharp.Core.Infrastructures.Websocket;
internal class WebsocketPipelineResponse : PipelineResponse
{

View file

@ -1,8 +1,8 @@
using BotSharp.Core.Realtime.Websocket.Common;
using System.ClientModel;
using System.Net.WebSockets;
using System.Runtime.CompilerServices;
namespace BotSharp.Core.Realtime.Websocket.Chat;
namespace BotSharp.Core.Session;
public class BotSharpRealtimeSession : IDisposable
{

View file

@ -1,10 +1,8 @@
using System.ClientModel;
using System.Net.WebSockets;
using System.Runtime.CompilerServices;
using BotSharp.Core.Realtime.Models.Chat;
using BotSharp.Core.Realtime.Models.Options;
using BotSharp.Core.Realtime.Websocket.Common;
namespace BotSharp.Core.Realtime.Websocket.Llm;
namespace BotSharp.Core.Session;
public class LlmRealtimeSession : IDisposable
{

View file

@ -42,11 +42,13 @@ global using BotSharp.Abstraction.Statistics.Services;
global using BotSharp.Abstraction.Loggers.Services;
global using BotSharp.Abstraction.Infrastructures.Events;
global using BotSharp.Abstraction.Templating.Constants;
global using BotSharp.Abstraction.Realtime.Models.Session;
global using BotSharp.Core.Repository;
global using BotSharp.Core.Routing;
global using BotSharp.Core.Agents.Services;
global using BotSharp.Core.Conversations.Services;
global using BotSharp.Core.Infrastructures;
global using BotSharp.Core.Infrastructures.Websocket;
global using BotSharp.Core.Users.Services;
global using BotSharp.Core.Statistics.Services;
global using BotSharp.Core.Loggers.Services;

View file

@ -3,6 +3,7 @@ using BotSharp.Abstraction.Files.Enums;
using BotSharp.Abstraction.Files.Utilities;
using BotSharp.Abstraction.Options;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Users.Dtos;
using BotSharp.Core.Infrastructures;
namespace BotSharp.OpenAPI.Controllers;
@ -108,7 +109,7 @@ public class ConversationController : ControllerBase
CreatedAt = message.CreatedAt,
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
Data = message.Data,
Sender = UserViewModel.FromUser(user),
Sender = UserDto.FromUser(user),
Payload = message.Payload,
HasMessageFiles = fileMessages.Any(x => x.MessageId.IsEqualTo(message.MessageId) && x.FileSource == FileSourceType.User)
});
@ -124,7 +125,7 @@ public class ConversationController : ControllerBase
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
Function = message.FunctionName,
Data = message.Data,
Sender = new UserViewModel
Sender = new()
{
FirstName = agent?.Name ?? "Unkown",
Role = message.Role,

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Conversations.Dtos;
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Conversations;
@ -5,7 +6,7 @@ namespace BotSharp.OpenAPI.ViewModels.Conversations;
public class UpdateMessageModel
{
[JsonPropertyName("message")]
public ChatResponseModel Message { get; set; } = null!;
public ChatResponseDto Message { get; set; } = null!;
[JsonPropertyName("inner_index")]
public int InnerIndex { get; set; }

View file

@ -1,40 +1,7 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Instructs.Models;
using BotSharp.Abstraction.Messaging;
using BotSharp.Abstraction.Messaging.Models.RichContent;
using System.Text.Json.Serialization;
using BotSharp.Abstraction.Conversations.Dtos;
namespace BotSharp.OpenAPI.ViewModels.Conversations;
public class ChatResponseModel : InstructResult
public class ChatResponseModel : ChatResponseDto
{
[JsonPropertyName("conversation_id")]
public string ConversationId { get; set; } = string.Empty;
public UserViewModel Sender { get; set; } = new UserViewModel();
public string? Function { get; set; }
/// <summary>
/// Planner instruction
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FunctionCallFromLlm? Instruction { get; set; }
/// <summary>
/// Rich message for UI rendering
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("rich_content")]
public RichContent<IRichMessage>? RichContent { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("payload")]
public string? Payload { get; set; }
[JsonPropertyName("has_message_files")]
public bool HasMessageFiles { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}

View file

@ -1,51 +1,15 @@
using System.Text.Json.Serialization;
using BotSharp.Abstraction.Conversations.Dtos;
namespace BotSharp.OpenAPI.ViewModels.Conversations;
public class ConversationViewModel
public class ConversationViewModel : ConversationDto
{
public string Id { get; set; }
[JsonPropertyName("agent_id")]
public string AgentId { get; set; }
[JsonPropertyName("agent_name")]
public string AgentName { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; } = string.Empty;
[JsonPropertyName("title_alias")]
public string TitleAlias { get; set; } = string.Empty;
public UserViewModel User { get; set; } = new UserViewModel();
public string Event { get; set; }
public string Channel { get; set; } = ConversationChannel.OpenAPI;
/// <summary>
/// Agent task id
/// </summary>
[JsonPropertyName("task_id")]
public string? TaskId { get; set; }
public string Status { get; set; }
public Dictionary<string, string> States { get; set; } = [];
public List<string> Tags { get; set; } = new();
[JsonPropertyName("updated_time")]
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
[JsonPropertyName("created_time")]
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
public static ConversationViewModel FromSession(Conversation sess)
{
return new ConversationViewModel
{
Id = sess.Id,
User = new UserViewModel
User = new()
{
Id = sess.UserId
},

View file

@ -1,43 +1,14 @@
using BotSharp.Abstraction.Users.Dtos;
using BotSharp.Abstraction.Users.Enums;
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Users;
public class UserViewModel
public class UserViewModel : UserDto
{
public string Id { get; set; } = string.Empty;
[JsonPropertyName("user_name")]
public string UserName { get; set; } = string.Empty;
[JsonPropertyName("first_name")]
public string FirstName { get; set; } = string.Empty;
[JsonPropertyName("last_name")]
public string? LastName { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
[JsonPropertyName("full_name")]
public string FullName => $"{FirstName} {LastName}".Trim();
public string? Source { get; set; }
[JsonPropertyName("external_id")]
public string? ExternalId { get; set; }
public string Avatar { get; set; } = "/user/avatar";
public IEnumerable<string> Permissions { get; set; } = [];
[JsonPropertyName("agent_actions")]
public IEnumerable<UserAgentActionViewModel> AgentActions { get; set; } = [];
[JsonPropertyName("create_date")]
public DateTime CreateDate { get; set; }
[JsonPropertyName("update_date")]
public DateTime UpdateDate { get; set; }
public string RegionCode { get; set; } = "CN";
public static UserViewModel FromUser(User user)
{
if (user == null)
@ -57,8 +28,6 @@ public class UserViewModel
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
//Email = Utilities.HideMiddleDigits(user.Email, true),
//Phone = Utilities.HideMiddleDigits((!string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone)),
Email = user.Email,
Phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone,
Type = user.Type,

View file

@ -19,8 +19,6 @@
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Crontab\BotSharp.Core.Crontab.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
</Project>

View file

@ -1,5 +1,4 @@
using BotSharp.Abstraction.Interpreters.Settings;
using BotSharp.Core.Crontab.Abstraction;
using BotSharp.Abstraction.Crontab;
using BotSharp.Plugin.ChatHub.Hooks;
using Microsoft.Extensions.Configuration;

View file

@ -1,3 +1,5 @@
using BotSharp.Abstraction.Realtime.Models.Session;
using BotSharp.Core.Session;
using Microsoft.AspNetCore.Http;
using System.Net.WebSockets;

View file

@ -1,4 +1,6 @@
using BotSharp.Abstraction.Conversations.Dtos;
using BotSharp.Abstraction.SideCar;
using BotSharp.Abstraction.Users.Dtos;
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub.Hooks;
@ -43,10 +45,10 @@ public class ChatHubConversationHook : ConversationHookBase
if (!AllowSendingMessage()) return;
var userService = _services.GetRequiredService<IUserService>();
var conv = ConversationViewModel.FromSession(conversation);
var conv = ConversationDto.FromSession(conversation);
var user = await userService.GetUser(conv.User.Id);
conv.User = UserViewModel.FromUser(user);
conv.User = UserDto.FromUser(user);
await InitClientConversation(conv.Id, conv);
await base.OnConversationInitialized(conversation);
@ -61,13 +63,13 @@ public class ChatHubConversationHook : ConversationHookBase
var sender = await userService.GetMyProfile();
// Update console conversation UI for CSR
var model = new ChatResponseModel()
var model = new ChatResponseDto()
{
ConversationId = conv.ConversationId,
MessageId = message.MessageId,
Payload = message.Payload,
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
Sender = UserViewModel.FromUser(sender)
Sender = UserDto.FromUser(sender)
};
await ReceiveClientMessage(conv.ConversationId, model);
@ -107,7 +109,7 @@ public class ChatHubConversationHook : ConversationHookBase
var conv = _services.GetRequiredService<IConversationService>();
var state = _services.GetRequiredService<IConversationStateService>();
var json = JsonSerializer.Serialize(new ChatResponseModel()
var json = JsonSerializer.Serialize(new ChatResponseDto()
{
ConversationId = conv.ConversationId,
MessageId = message.MessageId,
@ -116,7 +118,7 @@ public class ChatHubConversationHook : ConversationHookBase
RichContent = message.SecondaryRichContent ?? message.RichContent,
Data = message.Data,
States = state.GetStates(),
Sender = new UserViewModel()
Sender = new()
{
FirstName = "AI",
LastName = "Assistant",
@ -140,7 +142,7 @@ public class ChatHubConversationHook : ConversationHookBase
public override async Task OnNotificationGenerated(RoleDialogModel message)
{
var conv = _services.GetRequiredService<IConversationService>();
var json = JsonSerializer.Serialize(new ChatResponseModel()
var json = JsonSerializer.Serialize(new ChatResponseDto()
{
ConversationId = conv.ConversationId,
MessageId = message.MessageId,
@ -148,7 +150,7 @@ public class ChatHubConversationHook : ConversationHookBase
Function = message.FunctionName,
RichContent = message.SecondaryRichContent ?? message.RichContent,
Data = message.Data,
Sender = new UserViewModel()
Sender = new()
{
FirstName = "AI",
LastName = "Assistant",
@ -163,7 +165,7 @@ public class ChatHubConversationHook : ConversationHookBase
public override async Task OnMessageDeleted(string conversationId, string messageId)
{
var model = new ChatResponseModel
var model = new ChatResponseDto
{
ConversationId = conversationId,
MessageId = messageId
@ -180,7 +182,7 @@ public class ChatHubConversationHook : ConversationHookBase
return sidecar == null || !sidecar.IsEnabled();
}
private async Task InitClientConversation(string conversationId, ConversationViewModel conversation)
private async Task InitClientConversation(string conversationId, ConversationDto conversation)
{
try
{
@ -199,7 +201,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
}
private async Task ReceiveClientMessage(string conversationId, ChatResponseModel model)
private async Task ReceiveClientMessage(string conversationId, ChatResponseDto model)
{
try
{
@ -257,7 +259,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
}
private async Task DeleteMessage(string conversationId, ChatResponseModel model)
private async Task DeleteMessage(string conversationId, ChatResponseDto model)
{
try
{

View file

@ -1,5 +1,6 @@
using BotSharp.Abstraction.Conversations.Dtos;
using BotSharp.Abstraction.Crontab;
using BotSharp.Abstraction.Crontab.Models;
using BotSharp.Core.Crontab.Abstraction;
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub.Hooks;
@ -34,13 +35,13 @@ public class ChatHubCrontabHook : ICrontabHook
public async Task OnCronTriggered(CrontabItem item)
{
var json = JsonSerializer.Serialize(new ChatResponseModel()
var json = JsonSerializer.Serialize(new ChatResponseDto()
{
ConversationId = item.ConversationId,
MessageId = Guid.NewGuid().ToString(),
Text = item.ExecutionResult,
Function = "",
Sender = new UserViewModel()
Sender = new()
{
FirstName = "Crontab",
LastName = "AI",

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Conversations.Dtos;
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub.Hooks;
@ -63,13 +64,13 @@ public class WelcomeHook : ConversationHookBase
RichContent = richContent
};
var json = JsonSerializer.Serialize(new ChatResponseModel()
var json = JsonSerializer.Serialize(new ChatResponseDto()
{
ConversationId = conversation.Id,
MessageId = dialog.MessageId,
Text = message.Text,
RichContent = richContent,
Sender = new UserViewModel()
Sender = new()
{
FirstName = agent.Name,
LastName = "",

View file

@ -32,12 +32,6 @@ global using BotSharp.Abstraction.Messaging.Models.RichContent;
global using BotSharp.Abstraction.Templating;
global using BotSharp.Abstraction.Realtime;
global using BotSharp.Abstraction.Realtime.Models;
global using BotSharp.OpenAPI.ViewModels.Conversations;
global using BotSharp.OpenAPI.ViewModels.Users;
global using BotSharp.Plugin.ChatHub.Settings;
global using BotSharp.Plugin.ChatHub.Enums;
global using BotSharp.Plugin.ChatHub.Models.Stream;
global using BotSharp.Core.Realtime.Models.Chat;
global using BotSharp.Core.Realtime.Models.Options;
global using BotSharp.Core.Realtime.Websocket.Chat;
global using BotSharp.Plugin.ChatHub.Models.Stream;

View file

@ -13,7 +13,6 @@
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
</ItemGroup>
</Project>

View file

@ -11,7 +11,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>

View file

@ -58,7 +58,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>

View file

@ -15,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
</Project>

View file

@ -11,7 +11,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
public string Provider => "openai";
public string Model => _model;
private readonly RealtimeModelSettings _settings;
private readonly IServiceProvider _services;
private readonly ILogger<RealTimeCompletionProvider> _logger;
private readonly BotSharpOptions _botsharpOptions;
@ -20,12 +19,10 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
private LlmRealtimeSession _session;
public RealTimeCompletionProvider(
RealtimeModelSettings settings,
ILogger<RealTimeCompletionProvider> logger,
IServiceProvider services,
ILogger<RealTimeCompletionProvider> logger,
BotSharpOptions botsharpOptions)
{
_settings = settings;
_logger = logger;
_services = services;
_botsharpOptions = botsharpOptions;
@ -290,26 +287,27 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
return fn;
}).ToArray();
var realtimeModelSettings = _services.GetRequiredService<RealtimeModelSettings>();
var sessionUpdate = new
{
type = "session.update",
session = new RealtimeSessionUpdateRequest
{
InputAudioFormat = _settings.InputAudioFormat,
OutputAudioFormat = _settings.OutputAudioFormat,
Voice = _settings.Voice,
InputAudioFormat = realtimeModelSettings.InputAudioFormat,
OutputAudioFormat = realtimeModelSettings.OutputAudioFormat,
Voice = realtimeModelSettings.Voice,
Instructions = instruction,
ToolChoice = "auto",
Tools = functions,
Modalities = _settings.Modalities,
Temperature = Math.Max(options.Temperature ?? _settings.Temperature, 0.6f),
MaxResponseOutputTokens = _settings.MaxResponseOutputTokens,
Modalities = realtimeModelSettings.Modalities,
Temperature = Math.Max(options.Temperature ?? realtimeModelSettings.Temperature, 0.6f),
MaxResponseOutputTokens = realtimeModelSettings.MaxResponseOutputTokens,
TurnDetection = new RealtimeSessionTurnDetection
{
InterruptResponse = _settings.InterruptResponse/*,
Threshold = _settings.TurnDetection.Threshold,
PrefixPadding = _settings.TurnDetection.PrefixPadding,
SilenceDuration = _settings.TurnDetection.SilenceDuration*/
InterruptResponse = realtimeModelSettings.InterruptResponse/*,
Threshold = realtimeModelSettings.TurnDetection.Threshold,
PrefixPadding = realtimeModelSettings.TurnDetection.PrefixPadding,
SilenceDuration = realtimeModelSettings.TurnDetection.SilenceDuration*/
},
InputAudioNoiseReduction = new InputAudioNoiseReduction
{
@ -318,15 +316,15 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
}
};
if (_settings.InputAudioTranscribe)
if (realtimeModelSettings.InputAudioTranscribe)
{
var words = new List<string>();
HookEmitter.Emit<IRealtimeHook>(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)));
sessionUpdate.session.InputAudioTranscription = new InputAudioTranscription
{
Model = _settings.InputAudioTranscription.Model,
Language = _settings.InputAudioTranscription.Language,
Model = realtimeModelSettings.InputAudioTranscription.Model,
Language = realtimeModelSettings.InputAudioTranscription.Language,
Prompt = string.Join(", ", words.Select(x => x.ToLower().Trim()).Distinct()).SubstringMax(1024)
};
}

View file

@ -29,10 +29,8 @@ global using BotSharp.Abstraction.MLTasks.Settings;
global using BotSharp.Abstraction.Options;
global using BotSharp.Abstraction.Realtime;
global using BotSharp.Abstraction.Realtime.Models;
global using BotSharp.Abstraction.Realtime.Models.Session;
global using BotSharp.Core.Infrastructures;
global using BotSharp.Core.Session;
global using BotSharp.Plugin.OpenAI.Models;
global using BotSharp.Plugin.OpenAI.Settings;
global using BotSharp.Core.Realtime.Models.Chat;
global using BotSharp.Core.Realtime.Models.Options;
global using BotSharp.Core.Realtime.Websocket.Llm;
global using BotSharp.Plugin.OpenAI.Settings;

View file

@ -105,8 +105,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Crontab\BotSharp.Core.Crontab.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>

View file

@ -1,7 +1,7 @@
using BotSharp.Abstraction.Crontab;
using BotSharp.Abstraction.Crontab.Models;
using BotSharp.Abstraction.Models;
using BotSharp.Abstraction.SideCar;
using BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Plugin.SqlDriver.Hooks;

View file

@ -1,5 +1,5 @@
using BotSharp.Abstraction.Crontab;
using BotSharp.Abstraction.Planning;
using BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Plugin.SqlDriver;

View file

@ -6,27 +6,29 @@ global using System.Text.RegularExpressions;
global using System.Threading.Tasks;
global using System.Linq;
global using System.Text.Json;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.Logging;
global using BotSharp.Abstraction.Conversations;
global using BotSharp.Abstraction.Plugins;
global using BotSharp.Abstraction.Conversations.Models;
global using BotSharp.Plugin.SqlDriver.Models;
global using BotSharp.Abstraction.Functions;
global using BotSharp.Abstraction.Agents.Models;
global using BotSharp.Abstraction.Templating;
global using Microsoft.Extensions.DependencyInjection;
global using BotSharp.Abstraction.Agents;
global using BotSharp.Abstraction.Utilities;
global using BotSharp.Abstraction.Knowledges;
global using BotSharp.Abstraction.Knowledges.Models;
global using BotSharp.Abstraction.Settings;
global using BotSharp.Plugin.SqlDriver.Hooks;
global using BotSharp.Plugin.SqlDriver.Services;
global using BotSharp.Abstraction.Agents.Enums;
global using BotSharp.Abstraction.Instructs;
global using BotSharp.Abstraction.Instructs.Models;
global using BotSharp.Abstraction.Routing;
global using BotSharp.Plugin.SqlDriver.Models;
global using BotSharp.Plugin.SqlDriver.Hooks;
global using BotSharp.Plugin.SqlDriver.Services;
global using BotSharp.Plugin.SqlDriver.Interfaces;
global using BotSharp.Plugin.SqlDriver.Helpers;
global using BotSharp.Plugin.SqlDriver.Settings;

View file

@ -42,7 +42,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>

View file

@ -44,7 +44,6 @@
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Rules\BotSharp.Core.Rules.csproj" />
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Crontab\BotSharp.Core.Crontab.csproj" />
<ProjectReference Include="..\Infrastructure\BotSharp.Core.SideCar\BotSharp.Core.SideCar.csproj" />
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
<ProjectReference Include="..\Infrastructure\BotSharp.Logger\BotSharp.Logger.csproj" />
<ProjectReference Include="..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />

View file

@ -13,15 +13,14 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit"/>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.AnthropicAI\BotSharp.Plugin.AnthropicAI.csproj" />
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.GoogleAI\BotSharp.Plugin.GoogleAI.csproj" />