66
77#include " BaseQueryProxy.h"
88#include " EvolutionMettaParser.h"
9+ #include " LinkCreationProxy.h"
910#include " PatternMatchingQueryProxy.h"
1011#include " PortPool.h"
1112#include " QueryEvolutionProxy.h"
1920using namespace command_router ;
2021using namespace query_engine ;
2122using namespace evolution ;
23+ using namespace link_creation_agent ;
2224using namespace service_bus ;
2325using namespace commons ;
2426
@@ -41,6 +43,22 @@ void apply_direct_evolution_parameters(Properties& evo_parameters, const Propert
4143 }
4244}
4345
46+ // Keep link-creation defaults, then overlay query + link-creation keys. Context-agent
47+ // keys (use_cache, initial_rent_rate, ...) stay off the downstream proxy.
48+ void apply_direct_link_creation_parameters (Properties& lc_parameters,
49+ const Properties& router_parameters) {
50+ Properties allowed = SystemParametersSingleton::get_instance ()->get_link_creation_agent_params () +
51+ SystemParametersSingleton::get_instance ()->get_query_agent_params ();
52+ allowed[LinkCreationProxy::LOG_NEW_LINKS ] = true ;
53+ allowed[LinkCreationProxy::LINK_CREATION_LOG_FILE_NAME ] = string (" " );
54+ allowed[LinkCreationProxy::LINK_CREATOR_EXTRA_PARAMETERS ] = string (" " );
55+ for (const auto & entry : router_parameters) {
56+ if (allowed.find (entry.first ) != allowed.end ()) {
57+ lc_parameters[entry.first ] = entry.second ;
58+ }
59+ }
60+ }
61+
4462} // namespace
4563
4664BusCommandRouterProcessor::BusCommandRouterProcessor (shared_ptr<ServiceBus> service_bus)
@@ -134,6 +152,8 @@ void BusCommandRouterProcessor::run_command_internal(shared_ptr<BusCommandRouter
134152 handle_query (router_proxy, arg);
135153 } else if (command == " evolution" ) {
136154 handle_evolution (router_proxy, arg);
155+ } else if (command == " link_creation" ) {
156+ handle_link_creation (router_proxy, arg);
137157 } else {
138158 RAISE_ERROR (" Unknown router command: " + command);
139159 }
@@ -312,3 +332,27 @@ void BusCommandRouterProcessor::handle_evolution(shared_ptr<BusCommandRouterProx
312332 apply_direct_evolution_parameters (evo_proxy->parameters , proxy->parameters );
313333 this ->forward_to_service (proxy, evo_proxy);
314334}
335+
336+ void BusCommandRouterProcessor::handle_link_creation (shared_ptr<BusCommandRouterProxy> proxy,
337+ const string& arg) {
338+ string context = proxy->parameters .get <string>(CONTEXT_KEY );
339+
340+ LinkCreationMettaArgs metta_args;
341+ if (!try_parse_link_creation_metta_arg (arg, metta_args)) {
342+ RAISE_ERROR (
343+ " Link creation ARG must be a labeled MeTTa form ((query ...) (lc <link-creator-tag>))" );
344+ }
345+
346+ const bool use_metta = proxy->parameters .get <bool >(BaseQueryProxy::USE_METTA_AS_QUERY_TOKENS );
347+ vector<string> query_tokens;
348+ if (use_metta) {
349+ query_tokens = {normalize_metta_percent_variables (metta_args.query )};
350+ } else {
351+ query_tokens = Utils::split (metta_args.query , ' ' );
352+ }
353+
354+ auto lc_proxy = make_shared<LinkCreationProxy>(
355+ query_tokens, context, metta_args.link_creator_tag , BaseProxy::NONE );
356+ apply_direct_link_creation_parameters (lc_proxy->parameters , proxy->parameters );
357+ this ->forward_to_service (proxy, lc_proxy);
358+ }
0 commit comments