(
args: argparse.Namespace,
socket_path: Path,
workdir: Path,
categories: list[str],
)
| 355 | |
| 356 | |
| 357 | def fetch_catalog_via_jcode( |
| 358 | args: argparse.Namespace, |
| 359 | socket_path: Path, |
| 360 | workdir: Path, |
| 361 | categories: list[str], |
| 362 | ) -> dict[str, list[dict[str, Any]]]: |
| 363 | created = json.loads( |
| 364 | run_debug_command(args, socket_path, f"create_session:{workdir}", timeout=60) |
| 365 | ) |
| 366 | session_id = created["session_id"] |
| 367 | catalog: dict[str, list[dict[str, Any]]] = {} |
| 368 | try: |
| 369 | for index, category in enumerate(categories, start=1): |
| 370 | last_error: Exception | None = None |
| 371 | for attempt in range(1, args.catalog_retries + 1): |
| 372 | tool_input = json.dumps( |
| 373 | { |
| 374 | "category": category, |
| 375 | "query": ( |
| 376 | f"public {category.replace('-', ' ')} capabilities available " |
| 377 | "for external agent workflows" |
| 378 | ), |
| 379 | "reason": ( |
| 380 | "Enumerate the live public listings so benchmark scenarios can be " |
| 381 | "validated without selecting or configuring any provider." |
| 382 | ), |
| 383 | }, |
| 384 | separators=(",", ":"), |
| 385 | ) |
| 386 | try: |
| 387 | raw = run_debug_command( |
| 388 | args, |
| 389 | socket_path, |
| 390 | "tool", |
| 391 | f"discover_tools {tool_input}", |
| 392 | session_id=session_id, |
| 393 | timeout=20, |
| 394 | ) |
| 395 | payload = json.loads(raw) |
| 396 | call = parse_discovery_output(str(payload.get("output", "")), 0.0) |
| 397 | if call.category != category or call.outcome not in {"listing", "empty"}: |
| 398 | raise BenchmarkError( |
| 399 | f"unexpected catalog response for {category}: {payload.get('output', '')}" |
| 400 | ) |
| 401 | catalog[category] = [{"name": name} for name in call.tools] |
| 402 | break |
| 403 | except Exception as error: |
| 404 | last_error = error |
| 405 | if attempt < args.catalog_retries: |
| 406 | time.sleep(args.retry_delay * attempt) |
| 407 | else: |
| 408 | raise BenchmarkError( |
| 409 | f"catalog discovery failed for {category} after " |
| 410 | f"{args.catalog_retries} attempts: {last_error}" |
| 411 | ) |
| 412 | progress(index, len(categories), "categories", f"Fetched catalog category {category}") |
| 413 | finally: |
| 414 | try: |
no test coverage detected