hotfix conflict

This commit is contained in:
nick.yi 2025-09-10 14:09:37 +08:00
commit 87c18c414f
5 changed files with 51 additions and 2 deletions

View file

@ -4,6 +4,7 @@ public class CrontabSettings
{
public CrontabBaseSetting EventSubscriber { get; set; } = new();
public CrontabBaseSetting Watcher { get; set; } = new();
public string LockName { get; set; } = "CrontabWatcher:locker";
public DebugSetting Debug { get; set; } = new();
}

View file

@ -10,11 +10,15 @@ public class CrontabWatcher : BackgroundService
{
private readonly ILogger _logger;
private readonly IServiceProvider _services;
private readonly CrontabSettings _cronSettings;
private string DIST_KEY;
public CrontabWatcher(IServiceProvider services, ILogger<CrontabWatcher> logger)
public CrontabWatcher(IServiceProvider services, ILogger<CrontabWatcher> logger, CrontabSettings cronSettings)
{
_logger = logger;
_services = services;
_cronSettings = cronSettings;
DIST_KEY = _cronSettings.LockName;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@ -29,7 +33,7 @@ public class CrontabWatcher : BackgroundService
{
var delay = Task.Delay(1000, stoppingToken);
await locker.LockAsync("CrontabWatcher:locker", async () =>
await locker.LockAsync(DIST_KEY, async () =>
{
await RunCronChecker(scope.ServiceProvider);
});

View file

@ -371,9 +371,11 @@ public class ConversationController : ControllerBase
{
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
response.Function = msg.FunctionName;
response.MessageLabel = msg.MessageLabel;
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
response.Instruction = msg.Instruction;
response.Data = msg.Data;
response.AdditionalMessageWrapper = ChatResponseWrapper.From(msg.AdditionalMessageWrapper, conversationId, inputMsg.MessageId);
});
var state = _services.GetRequiredService<IConversationStateService>();
@ -426,11 +428,13 @@ public class ConversationController : ControllerBase
async msg =>
{
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
response.MessageLabel = msg.MessageLabel;
response.Function = msg.FunctionName;
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
response.Instruction = msg.Instruction;
response.Data = msg.Data;
response.States = state.GetStates();
response.AdditionalMessageWrapper = ChatResponseWrapper.From(msg.AdditionalMessageWrapper, conversationId, inputMsg.MessageId);
await OnChunkReceived(Response, response);
});

View file

@ -1,7 +1,46 @@
using BotSharp.Abstraction.Conversations.Dtos;
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Conversations;
public class ChatResponseModel : ChatResponseDto
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("additional_message_wrapper")]
public ChatResponseWrapper? AdditionalMessageWrapper { get; set; }
}
public class ChatResponseWrapper
{
[JsonPropertyName("sending_interval")]
public int SendingInterval { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("messages")]
public List<ChatResponseModel>? Messages { get; set; }
public static ChatResponseWrapper? From(ChatMessageWrapper? wrapper, string conversationId, string? messageId = null)
{
if (wrapper == null)
{
return null;
}
return new ChatResponseWrapper
{
SendingInterval = wrapper.SendingInterval,
Messages = wrapper?.Messages?.Select(x => new ChatResponseModel
{
ConversationId = conversationId,
MessageId = messageId ?? x.MessageId,
Text = !string.IsNullOrEmpty(x.SecondaryContent) ? x.SecondaryContent : x.Content,
MessageLabel = x.MessageLabel,
Function = x.FunctionName,
RichContent = x.SecondaryRichContent ?? x.RichContent,
Instruction = x.Instruction,
Data = x.Data,
IsAppend = true
})?.ToList()
};
}
}

View file

@ -153,6 +153,7 @@ public class ChatHubConversationHook : ConversationHookBase
{
ConversationId = conv.ConversationId,
MessageId = item.MessageId,
MessageLabel = item.MessageLabel,
Text = !string.IsNullOrEmpty(item.SecondaryContent) ? item.SecondaryContent : item.Content,
Function = item.FunctionName,
RichContent = item.SecondaryRichContent ?? item.RichContent,