2023-09-28 17:16:39 +00:00
|
|
|
using BotSharp.Abstraction.Functions.Models;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Plugin.MongoStorage.Models;
|
|
|
|
|
|
|
|
|
|
public class FunctionDefMongoElement
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public FunctionParametersDefMongoElement Parameters { get; set; } = new FunctionParametersDefMongoElement();
|
|
|
|
|
|
|
|
|
|
public FunctionDefMongoElement()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FunctionDefMongoElement ToMongoElement(FunctionDef function)
|
|
|
|
|
{
|
|
|
|
|
return new FunctionDefMongoElement
|
|
|
|
|
{
|
|
|
|
|
Name = function.Name,
|
|
|
|
|
Description = function.Description,
|
|
|
|
|
Parameters = new FunctionParametersDefMongoElement
|
|
|
|
|
{
|
|
|
|
|
Type = function.Parameters.Type,
|
|
|
|
|
Properties = JsonSerializer.Serialize(function.Parameters.Properties),
|
|
|
|
|
Required = function.Parameters.Required,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FunctionDef ToDomainElement(FunctionDefMongoElement mongoFunction)
|
|
|
|
|
{
|
|
|
|
|
return new FunctionDef
|
|
|
|
|
{
|
|
|
|
|
Name = mongoFunction.Name,
|
|
|
|
|
Description = mongoFunction.Description,
|
|
|
|
|
Parameters = new FunctionParametersDef
|
|
|
|
|
{
|
|
|
|
|
Type = mongoFunction.Parameters.Type,
|
2023-10-16 04:21:40 +00:00
|
|
|
Properties = JsonSerializer.Deserialize<JsonDocument>(mongoFunction.Parameters.Properties.IfNullOrEmptyAs("{}")),
|
2023-09-28 17:16:39 +00:00
|
|
|
Required = mongoFunction.Parameters.Required,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FunctionParametersDefMongoElement
|
|
|
|
|
{
|
|
|
|
|
public string Type { get; set; }
|
|
|
|
|
public string Properties { get; set; }
|
|
|
|
|
public List<string> Required { get; set; } = new List<string>();
|
|
|
|
|
|
|
|
|
|
public FunctionParametersDefMongoElement()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|