JiriOndrusek commented on code in PR #9132:
URL: https://github.com/apache/camel-quarkus/pull/9132#discussion_r3955295437
##########
extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java:
##########
@@ -16,15 +16,105 @@
*/
package org.apache.camel.quarkus.component.ai.tool.deployment;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.annotations.ExecutionTime;
+import io.quarkus.deployment.annotations.Record;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
+import org.apache.camel.quarkus.component.ai.tool.AiToolRecorder;
+import org.apache.camel.quarkus.component.ai.tool.AiToolSpecConverterImpl;
+import org.apache.camel.quarkus.component.ai.tool.CamelAiToolProvider;
+import org.apache.camel.quarkus.component.ai.tool.CamelAiToolsInterceptor;
+import org.jboss.jandex.AnnotationInstance;
+import org.jboss.jandex.AnnotationTarget;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.IndexView;
+import org.jboss.logging.Logger;
class AiToolProcessor {
private static final String FEATURE = "camel-ai-tool";
+ private static final DotName CAMEL_AI_TOOLS_DOTNAME = DotName
+
.createSimple("org.apache.camel.quarkus.component.ai.tool.CamelAiTools");
+
+ private static final Logger LOG = Logger.getLogger(AiToolProcessor.class);
@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
+
+ @BuildStep(onlyIf = QuarkusLangchain4jPresent.class)
+ void registerCamelAiToolProvider(
+ CombinedIndexBuildItem combinedIndex,
+ BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
+
+ if (!new AiToolPresent().getAsBoolean()) {
+ Collection<AnnotationInstance> aiToolsAnnotations =
combinedIndex.getIndex()
+ .getAnnotations(CAMEL_AI_TOOLS_DOTNAME);
+ if (!aiToolsAnnotations.isEmpty()) {
+ LOG.warnf("@CamelAiTools annotations found but
camel-langchain4j-agent is not on the classpath. "
+ + "Add camel-langchain4j-agent dependency to enable
the Camel AI tool bridge. "
+ + "Affected classes: %s",
+ aiToolsAnnotations.stream()
+ .filter(a -> a.target().kind() ==
AnnotationTarget.Kind.CLASS)
+ .map(a ->
a.target().asClass().name().toString())
+ .collect(Collectors.joining(", ")));
+ }
+ return;
+ }
+
+ LOG.info("Camel AI Tool detected - registering CamelAiToolProvider as
CDI bean for ToolProvider auto-discovery");
+
additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(CamelAiToolProvider.class));
+ }
+
+ @BuildStep(onlyIf = { QuarkusLangchain4jPresent.class, AiToolPresent.class
})
+ AdditionalBeanBuildItem registerAiToolSpecConverter() {
+ return
AdditionalBeanBuildItem.unremovableOf(AiToolSpecConverterImpl.class);
+ }
+
+ @BuildStep(onlyIf = { QuarkusLangchain4jPresent.class, AiToolPresent.class
})
+ @Record(ExecutionTime.STATIC_INIT)
+ void configureCamelAiToolTags(
+ CombinedIndexBuildItem combinedIndex,
+ BuildProducer<AdditionalBeanBuildItem> additionalBeans,
+ AiToolRecorder recorder) {
+
+ IndexView index = combinedIndex.getIndex();
+ Map<String, String> tagMap = new HashMap<>();
+ for (AnnotationInstance annotation :
index.getAnnotations(CAMEL_AI_TOOLS_DOTNAME)) {
+ if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
+ String className =
annotation.target().asClass().name().toString();
+ if (annotation.value() == null) {
+ LOG.warnf("@CamelAiTools on %s has no value — skipping",
className);
Review Comment:
@CamelAiTools with no value (value() has default "") or a blank value is
skipped with only a build-time warning, and the service then receives all
registered tools — the opposite of the annotation's restrictive intent.
--
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]