Skip to content

Commit b3c02b3

Browse files
authored
Merge pull request #1355 from iceljc/features/add-resolve-block
Features/add resolve block
2 parents b52cbf5 + 007c536 commit b3c02b3

17 files changed

Lines changed: 452 additions & 292 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Abstraction.Agents;
2+
3+
public interface IInstructionResolver
4+
{
5+
string Name { get; }
6+
7+
Task<string> ResolveAsync(Agent agent, string instruction, IEnumerable<object?> args, IDictionary<string, object?> kwArgs)
8+
=> Task.FromResult(instruction);
9+
}

src/Infrastructure/BotSharp.Abstraction/Rules/RuleGraph.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public class RuleNode : GraphItem
177177
/// <summary>
178178
/// Node type: root, criteria, action, etc.
179179
/// </summary>
180+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
180181
public override string Type { get; set; } = "action";
181182

182183
/// <summary>
@@ -229,15 +230,28 @@ public override string ToString()
229230

230231
public class GraphItem
231232
{
233+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
232234
public virtual string Id { get; set; } = Guid.NewGuid().ToString();
235+
236+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
233237
public virtual string Name { get; set; } = null!;
238+
239+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
234240
public virtual string Type { get; set; } = null!;
241+
242+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
235243
public virtual IEnumerable<string> Labels { get; set; } = [];
236244
public virtual double Weight { get; set; } = 1.0;
245+
246+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
237247
public virtual string? Description { get; set; }
248+
249+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
238250
public virtual Dictionary<string, string?> Config { get; set; } = [];
239251

240252
private string? _alias;
253+
254+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
241255
public virtual string Alias
242256
{
243257
get => string.IsNullOrEmpty(_alias) ? Name : _alias;
@@ -267,6 +281,8 @@ public class EdgeItemPayload : GraphItem
267281

268282
public class RuleGraphInfo
269283
{
284+
[JsonPropertyName("graph_id")]
285+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
270286
public string GraphId { get; set; }
271287
public IEnumerable<RuleNode> Nodes { get; set; } = [];
272288
public IEnumerable<RuleEdge> Edges { get; set; } = [];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Templating;
2+
3+
public interface IRenderConfiguration
4+
{
5+
string Render(IServiceProvider services, string template, IDictionary<string, object> dict);
6+
void RegisterType(Type type);
7+
}

src/Infrastructure/BotSharp.Abstraction/Templating/ITemplateRender.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ namespace BotSharp.Abstraction.Templating;
33
public interface ITemplateRender
44
{
55
string Render(string template, IDictionary<string, object> dict);
6-
void RegisterType(Type type);
76
}

src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
4444
services.AddScoped(provider =>
4545
{
4646
var settingService = provider.GetRequiredService<ISettingService>();
47-
var render = provider.GetRequiredService<ITemplateRender>();
47+
var render = provider.GetRequiredService<IRenderConfiguration>();
4848
render.RegisterType(typeof(AgentSettings));
4949
return settingService.Bind<AgentSettings>("Agent");
5050
});

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public static IServiceCollection AddBotSharpCore(this IServiceCollection service
2525
{
2626
services.AddSingleton<IDistributedLocker, DistributedLocker>();
2727
// Register template render
28-
services.AddSingleton<ITemplateRender, TemplateRender>();
28+
services.AddSingleton<IRenderConfiguration, RenderConfiguration>();
29+
services.AddScoped<ITemplateRender, TemplateRender>();
2930

3031
services.AddScoped<ISettingService, SettingService>();
3132
services.AddScoped<IRoleService, RoleService>();

src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
3737
services.AddScoped(provider =>
3838
{
3939
var settingService = provider.GetRequiredService<ISettingService>();
40-
var render = provider.GetRequiredService<ITemplateRender>();
40+
var render = provider.GetRequiredService<IRenderConfiguration>();
4141
render.RegisterType(typeof(ConversationSetting));
4242
return settingService.Bind<ConversationSetting>("Conversation");
4343
});

0 commit comments

Comments
 (0)