-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-23978: Add AI panel slash commands to Camel TUI #24594
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
+3,859
−105
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
9e8b40b
CAMEL-23978: Add AI panel slash command registry
ammachado 87df544
CAMEL-23978: Add TUI AI CLI command executor
ammachado cd08b0b
CAMEL-23978: Wire local AI panel slash commands
ammachado 6d4ce48
CAMEL-23978: Show AI slash command placeholders
ammachado 9d3f6ea
CAMEL-23978: Document AI panel slash commands
ammachado 266cad5
CAMEL-23978: Harden AI panel slash command behavior
ammachado 450d54c
CAMEL-23978: Wire AI provider switch popup to /provider command
ammachado 5e7598b
CAMEL-23978: Improve AI panel slash command help and hints
ammachado a5245fe
CAMEL-23978: Align AI slash command help columns
ammachado a0143e7
CAMEL-23978: Persist TUI AI settings
ammachado cd47e70
CAMEL-23978: Polish AI panel thinking state
ammachado 6699a3a
CAMEL-23978: Add AI provider quick switch
ammachado 1040922
CAMEL-23978: Randomize AI panel thinking verb, apply formatter fix
ammachado 22fef85
CAMEL-23978: Fix AI provider switch bugs and agent thread races
ammachado 3675d86
CAMEL-23978: Restore agent thread test hook after rebase
ammachado dfb18f9
CAMEL-23978: Remove local superpowers dev artifact
ammachado a2fef2a
CAMEL-23978: Fix AI panel slash command review findings
ammachado f2a116f
CAMEL-23978: Document stopAgentThread() cancellation join limitation
ammachado 2a83126
CAMEL-23978: Extract AiProviderSelector from AiPanel
ammachado 592c18d
CAMEL-23978: Implement /model listing via provider APIs
ammachado 312bd2a
CAMEL-23978: Restore thinking dots animation, list all AI providers
ammachado 3681485
CAMEL-23978: Fix SettingsPopup AI-provider row test after rebase
ammachado a881374
CAMEL-23978: Show AI slash command placeholders
ammachado 134b843
CAMEL-23978: Address PR review feedback
ammachado 04d3d5a
CAMEL-23978: Remove duplicate placeholder block in AiPanel.renderInput
ammachado 1ae8f66
CAMEL-23978: Launch /run and /infra run as tracked background processes
ammachado f2d67a2
CAMEL-23978: Persist /model selection across TUI restarts
ammachado cae9f29
CAMEL-23978: Add TAB completion and fix clipped AI output
ammachado ba40132
CAMEL-23978: Harden AI model selection
ammachado d97d48f
CAMEL-23978: Address latest AI panel review feedback
ammachado f6008c3
CAMEL-23978: Serialize AI CLI execution
ammachado 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
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
150 changes: 150 additions & 0 deletions
150
...-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/LlmClientListModelsTest.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,150 @@ | ||
| /* | ||
| * 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.commands; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.net.InetSocketAddress; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import com.sun.net.httpserver.HttpServer; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * Verifies {@link LlmClient#listModels()} against each provider's real response shape (Ollama's {@code /api/tags}, | ||
| * OpenAI/Anthropic's {@code /v1/models}) using a local {@link HttpServer} instead of mocking the HTTP client, so the | ||
| * request path, auth headers, and JSON parsing are all exercised together. | ||
| */ | ||
| class LlmClientListModelsTest { | ||
|
|
||
| private HttpServer server; | ||
|
|
||
| @AfterEach | ||
| void stopServer() { | ||
| if (server != null) { | ||
| server.stop(0); | ||
| } | ||
| } | ||
|
|
||
| private String startServer(String path, int status, String body, AtomicReference<String> capturedHeader, String headerName) | ||
| throws IOException { | ||
| server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); | ||
| server.createContext(path, exchange -> { | ||
| if (capturedHeader != null) { | ||
| capturedHeader.set(exchange.getRequestHeaders().getFirst(headerName)); | ||
| } | ||
| byte[] bytes = body.getBytes(StandardCharsets.UTF_8); | ||
| exchange.sendResponseHeaders(status, bytes.length); | ||
| try (OutputStream os = exchange.getResponseBody()) { | ||
| os.write(bytes); | ||
| } | ||
| }); | ||
| server.start(); | ||
| return "http://127.0.0.1:" + server.getAddress().getPort(); | ||
| } | ||
|
|
||
| private String startRootServer(String body) throws IOException { | ||
| server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); | ||
| server.createContext("/", exchange -> { | ||
| byte[] bytes = body.getBytes(StandardCharsets.UTF_8); | ||
| int status = "/".equals(exchange.getRequestURI().getPath()) ? 200 : 404; | ||
| exchange.sendResponseHeaders(status, bytes.length); | ||
| try (OutputStream os = exchange.getResponseBody()) { | ||
| os.write(bytes); | ||
| } | ||
| }); | ||
| server.start(); | ||
| return "http://127.0.0.1:" + server.getAddress().getPort(); | ||
| } | ||
|
|
||
| @Test | ||
| void detectsOllamaFromRootResponseOnNonDefaultPort() throws IOException { | ||
| String baseUrl = startRootServer("Ollama is running"); | ||
| LlmClient client = LlmClient.create().withUrl(baseUrl); | ||
|
|
||
| assertTrue(client.detectEndpoint()); | ||
| assertEquals(LlmClient.ApiType.ollama, client.apiType()); | ||
| } | ||
|
|
||
| @Test | ||
| void listsOllamaModelsFromApiTags() throws IOException { | ||
| String baseUrl = startServer("/api/tags", 200, | ||
| "{\"models\":[{\"name\":\"llama3.2:latest\"},{\"name\":\"qwen3\"}]}", null, null); | ||
| LlmClient client = LlmClient.create().withApiType(LlmClient.ApiType.ollama).withUrl(baseUrl); | ||
|
|
||
| assertEquals(List.of("llama3.2:latest", "qwen3"), client.listModels()); | ||
| } | ||
|
|
||
| @Test | ||
| void listsOpenAiModelsFromV1ModelsWithBearerAuth() throws IOException { | ||
| AtomicReference<String> authHeader = new AtomicReference<>(); | ||
| String baseUrl = startServer("/v1/models", 200, | ||
| "{\"data\":[{\"id\":\"gpt-4o\"},{\"id\":\"gpt-4o-mini\"}]}", authHeader, "Authorization"); | ||
| LlmClient client = LlmClient.create().withApiType(LlmClient.ApiType.openai).withUrl(baseUrl).withApiKey("sk-test"); | ||
|
|
||
| assertEquals(List.of("gpt-4o", "gpt-4o-mini"), client.listModels()); | ||
| assertEquals("Bearer sk-test", authHeader.get()); | ||
| } | ||
|
|
||
| @Test | ||
| void listsAnthropicModelsFromV1ModelsWithApiKeyHeader() throws IOException { | ||
| AtomicReference<String> apiKeyHeader = new AtomicReference<>(); | ||
| String baseUrl = startServer("/v1/models", 200, | ||
| "{\"data\":[{\"id\":\"claude-sonnet-4-6\"}]}", apiKeyHeader, "x-api-key"); | ||
| LlmClient client | ||
| = LlmClient.create().withApiType(LlmClient.ApiType.anthropic).withUrl(baseUrl).withApiKey("sk-ant-test"); | ||
|
|
||
| assertEquals(List.of("claude-sonnet-4-6"), client.listModels()); | ||
| assertEquals("sk-ant-test", apiKeyHeader.get()); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsEmptyListOnNonOkStatus() throws IOException { | ||
| String baseUrl = startServer("/api/tags", 500, "{\"error\":\"boom\"}", null, null); | ||
| LlmClient client = LlmClient.create().withApiType(LlmClient.ApiType.ollama).withUrl(baseUrl); | ||
|
|
||
| assertTrue(client.listModels().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsEmptyListWhenModelListHasUnexpectedShape() throws IOException { | ||
| String baseUrl = startServer("/api/tags", 200, "{\"models\":{}}", null, null); | ||
| LlmClient client = LlmClient.create().withApiType(LlmClient.ApiType.ollama).withUrl(baseUrl); | ||
|
|
||
| assertTrue(client.listModels().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsEmptyListWhenEndpointUnreachable() { | ||
| LlmClient client = LlmClient.create().withApiType(LlmClient.ApiType.ollama).withUrl("http://127.0.0.1:1"); | ||
|
|
||
| assertTrue(client.listModels().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsEmptyListWhenApiTypeNotYetDetected() { | ||
| LlmClient client = LlmClient.create(); | ||
|
|
||
| assertTrue(client.listModels().isEmpty()); | ||
| } | ||
| } |
Oops, something went wrong.
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.