atiaomar1978-hub commented on code in PR #26055: URL: https://github.com/apache/camel/pull/26055#discussion_r3938003651
########## dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GenAiDependencyHelper.java: ########## @@ -0,0 +1,131 @@ +/* + * 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.dsl.jbang.core.common; + +import java.util.Collection; +import java.util.Properties; + +import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.DefaultCamelCatalog; +import org.apache.camel.tooling.model.ComponentModel; + +/** + * Adds optional GenAI observability dependencies using the same settings-driven approach as OpenTelemetry and LRA. + * <p> + * GenAI component and LangChain4j provider JARs are resolved by the existing silent-run download pipeline + * ({@code DependencyDownloaderComponentResolver}, {@code KnownDependenciesResolver}) — not by scanning route source. + * </p> + */ +public final class GenAiDependencyHelper { + + public static final String AI_OBSERVABILITY_ENABLED = "camel.aiObservability.enabled"; + + private GenAiDependencyHelper() { + } + + /** + * Adds {@code camel:ai-observability} when GenAI artifacts are already in the dependency set and observability is + * requested via {@code --observe} or {@code camel.aiObservability.enabled=true}. + */ + public static void addAiObservabilityIfNeeded(Collection<String> deps, Properties properties, boolean observe) { + addAiObservabilityIfNeeded(deps, properties, observe, new DefaultCamelCatalog()); + } + + static void addAiObservabilityIfNeeded( + Collection<String> deps, Properties properties, boolean observe, CamelCatalog catalog) { + if (!includeAiObservability(properties, observe)) { + return; + } + if (!hasGenAiDependency(deps, catalog)) { + return; + } + if (catalog.otherModel("ai-observability") != null) { + deps.add("camel:ai-observability"); + } + } + + static boolean includeAiObservability(Properties properties, boolean observe) { + String enabled = properties != null ? properties.getProperty(AI_OBSERVABILITY_ENABLED) : null; + if ("false".equalsIgnoreCase(enabled)) { + return false; + } + return observe || "true".equalsIgnoreCase(enabled); + } + + static boolean hasGenAiDependency(Collection<String> deps, CamelCatalog catalog) { + for (String dep : deps) { + if (dep == null || dep.isBlank()) { + continue; + } + if (isGenAiCamelComponent(dep, catalog)) { + return true; + } + if (isLangChain4jProviderJar(dep)) { + return true; + } + } + return false; + } + + private static boolean isGenAiCamelComponent(String dep, CamelCatalog catalog) { + if (dep.startsWith("camel:")) { + String scheme = dep.substring("camel:".length()); + int query = scheme.indexOf('?'); + if (query > 0) { + scheme = scheme.substring(0, query); + } + ComponentModel model = catalog.componentModel(scheme); + return model != null && isAiLabel(model.getLabel()); + } + return dep.contains(":camel-") && isAiArtifactId(dep); + } + + private static boolean isAiArtifactId(String dep) { + int idx = dep.indexOf(":camel-"); + if (idx < 0) { + return false; Review Comment: Fixed in 054c4fd: mvn: GenAI detection now uses CamelCatalog.modelFromMavenGAV() plus the catalog ai label. camel-ai-observability is explicitly excluded from hasGenAiDependency(), and alreadyHasAiObservability() prevents duplicate camel:ai-observability entries in Run.java ArrayList. _Cursor Agent on behalf of atiaomar1978-hub_ ########## dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GenAiDependencyHelper.java: ########## @@ -0,0 +1,131 @@ +/* + * 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.dsl.jbang.core.common; + +import java.util.Collection; +import java.util.Properties; + +import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.DefaultCamelCatalog; +import org.apache.camel.tooling.model.ComponentModel; + +/** + * Adds optional GenAI observability dependencies using the same settings-driven approach as OpenTelemetry and LRA. + * <p> + * GenAI component and LangChain4j provider JARs are resolved by the existing silent-run download pipeline + * ({@code DependencyDownloaderComponentResolver}, {@code KnownDependenciesResolver}) — not by scanning route source. + * </p> + */ +public final class GenAiDependencyHelper { + + public static final String AI_OBSERVABILITY_ENABLED = "camel.aiObservability.enabled"; + + private GenAiDependencyHelper() { + } + + /** + * Adds {@code camel:ai-observability} when GenAI artifacts are already in the dependency set and observability is + * requested via {@code --observe} or {@code camel.aiObservability.enabled=true}. + */ + public static void addAiObservabilityIfNeeded(Collection<String> deps, Properties properties, boolean observe) { + addAiObservabilityIfNeeded(deps, properties, observe, new DefaultCamelCatalog()); + } + + static void addAiObservabilityIfNeeded( + Collection<String> deps, Properties properties, boolean observe, CamelCatalog catalog) { + if (!includeAiObservability(properties, observe)) { + return; + } + if (!hasGenAiDependency(deps, catalog)) { + return; + } + if (catalog.otherModel("ai-observability") != null) { + deps.add("camel:ai-observability"); + } + } + + static boolean includeAiObservability(Properties properties, boolean observe) { + String enabled = properties != null ? properties.getProperty(AI_OBSERVABILITY_ENABLED) : null; + if ("false".equalsIgnoreCase(enabled)) { + return false; + } + return observe || "true".equalsIgnoreCase(enabled); + } + + static boolean hasGenAiDependency(Collection<String> deps, CamelCatalog catalog) { + for (String dep : deps) { + if (dep == null || dep.isBlank()) { + continue; + } + if (isGenAiCamelComponent(dep, catalog)) { + return true; + } + if (isLangChain4jProviderJar(dep)) { + return true; + } + } + return false; + } + + private static boolean isGenAiCamelComponent(String dep, CamelCatalog catalog) { + if (dep.startsWith("camel:")) { + String scheme = dep.substring("camel:".length()); + int query = scheme.indexOf('?'); + if (query > 0) { + scheme = scheme.substring(0, query); + } + ComponentModel model = catalog.componentModel(scheme); + return model != null && isAiLabel(model.getLabel()); + } + return dep.contains(":camel-") && isAiArtifactId(dep); + } + + private static boolean isAiArtifactId(String dep) { + int idx = dep.indexOf(":camel-"); + if (idx < 0) { + return false; + } + String artifact = dep.substring(idx + 1); + int colon = artifact.indexOf(':'); + if (colon > 0) { + artifact = artifact.substring(0, colon); + } + return artifact.startsWith("camel-langchain4j") + || artifact.startsWith("camel-openai") + || artifact.startsWith("camel-spring-ai") + || artifact.startsWith("camel-aws-bedrock") Review Comment: Fixed in 054c4fd: removed contains("-ai-") and prefix heuristics entirely. The mvn: branch now parses the GAV and queries the catalog via modelFromMavenGAV(), using the ai label as the authoritative check. _Cursor Agent on behalf of atiaomar1978-hub_ ########## dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties: ########## @@ -73,3 +73,17 @@ org.apache.qpid.jms.JmsConnectionFactory = org.apache.qpid:qpid-jms-client:${qpi org.messaginghub.pooled.jms.JmsPoolConnectionFactory = org.messaginghub:pooled-jms:${pooled-jms-version} org.postgresql.Driver = org.postgresql:postgresql:${pgjdbc-driver-version} org.postgresql.ds.PGSimpleDataSource = org.postgresql:postgresql:${pgjdbc-driver-version} + +dev.langchain4j.model.ollama = dev.langchain4j:langchain4j-ollama:${langchain4j-version} +dev.langchain4j.model.openai = dev.langchain4j:langchain4j-open-ai:${langchain4j-version} +dev.langchain4j.model.huggingface = dev.langchain4j:langchain4j-hugging-face:${langchain4j-beta-version} +dev.langchain4j.model.anthropic = dev.langchain4j:langchain4j-anthropic:${langchain4j-version} +dev.langchain4j.model.azure = dev.langchain4j:langchain4j-azure-open-ai:${langchain4j-version} +dev.langchain4j.model.mistralai = dev.langchain4j:langchain4j-mistral-ai:${langchain4j-version} +dev.langchain4j.model.vertexai = dev.langchain4j:langchain4j-vertex-ai:${langchain4j-version} +dev.langchain4j.model.googleai = dev.langchain4j:langchain4j-google-ai-gemini:${langchain4j-version} +dev.langchain4j.model.github = dev.langchain4j:langchain4j-github-models:${langchain4j-version} +dev.langchain4j.model.embedding.onnx = dev.langchain4j:langchain4j-embeddings:${langchain4j-beta-version} Review Comment: Yes, intentional — same pattern as camel.opentelemetry / camel.lra (lines 43-47). Added an inline comment in 054c4fd documenting that camel.aiObservability is a camel-main property prefix so any camel.aiObservability.* access triggers runtime download of camel:ai-observability. _Cursor Agent on behalf of atiaomar1978-hub_ ########## dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GenAiDependencyHelper.java: ########## @@ -0,0 +1,131 @@ +/* + * 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.dsl.jbang.core.common; + +import java.util.Collection; +import java.util.Properties; + +import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.DefaultCamelCatalog; +import org.apache.camel.tooling.model.ComponentModel; + +/** + * Adds optional GenAI observability dependencies using the same settings-driven approach as OpenTelemetry and LRA. + * <p> + * GenAI component and LangChain4j provider JARs are resolved by the existing silent-run download pipeline + * ({@code DependencyDownloaderComponentResolver}, {@code KnownDependenciesResolver}) — not by scanning route source. + * </p> + */ +public final class GenAiDependencyHelper { + Review Comment: Done in 054c4fd — AI_OBSERVABILITY_ENABLED is now package-private. _Cursor Agent on behalf of atiaomar1978-hub_ ########## dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/GenAiDependencyHelperTest.java: ########## @@ -0,0 +1,98 @@ +/* + * 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.dsl.jbang.core.common; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Properties; + +import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.DefaultCamelCatalog; +import org.apache.camel.tooling.model.ComponentModel; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class GenAiDependencyHelperTest { + + private final CamelCatalog catalog = new DefaultCamelCatalog(); + + @Test + void addsAiObservabilityWhenGenAiComponentPresentAndObserveEnabled() { + List<String> deps = new ArrayList<>(List.of("camel:langchain4j-chat")); + + GenAiDependencyHelper.addAiObservabilityIfNeeded(deps, new Properties(), true, catalog); + + assertThat(deps).contains("camel:ai-observability"); + } + + @Test + void addsAiObservabilityWhenGenAiPropertyEnabled() { + List<String> deps = new ArrayList<>(List.of("mvn:org.apache.camel:camel-openai")); + Properties properties = new Properties(); + properties.setProperty(GenAiDependencyHelper.AI_OBSERVABILITY_ENABLED, "true"); + + GenAiDependencyHelper.addAiObservabilityIfNeeded(deps, properties, false, catalog); + + assertThat(deps).contains("camel:ai-observability"); + } + + @Test + void skipsAiObservabilityWithoutGenAiArtifacts() { + List<String> deps = new ArrayList<>(List.of("camel:timer")); + + GenAiDependencyHelper.addAiObservabilityIfNeeded(deps, new Properties(), true, catalog); + + assertThat(deps).doesNotContain("camel:ai-observability"); + } + + @Test + void skipsAiObservabilityWhenExplicitlyDisabled() { + List<String> deps = new ArrayList<>(List.of("camel:langchain4j-chat")); + Properties properties = new Properties(); + properties.setProperty(GenAiDependencyHelper.AI_OBSERVABILITY_ENABLED, "false"); + + GenAiDependencyHelper.addAiObservabilityIfNeeded(deps, properties, true, catalog); + + assertThat(deps).doesNotContain("camel:ai-observability"); + } Review Comment: Done in 054c4fd — replaced the Mockito mock with real DefaultCamelCatalog (openai already has label ai in the catalog). _Cursor Agent on behalf of atiaomar1978-hub_ -- 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]
