Skip to content

CAMEL-24275: Native Google Gemini API for Camel JBang TUI - #25172

Open
atiaomar1978-hub wants to merge 5 commits into
apache:mainfrom
atiaomar1978-hub:CAMEL-24275-tui-gemini-native
Open

CAMEL-24275: Native Google Gemini API for Camel JBang TUI#25172
atiaomar1978-hub wants to merge 5 commits into
apache:mainfrom
atiaomar1978-hub:CAMEL-24275-tui-gemini-native

Conversation

@atiaomar1978-hub

@atiaomar1978-hub atiaomar1978-hub commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds ApiType.gemini to LlmClient for the Google Generative Language API (generativelanguage.googleapis.com), including env auto-detection (GEMINI_API_KEY; GOOGLE_API_KEY when --api-type=gemini is explicit), model listing, chat/generate with function calling (including id and thoughtSignature round-trip), and Gemini-aware URL health checks.
  • Uses x-goog-api-key for Gemini HTTP calls; generate URLs follow Google’s :generateContent path form.
  • Exposes gemini in the TUI provider selector; Doctor/AiPanel hints match auto-detection (GEMINI_API_KEY only).
  • Documents detection order and --api-type=gemini in the JBang AI manual and 4.22 upgrade guide.

Review follow-ups

  • Bugbot + Grok (425158b): configured API key, headers, thoughtSignature, auto-detect scope, URL health checks.
  • @davsclaus (d8e0e0f): Doctor/AiPanel aligned with auto-detect; removed dead query-param auth code.
  • @davsclaus follow-up (latest): explicit --url Gemini/proxy detection uses authenticated /models probe (tryDetectGeminiAtExplicitUrl).

Review status: @davsclaus approved on d8e0e0f; follow-up commit addresses non-blocking explicit-URL note.

Test plan

  • mvn test -pl dsl/camel-jbang/camel-jbang-core -Dtest=LlmClientGeminiTest,LlmClientListModelsTest
  • mvn test -pl dsl/camel-jbang/camel-jbang-plugin-tui -Dtest=AiProviderSelectorTest

https://issues.apache.org/jira/browse/CAMEL-24275

AI-generated PR description on behalf of atiaomar1978-hub

@atiaomar1978-hub

atiaomar1978-hub commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Post-review update (Bugbot + Grok)

Pushed commit 425158b addressing the main findings (configured API key, headers, thoughtSignature, auto-detect scope, URL health).

Update (@davsclausd8e0e0f)

Doctor/AiPanel aligned with Gemini auto-detect; removed dead appendGeminiApiKey; parameterless geminiGenerateContentUrl(). All five inline threads resolved. Approved by @davsclaus on d8e0e0f.

Update (explicit URL probe — 533eea65752)

Non-blocking review note: Gemini-compatible proxies reached via --url now use tryDetectGeminiAtExplicitUrl (/models + x-goog-api-key) instead of an unauthenticated /v1beta/models append. Covered by detectEndpointRecognizesGeminiCompatibleProxyWithApiKeyHeader.

Tests: LlmClientGeminiTest, LlmClientListModelsTest, AiProviderSelectorTest.

AI-generated comment on behalf of atiaomar1978-hub

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @atiaomar1978-hub — solid work adding native Gemini support with comprehensive tests and thoughtful design choices (like restricting auto-detection to GEMINI_API_KEY to avoid hijacking unrelated GOOGLE_API_KEY setups).

A few issues to address before merge — the most important one is a mismatch between what the Doctor reports and what auto-detection actually does.

This review covers project rules, conventions, and code correctness visible from the diff. It does not replace specialized review tools (CodeRabbit, SonarCloud) or static analysis.

This review was generated by an AI agent (Claude Code on behalf of davsclaus) and may contain inaccuracies. Please verify all suggestions before applying.

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

Follow-up (@davsclaus review)

Latest push: d8e0e0f4cea on CAMEL-24275-tui-gemini-native.

TUI messaging now matches Gemini auto-detection (Doctor no longer treats GOOGLE_API_KEY as auto-detect; hints updated in Doctor + AiPanel). Cleaned up leftover query-param auth in LlmClient.

Review threads resolved; ready for another look when CI is green.

AI-generated comment on behalf of atiaomar1978-hub

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work adding native Gemini support, @atiaomar1978-hub — the implementation is clean, well-tested, and follows the existing patterns in LlmClient.

Minor observations (non-blocking)

  1. applyDefaultModel asymmetry — the Gemini case checks DEFAULT_OLLAMA_MODEL.equals(model) to handle provider switching from Ollama, but the existing OpenAI and Anthropic cases do not have this guard. The Gemini approach is actually more robust; consider adding the same guard to the other providers in a follow-up.

  2. tryExplicitUrl health check for non-standard Gemini endpoints — the special-case bypass in the EXPLICIT_URL_HEALTH_CHECK_SUFFIXES loop works well for generativelanguage.googleapis.com, but the fallback tryHealthCheck(url + "/v1beta/models") for non-standard endpoints runs without API key headers. Minor edge case since those users would need --api-type=gemini anyway.

Everything else looks solid: API key via x-goog-api-key header (not URL query), GOOGLE_API_KEY scoped to explicit mode only, ToolCall record change is source-compatible, tests use AssertJ and package-private visibility per conventions, and documentation is properly updated.

This review was generated by an AI agent (Claude Code on behalf of davsclaus) and may contain inaccuracies. Please verify all suggestions before applying.

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

Latest push (533eea65752)

  • Branch: CAMEL-24275-tui-gemini-native
  • @davsclaus approved after d8e0e0f; this commit adds the explicit-URL Gemini proxy health check with API key headers.
  • Tests re-run locally (AssertJ): LlmClientGeminiTest, LlmClientListModelsTest, AiProviderSelectorTest.

