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


##########
components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/AiToolSpecToLangChain4j.java:
##########
@@ -48,11 +53,60 @@ public static ToolSpecification 
toToolSpecification(AiToolSpec spec) {
 
         if (spec.getParameterDefs() != null && 
!spec.getParameterDefs().isEmpty()) {
             builder.parameters(buildSchema(spec.getParameterDefs()));

Review Comment:
   Non-blocking: `JsonSchemaElementJsonUtils` is from 
`dev.langchain4j.internal` — an internal API that may change without notice in 
future LangChain4j releases. The `stripSchemaMetadata()` fallback helps, but 
this is a maintenance risk worth tracking.



##########
components/camel-ai/camel-ai-tool/src/main/java/org/apache/camel/component/ai/tool/AiToolParameterHelper.java:
##########
@@ -150,6 +159,161 @@ public static String buildJsonSchemaFromDefs(Map<String, 
ParameterDef> defs) {
         return schema.toJson();
     }
 
+    /**
+     * Validates that flat {@code parameter.*} metadata and {@code argSchema} 
are not both configured.
+     */
+    public static void validateParameterSourceExclusive(Map<String, String> 
parameters, String argSchema) {
+        boolean hasParameters = parameters != null && !parameters.isEmpty();
+        boolean hasArgSchema = argSchema != null && !argSchema.isBlank();
+        if (hasParameters && hasArgSchema) {
+            throw new IllegalArgumentException(
+                    "argSchema and parameter.* are mutually exclusive on 
ai-tool endpoints");
+        }
+    }
+
+    /**
+     * Resolves, validates, and normalizes a raw JSON Schema for tool input.
+     */
+    public static String resolveArgSchema(CamelContext camelContext, String 
argSchema) {
+        if (argSchema == null || argSchema.isBlank()) {
+            throw new IllegalArgumentException("argSchema must not be blank");
+        }
+
+        String resolved = camelContext.resolvePropertyPlaceholders(argSchema);
+        String content = resolveResourceContent(camelContext, resolved);
+        if (content != null) {
+            resolved = content;
+        }
+
+        JsonObject root = parseJsonObject(resolved, argSchema);
+        validateRootSchemaObject(root);
+        return root.toJson();
+    }
+
+    /**
+     * Returns top-level property names declared in a JSON Schema object.
+     */
+    public static Set<String> extractTopLevelPropertyNames(String jsonSchema) {
+        if (jsonSchema == null || jsonSchema.isBlank()) {
+            return Set.of();
+        }
+        JsonObject root = parseJsonObject(jsonSchema, jsonSchema);
+        Map<String, Object> properties = requirePropertiesMap(root, 
jsonSchema);
+        if (properties.isEmpty()) {
+            return Set.of();
+        }
+        return Set.copyOf(properties.keySet());
+    }
+
+    /**
+     * Returns top-level required property names declared in a JSON Schema 
object.
+     */
+    public static Set<String> extractRequiredPropertyNames(String jsonSchema) {
+        if (jsonSchema == null || jsonSchema.isBlank()) {
+            return Set.of();
+        }
+        JsonObject root = parseJsonObject(jsonSchema, jsonSchema);
+        Collection<?> required = readRequiredArray(root, jsonSchema);
+        if (required.isEmpty()) {
+            return Set.of();
+        }
+        Set<String> names = new LinkedHashSet<>();
+        for (Object value : required) {
+            if (value != null) {
+                names.add(value.toString());
+            }
+        }
+        return Set.copyOf(names);

Review Comment:
   Non-blocking: this broad `catch (Exception)` silently swallows errors for 
non-resource values. If a user provides a scheme-less resource path like 
`schemas/order.json` that fails to load, the error is swallowed and the value 
is treated as inline JSON — resulting in a confusing JSON parse error rather 
than a clear "resource not found" error.



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