Skip to content

Commit 907df3e

Browse files
author
vguruparan
committed
Merge branch 'master' of github.com:visagang/BotSharp into features/vguruparan
2 parents be5a266 + 3a6cd46 commit 907df3e

47 files changed

Lines changed: 2763 additions & 880 deletions

File tree

Some content is hidden

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

src/Infrastructure/BotSharp.Abstraction/Conversations/Dtos/ChatResponseDto.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public class ChatResponseDto : InstructResult
4646
[JsonPropertyName("is_streaming")]
4747
public bool IsStreaming { get; set; }
4848

49+
[JsonPropertyName("thought")]
50+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
51+
public Dictionary<string, string?>? Thought { get; set; }
52+
4953
[JsonPropertyName("meta_data")]
5054
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
5155
public Dictionary<string, string?>? MetaData { get; set; }

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public class DialogMetaData
114114
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
115115
public string? ToolCallId { get; set; }
116116

117+
[JsonPropertyName("thought")]
118+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
119+
public Dictionary<string, string?>? Thought { get; set; }
120+
117121
[JsonPropertyName("meta_data")]
118122
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
119123
public Dictionary<string, string?>? MetaData { get; set; }

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class RoleDialogModel : ITrackableMessage
7676
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
7777
public string? ToolCallId { get; set; }
7878

79+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
80+
public Dictionary<string, string?>? Thought { get; set; }
81+
7982
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8083
public Dictionary<string, string?>? MetaData { get; set; }
8184

@@ -141,7 +144,6 @@ public class RoleDialogModel : ITrackableMessage
141144
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
142145
public bool IsStreaming { get; set; }
143146

144-
145147
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
146148
public bool IsFromUser => Role == AgentRole.User;
147149

@@ -210,6 +212,7 @@ public static RoleDialogModel From(RoleDialogModel source,
210212
Data = source.Data,
211213
IsStreaming = source.IsStreaming,
212214
Annotations = source.Annotations,
215+
Thought = source.Thought != null ? new(source.Thought) : null,
213216
MetaData = source.MetaData != null ? new(source.MetaData) : null
214217
};
215218
}

