refine
This commit is contained in:
parent
8a6eb7d2ef
commit
e35fbc7439
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace BotSharp.Core.Crontab.Abstraction;
|
namespace BotSharp.Abstraction.Crontab;
|
||||||
|
|
||||||
public interface ICrontabHook
|
public interface ICrontabHook
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace BotSharp.Core.Crontab.Abstraction;
|
namespace BotSharp.Abstraction.Crontab;
|
||||||
|
|
||||||
public interface ICrontabService
|
public interface ICrontabService
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace BotSharp.Core.Crontab.Abstraction;
|
namespace BotSharp.Abstraction.Crontab;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provide a cron source for the crontab service.
|
/// Provide a cron source for the crontab service.
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
namespace BotSharp.Core.Realtime.Models.Options;
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
|
|
||||||
public class ChatSessionOptions
|
public class ChatSessionOptions
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace BotSharp.Core.Realtime.Models.Chat;
|
namespace BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
|
|
||||||
public class ChatSessionUpdate
|
public class ChatSessionUpdate
|
||||||
{
|
{
|
||||||
|
|
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>$(TargetFramework)</TargetFramework>
|
<TargetFramework>$(TargetFramework)</TargetFramework>
|
||||||
|
|
@ -10,6 +10,12 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Models\**" />
|
||||||
|
<EmbeddedResource Remove="Models\**" />
|
||||||
|
<None Remove="Models\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<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\functions\util-crontab-schedule_task.json" />
|
||||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-crontab-schedule_task.fn.liquid" />
|
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-crontab-schedule_task.fn.liquid" />
|
||||||
|
|
@ -35,8 +41,4 @@
|
||||||
<PackageReference Include="NCrontab" />
|
<PackageReference Include="NCrontab" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Models\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,5 @@
|
||||||
using BotSharp.Core.Crontab.Hooks;
|
using BotSharp.Core.Crontab.Hooks;
|
||||||
using Microsoft.Extensions.Logging;
|
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;
|
namespace BotSharp.Core.Crontab.Functions;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
global using BotSharp.Abstraction.Agents.Enums;
|
global using BotSharp.Abstraction.Agents.Enums;
|
||||||
|
global using BotSharp.Abstraction.Crontab;
|
||||||
global using BotSharp.Abstraction.Crontab.Models;
|
global using BotSharp.Abstraction.Crontab.Models;
|
||||||
global using BotSharp.Abstraction.Agents;
|
global using BotSharp.Abstraction.Agents;
|
||||||
global using BotSharp.Abstraction.Plugins;
|
global using BotSharp.Abstraction.Plugins;
|
||||||
global using BotSharp.Abstraction.Conversations.Models;
|
global using BotSharp.Abstraction.Conversations.Models;
|
||||||
global using BotSharp.Abstraction.Functions;
|
global using BotSharp.Abstraction.Functions;
|
||||||
global using BotSharp.Core.Crontab.Services;
|
global using BotSharp.Core.Crontab.Services;
|
||||||
global using BotSharp.Core.Crontab.Abstraction;
|
|
||||||
|
|
@ -28,13 +28,7 @@ public class McpToolAgentHook : AgentHookBase
|
||||||
agent.SecondaryFunctions ??= [];
|
agent.SecondaryFunctions ??= [];
|
||||||
|
|
||||||
var functions = GetMcpContent(agent).Result;
|
var functions = GetMcpContent(agent).Result;
|
||||||
foreach (var fn in functions)
|
agent.SecondaryFunctions = agent.SecondaryFunctions.Concat(functions).DistinctBy(x => x.Name).ToList();
|
||||||
{
|
|
||||||
if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase)))
|
|
||||||
{
|
|
||||||
agent.SecondaryFunctions.Add(fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<FunctionDef>> GetMcpContent(Agent agent)
|
private async Task<IEnumerable<FunctionDef>> GetMcpContent(Agent agent)
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,9 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NAudio" />
|
<PackageReference Include="NAudio" />
|
||||||
<PackageReference Include="System.ClientModel" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
|
||||||
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
|
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
global using System.Net.WebSockets;
|
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Text.Json;
|
global using System.Text.Json;
|
||||||
|
|
||||||
|
|
@ -15,7 +14,3 @@ global using BotSharp.Abstraction.Agents;
|
||||||
global using BotSharp.Abstraction.Routing;
|
global using BotSharp.Abstraction.Routing;
|
||||||
global using BotSharp.Abstraction.Agents.Enums;
|
global using BotSharp.Abstraction.Agents.Enums;
|
||||||
global using BotSharp.Abstraction.Conversations.Models;
|
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;
|
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,8 @@ public class BasicAgentHook : AgentHookBase
|
||||||
|
|
||||||
var (functions, templates) = GetUtilityContent(agent);
|
var (functions, templates) = GetUtilityContent(agent);
|
||||||
|
|
||||||
foreach (var fn in functions)
|
agent.SecondaryFunctions = agent.SecondaryFunctions.Concat(functions).DistinctBy(x => x.Name).ToList();
|
||||||
{
|
agent.SecondaryInstructions = agent.SecondaryInstructions.Concat(templates).Distinct().ToList();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" />
|
<PackageReference Include="Microsoft.Extensions.Http" />
|
||||||
<PackageReference Include="Nanoid" />
|
<PackageReference Include="Nanoid" />
|
||||||
<PackageReference Include="Rougamo.Fody" />
|
<PackageReference Include="Rougamo.Fody" />
|
||||||
|
<PackageReference Include="System.ClientModel" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
using BotSharp.Core.Realtime.Models.Options;
|
using BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
using System.ClientModel;
|
using System.ClientModel;
|
||||||
|
using System.Net.WebSockets;
|
||||||
|
|
||||||
namespace BotSharp.Core.Realtime.Websocket.Common;
|
namespace BotSharp.Core.Infrastructures.Websocket;
|
||||||
|
|
||||||
internal class AsyncWebsocketDataCollectionResult : AsyncCollectionResult<ClientResult>
|
internal class AsyncWebsocketDataCollectionResult : AsyncCollectionResult<ClientResult>
|
||||||
{
|
{
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
using BotSharp.Core.Realtime.Models.Options;
|
using BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.ClientModel;
|
using System.ClientModel;
|
||||||
|
using System.Net.WebSockets;
|
||||||
|
|
||||||
namespace BotSharp.Core.Realtime.Websocket.Common;
|
namespace BotSharp.Core.Infrastructures.Websocket;
|
||||||
|
|
||||||
internal class AsyncWebsocketDataResultEnumerator : IAsyncEnumerator<ClientResult>
|
internal class AsyncWebsocketDataResultEnumerator : IAsyncEnumerator<ClientResult>
|
||||||
{
|
{
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using System.ClientModel.Primitives;
|
using System.ClientModel.Primitives;
|
||||||
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.WebSockets;
|
||||||
|
|
||||||
namespace BotSharp.Core.Realtime.Websocket.Common;
|
namespace BotSharp.Core.Infrastructures.Websocket;
|
||||||
|
|
||||||
internal class WebsocketPipelineResponse : PipelineResponse
|
internal class WebsocketPipelineResponse : PipelineResponse
|
||||||
{
|
{
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
using BotSharp.Core.Realtime.Websocket.Common;
|
|
||||||
using System.ClientModel;
|
using System.ClientModel;
|
||||||
|
using System.Net.WebSockets;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace BotSharp.Core.Realtime.Websocket.Chat;
|
namespace BotSharp.Core.Session;
|
||||||
|
|
||||||
public class BotSharpRealtimeSession : IDisposable
|
public class BotSharpRealtimeSession : IDisposable
|
||||||
{
|
{
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
using System.ClientModel;
|
using System.ClientModel;
|
||||||
|
using System.Net.WebSockets;
|
||||||
using System.Runtime.CompilerServices;
|
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
|
public class LlmRealtimeSession : IDisposable
|
||||||
{
|
{
|
||||||
|
|
@ -42,11 +42,13 @@ global using BotSharp.Abstraction.Statistics.Services;
|
||||||
global using BotSharp.Abstraction.Loggers.Services;
|
global using BotSharp.Abstraction.Loggers.Services;
|
||||||
global using BotSharp.Abstraction.Infrastructures.Events;
|
global using BotSharp.Abstraction.Infrastructures.Events;
|
||||||
global using BotSharp.Abstraction.Templating.Constants;
|
global using BotSharp.Abstraction.Templating.Constants;
|
||||||
|
global using BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
global using BotSharp.Core.Repository;
|
global using BotSharp.Core.Repository;
|
||||||
global using BotSharp.Core.Routing;
|
global using BotSharp.Core.Routing;
|
||||||
global using BotSharp.Core.Agents.Services;
|
global using BotSharp.Core.Agents.Services;
|
||||||
global using BotSharp.Core.Conversations.Services;
|
global using BotSharp.Core.Conversations.Services;
|
||||||
global using BotSharp.Core.Infrastructures;
|
global using BotSharp.Core.Infrastructures;
|
||||||
|
global using BotSharp.Core.Infrastructures.Websocket;
|
||||||
global using BotSharp.Core.Users.Services;
|
global using BotSharp.Core.Users.Services;
|
||||||
global using BotSharp.Core.Statistics.Services;
|
global using BotSharp.Core.Statistics.Services;
|
||||||
global using BotSharp.Core.Loggers.Services;
|
global using BotSharp.Core.Loggers.Services;
|
||||||
|
|
@ -3,6 +3,7 @@ using BotSharp.Abstraction.Files.Enums;
|
||||||
using BotSharp.Abstraction.Files.Utilities;
|
using BotSharp.Abstraction.Files.Utilities;
|
||||||
using BotSharp.Abstraction.Options;
|
using BotSharp.Abstraction.Options;
|
||||||
using BotSharp.Abstraction.Routing;
|
using BotSharp.Abstraction.Routing;
|
||||||
|
using BotSharp.Abstraction.Users.Dtos;
|
||||||
using BotSharp.Core.Infrastructures;
|
using BotSharp.Core.Infrastructures;
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.Controllers;
|
namespace BotSharp.OpenAPI.Controllers;
|
||||||
|
|
@ -108,7 +109,7 @@ public class ConversationController : ControllerBase
|
||||||
CreatedAt = message.CreatedAt,
|
CreatedAt = message.CreatedAt,
|
||||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||||
Data = message.Data,
|
Data = message.Data,
|
||||||
Sender = UserViewModel.FromUser(user),
|
Sender = UserDto.FromUser(user),
|
||||||
Payload = message.Payload,
|
Payload = message.Payload,
|
||||||
HasMessageFiles = fileMessages.Any(x => x.MessageId.IsEqualTo(message.MessageId) && x.FileSource == FileSourceType.User)
|
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,
|
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||||
Function = message.FunctionName,
|
Function = message.FunctionName,
|
||||||
Data = message.Data,
|
Data = message.Data,
|
||||||
Sender = new UserViewModel
|
Sender = new()
|
||||||
{
|
{
|
||||||
FirstName = agent?.Name ?? "Unkown",
|
FirstName = agent?.Name ?? "Unkown",
|
||||||
Role = message.Role,
|
Role = message.Role,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
||||||
|
|
@ -5,7 +6,7 @@ namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
||||||
public class UpdateMessageModel
|
public class UpdateMessageModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("message")]
|
[JsonPropertyName("message")]
|
||||||
public ChatResponseModel Message { get; set; } = null!;
|
public ChatResponseDto Message { get; set; } = null!;
|
||||||
|
|
||||||
[JsonPropertyName("inner_index")]
|
[JsonPropertyName("inner_index")]
|
||||||
public int InnerIndex { get; set; }
|
public int InnerIndex { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,7 @@
|
||||||
using BotSharp.Abstraction.Functions.Models;
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
using BotSharp.Abstraction.Instructs.Models;
|
|
||||||
using BotSharp.Abstraction.Messaging;
|
|
||||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,15 @@
|
||||||
using System.Text.Json.Serialization;
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
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)
|
public static ConversationViewModel FromSession(Conversation sess)
|
||||||
{
|
{
|
||||||
return new ConversationViewModel
|
return new ConversationViewModel
|
||||||
{
|
{
|
||||||
Id = sess.Id,
|
Id = sess.Id,
|
||||||
User = new UserViewModel
|
User = new()
|
||||||
{
|
{
|
||||||
Id = sess.UserId
|
Id = sess.UserId
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,14 @@
|
||||||
|
using BotSharp.Abstraction.Users.Dtos;
|
||||||
using BotSharp.Abstraction.Users.Enums;
|
using BotSharp.Abstraction.Users.Enums;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Users;
|
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")]
|
[JsonPropertyName("agent_actions")]
|
||||||
public IEnumerable<UserAgentActionViewModel> AgentActions { get; set; } = [];
|
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)
|
public static UserViewModel FromUser(User user)
|
||||||
{
|
{
|
||||||
if (user == null)
|
if (user == null)
|
||||||
|
|
@ -57,8 +28,6 @@ public class UserViewModel
|
||||||
UserName = user.UserName,
|
UserName = user.UserName,
|
||||||
FirstName = user.FirstName,
|
FirstName = user.FirstName,
|
||||||
LastName = user.LastName,
|
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,
|
Email = user.Email,
|
||||||
Phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone,
|
Phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone,
|
||||||
Type = user.Type,
|
Type = user.Type,
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Crontab\BotSharp.Core.Crontab.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using BotSharp.Abstraction.Interpreters.Settings;
|
using BotSharp.Abstraction.Crontab;
|
||||||
using BotSharp.Core.Crontab.Abstraction;
|
|
||||||
using BotSharp.Plugin.ChatHub.Hooks;
|
using BotSharp.Plugin.ChatHub.Hooks;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
using BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
|
using BotSharp.Core.Session;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
using BotSharp.Abstraction.SideCar;
|
using BotSharp.Abstraction.SideCar;
|
||||||
|
using BotSharp.Abstraction.Users.Dtos;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
namespace BotSharp.Plugin.ChatHub.Hooks;
|
namespace BotSharp.Plugin.ChatHub.Hooks;
|
||||||
|
|
@ -43,10 +45,10 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
if (!AllowSendingMessage()) return;
|
if (!AllowSendingMessage()) return;
|
||||||
|
|
||||||
var userService = _services.GetRequiredService<IUserService>();
|
var userService = _services.GetRequiredService<IUserService>();
|
||||||
var conv = ConversationViewModel.FromSession(conversation);
|
var conv = ConversationDto.FromSession(conversation);
|
||||||
|
|
||||||
var user = await userService.GetUser(conv.User.Id);
|
var user = await userService.GetUser(conv.User.Id);
|
||||||
conv.User = UserViewModel.FromUser(user);
|
conv.User = UserDto.FromUser(user);
|
||||||
|
|
||||||
await InitClientConversation(conv.Id, conv);
|
await InitClientConversation(conv.Id, conv);
|
||||||
await base.OnConversationInitialized(conversation);
|
await base.OnConversationInitialized(conversation);
|
||||||
|
|
@ -61,13 +63,13 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
var sender = await userService.GetMyProfile();
|
var sender = await userService.GetMyProfile();
|
||||||
|
|
||||||
// Update console conversation UI for CSR
|
// Update console conversation UI for CSR
|
||||||
var model = new ChatResponseModel()
|
var model = new ChatResponseDto()
|
||||||
{
|
{
|
||||||
ConversationId = conv.ConversationId,
|
ConversationId = conv.ConversationId,
|
||||||
MessageId = message.MessageId,
|
MessageId = message.MessageId,
|
||||||
Payload = message.Payload,
|
Payload = message.Payload,
|
||||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||||
Sender = UserViewModel.FromUser(sender)
|
Sender = UserDto.FromUser(sender)
|
||||||
};
|
};
|
||||||
await ReceiveClientMessage(conv.ConversationId, model);
|
await ReceiveClientMessage(conv.ConversationId, model);
|
||||||
|
|
||||||
|
|
@ -107,7 +109,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
|
|
||||||
var conv = _services.GetRequiredService<IConversationService>();
|
var conv = _services.GetRequiredService<IConversationService>();
|
||||||
var state = _services.GetRequiredService<IConversationStateService>();
|
var state = _services.GetRequiredService<IConversationStateService>();
|
||||||
var json = JsonSerializer.Serialize(new ChatResponseModel()
|
var json = JsonSerializer.Serialize(new ChatResponseDto()
|
||||||
{
|
{
|
||||||
ConversationId = conv.ConversationId,
|
ConversationId = conv.ConversationId,
|
||||||
MessageId = message.MessageId,
|
MessageId = message.MessageId,
|
||||||
|
|
@ -116,7 +118,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
RichContent = message.SecondaryRichContent ?? message.RichContent,
|
RichContent = message.SecondaryRichContent ?? message.RichContent,
|
||||||
Data = message.Data,
|
Data = message.Data,
|
||||||
States = state.GetStates(),
|
States = state.GetStates(),
|
||||||
Sender = new UserViewModel()
|
Sender = new()
|
||||||
{
|
{
|
||||||
FirstName = "AI",
|
FirstName = "AI",
|
||||||
LastName = "Assistant",
|
LastName = "Assistant",
|
||||||
|
|
@ -140,7 +142,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
public override async Task OnNotificationGenerated(RoleDialogModel message)
|
public override async Task OnNotificationGenerated(RoleDialogModel message)
|
||||||
{
|
{
|
||||||
var conv = _services.GetRequiredService<IConversationService>();
|
var conv = _services.GetRequiredService<IConversationService>();
|
||||||
var json = JsonSerializer.Serialize(new ChatResponseModel()
|
var json = JsonSerializer.Serialize(new ChatResponseDto()
|
||||||
{
|
{
|
||||||
ConversationId = conv.ConversationId,
|
ConversationId = conv.ConversationId,
|
||||||
MessageId = message.MessageId,
|
MessageId = message.MessageId,
|
||||||
|
|
@ -148,7 +150,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
Function = message.FunctionName,
|
Function = message.FunctionName,
|
||||||
RichContent = message.SecondaryRichContent ?? message.RichContent,
|
RichContent = message.SecondaryRichContent ?? message.RichContent,
|
||||||
Data = message.Data,
|
Data = message.Data,
|
||||||
Sender = new UserViewModel()
|
Sender = new()
|
||||||
{
|
{
|
||||||
FirstName = "AI",
|
FirstName = "AI",
|
||||||
LastName = "Assistant",
|
LastName = "Assistant",
|
||||||
|
|
@ -163,7 +165,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
|
|
||||||
public override async Task OnMessageDeleted(string conversationId, string messageId)
|
public override async Task OnMessageDeleted(string conversationId, string messageId)
|
||||||
{
|
{
|
||||||
var model = new ChatResponseModel
|
var model = new ChatResponseDto
|
||||||
{
|
{
|
||||||
ConversationId = conversationId,
|
ConversationId = conversationId,
|
||||||
MessageId = messageId
|
MessageId = messageId
|
||||||
|
|
@ -180,7 +182,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
||||||
return sidecar == null || !sidecar.IsEnabled();
|
return sidecar == null || !sidecar.IsEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task InitClientConversation(string conversationId, ConversationViewModel conversation)
|
private async Task InitClientConversation(string conversationId, ConversationDto conversation)
|
||||||
{
|
{
|
||||||
try
|
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
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
|
using BotSharp.Abstraction.Crontab;
|
||||||
using BotSharp.Abstraction.Crontab.Models;
|
using BotSharp.Abstraction.Crontab.Models;
|
||||||
using BotSharp.Core.Crontab.Abstraction;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
namespace BotSharp.Plugin.ChatHub.Hooks;
|
namespace BotSharp.Plugin.ChatHub.Hooks;
|
||||||
|
|
@ -34,13 +35,13 @@ public class ChatHubCrontabHook : ICrontabHook
|
||||||
|
|
||||||
public async Task OnCronTriggered(CrontabItem item)
|
public async Task OnCronTriggered(CrontabItem item)
|
||||||
{
|
{
|
||||||
var json = JsonSerializer.Serialize(new ChatResponseModel()
|
var json = JsonSerializer.Serialize(new ChatResponseDto()
|
||||||
{
|
{
|
||||||
ConversationId = item.ConversationId,
|
ConversationId = item.ConversationId,
|
||||||
MessageId = Guid.NewGuid().ToString(),
|
MessageId = Guid.NewGuid().ToString(),
|
||||||
Text = item.ExecutionResult,
|
Text = item.ExecutionResult,
|
||||||
Function = "",
|
Function = "",
|
||||||
Sender = new UserViewModel()
|
Sender = new()
|
||||||
{
|
{
|
||||||
FirstName = "Crontab",
|
FirstName = "Crontab",
|
||||||
LastName = "AI",
|
LastName = "AI",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
namespace BotSharp.Plugin.ChatHub.Hooks;
|
namespace BotSharp.Plugin.ChatHub.Hooks;
|
||||||
|
|
@ -63,13 +64,13 @@ public class WelcomeHook : ConversationHookBase
|
||||||
RichContent = richContent
|
RichContent = richContent
|
||||||
};
|
};
|
||||||
|
|
||||||
var json = JsonSerializer.Serialize(new ChatResponseModel()
|
var json = JsonSerializer.Serialize(new ChatResponseDto()
|
||||||
{
|
{
|
||||||
ConversationId = conversation.Id,
|
ConversationId = conversation.Id,
|
||||||
MessageId = dialog.MessageId,
|
MessageId = dialog.MessageId,
|
||||||
Text = message.Text,
|
Text = message.Text,
|
||||||
RichContent = richContent,
|
RichContent = richContent,
|
||||||
Sender = new UserViewModel()
|
Sender = new()
|
||||||
{
|
{
|
||||||
FirstName = agent.Name,
|
FirstName = agent.Name,
|
||||||
LastName = "",
|
LastName = "",
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,6 @@ global using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||||
global using BotSharp.Abstraction.Templating;
|
global using BotSharp.Abstraction.Templating;
|
||||||
global using BotSharp.Abstraction.Realtime;
|
global using BotSharp.Abstraction.Realtime;
|
||||||
global using BotSharp.Abstraction.Realtime.Models;
|
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.Settings;
|
||||||
global using BotSharp.Plugin.ChatHub.Enums;
|
global using BotSharp.Plugin.ChatHub.Enums;
|
||||||
global using BotSharp.Plugin.ChatHub.Models.Stream;
|
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;
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -11,7 +11,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
||||||
public string Provider => "openai";
|
public string Provider => "openai";
|
||||||
public string Model => _model;
|
public string Model => _model;
|
||||||
|
|
||||||
private readonly RealtimeModelSettings _settings;
|
|
||||||
private readonly IServiceProvider _services;
|
private readonly IServiceProvider _services;
|
||||||
private readonly ILogger<RealTimeCompletionProvider> _logger;
|
private readonly ILogger<RealTimeCompletionProvider> _logger;
|
||||||
private readonly BotSharpOptions _botsharpOptions;
|
private readonly BotSharpOptions _botsharpOptions;
|
||||||
|
|
@ -20,12 +19,10 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
||||||
private LlmRealtimeSession _session;
|
private LlmRealtimeSession _session;
|
||||||
|
|
||||||
public RealTimeCompletionProvider(
|
public RealTimeCompletionProvider(
|
||||||
RealtimeModelSettings settings,
|
|
||||||
ILogger<RealTimeCompletionProvider> logger,
|
|
||||||
IServiceProvider services,
|
IServiceProvider services,
|
||||||
|
ILogger<RealTimeCompletionProvider> logger,
|
||||||
BotSharpOptions botsharpOptions)
|
BotSharpOptions botsharpOptions)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_services = services;
|
_services = services;
|
||||||
_botsharpOptions = botsharpOptions;
|
_botsharpOptions = botsharpOptions;
|
||||||
|
|
@ -290,26 +287,27 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
||||||
return fn;
|
return fn;
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
|
var realtimeModelSettings = _services.GetRequiredService<RealtimeModelSettings>();
|
||||||
var sessionUpdate = new
|
var sessionUpdate = new
|
||||||
{
|
{
|
||||||
type = "session.update",
|
type = "session.update",
|
||||||
session = new RealtimeSessionUpdateRequest
|
session = new RealtimeSessionUpdateRequest
|
||||||
{
|
{
|
||||||
InputAudioFormat = _settings.InputAudioFormat,
|
InputAudioFormat = realtimeModelSettings.InputAudioFormat,
|
||||||
OutputAudioFormat = _settings.OutputAudioFormat,
|
OutputAudioFormat = realtimeModelSettings.OutputAudioFormat,
|
||||||
Voice = _settings.Voice,
|
Voice = realtimeModelSettings.Voice,
|
||||||
Instructions = instruction,
|
Instructions = instruction,
|
||||||
ToolChoice = "auto",
|
ToolChoice = "auto",
|
||||||
Tools = functions,
|
Tools = functions,
|
||||||
Modalities = _settings.Modalities,
|
Modalities = realtimeModelSettings.Modalities,
|
||||||
Temperature = Math.Max(options.Temperature ?? _settings.Temperature, 0.6f),
|
Temperature = Math.Max(options.Temperature ?? realtimeModelSettings.Temperature, 0.6f),
|
||||||
MaxResponseOutputTokens = _settings.MaxResponseOutputTokens,
|
MaxResponseOutputTokens = realtimeModelSettings.MaxResponseOutputTokens,
|
||||||
TurnDetection = new RealtimeSessionTurnDetection
|
TurnDetection = new RealtimeSessionTurnDetection
|
||||||
{
|
{
|
||||||
InterruptResponse = _settings.InterruptResponse/*,
|
InterruptResponse = realtimeModelSettings.InterruptResponse/*,
|
||||||
Threshold = _settings.TurnDetection.Threshold,
|
Threshold = realtimeModelSettings.TurnDetection.Threshold,
|
||||||
PrefixPadding = _settings.TurnDetection.PrefixPadding,
|
PrefixPadding = realtimeModelSettings.TurnDetection.PrefixPadding,
|
||||||
SilenceDuration = _settings.TurnDetection.SilenceDuration*/
|
SilenceDuration = realtimeModelSettings.TurnDetection.SilenceDuration*/
|
||||||
},
|
},
|
||||||
InputAudioNoiseReduction = new InputAudioNoiseReduction
|
InputAudioNoiseReduction = new InputAudioNoiseReduction
|
||||||
{
|
{
|
||||||
|
|
@ -318,15 +316,15 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_settings.InputAudioTranscribe)
|
if (realtimeModelSettings.InputAudioTranscribe)
|
||||||
{
|
{
|
||||||
var words = new List<string>();
|
var words = new List<string>();
|
||||||
HookEmitter.Emit<IRealtimeHook>(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)));
|
HookEmitter.Emit<IRealtimeHook>(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)));
|
||||||
|
|
||||||
sessionUpdate.session.InputAudioTranscription = new InputAudioTranscription
|
sessionUpdate.session.InputAudioTranscription = new InputAudioTranscription
|
||||||
{
|
{
|
||||||
Model = _settings.InputAudioTranscription.Model,
|
Model = realtimeModelSettings.InputAudioTranscription.Model,
|
||||||
Language = _settings.InputAudioTranscription.Language,
|
Language = realtimeModelSettings.InputAudioTranscription.Language,
|
||||||
Prompt = string.Join(", ", words.Select(x => x.ToLower().Trim()).Distinct()).SubstringMax(1024)
|
Prompt = string.Join(", ", words.Select(x => x.ToLower().Trim()).Distinct()).SubstringMax(1024)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,8 @@ global using BotSharp.Abstraction.MLTasks.Settings;
|
||||||
global using BotSharp.Abstraction.Options;
|
global using BotSharp.Abstraction.Options;
|
||||||
global using BotSharp.Abstraction.Realtime;
|
global using BotSharp.Abstraction.Realtime;
|
||||||
global using BotSharp.Abstraction.Realtime.Models;
|
global using BotSharp.Abstraction.Realtime.Models;
|
||||||
|
global using BotSharp.Abstraction.Realtime.Models.Session;
|
||||||
global using BotSharp.Core.Infrastructures;
|
global using BotSharp.Core.Infrastructures;
|
||||||
|
global using BotSharp.Core.Session;
|
||||||
global using BotSharp.Plugin.OpenAI.Models;
|
global using BotSharp.Plugin.OpenAI.Models;
|
||||||
global using BotSharp.Plugin.OpenAI.Settings;
|
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;
|
|
||||||
|
|
@ -105,8 +105,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<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" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
using BotSharp.Abstraction.Crontab;
|
||||||
using BotSharp.Abstraction.Crontab.Models;
|
using BotSharp.Abstraction.Crontab.Models;
|
||||||
using BotSharp.Abstraction.Models;
|
using BotSharp.Abstraction.Models;
|
||||||
using BotSharp.Abstraction.SideCar;
|
using BotSharp.Abstraction.SideCar;
|
||||||
using BotSharp.Core.Crontab.Abstraction;
|
|
||||||
|
|
||||||
namespace BotSharp.Plugin.SqlDriver.Hooks;
|
namespace BotSharp.Plugin.SqlDriver.Hooks;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
using BotSharp.Abstraction.Crontab;
|
||||||
using BotSharp.Abstraction.Planning;
|
using BotSharp.Abstraction.Planning;
|
||||||
using BotSharp.Core.Crontab.Abstraction;
|
|
||||||
|
|
||||||
namespace BotSharp.Plugin.SqlDriver;
|
namespace BotSharp.Plugin.SqlDriver;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,29 @@ global using System.Text.RegularExpressions;
|
||||||
global using System.Threading.Tasks;
|
global using System.Threading.Tasks;
|
||||||
global using System.Linq;
|
global using System.Linq;
|
||||||
global using System.Text.Json;
|
global using System.Text.Json;
|
||||||
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
global using BotSharp.Abstraction.Conversations;
|
global using BotSharp.Abstraction.Conversations;
|
||||||
global using BotSharp.Abstraction.Plugins;
|
global using BotSharp.Abstraction.Plugins;
|
||||||
global using BotSharp.Abstraction.Conversations.Models;
|
global using BotSharp.Abstraction.Conversations.Models;
|
||||||
global using BotSharp.Plugin.SqlDriver.Models;
|
|
||||||
global using BotSharp.Abstraction.Functions;
|
global using BotSharp.Abstraction.Functions;
|
||||||
global using BotSharp.Abstraction.Agents.Models;
|
global using BotSharp.Abstraction.Agents.Models;
|
||||||
global using BotSharp.Abstraction.Templating;
|
global using BotSharp.Abstraction.Templating;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
|
||||||
global using BotSharp.Abstraction.Agents;
|
global using BotSharp.Abstraction.Agents;
|
||||||
global using BotSharp.Abstraction.Utilities;
|
global using BotSharp.Abstraction.Utilities;
|
||||||
global using BotSharp.Abstraction.Knowledges;
|
global using BotSharp.Abstraction.Knowledges;
|
||||||
global using BotSharp.Abstraction.Knowledges.Models;
|
global using BotSharp.Abstraction.Knowledges.Models;
|
||||||
global using BotSharp.Abstraction.Settings;
|
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.Agents.Enums;
|
||||||
global using BotSharp.Abstraction.Instructs;
|
global using BotSharp.Abstraction.Instructs;
|
||||||
global using BotSharp.Abstraction.Instructs.Models;
|
global using BotSharp.Abstraction.Instructs.Models;
|
||||||
global using BotSharp.Abstraction.Routing;
|
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.Interfaces;
|
||||||
global using BotSharp.Plugin.SqlDriver.Helpers;
|
global using BotSharp.Plugin.SqlDriver.Helpers;
|
||||||
global using BotSharp.Plugin.SqlDriver.Settings;
|
global using BotSharp.Plugin.SqlDriver.Settings;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@
|
||||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Rules\BotSharp.Core.Rules.csproj" />
|
<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.Crontab\BotSharp.Core.Crontab.csproj" />
|
||||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.SideCar\BotSharp.Core.SideCar.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.Logger\BotSharp.Logger.csproj" />
|
||||||
<ProjectReference Include="..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
|
<ProjectReference Include="..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
|
||||||
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
|
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,14 @@
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||||
<PackageReference Include="Shouldly" />
|
<PackageReference Include="Shouldly" />
|
||||||
<PackageReference Include="xunit" />
|
<PackageReference Include="xunit" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio"/>
|
<PackageReference Include="xunit.runner.visualstudio" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Xunit"/>
|
<Using Include="Xunit" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
|
||||||
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.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.AnthropicAI\BotSharp.Plugin.AnthropicAI.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.GoogleAI\BotSharp.Plugin.GoogleAI.csproj" />
|
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.GoogleAI\BotSharp.Plugin.GoogleAI.csproj" />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue