davsclaus commented on code in PR #27082:
URL: https://github.com/apache/camel/pull/27082#discussion_r4136334435


##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/TransformTools.java:
##########
@@ -151,6 +158,7 @@ private String transformYamlToXml(String yaml) throws 
Exception {
 
             RoutesDefinition rd = new RoutesDefinition();
             rd.setRoutes(routeDefs);
+            
rd.setSemantic(DefaultSemanticDefinitionConfigurer.getDefinition(ctx));

Review Comment:
   Nit: this ties the MCP module to the camel-semantic implementation class 
through a public static helper. Adding an export method to 
`org.apache.camel.model.spi.SemanticDefinitionConfigurer` (looked up as a 
context plugin like `SemanticDefinitionHelper` does) would keep MCP on the SPI 
only. Also note the conversion writes resolved values and explicit defaults, 
and a placeholder with no default would probably fail to resolve in this 
throwaway context.



##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/DefaultSemanticDefinitionConfigurer.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.semantic;
+
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.PropertyDefinition;
+import org.apache.camel.model.app.SemanticDefinition;
+import org.apache.camel.model.app.SemanticQuestionDefinition;
+import org.apache.camel.model.spi.SemanticDefinitionConfigurer;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.util.StringHelper;
+
+/** Converts Java/XML declarations to the same immutable questions used by 
YAML and programmatic registration. */
+public class DefaultSemanticDefinitionConfigurer implements 
SemanticDefinitionConfigurer {
+    @Override
+    public void configure(CamelContext context, Resource resource, String 
source, SemanticDefinition definition) {
+        Map<String, SemanticQuestion> questions = new LinkedHashMap<>();
+        if (definition != null) {
+            for (SemanticQuestionDefinition question : 
definition.getQuestions()) {
+                String name = question.getName();
+                if (name == null || name.isBlank()) {
+                    throw new IllegalArgumentException("Semantic question 
requires a nonblank name");
+                }
+                if (questions.containsKey(name)) {
+                    throw new IllegalArgumentException("Duplicate semantic 
question: " + name);
+                }
+                try {
+                    questions.put(name, question(context, question));
+                } catch (IllegalArgumentException e) {
+                    throw new IllegalArgumentException("Invalid semantic 
question '" + name + "': " + e.getMessage(), e);
+                }
+            }
+        }
+        // A YAML loader can register its own declarations from the same 
resource before its RouteBuilder runs.
+        SemanticQuestions.get(context).replace("model:" + source, resource, 
questions);
+    }
+
+    /** Export a snapshot of the registered questions and their effective 
decision policies. */
+    public static SemanticDefinition getDefinition(CamelContext context) {

Review Comment:
   Minor: the exported definition always includes threshold, uncertainty and 
uncertaintyPolicy for boolean questions, even when they are the defaults. 
Leaving out default values would keep the converted output minimal.



##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/TransformTools.java:
##########
@@ -176,16 +184,25 @@ private String transformJavaToFormat(String java, String 
targetFormat) throws Ex
                         "Could not parse Java route. Ensure it contains a 
valid route definition.");
             }
 
+            // Java expression clauses are normally materialized when 
processors are created.
+            routeDefs.forEach(route -> 
ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), 
ExpressionNode.class)
+                    .forEach(ExpressionNode::preCreateProcessor));

Review Comment:
   This pre-creates expression clauses for every converted Java route, not only 
semantic ones. Looks like a general fix for Java→YAML/XML. Could you add a 
small test with a non-semantic expression clause (e.g. `.filter().simple(...)`) 
so it's covered?



-- 
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]

Reply via email to