refine agent and update
This commit is contained in:
parent
88f45927a9
commit
d238064af9
|
|
@ -335,6 +335,8 @@ public class FileRepository : IBotSharpRepository
|
|||
|
||||
private void UpdateAgentProfiles(string agentId, List<string> profiles)
|
||||
{
|
||||
if (profiles.IsNullOrEmpty()) return;
|
||||
|
||||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
if (agent == null) return;
|
||||
|
||||
|
|
@ -346,6 +348,8 @@ public class FileRepository : IBotSharpRepository
|
|||
|
||||
private void UpdateAgentRoutingRules(string agentId, List<RoutingRule> rules)
|
||||
{
|
||||
if (rules.IsNullOrEmpty()) return;
|
||||
|
||||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
if (agent == null) return;
|
||||
|
||||
|
|
@ -453,6 +457,10 @@ public class FileRepository : IBotSharpRepository
|
|||
agent.Name = inputAgent.Name;
|
||||
agent.Description = inputAgent.Description;
|
||||
agent.IsPublic = inputAgent.IsPublic;
|
||||
agent.Disabled = inputAgent.Disabled;
|
||||
agent.AllowRouting = inputAgent.AllowRouting;
|
||||
agent.Profiles = inputAgent.Profiles;
|
||||
agent.RoutingRules = inputAgent.RoutingRules;
|
||||
agent.UpdatedDateTime = DateTime.UtcNow;
|
||||
var json = JsonSerializer.Serialize(agent, _options);
|
||||
File.WriteAllText(agentFile, json);
|
||||
|
|
|
|||
|
|
@ -66,6 +66,38 @@ public class AgentController : ControllerBase, IApiAdapter
|
|||
await _agentService.UpdateAgent(model, AgentField.IsPublic);
|
||||
}
|
||||
|
||||
[HttpPut("/agent/{agentId}/disabled")]
|
||||
public async Task UpdateAgentDisabled([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
{
|
||||
var model = agent.ToAgent();
|
||||
model.Id = agentId;
|
||||
await _agentService.UpdateAgent(model, AgentField.Disabled);
|
||||
}
|
||||
|
||||
[HttpPut("/agent/{agentId}/allow-routing")]
|
||||
public async Task UpdateAgentAllowRouting([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
{
|
||||
var model = agent.ToAgent();
|
||||
model.Id = agentId;
|
||||
await _agentService.UpdateAgent(model, AgentField.AllowRouting);
|
||||
}
|
||||
|
||||
[HttpPut("/agent/{agentId}/profiles")]
|
||||
public async Task UpdateAgentProfiles([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
{
|
||||
var model = agent.ToAgent();
|
||||
model.Id = agentId;
|
||||
await _agentService.UpdateAgent(model, AgentField.Profiles);
|
||||
}
|
||||
|
||||
[HttpPut("/agent/{agentId}/routing-rules")]
|
||||
public async Task UpdateAgentRoutingRules([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
{
|
||||
var model = agent.ToAgent();
|
||||
model.Id = agentId;
|
||||
await _agentService.UpdateAgent(model, AgentField.RoutingRules);
|
||||
}
|
||||
|
||||
[HttpPut("/agent/{agentId}/instruction")]
|
||||
public async Task UpdateAgentInstruction([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
{
|
||||
|
|
@ -83,7 +115,7 @@ public class AgentController : ControllerBase, IApiAdapter
|
|||
}
|
||||
|
||||
[HttpPut("/agent/{agentId}/templates")]
|
||||
public async Task UpdateAgenttemplates([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
public async Task UpdateAgentTemplates([FromRoute] string agentId, [FromBody] AgentUpdateModel agent)
|
||||
{
|
||||
var model = agent.ToAgent();
|
||||
model.Id = agentId;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class AgentCreationModel
|
|||
public bool AllowRouting { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
public List<string> Profiles { get; set; }
|
||||
public List<RoutingRule> RoutingRules { get; set; }
|
||||
public List<RoutingRuleUpdateModel> RoutingRules { get; set; }
|
||||
|
||||
public Agent ToAgent()
|
||||
{
|
||||
|
|
@ -31,7 +31,9 @@ public class AgentCreationModel
|
|||
AllowRouting = AllowRouting,
|
||||
Disabled = Disabled,
|
||||
Profiles = Profiles,
|
||||
RoutingRules = RoutingRules
|
||||
RoutingRules = RoutingRules?
|
||||
.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?
|
||||
.ToList() ?? new List<RoutingRule>()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ public class AgentUpdateModel
|
|||
/// <summary>
|
||||
/// Profile by channel
|
||||
/// </summary>
|
||||
public List<string> Profiles { get; set; }
|
||||
public List<string>? Profiles { get; set; }
|
||||
|
||||
public List<RoutingRule> RoutingRules { get; set; }
|
||||
public List<RoutingRuleUpdateModel>? RoutingRules { get; set; }
|
||||
|
||||
public Agent ToAgent()
|
||||
{
|
||||
|
|
@ -56,7 +56,9 @@ public class AgentUpdateModel
|
|||
Disabled = Disabled,
|
||||
AllowRouting = AllowRouting,
|
||||
Profiles = Profiles ?? new List<string>(),
|
||||
RoutingRules = RoutingRules ?? new List<RoutingRule>(),
|
||||
RoutingRules = RoutingRules?
|
||||
.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?
|
||||
.ToList() ?? new List<RoutingRule>(),
|
||||
Instruction = Instruction ?? string.Empty,
|
||||
Templates = Templates ?? new List<AgentTemplate>(),
|
||||
Functions = Functions ?? new List<string>(),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Agents;
|
||||
|
||||
|
|
@ -12,6 +13,11 @@ public class AgentViewModel
|
|||
public List<string> Functions { get; set; }
|
||||
public List<AgentResponse> Responses { get; set; }
|
||||
public bool IsPublic { get; set; }
|
||||
public bool AllowRouting { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
public List<string> Profiles { get; set; }
|
||||
public List<RoutingRule> RoutingRules { get; set; }
|
||||
|
||||
public DateTime CreatedDateTime { get; set; }
|
||||
public DateTime UpdatedDateTime { get; set; }
|
||||
|
||||
|
|
@ -27,6 +33,10 @@ public class AgentViewModel
|
|||
Functions = agent.Functions,
|
||||
Responses = agent.Responses,
|
||||
IsPublic= agent.IsPublic,
|
||||
Disabled = agent.Disabled,
|
||||
AllowRouting = agent.AllowRouting,
|
||||
Profiles = agent.Profiles,
|
||||
RoutingRules = agent.RoutingRules,
|
||||
CreatedDateTime = agent.CreatedDateTime,
|
||||
UpdatedDateTime = agent.UpdatedDateTime
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
using BotSharp.Abstraction.Routing.Models;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Agents;
|
||||
|
||||
public class RoutingRuleUpdateModel
|
||||
{
|
||||
public string Field { get; set; }
|
||||
public bool Required { get; set; }
|
||||
public string? RedirectTo { get; set; }
|
||||
|
||||
public RoutingRuleUpdateModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static RoutingRule ToDomainElement(RoutingRuleUpdateModel model)
|
||||
{
|
||||
return new RoutingRule
|
||||
{
|
||||
Field = model.Field,
|
||||
Required = model.Required,
|
||||
RedirectTo = model.RedirectTo
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
namespace BotSharp.Plugin.MongoStorage.Collections;
|
||||
|
||||
public class RoutingItemCollection : MongoBase
|
||||
{
|
||||
public Guid AgentId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public List<string> RequiredFields { get; set; }
|
||||
public Guid? RedirectTo { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
namespace BotSharp.Plugin.MongoStorage.Collections;
|
||||
|
||||
public class RoutingProfileCollection : MongoBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<Guid> AgentIds { get; set; }
|
||||
}
|
||||
|
|
@ -42,10 +42,4 @@ public class MongoDbContext
|
|||
|
||||
public IMongoCollection<UserAgentCollection> UserAgents
|
||||
=> Database.GetCollection<UserAgentCollection>($"{_collectionPrefix}_UserAgents");
|
||||
|
||||
public IMongoCollection<RoutingItemCollection> RoutingItems
|
||||
=> Database.GetCollection<RoutingItemCollection>($"{_collectionPrefix}_RoutingItems");
|
||||
|
||||
public IMongoCollection<RoutingProfileCollection> RoutingProfiles
|
||||
=> Database.GetCollection<RoutingProfileCollection>($"{_collectionPrefix}_RoutingProfiles");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue