Skip to content

Commit ee03d8a

Browse files
authored
Merge pull request #1305 from iceljc/features/add-message-queue-3
Features/add graph rule engine
2 parents 4295bd6 + f76ea45 commit ee03d8a

File tree

78 files changed

+3698
-153
lines changed

Some content is hidden

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

78 files changed

+3698
-153
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageVersion Include="Google_GenerativeAI.Live" Version="3.6.3" />
1111
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
1212
<PackageVersion Include="Polly" Version="8.4.2" />
13+
<PackageVersion Include="RabbitMQ.Client" Version="7.2.0" />
1314
<PackageVersion Include="SharpFuzz" Version="2.2.0" />
1415
<PackageVersion Include="SharpHook" Version="5.3.9" />
1516
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.12" />

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ public class AgentRule
88
[JsonPropertyName("disabled")]
99
public bool Disabled { get; set; }
1010

11-
[JsonPropertyName("criteria")]
12-
public string Criteria { get; set; } = string.Empty;
11+
[JsonPropertyName("config")]
12+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
13+
public RuleConfig? Config { get; set; }
1314
}
15+
16+
public class RuleConfig
17+
{
18+
[JsonPropertyName("topology_name")]
19+
public string? TopologyName { get; set; }
20+
}

src/Infrastructure/BotSharp.Abstraction/Coding/Contexts/CodeExecutionContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ public class CodeExecutionContext
44
{
55
public AgentCodeScript CodeScript { get; set; }
66
public List<KeyValue> Arguments { get; set; } = [];
7+
public string? InvokeFrom { get; set; }
78
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace BotSharp.Abstraction.Graph.Models;
2+
3+
public class GraphInstance
4+
{
5+
/// <summary>
6+
/// Graph id
7+
/// </summary>
8+
public string Id { get; set; }
9+
10+
/// <summary>
11+
/// Graph name
12+
/// </summary>
13+
public string Name { get; set; }
14+
15+
/// <summary>
16+
/// Graph description
17+
/// </summary>
18+
public string Description { get; set; }
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace BotSharp.Abstraction.Infrastructures.MessageQueues;
2+
3+
/// <summary>
4+
/// Abstract interface for message queue consumers.
5+
/// Implement this interface to create consumers that are independent of MQ products (e.g., RabbitMQ, Kafka, Azure Service Bus).
6+
/// </summary>
7+
public interface IMQConsumer : IDisposable
8+
{
9+
/// <summary>
10+
/// Gets the consumer config
11+
/// </summary>
12+
object Config { get; }
13+
14+
/// <summary>
15+
/// Handles the received message from the queue.
16+
/// </summary>
17+
/// <param name="channel">The consumer channel identifier</param>
18+
/// <param name="data">The message data as string</param>
19+
/// <returns>True if the message was handled successfully, false otherwise</returns>
20+
Task<bool> HandleMessageAsync(string channel, string data);
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using BotSharp.Abstraction.Infrastructures.MessageQueues.Models;
2+
3+
namespace BotSharp.Abstraction.Infrastructures.MessageQueues;
4+
5+
public interface IMQService : IDisposable
6+
{
7+
/// <summary>
8+
/// Subscribe a consumer to the message queue.
9+
/// The consumer will be initialized with the appropriate MQ-specific infrastructure.
10+
/// </summary>
11+
/// <param name="key">Unique identifier for the consumer</param>
12+
/// <param name="consumer">The consumer implementing IMQConsumer interface</param>
13+
/// <returns>Task<bool> representing the async subscription operation</returns>
14+
Task<bool> SubscribeAsync(string key, IMQConsumer consumer);
15+
16+
/// <summary>
17+
/// Unsubscribe a consumer from the message queue.
18+
/// </summary>
19+
/// <param name="key">Unique identifier for the consumer</param>
20+
/// <returns>Task<bool> representing the async unsubscription operation</returns>
21+
Task<bool> UnsubscribeAsync(string key);
22+
23+
/// <summary>
24+
/// Publish payload to message queue
25+
/// </summary>
26+
/// <typeparam name="T"></typeparam>
27+
/// <param name="payload"></param>
28+
/// <param name="options"></param>
29+
/// <returns></returns>
30+
Task<bool> PublishAsync<T>(T payload, MQPublishOptions options);
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace BotSharp.Abstraction.Infrastructures.MessageQueues;
4+
5+
/// <summary>
6+
/// Abstract base class for RabbitMQ consumers.
7+
/// Implements IMQConsumer to allow other projects to define consumers independently of RabbitMQ.
8+
/// The RabbitMQ-specific infrastructure is handled by RabbitMQService.
9+
/// </summary>
10+
public abstract class MQConsumerBase : IMQConsumer
11+
{
12+
protected readonly IServiceProvider _services;
13+
protected readonly ILogger _logger;
14+
private bool _disposed = false;
15+
16+
/// <summary>
17+
/// Gets the consumer config for this consumer.
18+
/// Override this property to customize exchange, queue and routing configuration.
19+
/// </summary>
20+
public abstract object Config { get; }
21+
22+
protected MQConsumerBase(
23+
IServiceProvider services,
24+
ILogger logger)
25+
{
26+
_services = services;
27+
_logger = logger;
28+
}
29+
30+
/// <summary>
31+
/// Handles the received message from the queue.
32+
/// </summary>
33+
/// <param name="channel">The consumer channel identifier</param>
34+
/// <param name="data">The message data as string</param>
35+
/// <returns>True if the message was handled successfully, false otherwise</returns>
36+
public abstract Task<bool> HandleMessageAsync(string channel, string data);
37+
38+
public void Dispose()
39+
{
40+
if (_disposed)
41+
{
42+
return;
43+
}
44+
45+
var consumerName = GetType().Name;
46+
_logger.LogWarning($"Disposing consumer: {consumerName}");
47+
_disposed = true;
48+
GC.SuppressFinalize(this);
49+
}
50+
}
51+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Infrastructures.MessageQueues;
2+
3+
public class MessageQueueSettings
4+
{
5+
public bool Enabled { get; set; }
6+
public string Provider { get; set; }
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace BotSharp.Abstraction.Infrastructures.MessageQueues.Models;
2+
3+
public class MQMessage<T>
4+
{
5+
public MQMessage(T payload, string messageId)
6+
{
7+
Payload = payload;
8+
MessageId = messageId;
9+
}
10+
11+
public T Payload { get; set; }
12+
public string MessageId { get; set; }
13+
public DateTime CreateDate { get; set; } = DateTime.UtcNow;
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Text.Json;
2+
3+
namespace BotSharp.Abstraction.Infrastructures.MessageQueues.Models;
4+
5+
/// <summary>
6+
/// Configuration options for publishing messages to a message queue.
7+
/// These options are MQ-product agnostic and can be adapted by different implementations.
8+
/// </summary>
9+
public class MQPublishOptions
10+
{
11+
/// <summary>
12+
/// The topic name (exchange in RabbitMQ, topic in Kafka/Azure Service Bus).
13+
/// </summary>
14+
public string TopicName { get; set; } = string.Empty;
15+
16+
/// <summary>
17+
/// The routing key (partition key in some MQ systems, used for message routing).
18+
/// </summary>
19+
public string RoutingKey { get; set; } = string.Empty;
20+
21+
/// <summary>
22+
/// Delay in milliseconds before the message is delivered.
23+
/// </summary>
24+
public long DelayMilliseconds { get; set; }
25+
26+
/// <summary>
27+
/// Optional unique identifier for the message.
28+
/// </summary>
29+
public string? MessageId { get; set; }
30+
31+
/// <summary>
32+
/// Additional arguments for the publish configuration (MQ-specific).
33+
/// </summary>
34+
public Dictionary<string, object?> Arguments { get; set; } = [];
35+
36+
/// <summary>
37+
/// Json serializer options
38+
/// </summary>
39+
public JsonSerializerOptions? JsonOptions { get; set; }
40+
}

0 commit comments

Comments
 (0)