Merge pull request #1115 from iceljc/features/add-optional-migrate-agents

add option agents
This commit is contained in:
iceljc 2025-07-28 19:22:35 -05:00 committed by GitHub
commit d1a3ded0a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 6 deletions

View file

@ -10,7 +10,7 @@ namespace BotSharp.Abstraction.Agents;
public interface IAgentService
{
Task<Agent> CreateAgent(Agent agent);
Task<string> RefreshAgents();
Task<string> RefreshAgents(IEnumerable<string>? agentIds = null);
Task<PagedItems<Agent>> GetAgents(AgentFilter filter);
Task<List<IdName>> GetAgentOptions(List<string>? agentIds = null, bool byName = false);
Task<IEnumerable<AgentUtility>> GetAgentUtilityOptions();

View file

@ -6,7 +6,7 @@ namespace BotSharp.Core.Agents.Services;
public partial class AgentService
{
public async Task<string> RefreshAgents()
public async Task<string> RefreshAgents(IEnumerable<string>? agentIds = null)
{
string refreshResult;
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
@ -28,7 +28,13 @@ public partial class AgentService
}
var refreshedAgents = new List<string>();
foreach (var dir in Directory.GetDirectories(agentDir))
var dirs = Directory.GetDirectories(agentDir);
if (!agentIds.IsNullOrEmpty())
{
dirs = dirs.Where(x => agentIds.Contains(x.Split(Path.DirectorySeparatorChar).Last())).ToArray();
}
foreach (var dir in dirs)
{
try
{
@ -78,7 +84,7 @@ public partial class AgentService
}
else
{
refreshResult = "No agent gets refreshed!";
refreshResult = "No agent gets migrated!";
}
_logger.LogInformation(refreshResult);

View file

@ -111,9 +111,9 @@ public class AgentController : ControllerBase
[BotSharpAuth]
[HttpPost("/refresh-agents")]
public async Task<string> RefreshAgents()
public async Task<string> RefreshAgents([FromBody] AgentMigrationModel request)
{
return await _agentService.RefreshAgents();
return await _agentService.RefreshAgents(request?.AgentIds);
}
[HttpPut("/agent/file/{agentId}")]

View file

@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Agents;
public class AgentMigrationModel
{
[JsonPropertyName("agent_ids")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IEnumerable<string>? AgentIds { get; set; }
}