Skip to content

Commit 330bbc3

Browse files
authored
Merge pull request #1056 from yileicn/master
optimize Hook
2 parents 6fa8950 + 9cdf917 commit 330bbc3

File tree

40 files changed

+146
-238
lines changed

40 files changed

+146
-238
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
using BotSharp.Abstraction.Functions.Models;
2+
using BotSharp.Abstraction.Hooks;
23

34
namespace BotSharp.Abstraction.Agents;
45

5-
public interface IAgentHook
6+
public interface IAgentHook : IHookBase
67
{
7-
/// <summary>
8-
/// Agent Id
9-
/// </summary>
10-
string SelfId { get; }
118
Agent Agent { get; }
129
void SetAgent(Agent agent);
1310

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using BotSharp.Abstraction.Hooks;
2+
13
namespace BotSharp.Abstraction.Conversations;
24

3-
public interface IConversationHook
5+
public interface IConversationHook : IHookBase
46
{
57
int Priority { get; }
68
Agent Agent { get; }

src/Infrastructure/BotSharp.Abstraction/Crontab/ICrontabHook.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using BotSharp.Abstraction.Hooks;
2+
13
namespace BotSharp.Abstraction.Crontab;
24

3-
public interface ICrontabHook
5+
public interface ICrontabHook : IHookBase
46
{
57
string[]? Triggers
68
=> null;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace BotSharp.Abstraction.Hooks
8+
{
9+
public interface IHookBase
10+
{
11+
/// <summary>
12+
/// Agent Id
13+
/// </summary>
14+
string SelfId => string.Empty;
15+
bool IsMatch(string id) => string.IsNullOrEmpty(SelfId) || SelfId == id;
16+
}
17+
}

src/Infrastructure/BotSharp.Abstraction/Instructs/IInstructHook.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
using BotSharp.Abstraction.Hooks;
12
using BotSharp.Abstraction.Instructs.Models;
23

34
namespace BotSharp.Abstraction.Instructs;
45

5-
public interface IInstructHook
6+
public interface IInstructHook : IHookBase
67
{
7-
string SelfId { get; }
88
Task BeforeCompletion(Agent agent, RoleDialogModel message);
99
Task AfterCompletion(Agent agent, InstructResult result);
1010
Task OnResponseGenerated(InstructResponseModel response);

src/Infrastructure/BotSharp.Abstraction/Loggers/IContentGeneratingHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using BotSharp.Abstraction.Functions.Models;
2+
using BotSharp.Abstraction.Hooks;
23

34
namespace BotSharp.Abstraction.Loggers;
45

56
/// <summary>
67
/// Model content generating hook, it can be used for logging, metrics and tracing.
78
/// </summary>
8-
public interface IContentGeneratingHook
9+
public interface IContentGeneratingHook : IHookBase
910
{
1011
/// <summary>
1112
/// Before content generating.

src/Infrastructure/BotSharp.Abstraction/Planning/IPlanningHook.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using BotSharp.Abstraction.Hooks;
2+
13
namespace BotSharp.Abstraction.Planning;
24

3-
public interface IPlanningHook
5+
public interface IPlanningHook : IHookBase
46
{
57
Task<string> GetSummaryAdditionalRequirements(string planner, RoleDialogModel message)
68
=> Task.FromResult(string.Empty);

src/Infrastructure/BotSharp.Abstraction/Realtime/IRealtimeHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using BotSharp.Abstraction.Hooks;
12
using BotSharp.Abstraction.MLTasks;
23

34
namespace BotSharp.Abstraction.Realtime;
45

5-
public interface IRealtimeHook
6+
public interface IRealtimeHook : IHookBase
67
{
78
Task OnModelReady(Agent agent, IRealTimeCompletion completer);
89
string[] OnModelTranscriptPrompt(Agent agent);

src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using BotSharp.Abstraction.Functions.Models;
2+
using BotSharp.Abstraction.Hooks;
23

34
namespace BotSharp.Abstraction.Routing;
45

5-
public interface IRoutingHook
6+
public interface IRoutingHook : IHookBase
67
{
78
/// <summary>
89
/// Routing instruction is received from Router

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ await HookEmitter.Emit<ICrontabHook>(_services, async hook =>
125125
await hook.OnCronTriggered(item);
126126
await hook.OnTaskExecuted(item);
127127
}
128-
});
128+
}, item.AgentId);
129129
}
130130
}

0 commit comments

Comments
 (0)