src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmModelSetting.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ public class ReasoningSetting
9999
public class WebSearchSetting
100100
{
101101
public bool IsDefault { get; set; }
102+
103+
[Obsolete("Set SearchContextSize in Parameters")]
102104
public string? SearchContextSize { get; set; }
105+
public Dictionary<string, ModelParamSetting>? Parameters { get; set; }
103106
}
104107
#endregion
105108

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace BotSharp.Abstraction.Rules.Constants;
2+
3+
public static class RuleConstant
4+
{
5+
public const int MAX_GRAPH_RECURSION = 1000;
6+
7+
public const string INPUT_SCHEMA_KEY = "input_schema";
8+
public const string OUTPUT_SCHEMA_KEY = "output_schema";
9+
10+
public static IEnumerable<string> CONDITION_NODE_TYPES = new List<string>
11+
{
12+
"condition",
13+
"criteria"
14+
};
15+
16+
public static IEnumerable<string> ACTION_NODE_TYPES = new List<string>
17+
{
18+
"action"
19+
};
20+
21+
public static IEnumerable<string> ROOT_NODE_TYPES = new List<string>
22+
{
23+
"root",
24+
"start"
25+
};
26+
27+
public static IEnumerable<string> END_NODE_TYPES = new List<string>
28+
{
29+
"end",
30+
"terminal"
31+
};
32+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
namespace BotSharp.Core.Rules.Engines;
2+
3+
/// <summary>
4+
/// Abstraction over the data structure that drives graph traversal order.
5+
/// Stack → DFS, Queue → BFS. Swap the frontier mid-traversal to switch strategy.
6+
/// </summary>
7+
public interface IFrontier<T>
8+
{
9+
void Add(T item);
10+
T Remove();
11+
int Count { get; }
12+
13+
/// <summary>
14+
/// Drain every remaining item into <paramref name="other"/>, preserving order.
15+
/// </summary>
16+
void DrainTo(IFrontier<T> other);
17+
}
18+
19+
/// <summary>
20+
/// LIFO frontier – produces depth-first traversal.
21+
/// </summary>
22+
public sealed class StackFrontier<T> : IFrontier<T>
23+
{
24+
private readonly Stack<T> _stack = new();
25+
26+
public int Count => _stack.Count;
27+
28+
public void Add(T item) => _stack.Push(item);
29+
30+
public T Remove() => _stack.Pop();
31+
32+
public void DrainTo(IFrontier<T> other)
33+
{
34+
// Pop gives items in priority order (highest-weight first).
35+
var items = new List<T>();
36+
while (_stack.Count > 0)
37+
{
38+
items.Add(_stack.Pop());
39+
}
40+
41+
if (other is StackFrontier<T>)
42+
{
43+
items.Reverse();
44+
}
45+
46+
foreach (var item in items)
47+
{
48+
other.Add(item);
49+
}
50+
}
51+
}
52+
53+
/// <summary>
54+
/// FIFO frontier – produces breadth-first traversal.
55+
/// </summary>
56+
public sealed class QueueFrontier<T> : IFrontier<T>
57+
{
58+
private readonly Queue<T> _queue = new();
59+
60+
public int Count => _queue.Count;
61+
62+
public void Add(T item) => _queue.Enqueue(item);
63+
64+
public T Remove() => _queue.Dequeue();
65+
66+
public void DrainTo(IFrontier<T> other)
67+
{
68+
// Dequeue gives items in priority order (highest-weight first).
69+
var items = new List<T>();
70+
while (_queue.Count > 0)
71+
{
72+
items.Add(_queue.Dequeue());
73+
}
74+
75+
if (other is StackFrontier<T>)
76+
{
77+
items.Reverse();
78+
}
79+
80+
foreach (var item in items)
81+
{
82+
other.Add(item);
83+
}
84+
}
85+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace BotSharp.Abstraction.Rules;
2+
3+
public interface IRuleEnd : IRuleFlowUnit
4+
{
5+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ public interface IRuleFlowUnit
1818
/// The trigger names
1919
/// </summary>
2020
IEnumerable<string>? Triggers => null;
21+
22+
/// <summary>
23+
/// Schema describing the expected input parameters.
24+
/// Used for validating that upstream nodes produce the required fields.
25+
/// </summary>
26+
FlowUnitSchema? InputSchema => null;
27+
28+
/// <summary>
29+
/// Schema describing the output this unit produces.
30+
/// Used for validating that downstream nodes receive the expected fields.
31+
/// </summary>
32+
FlowUnitSchema? OutputSchema => null;
2133
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace BotSharp.Abstraction.Rules;
2+
3+
public interface IRuleRoot : IRuleFlowUnit
4+
{
5+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace BotSharp.Abstraction.Rules.Models;
4+
5+
/// <summary>
6+
/// Describes the input or output contract of a rule flow unit (action or condition).
7+
/// Follows a JSON Schema-like structure with "properties" and "required" fields.
8+
/// </summary>
9+
public class FlowUnitSchema
10+
{
11+
/// <summary>
12+
/// Property definitions keyed by parameter name.
13+
/// </summary>
14+
[JsonPropertyName("properties")]
15+
public Dictionary<string, FlowUnitSchemaProperty> Properties { get; set; } = [];
16+
17+
/// <summary>
18+
/// List of required property names.
19+
/// </summary>
20+
[JsonPropertyName("required")]
21+
public List<string> Required { get; set; } = [];
22+
23+
public FlowUnitSchema() { }
24+
25+
public FlowUnitSchema(
26+
Dictionary<string, FlowUnitSchemaProperty> properties,
27+
List<string>? required = null)
28+
{
29+
Properties = properties;
30+
Required = required ?? [];
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Describes a single property in a FlowUnitSchema.
36+
/// </summary>
37+
public class FlowUnitSchemaProperty
38+
{
39+
/// <summary>
40+
/// JSON type: "string", "number", "boolean", "object", "array"
41+
/// </summary>
42+
[JsonPropertyName("type")]
43+
public string Type { get; set; } = "string";
44+
45+
/// <summary>
46+
/// A brief explanation of the property's purpose.
47+
/// </summary>
48+
[JsonPropertyName("description")]
49+
public string? Description { get; set; }
50+
51+
public FlowUnitSchemaProperty() { }
52+
53+
public FlowUnitSchemaProperty(string type, string? description = null)
54+
{
55+
Type = type;
56+
Description = description;
57+
}
58+
}

0 commit comments

Comments
 (0)