AI-generated comment on behalf of atiaomar1978-hub

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • docs
  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-jbang-plugin-tui

🔬 Scalpel shadow comparison — Scalpel: 8 tested, 8 compile-only — current: 6 all tested

Maveniverse Scalpel detected 16 affected modules (current approach: 6).

⚠️ Modules only in Scalpel (10)
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-launcher
  • coverage
  • docs

Skip-tests mode would test 8 modules (3 direct + 5 downstream), skip tests for 8 (generated code, meta-modules)

Modules Scalpel would test (8)
  • camel-jbang-core
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • docs
Modules with tests skipped (8)
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-launcher
  • coverage

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 1 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (16 modules)
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Launcher
  • Camel :: Launcher :: Container

⚙️ View full build and test results

@davsclaus
davsclaus force-pushed the CAMEL-24275-tui-gemini-native branch from 533eea6 to 9061093 Compare July 28, 2026 07:37

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured PR that adds native Google Gemini API support following existing patterns for Anthropic/OpenAI. Prior review feedback from davsclaus was fully addressed.

Highlights:

  • The ToolCall record change (adding thoughtSignature field with backward-compatible 3-arg convenience constructor) is source-compatible with all existing callers.
  • Gemini API key resolution is well-designed: auto-detect only checks GEMINI_API_KEY (avoiding hijacking unrelated GOOGLE_API_KEY setups), while explicit --api-type=gemini accepts both.
  • Test coverage is strong: 11 tests in LlmClientGeminiTest covering URL normalization, model filtering, response parsing (including function calls and thoughtSignature round-trip), endpoint detection, and auth header verification.
  • All test conventions are followed: package-private classes/methods, AssertJ assertions, no Thread.sleep(), proper @AfterEach cleanup.

Minor notes (non-blocking):

  • buildGeminiGenerateRequestForTest uses a *ForTest naming pattern in production code — consider a more neutral name (e.g., buildGeminiRequestWithContents) in a follow-up.
  • In tryDetectGeminiAtExplicitUrl, when the endpoint is not a known Gemini domain, resolveGeminiApiKeyFromEnv() also accepts GOOGLE_API_KEY, which could trigger a Gemini probe against a non-Gemini URL when GOOGLE_API_KEY is set for unrelated GCP services. Risk is low since the probe requires a 200 response.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@davsclaus davsclaus added this to the 4.22.0 milestone Jul 28, 2026
@davsclaus davsclaus added the enhancement New feature or request label Jul 28, 2026
@davsclaus

Copy link
Copy Markdown
Contributor

the other PR was merged so this need rebase and fixing the code

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

AI-generated comment on behalf of atiaomar1978-hub

Rebased onto main after CAMEL-24276 (Azure OpenAI) merged. Conflicts resolved by keeping both providers:

  • Auto-detect order: Anthropic → Vertex → Azure OpenAIGemini → OpenAI → Ollama
  • @davsclaus review fixes retained (Doctor/AiPanel use GEMINI_API_KEY only for auto-detect hints; dead query-param auth removed)
  • Added missing tryHealthCheck(url, headers) overload so Gemini health checks compile with Azure’s 3-arg variant

Latest commit: rebased branch + compile fix. Tests: LlmClientGeminiTest (11), LlmClientListModelsTest (13), AiProviderSelectorTest (7) — all green locally.

@atiaomar1978-hub
atiaomar1978-hub force-pushed the CAMEL-24275-tui-gemini-native branch from 9061093 to baf07a0 Compare July 30, 2026 15:38
Omar Atie and others added 5 commits July 31, 2026 15:42
Wire ApiType.gemini to generativelanguage.googleapis.com with env key
detection, model listing, tool calling, provider selector, and docs/tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Honor configured API keys, use x-goog-api-key headers, preserve function
call id/thoughtSignature, limit GOOGLE_API_KEY to explicit gemini mode,
and fix explicit URL health checks.

Co-authored-by: Cursor <cursoragent@cursor.com>
…code

Doctor and AiPanel mention GEMINI_API_KEY only for auto-detect; drop unused
appendGeminiApiKey and geminiGenerateContentUrl key parameter.

Co-authored-by: Cursor <cursoragent@cursor.com>
Probe /models with x-goog-api-key for non-google hosts instead of an
unauthenticated /v1beta/models suffix; add AssertJ coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add tryHealthCheck(url, headers) delegating to the Azure-aware 3-arg
overload so Gemini explicit URL detection compiles alongside Azure OpenAI.

Co-authored-by: Cursor <cursoragent@cursor.com>
@atiaomar1978-hub
atiaomar1978-hub force-pushed the CAMEL-24275-tui-gemini-native branch from baf07a0 to 77702fa Compare July 31, 2026 23:37
@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

Rebased onto latest `main` and resolved merge conflicts (AI-generated on behalf of atiaomar1978-hub).

Conflicts resolved by keeping both Gemini support and the watsonx.ai integration from `main`:

  • `LlmClient.java` — merged `ApiType.gemini` + `watsonx`, combined auto-detect order, both model-list methods
  • `AiPanel.java` — init hint mentions `GEMINI_API_KEY` and `WATSONX_APIKEY`
  • `AiProviderSelectorTest.java` — provider lists include both providers

Local tests: `LlmClientGeminiTest`, `LlmClientWatsonxTest`, `LlmClientAzureTest`, `AiProviderSelectorTest` (8/8 passed)

Branch rebased and force-pushed: `77702fae2da`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs dsl enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants