BotSharp/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs

51 lines
1.7 KiB
C#
Raw Normal View History

2023-06-23 04:43:00 +00:00
using BotSharp.Abstraction.Agents.Models;
2023-08-26 04:41:01 +00:00
using BotSharp.Abstraction.Repositories;
2023-06-29 23:14:57 +00:00
using System.IO;
2023-06-23 04:43:00 +00:00
namespace BotSharp.Core.Agents.Services;
public partial class AgentService
{
public async Task UpdateAgent(Agent agent)
{
2023-08-10 04:53:22 +00:00
var db = _services.GetRequiredService<IBotSharpRepository>();
2023-06-26 23:08:24 +00:00
2023-07-21 21:56:14 +00:00
db.Transaction<IBotSharpTable>(delegate
2023-06-26 23:08:24 +00:00
{
2023-07-25 02:22:18 +00:00
var record = (from a in db.Agent
join ua in db.UserAgent on a.Id equals ua.AgentId
2023-08-16 12:11:24 +00:00
join u in db.User on ua.UserId equals u.Id
where (ua.UserId == _user.Id || u.ExternalId == _user.Id) &&
a.Id == agent.Id
2023-08-28 05:28:14 +00:00
select a).FirstOrDefault();
if (record == null) return;
2023-06-26 23:08:24 +00:00
record.Name = agent.Name;
2023-08-28 05:28:14 +00:00
if (!string.IsNullOrEmpty(agent.Description))
record.Description = agent.Description;
if (!string.IsNullOrEmpty(agent.Instruction))
record.Instruction = agent.Instruction;
if (!string.IsNullOrEmpty(agent.Functions))
record.Functions = agent.Functions;
if (!agent.Routes.IsEmpty())
record.Routes = agent.Routes;
2023-08-26 04:41:01 +00:00
record.UpdatedTime = DateTime.UtcNow;
2023-08-28 05:28:14 +00:00
db.Add<IBotSharpTable>(record);
2023-06-26 23:08:24 +00:00
});
2023-06-29 23:14:57 +00:00
// Save instruction to file
2023-08-28 05:28:14 +00:00
//var dir = GetAgentDataDir(agent.Id);
//var instructionFile = Path.Combine(dir, "instruction.txt");
//File.WriteAllText(instructionFile, agent.Instruction);
2023-06-29 23:14:57 +00:00
2023-08-28 05:28:14 +00:00
//var samplesFile = Path.Combine(dir, "samples.txt");
//File.WriteAllText(samplesFile, agent.Samples);
2023-06-23 04:43:00 +00:00
}
}