diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs
index 190b6cb8..61cb0f4d 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs
@@ -25,5 +25,6 @@ public enum AgentTaskField
Name,
Description,
Enabled,
- Content
+ Content,
+ DirectAgentId
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Tasks/Models/AgentTask.cs b/src/Infrastructure/BotSharp.Abstraction/Tasks/Models/AgentTask.cs
index 5aeed736..b3a6aaf2 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Tasks/Models/AgentTask.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Tasks/Models/AgentTask.cs
@@ -1,15 +1,9 @@
namespace BotSharp.Abstraction.Tasks.Models;
-public class AgentTask
+public class AgentTask : AgentTaskMetaData
{
public string Id { get; set; }
- public string Name { get; set; }
- public string? Description { get; set; }
public string Content { get; set; }
- public bool Enabled { get; set; }
- public string? DirectAgentId { get; set; }
- public DateTime CreatedDateTime { get; set; }
- public DateTime UpdatedDateTime { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public string AgentId { get; set; }
@@ -29,3 +23,13 @@ public class AgentTask
Description = description;
}
}
+
+public class AgentTaskMetaData
+{
+ public string Name { get; set; }
+ public string? Description { get; set; }
+ public bool Enabled { get; set; }
+ public string? DirectAgentId { get; set; }
+ public DateTime CreatedDateTime { get; set; }
+ public DateTime UpdatedDateTime { get; set; }
+}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
index 32db29b8..d11752f6 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
@@ -2,12 +2,34 @@ namespace BotSharp.Abstraction.Utilities;
public class Pagination
{
- public int Page { get; set; } = 1;
- ///
- /// Use -1 for all records
- ///
- public int Size { get; set; } = 20;
- public int Offset => (Page - 1) * Size;
+ private int _page;
+ private int _size;
+
+ public int Page
+ {
+ get { return _page > 0 ? _page : 1; }
+ set { _page = value; }
+ }
+
+ public int Size
+ {
+ get
+ {
+ if (_size <= 0) return 20;
+ if (_size > 100) return 100;
+
+ return _size;
+ }
+ set
+ {
+ _size = value;
+ }
+ }
+
+ public int Offset
+ {
+ get { return (Page - 1) * Size; }
+ }
}
public class PagedItems
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs
index 57d19270..aa1d798e 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs
@@ -116,17 +116,17 @@ public partial class FileRepository
var fileName = $"{Guid.NewGuid()}.liquid";
var taskFile = Path.Combine(taskDir, fileName);
-
- var model = new AgentTaskFileModel
+ var metaData = new AgentTaskMetaData
{
Name = task.Name,
Description = task.Description,
Enabled = task.Enabled,
+ DirectAgentId = task.DirectAgentId,
CreatedDateTime = DateTime.UtcNow,
UpdatedDateTime = DateTime.UtcNow
};
- var fileContent = BuildAgentTaskFileContent(model, task.Content);
+ var fileContent = BuildAgentTaskFileContent(metaData, task.Content);
File.WriteAllText(taskFile, fileContent);
}
@@ -146,11 +146,12 @@ public partial class FileRepository
var parsedTask = ParseAgentTask(taskFile);
if (parsedTask == null) return;
- var model = new AgentTaskFileModel
+ var metaData = new AgentTaskMetaData
{
Name = parsedTask.Name,
Description = parsedTask.Description,
Enabled = parsedTask.Enabled,
+ DirectAgentId = parsedTask.DirectAgentId,
CreatedDateTime = parsedTask.CreatedDateTime,
UpdatedDateTime = DateTime.UtcNow
};
@@ -159,26 +160,30 @@ public partial class FileRepository
switch (field)
{
case AgentTaskField.Name:
- model.Name = task.Name;
+ metaData.Name = task.Name;
break;
case AgentTaskField.Description:
- model.Description = task.Description;
+ metaData.Description = task.Description;
break;
case AgentTaskField.Enabled:
- model.Enabled = task.Enabled;
+ metaData.Enabled = task.Enabled;
+ break;
+ case AgentTaskField.DirectAgentId:
+ metaData.DirectAgentId = task.DirectAgentId;
break;
case AgentTaskField.Content:
content = task.Content;
break;
case AgentTaskField.All:
- model.Name = task.Name;
- model.Description = task.Description;
- model.Enabled = task.Enabled;
+ metaData.Name = task.Name;
+ metaData.Description = task.Description;
+ metaData.Enabled = task.Enabled;
+ metaData.DirectAgentId = task.DirectAgentId;
content = task.Content;
break;
}
- var fileContent = BuildAgentTaskFileContent(model, content);
+ var fileContent = BuildAgentTaskFileContent(metaData, content);
File.WriteAllText(taskFile, fileContent);
}
@@ -211,18 +216,9 @@ public partial class FileRepository
return taskFile;
}
- private string BuildAgentTaskFileContent(AgentTaskFileModel fileModel, string taskContent)
+ private string BuildAgentTaskFileContent(AgentTaskMetaData metaData, string taskContent)
{
- return $"{AGENT_TASK_PREFIX}\n{JsonSerializer.Serialize(fileModel, _options)}\n{AGENT_TASK_SUFFIX}\n\n{taskContent}";
+ return $"{AGENT_TASK_PREFIX}\n{JsonSerializer.Serialize(metaData, _options)}\n{AGENT_TASK_SUFFIX}\n\n{taskContent}";
}
#endregion
}
-
-internal class AgentTaskFileModel
-{
- public string Name { get; set; }
- public string? Description { get; set; }
- public bool Enabled { get; set; }
- public DateTime CreatedDateTime { get; set; }
- public DateTime UpdatedDateTime { get; set; }
-}
diff --git a/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs b/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs
index 5a4c182f..1e7cdfdf 100644
--- a/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs
+++ b/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs
@@ -13,6 +13,11 @@ public class AgentTaskService : IAgentTaskService
_services = services;
}
+ ///
+ /// Get agent tasks using pagination
+ ///
+ ///
+ ///
public async Task> GetTasks(AgentTaskFilter filter)
{
var db = _services.GetRequiredService();
@@ -20,6 +25,12 @@ public class AgentTaskService : IAgentTaskService
return await Task.FromResult(pagedTasks);
}
+ ///
+ /// Get an agent task
+ ///
+ ///
+ ///
+ ///
public async Task GetTask(string agentId, string taskId)
{
var db = _services.GetRequiredService();
@@ -27,6 +38,11 @@ public class AgentTaskService : IAgentTaskService
return await Task.FromResult(task);
}
+ ///
+ /// Create a new agent task
+ ///
+ ///
+ ///
public async Task CreateTask(AgentTask task)
{
var db = _services.GetRequiredService();
@@ -34,6 +50,12 @@ public class AgentTaskService : IAgentTaskService
await Task.CompletedTask;
}
+ ///
+ /// Update an agent task by a single field or all fields
+ ///
+ ///
+ ///
+ ///
public async Task UpdateTask(AgentTask task, AgentTaskField field)
{
var db = _services.GetRequiredService();
@@ -41,6 +63,12 @@ public class AgentTaskService : IAgentTaskService
await Task.CompletedTask;
}
+ ///
+ /// Delete an agent task
+ ///
+ ///
+ ///
+ ///
public async Task DeleteTask(string agentId, string taskId)
{
var db = _services.GetRequiredService();
diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentTaskController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentTaskController.cs
index 09ab468e..3d585378 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentTaskController.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentTaskController.cs
@@ -15,6 +15,12 @@ public class AgentTaskController : ControllerBase
_services = services;
}
+ ///
+ /// Get an agent task
+ ///
+ ///
+ ///
+ ///
[HttpGet("/agent/{agentId}/task/{taskId}")]
public async Task GetAgentTask([FromRoute] string agentId, [FromRoute] string taskId)
{
@@ -24,6 +30,11 @@ public class AgentTaskController : ControllerBase
return AgentTaskViewModel.From(task);
}
+ ///
+ /// Get agent tasks by pagination
+ ///
+ ///
+ ///
[HttpGet("/agent/tasks")]
public async Task> GetAgentTasks([FromQuery] AgentTaskFilter filter)
{
@@ -35,6 +46,12 @@ public class AgentTaskController : ControllerBase
};
}
+ ///
+ /// Create a new agent task
+ ///
+ ///
+ ///
+ ///
[HttpPost("/agent/{agentId}/task")]
public async Task CreateAgentTask([FromRoute] string agentId, [FromBody] AgentTaskCreateModel task)
{
@@ -43,6 +60,13 @@ public class AgentTaskController : ControllerBase
await _agentTaskService.CreateTask(agentTask);
}
+ ///
+ /// Update an agent task
+ ///
+ ///
+ ///
+ ///
+ ///
[HttpPut("/agent/{agentId}/task/{taskId}")]
public async Task UpdateAgentTask([FromRoute] string agentId, [FromRoute] string taskId, [FromBody] AgentTaskUpdateModel task)
{
@@ -52,6 +76,14 @@ public class AgentTaskController : ControllerBase
await _agentTaskService.UpdateTask(agentTask, AgentTaskField.All);
}
+ ///
+ /// Update an agent task by a single field
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
[HttpPatch("/agent/{agentId}/task/{taskId}/{field}")]
public async Task PatchAgentTaskByField([FromRoute] string agentId, [FromRoute] string taskId, [FromRoute] AgentTaskField field, [FromBody] AgentTaskUpdateModel task)
{
@@ -61,6 +93,12 @@ public class AgentTaskController : ControllerBase
await _agentTaskService.UpdateTask(agentTask, field);
}
+ ///
+ /// Delete an agent task
+ ///
+ ///
+ ///
+ ///
[HttpDelete("/agent/{agentId}/task/{taskId}")]
public async Task DeleteAgentTask([FromRoute] string agentId, [FromRoute] string taskId)
{
diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskCreateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskCreateModel.cs
index 89565e9f..03410f18 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskCreateModel.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskCreateModel.cs
@@ -8,6 +8,7 @@ public class AgentTaskCreateModel
public string? Description { get; set; }
public string Content { get; set; }
public bool Enabled { get; set; }
+ public string? DirectAgentId { get; set; }
public AgentTask ToAgentTask()
{
@@ -16,7 +17,8 @@ public class AgentTaskCreateModel
Name = Name,
Description = Description,
Content = Content,
- Enabled = Enabled
+ Enabled = Enabled,
+ DirectAgentId = DirectAgentId
};
}
}
diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskUpdateModel.cs
index 143aee0d..5dcea21c 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskUpdateModel.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskUpdateModel.cs
@@ -8,6 +8,7 @@ public class AgentTaskUpdateModel
public string? Description { get; set; }
public string? Content { get; set; }
public bool Enabled { get; set; }
+ public string? DirectAgentId { get; set; }
public AgentTask ToAgentTask()
{
@@ -16,7 +17,8 @@ public class AgentTaskUpdateModel
Name = Name,
Description = Description,
Content = Content,
- Enabled = Enabled
+ Enabled = Enabled,
+ DirectAgentId = DirectAgentId
};
}
}
diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskViewModel.cs
index a0b9848a..1e77f250 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskViewModel.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentTaskViewModel.cs
@@ -32,9 +32,9 @@ public class AgentTaskViewModel
Enabled = task.Enabled,
AgentId = task.AgentId,
AgentName = task.Agent?.Name,
+ DirectAgentId = task?.DirectAgentId,
CreatedDateTime = task.CreatedDateTime,
- UpdatedDateTime = task.UpdatedDateTime,
- DirectAgentId = task?.DirectAgentId
+ UpdatedDateTime = task.UpdatedDateTime
};
}
}
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs
index 198b70c1..6acc4f5b 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs
@@ -7,6 +7,7 @@ public class AgentTaskDocument : MongoBase
public string Content { get; set; }
public bool Enabled { get; set; }
public string AgentId { get; set; }
+ public string? DirectAgentId { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }
}
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs
index ac3dd97e..01e64e3e 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs
@@ -38,6 +38,7 @@ public partial class MongoRepository
Description = x.Description,
Enabled = x.Enabled,
AgentId = x.AgentId,
+ DirectAgentId = x.DirectAgentId,
Content = x.Content,
CreatedDateTime = x.CreatedTime,
UpdatedDateTime = x.UpdatedTime,
@@ -68,6 +69,7 @@ public partial class MongoRepository
Description = taskDoc.Description,
Enabled = taskDoc.Enabled,
AgentId = taskDoc.AgentId,
+ DirectAgentId = taskDoc.DirectAgentId,
Content = taskDoc.Content,
CreatedDateTime = taskDoc.CreatedTime,
UpdatedDateTime = taskDoc.UpdatedTime,
@@ -86,6 +88,7 @@ public partial class MongoRepository
Description = task.Description,
Enabled = task.Enabled,
AgentId = task.AgentId,
+ DirectAgentId = task.DirectAgentId,
Content = task.Content,
CreatedTime = DateTime.UtcNow,
UpdatedTime = DateTime.UtcNow
@@ -116,11 +119,15 @@ public partial class MongoRepository
case AgentTaskField.Content:
taskDoc.Content = task.Content;
break;
+ case AgentTaskField.DirectAgentId:
+ taskDoc.DirectAgentId = task.DirectAgentId;
+ break;
case AgentTaskField.All:
taskDoc.Name = task.Name;
taskDoc.Description = task.Description;
taskDoc.Enabled = task.Enabled;
taskDoc.Content = task.Content;
+ taskDoc.DirectAgentId = task.DirectAgentId;
break;
}