#!/usr/bin/env bash # Copyright AI-Catalog Contributors (https://github.com/Agent-Card/ai-catalog-cli) # Copyright AGNTCY Contributors (https://github.com/agntcy) # SPDX-License-Identifier: Apache-2.0 # Consumer workflow walkthrough for ai-catalog. # # Covers the full CLI surface: # Author: validate (text/json/stdin), format, trust inspect (text/json) # Consumer: catalog add/list/update/remove, search (text/json/regex/limit), # show (text/json/scoped), pull (inline-data/file-url) # # Runs entirely offline using file:// URLs. # Uses AI_CATALOG_CACHE_DIR to keep all state in a temp directory so the # walkthrough never touches the user's ~/.ai-catalog/ registry. set -euo pipefail if [[ -t 2 ]]; then BOLD=$'\033[1m' DIM=$'\033[2m' CYAN=$'\033[1;36m' GREEN=$'\033[1;32m' RESET=$'\033[0m' else BOLD='' DIM='' CYAN='' GREEN='' RESET='' fi step_count=0 # Each section runs to completion, then waits for Enter. Skipped when stdin is # not a terminal so piped and redirected runs cannot block. section() { if [[ "$step_count" -gt 0 && -t 0 ]]; then printf '\n%s ── press enter to continue ──%s' "$DIM" "$RESET" >&2 read -r || true fi echo >&2 echo "${BOLD}────────────────────────────────────────────────────────${RESET}" >&2 echo "${BOLD} $*${RESET}" >&2 echo "${BOLD}────────────────────────────────────────────────────────${RESET}" >&2 } step() { step_count=$((step_count + 1)) echo >&2 echo "${CYAN}== $* ==${RESET}" >&2 } require_tool() { if ! command -v "$1" >/dev/null 2>&1; then echo "error: $1 is required for this walkthrough" >&2 exit 1 fi } echo_cmd() { printf '%s$ %s%s\n' "$GREEN" "$*" "$RESET" >&2 } run_cli() { local display=() arg needs_quoting for arg in "$@"; do needs_quoting=0 [[ "$arg" =~ [^A-Za-z0-9_./:@=-] ]] && needs_quoting=1 arg="${arg//$tmp_root/\$DEMO}" if [[ "$needs_quoting" == "1" ]]; then arg="'$arg'" fi display+=("$arg") done echo_cmd "ai-catalog ${display[*]}" cargo run -q -- "$@" } require_tool cargo workspace_root="$(cd "$(dirname "$0")/.." && pwd)" tmp_root="$(mktemp -d -t ai-catalog-consumer-demo)" export AI_CATALOG_CACHE_DIR="$tmp_root/cache" cleanup() { rm -rf "$tmp_root" } trap cleanup EXIT cd "$workspace_root" # ── Write fixture files ─────────────────────────────────────────────────────── eval_suite_path="$tmp_root/eval-suite-v3.jsonl" nested_catalog_path="$tmp_root/datasets-catalog.json" root_catalog_path="$tmp_root/demo-catalog.json" pull_dir="$tmp_root/pulled" mkdir -p "$pull_dir" # A small pullable artifact (JSONL file) referenced by the nested catalog cat > "$eval_suite_path" <<'EOF' {"prompt": "What is 2+2?", "expected": "4"} {"prompt": "Translate 'hello' to French", "expected": "bonjour"} {"prompt": "Summarise the A2A protocol in one sentence", "expected": "A2A enables AI agents to communicate using JSON-RPC 2.0 over HTTP."} EOF # Nested catalog with two dataset entries cat > "$nested_catalog_path" < "$root_catalog_path" <&2