2024-11-20 08:24:26 +00:00
|
|
|
using BotSharp.Abstraction.Agents.Enums;
|
|
|
|
|
using BotSharp.Abstraction.Agents.Settings;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Plugin.SqlDriver.Hooks;
|
|
|
|
|
|
|
|
|
|
public class SqlDriverAgentHook : AgentHookBase, IAgentHook
|
|
|
|
|
{
|
|
|
|
|
private const string SQL_TABLE_DEFINITION_FN = "sql_table_definition";
|
|
|
|
|
private const string VERIFY_DICTIONARY_TERM_FN = "verify_dictionary_term";
|
|
|
|
|
private const string SQL_SELECT_FN = "sql_select";
|
|
|
|
|
|
|
|
|
|
public override string SelfId => BuiltInAgentId.Planner;
|
|
|
|
|
|
|
|
|
|
public SqlDriverAgentHook(IServiceProvider services, AgentSettings settings)
|
|
|
|
|
: base(services, settings)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnAgentLoaded(Agent agent)
|
|
|
|
|
{
|
|
|
|
|
var dbType = SqlDriverHelper.GetDatabaseType(_services);
|
2024-11-20 16:13:40 +00:00
|
|
|
agent.TemplateDict["db_type"] = dbType;
|
2024-11-20 08:24:26 +00:00
|
|
|
|
2024-11-20 16:13:40 +00:00
|
|
|
var utilityLoads = new List<AgentUtility>
|
2024-11-20 08:24:26 +00:00
|
|
|
{
|
2024-11-20 16:13:40 +00:00
|
|
|
new AgentUtility
|
2024-11-20 08:24:26 +00:00
|
|
|
{
|
2024-11-20 16:13:40 +00:00
|
|
|
Name = UtilityName.SqlTableDefinition,
|
2024-11-20 08:24:26 +00:00
|
|
|
Content = new UtilityContent
|
|
|
|
|
{
|
|
|
|
|
Functions = new List<UtilityFunction> { new(SQL_TABLE_DEFINITION_FN) },
|
2024-11-20 16:13:40 +00:00
|
|
|
Templates = new List<UtilityTemplate> { new($"{SQL_TABLE_DEFINITION_FN}.fn") }
|
2024-11-20 08:24:26 +00:00
|
|
|
}
|
|
|
|
|
},
|
2024-11-20 16:13:40 +00:00
|
|
|
new AgentUtility
|
2024-11-20 08:24:26 +00:00
|
|
|
{
|
2024-11-20 16:13:40 +00:00
|
|
|
Name = UtilityName.SqlDictionaryLookup,
|
2024-11-20 08:24:26 +00:00
|
|
|
Content = new UtilityContent
|
|
|
|
|
{
|
|
|
|
|
Functions = new List<UtilityFunction> { new(VERIFY_DICTIONARY_TERM_FN) },
|
2024-11-20 16:13:40 +00:00
|
|
|
Templates = new List<UtilityTemplate> { new($"{VERIFY_DICTIONARY_TERM_FN}.fn") }
|
2024-11-20 08:24:26 +00:00
|
|
|
}
|
|
|
|
|
},
|
2024-11-20 16:13:40 +00:00
|
|
|
new AgentUtility
|
2024-11-20 08:24:26 +00:00
|
|
|
{
|
2024-11-20 16:13:40 +00:00
|
|
|
Name = UtilityName.SqlExecutor,
|
2024-11-20 08:24:26 +00:00
|
|
|
Content = new UtilityContent
|
|
|
|
|
{
|
|
|
|
|
Functions = new List<UtilityFunction> { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) },
|
2024-11-20 16:13:40 +00:00
|
|
|
Templates = new List<UtilityTemplate> { new($"sql_executor.fn") }
|
2024-11-20 08:24:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
base.OnLoadAgentUtility(agent, utilityLoads);
|
|
|
|
|
base.OnAgentLoaded(agent);
|
|
|
|
|
}
|
|
|
|
|
}
|