davsclaus commented on code in PR #29911:
URL: https://github.com/apache/camel/pull/29911#discussion_r4577849488
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ToolArgumentAliases.java:
##########
@@ -51,6 +53,25 @@ public final class ToolArgumentAliases {
// a path says more than a file name, so it wins when a call gives
both
"camel_validate_source", pairs("path", "file", "filename", "file",
"name", "file", "source", "content"));
+ /**
+ * The names a call may give the integration a tool acts on by. The
runtime tools of the MCP server take
+ * {@code nameOrPid}; camel_run, camel_get_log, camel_get_errors,
camel_control and camel_eval_expression take
+ * {@code name}. A model that carries one over to the other kind of tool
must not act on another integration
+ * (CAMEL-26932).
+ */
+ private static final Map<String, String> TO_NAME_OR_PID
+ = pairs("name", "nameOrPid", "pid", "nameOrPid", "integration",
"nameOrPid");
+ private static final Map<String, String> TO_NAME = pairs("nameOrPid",
"name", "pid", "name", "integration", "name");
+ private static final Set<String> NAME_TOOLS
+ = Set.of("camel_get_log", "camel_get_errors", "camel_control",
"camel_eval_expression");
+
+ /**
+ * Arguments that name an integration, in lower case: a call that gives
one the tool ignores must not act on the
+ * only integration that runs.
+ */
+ private static final Set<String> SELECTORS = Set.of("name", "nameorpid",
"pid", "integration", "integrationname",
+ "process", "processname", "app", "appname", "context",
"contextname");
Review Comment:
Added `application` to `SELECTORS` in 5c9868a35ace, with a case in
`ToolArgumentAliasesTest.anIgnoredArgumentThatNamesTheIntegrationIsTheSelector`.
_Claude Code on behalf of davsclaus_
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ToolArgumentAliases.java:
##########
@@ -114,6 +135,37 @@ public static Map<String, String> aliases(String tool) {
return ALIASES.getOrDefault(tool, Map.of());
}
+ /**
+ * The aliases of a tool with the given arguments, alias to declared name:
those of {@link #aliases(String)}, and
+ * the other names of the argument that picks the integration the tool
acts on.
+ */
+ public static Map<String, String> aliases(String tool, List<String> names)
{
+ Map<String, String> answer = new LinkedHashMap<>(aliases(tool));
+ if (names.contains("nameOrPid")) {
+ TO_NAME_OR_PID.forEach(answer::putIfAbsent);
+ } else if (NAME_TOOLS.contains(tool) && names.contains("name")) {
+ TO_NAME.forEach(answer::putIfAbsent);
+ }
+ return answer;
+ }
+
+ /**
+ * The argument a call gave to name an integration that the tool ignored,
while it did not give the argument the
+ * tool picks its integration by: the tool would act on the only
integration that runs, which may be another one.
+ * Null when there is none.
+ */
+ public static String ignoredSelector(Resolved<?> resolved) {
+ String selector = resolved.declared().stream().map(Argument::name)
+ .filter(n -> n.equals("nameOrPid") || n.equals("name") &&
NAME_TOOLS.contains(resolved.tool()))
Review Comment:
Grouped with parentheses in 5c9868a35ace.
_Claude Code on behalf of davsclaus_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]