davsclaus commented on code in PR #26607:
URL: https://github.com/apache/camel/pull/26607#discussion_r4051604335
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiToolRegistry.java:
##########
@@ -1708,39 +1708,59 @@ private String callListExamples(Map<String, Object>
args) {
String filter = args.get("filter") instanceof String v ? v : null;
String level = args.get("level") instanceof String v ? v : null;
+ int limit = args.get("limit") instanceof Number n && n.intValue() > 0
? n.intValue() : 50;
List<JsonObject> filtered = catalog;
if (filter != null && !filter.isEmpty()) {
filtered = ExampleHelper.filterExamples(filtered, filter);
}
- if (level != null && !level.isEmpty()) {
- String lowerLevel = level.toLowerCase();
- filtered = filtered.stream()
- .filter(e ->
lowerLevel.equals(e.getStringOrDefault("level", "")))
- .toList();
- }
+ JsonArray groups = new JsonArray();
JsonArray examples = new JsonArray();
- for (JsonObject entry : filtered) {
- JsonObject ex = new JsonObject();
- ex.put("name", entry.getStringOrDefault("name", ""));
- ex.put("title", entry.getStringOrDefault("title", ""));
- ex.put("description", entry.getStringOrDefault("description", ""));
- ex.put("level", entry.getStringOrDefault("level", ""));
- ex.put("category", ExampleHelper.getCategory(entry));
- ex.put("tags", toJsonArray(
- entry.get("tags") instanceof java.util.Collection<?> c
- ? c.stream().map(Object::toString).toList()
- : List.of()));
- ex.put("bundled", ExampleHelper.isBundled(entry));
- ex.put("requiresDocker", ExampleHelper.requiresDocker(entry));
- ex.put("infraServices",
toJsonArray(ExampleHelper.getInfraServices(entry)));
- examples.add(ex);
+ int total = 0;
+ for (Map.Entry<String, List<JsonObject>> group :
ExampleHelper.groupByLevel(filtered).entrySet()) {
+ if (level != null && !level.isEmpty() &&
!group.getKey().equalsIgnoreCase(level)) {
+ continue;
+ }
+ total += group.getValue().size();
+ JsonObject g = new JsonObject();
+ g.put("level", group.getKey());
+ g.put("title", ExampleHelper.getGroupTitle(group.getKey()));
+ g.put("intro", ExampleHelper.getGroupIntro(group.getKey()));
+ g.put("count", group.getValue().size());
+ groups.add(g);
+ for (JsonObject entry : group.getValue()) {
+ if (examples.size() >= limit) {
+ break;
+ }
Review Comment:
Right, that was a per-group cap. Now continue, with a test that limit=2
without a level gives count 2, in 1263033072c2.
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ToolRegistry.java:
##########
@@ -942,39 +942,71 @@ private static void registerCatalogTools() {
private static void registerExampleTools() {
register(tool("list_examples",
- "List available Camel CLI examples. Returns name, title,
description, difficulty level, and tags.")
+ "List the Camel CLI examples, grouped as the ladder of the
examples (quick-start, run, transform, "
+ + "route, fail-well, connect,
connect-service, contracts, ai, cloud, showcase). "
+ + "Returns the groups (level, title,
intro) and the examples in reading order with "
+ + "name, title, description, level,
order, tags, what they teach, the infra "
+ + "services they need, whether they are
bundled and their files. "
+ + "Call it without arguments for the
whole ladder, with level for one group.")
.param("filter", "string",
"Filter by name, description, or tag
(case-insensitive)", false)
.param("level", "string",
- "Filter by difficulty: beginner, intermediate, or
advanced", false)
+ "Only the examples of one group: quick-start, run,
transform, route, fail-well, connect, "
+ + "connect-service, contracts, ai,
cloud or showcase",
+ false)
+ .param("limit", "integer", "Maximum number of examples to
return (default: 50)", false)
.executor((ctx, args) -> {
String filter = args.get("filter");
String level = args.get("level");
+ int limit = 50;
+ String limitArg = args.get("limit");
+ if (limitArg != null && !limitArg.isBlank()) {
+ try {
+ limit = Integer.parseInt(limitArg.trim());
+ } catch (NumberFormatException e) {
+ throw new ToolExecutionException("limit must be a
number: " + limitArg);
+ }
+ }
Review Comment:
Guarded: a limit of zero or less falls back to 50, with a test, in
1263033072c2.
--
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]