Skip to content

Refine/refine project dep #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Abstraction.Crontab;

public interface ICrontabHook
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Abstraction.Crontab;

public interface ICrontabService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BotSharp.Core.Crontab.Abstraction;
namespace BotSharp.Abstraction.Crontab;

/// <summary>
/// Provide a cron source for the crontab service.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BotSharp.Core.Realtime.Models.Options;
using System.Text.Json;

namespace BotSharp.Abstraction.Realtime.Models.Session;

public class ChatSessionOptions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BotSharp.Core.Realtime.Models.Chat;
namespace BotSharp.Abstraction.Realtime.Models.Session;

public class ChatSessionUpdate
{
Expand Down
5 changes: 5 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Rules/IRuleAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BotSharp.Abstraction.Rules;

public interface IRuleAction
{
}
5 changes: 5 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Rules/IRuleConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BotSharp.Abstraction.Rules;

public interface IRuleConfig
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BotSharp.Abstraction.Rules;

public interface IRuleCriteria
{
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using BotSharp.Abstraction.Models;

namespace BotSharp.Core.Rules.Engines;
namespace BotSharp.Abstraction.Rules;

public interface IRuleEngine
{
Expand Down
73 changes: 73 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Users/Dtos/UserDto.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TargetFramework)</TargetFramework>
Expand Down Expand Up @@ -35,8 +35,4 @@
<PackageReference Include="NCrontab" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/BotSharp.Core.Crontab/Using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
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;
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ private static async Task RegisterFunctionCall(IServiceCollection services, McpS
});
}
}
catch { }
catch (Exception ex)
{
Console.WriteLine($"Error when registering {server?.Name} MCP tools. {ex.Message}\r\n{ex.InnerException}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ public override void OnAgentMcpToolLoaded(Agent agent)
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, StringComparer.OrdinalIgnoreCase).ToList();
}

private async Task<IEnumerable<FunctionDef>> GetMcpContent(Agent agent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
5 changes: 0 additions & 5 deletions src/Infrastructure/BotSharp.Core.Realtime/Using.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,7 +14,3 @@
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;
5 changes: 0 additions & 5 deletions src/Infrastructure/BotSharp.Core.Rules/Actions/IRuleAction.cs

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 3 additions & 15 deletions src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,9 @@ public override void OnAgentUtilityLoaded(Agent agent)

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)
{
if (!agent.SecondaryInstructions.Any(x => x.Contains(prompt.Content, StringComparison.OrdinalIgnoreCase)))
{
agent.SecondaryInstructions.Add(prompt.Content);
}
}
agent.SecondaryFunctions = agent.SecondaryFunctions.Concat(functions).DistinctBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList();
var contents = templates.Select(x => x.Content);
agent.SecondaryInstructions = agent.SecondaryInstructions.Concat(contents).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
}


Expand Down
1 change: 1 addition & 0 deletions src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="Nanoid" />
<PackageReference Include="Rougamo.Fody" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
{
Expand Down
Loading
Loading