Skip to content

Commit 80e292a

Browse files
committed
Merge branch 'master' of https://github.com/Joannall/BotSharp
2 parents 00320fe + cd7fdf4 commit 80e292a

File tree

43 files changed

+347
-85
lines changed

Some content is hidden

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

43 files changed

+347
-85
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public enum AgentField
1717
Response,
1818
Sample,
1919
LlmConfig,
20-
Utility
20+
Utility,
21+
MaxMessageCount
2122
}
2223

2324
public enum AgentTaskField

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public class Agent
104104
/// </summary>
105105
public string? InheritAgentId { get; set; }
106106

107+
/// <summary>
108+
/// Maximum message count when load conversation
109+
/// </summary>
110+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
111+
public int? MaxMessageCount { get; set; }
112+
107113
public List<RoutingRule> RoutingRules { get; set; } = new();
108114

109115
/// <summary>
@@ -133,6 +139,8 @@ public static Agent Clone(Agent agent)
133139
Knowledges = agent.Knowledges,
134140
IsPublic = agent.IsPublic,
135141
Disabled = agent.Disabled,
142+
MergeUtility = agent.MergeUtility,
143+
MaxMessageCount = agent.MaxMessageCount,
136144
Profiles = agent.Profiles,
137145
RoutingRules = agent.RoutingRules,
138146
LlmConfig = agent.LlmConfig,

src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@ namespace BotSharp.Abstraction.Conversations;
22

33
public abstract class ConversationHookBase : IConversationHook
44
{
5-
protected Agent _agent;
6-
public Agent Agent => _agent;
5+
public Agent Agent { get; private set; }
76

8-
protected Conversation _conversation;
9-
public Conversation Conversation => _conversation;
7+
public Conversation Conversation { get; private set; }
108

11-
protected List<RoleDialogModel> _dialogs;
12-
public List<RoleDialogModel> Dialogs => _dialogs;
9+
public List<RoleDialogModel> Dialogs { get; private set; }
1310

14-
protected int _priority = 0;
15-
public int Priority => _priority;
11+
public int Priority { get; protected set; } = 0;
1612

1713
public IConversationHook SetAgent(Agent agent)
1814
{
19-
_agent = agent;
15+
Agent = agent;
2016
return this;
2117
}
2218

2319
public IConversationHook SetConversation(Conversation conversation)
2420
{
25-
_conversation = conversation;
21+
Conversation = conversation;
2622
return this;
2723
}
2824

@@ -37,7 +33,7 @@ public virtual Task OnDialogRecordLoaded(RoleDialogModel dialog)
3733

3834
public virtual Task OnDialogsLoaded(List<RoleDialogModel> dialogs)
3935
{
40-
_dialogs = dialogs;
36+
Dialogs = dialogs;
4137
return Task.CompletedTask;
4238
}
4339

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace BotSharp.Abstraction.Conversations;
2+
3+
public class ConversationHookProvider
4+
{
5+
public IEnumerable<IConversationHook> Hooks { get; }
6+
7+
private readonly Lazy<IEnumerable<IConversationHook>> _hooksOrderByPriority;
8+
9+
public IEnumerable<IConversationHook> HooksOrderByPriority
10+
=> _hooksOrderByPriority.Value;
11+
12+
public ConversationHookProvider(IEnumerable<IConversationHook> conversationHooks)
13+
{
14+
Hooks = conversationHooks;
15+
_hooksOrderByPriority = new Lazy<IEnumerable<IConversationHook>>(() =>
16+
{
17+
return conversationHooks.OrderBy(hook => hook.Priority).ToArray();
18+
});
19+
}
20+
}

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface IConversationService
1212
Task<Conversation> GetConversation(string id);
1313
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter);
1414
Task<Conversation> UpdateConversationTitle(string id, string title);
15+
Task<Conversation> UpdateConversationTitleAlias(string id, string titleAlias);
1516
Task<bool> UpdateConversationTags(string conversationId, List<string> tags);
1617
Task<bool> UpdateConversationMessage(string conversationId, UpdateMessageRequest request);
1718
Task<List<Conversation>> GetLastConversations();

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Conversation
1313
/// </summary>
1414
public string? TaskId { get; set; }
1515
public string Title { get; set; } = string.Empty;
16+
public string TitleAlias { get; set; } = string.Empty;
1617

1718
[JsonIgnore]
1819
public List<DialogElement> Dialogs { get; set; } = new();

src/Infrastructure/BotSharp.Abstraction/Crontab/Models/CrontabItem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ public class CrontabItem : ScheduleTaskArgs
1414
[JsonPropertyName("execution_result")]
1515
public string ExecutionResult { get; set; } = null!;
1616

17+
[JsonPropertyName("execution_count")]
18+
public int ExecutionCount { get; set; }
19+
20+
[JsonPropertyName("max_execution_count")]
21+
public int MaxExecutionCount { get; set; }
22+
23+
[JsonPropertyName("expire_seconds")]
24+
public int ExpireSeconds { get; set; } = 60;
25+
1726
[JsonPropertyName("created_time")]
1827
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
1928

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ConversationFilter
88
/// </summary>
99
public string? Id { get; set; }
1010
public string? Title { get; set; }
11+
public string? TitleAlias { get; set; }
1112
public string? AgentId { get; set; }
1213
public string? Status { get; set; }
1314
public string? Channel { get; set; }

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
5353

5454
#region Agent
5555
void UpdateAgent(Agent agent, AgentField field);
56-
Agent? GetAgent(string agentId);
56+
Agent? GetAgent(string agentId, bool basicsOnly = false);
5757
List<Agent> GetAgents(AgentFilter filter);
5858
List<UserAgent> GetUserAgents(string userId);
5959
void BulkInsertAgents(List<Agent> agents);
@@ -86,6 +86,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
8686
Conversation GetConversation(string conversationId);
8787
PagedItems<Conversation> GetConversations(ConversationFilter filter);
8888
void UpdateConversationTitle(string conversationId, string title);
89+
void UpdateConversationTitleAlias(string conversationId, string titleAlias);
8990
bool UpdateConversationTags(string conversationId, List<string> tags);
9091
bool UpdateConversationMessage(string conversationId, UpdateMessageRequest request);
9192
void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint);

src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void OnAgentUtilityLoaded(Agent agent)
4747
var entryAgentId = routing.EntryAgentId;
4848
if (!string.IsNullOrEmpty(entryAgentId))
4949
{
50-
var entryAgent = db.GetAgent(entryAgentId);
50+
var entryAgent = db.GetAgent(entryAgentId, basicsOnly: true);
5151
var (fns, tps) = GetUniqueContent(entryAgent?.Utilities);
5252
functionNames = functionNames.Concat(fns).Distinct().ToList();
5353
templateNames = templateNames.Concat(tps).Distinct().ToList();

0 commit comments

Comments
 (0)