-
Notifications
You must be signed in to change notification settings - Fork 5.2k
CAMEL-24566: Auto-discover GenAI dependencies in Camel CLI #26055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davsclaus
merged 5 commits into
apache:main
from
atiaomar1978-hub:feature/CAMEL-24566-genai-dependency-auto-discovery
Sep 5, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0342b5
CAMEL-24566: Auto-discover GenAI dependencies in Camel CLI
cursoragent 023e9c6
CAMEL-24566: Address review feedback on GenAI dependency discovery
cursoragent 04413ce
CAMEL-24566: Replace route source scanning with catalog-based depende…
cursoragent ea1ba9d
Regen
davsclaus 054c4fd
CAMEL-24566: Address gnodet review on GenAiDependencyHelper
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...bang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GenAiDependencyHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| /* | ||
| * 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.maven.MavenGav; | ||
| import org.apache.camel.tooling.model.ArtifactModel; | ||
| 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 { | ||
|
|
||
| static final String AI_OBSERVABILITY_ENABLED = "camel.aiObservability.enabled"; | ||
|
|
||
| private static final String AI_OBSERVABILITY_ARTIFACT = "camel-ai-observability"; | ||
| private static final String AI_OBSERVABILITY_SCHEME = "ai-observability"; | ||
|
|
||
| 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 (alreadyHasAiObservability(deps)) { | ||
| return; | ||
| } | ||
| if (catalog.otherModel(AI_OBSERVABILITY_SCHEME) != 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 (isGenAiCamelScheme(dep, catalog)) { | ||
| return true; | ||
| } | ||
| if (isGenAiMavenArtifact(dep, catalog)) { | ||
| return true; | ||
| } | ||
| if (isLangChain4jProviderJar(dep)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean isGenAiCamelScheme(String dep, CamelCatalog catalog) { | ||
| if (!dep.startsWith("camel:")) { | ||
| return false; | ||
| } | ||
| String scheme = dep.substring("camel:".length()); | ||
| int query = scheme.indexOf('?'); | ||
| if (query > 0) { | ||
| scheme = scheme.substring(0, query); | ||
| } | ||
| if (AI_OBSERVABILITY_SCHEME.equals(scheme)) { | ||
| return false; | ||
| } | ||
| ComponentModel model = catalog.componentModel(scheme); | ||
| return model != null && isAiLabel(model.getLabel()); | ||
| } | ||
|
|
||
| private static boolean isGenAiMavenArtifact(String dep, CamelCatalog catalog) { | ||
| if (!dep.startsWith("mvn:")) { | ||
| return false; | ||
| } | ||
| try { | ||
| MavenGav gav = MavenGav.parseGav(dep.substring(4)); | ||
| String artifactId = gav.getArtifactId(); | ||
| if (artifactId == null || AI_OBSERVABILITY_ARTIFACT.equals(artifactId)) { | ||
| return false; | ||
| } | ||
| ArtifactModel<?> model = catalog.modelFromMavenGAV(gav.getGroupId(), artifactId, gav.getVersion()); | ||
| return model != null && isAiLabel(model.getLabel()); | ||
| } catch (Exception e) { | ||
| return false; | ||
|
davsclaus marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| private static boolean alreadyHasAiObservability(Collection<String> deps) { | ||
| for (String dep : deps) { | ||
| if (dep == null || dep.isBlank()) { | ||
| continue; | ||
| } | ||
| if (dep.startsWith("camel:")) { | ||
| String scheme = dep.substring("camel:".length()); | ||
| int query = scheme.indexOf('?'); | ||
| if (query > 0) { | ||
| scheme = scheme.substring(0, query); | ||
| } | ||
| if (AI_OBSERVABILITY_SCHEME.equals(scheme)) { | ||
| return true; | ||
| } | ||
| } else if (dep.startsWith("mvn:") && dep.contains(":" + AI_OBSERVABILITY_ARTIFACT)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean isLangChain4jProviderJar(String dep) { | ||
| return dep.contains("dev.langchain4j:langchain4j-"); | ||
| } | ||
|
|
||
| private static boolean isAiLabel(String label) { | ||
| if (label == null || label.isBlank()) { | ||
| return false; | ||
| } | ||
| for (String token : label.split(",")) { | ||
| if ("ai".equals(token.trim())) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...-core/src/test/java/org/apache/camel/dsl/jbang/core/common/GenAiDependencyHelperTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * 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.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| 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"); | ||
| } | ||
|
davsclaus marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| void detectsLangChain4jProviderJar() { | ||
| Collection<String> deps = List.of("mvn:dev.langchain4j:langchain4j-ollama:1.0.0"); | ||
|
|
||
| assertThat(GenAiDependencyHelper.hasGenAiDependency(deps, catalog)).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void detectsGenAiComponentFromCatalogLabel() { | ||
| assertThat(GenAiDependencyHelper.hasGenAiDependency(List.of("camel:openai"), catalog)).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void timerComponentIsNotGenAi() { | ||
| assertThat(GenAiDependencyHelper.hasGenAiDependency(List.of("camel:timer"), catalog)).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| void explicitAiObservabilityMavenDepDoesNotCountAsGenAiRouteDependency() { | ||
| assertThat(GenAiDependencyHelper.hasGenAiDependency( | ||
| List.of("mvn:org.apache.camel:camel-ai-observability"), catalog)).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| void doesNotDuplicateAiObservabilityWhenExplicitlyProvided() { | ||
| List<String> deps = new ArrayList<>( | ||
| List.of( | ||
| "camel:openai", | ||
| "mvn:org.apache.camel:camel-ai-observability")); | ||
|
|
||
| GenAiDependencyHelper.addAiObservabilityIfNeeded(deps, new Properties(), true, catalog); | ||
|
|
||
| assertThat(deps).contains("mvn:org.apache.camel:camel-ai-observability"); | ||
| assertThat(deps.stream().filter("camel:ai-observability"::equals)).hasSize(0); | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
dsl/camel-jbang/camel-jbang-core/src/test/resources/genai/langchain4j-route.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| - from: | ||
| uri: timer:tick | ||
| steps: | ||
| - to: langchain4j-chat:myModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.