|
| 1 | +import { Command } from "commander" |
| 2 | +import type { OpenSeaClient } from "../client.js" |
| 3 | +import type { OutputFormat } from "../output.js" |
| 4 | +import { outputGet } from "../output.js" |
| 5 | +import { parseIntOption } from "../parse.js" |
| 6 | + |
| 7 | +export function toolsCommand( |
| 8 | + getClient: () => OpenSeaClient, |
| 9 | + getFormat: () => OutputFormat, |
| 10 | +): Command { |
| 11 | + const cmd = new Command("tools").description( |
| 12 | + "Search, list, and inspect registered AI agent tools (ERC-8257)", |
| 13 | + ) |
| 14 | + |
| 15 | + cmd |
| 16 | + .command("search") |
| 17 | + .description("Search registered tools by name, tags, creator, or criteria") |
| 18 | + .option("--query <text>", "Search query text") |
| 19 | + .option("--registry-chain <chain>", "Filter by registry chain ID") |
| 20 | + .option("--tags <tags>", "Comma-separated tags to filter by") |
| 21 | + .option( |
| 22 | + "--access-type <type>", |
| 23 | + "Filter by access type (open, nft_gated, subscription)", |
| 24 | + ) |
| 25 | + .option("--creator <address>", "Filter by creator address") |
| 26 | + .option( |
| 27 | + "--sort-by <sort>", |
| 28 | + "Sort order (relevance, newest, most_used)", |
| 29 | + "relevance", |
| 30 | + ) |
| 31 | + .option("--limit <limit>", "Number of results", "20") |
| 32 | + .option("--next <cursor>", "Pagination cursor") |
| 33 | + .action( |
| 34 | + async (options: { |
| 35 | + query?: string |
| 36 | + registryChain?: string |
| 37 | + tags?: string |
| 38 | + accessType?: string |
| 39 | + creator?: string |
| 40 | + sortBy: string |
| 41 | + limit: string |
| 42 | + next?: string |
| 43 | + }) => { |
| 44 | + const client = getClient() |
| 45 | + await outputGet(client, getFormat(), "/api/v2/tools/search", { |
| 46 | + query: options.query, |
| 47 | + registry_chain: options.registryChain, |
| 48 | + tags: options.tags, |
| 49 | + access_type: options.accessType, |
| 50 | + creator: options.creator, |
| 51 | + sort_by: options.sortBy, |
| 52 | + limit: parseIntOption(options.limit, "--limit"), |
| 53 | + "cursor.value": options.next, |
| 54 | + }) |
| 55 | + }, |
| 56 | + ) |
| 57 | + |
| 58 | + cmd |
| 59 | + .command("get") |
| 60 | + .description( |
| 61 | + "Get detailed info about a registered tool by its composite key", |
| 62 | + ) |
| 63 | + .argument("<registry_chain>", "Registry chain ID (e.g., 8453 for Base)") |
| 64 | + .argument("<registry_addr>", "Registry contract address") |
| 65 | + .argument("<tool_id>", "Numeric tool ID") |
| 66 | + .action( |
| 67 | + async (registryChain: string, registryAddr: string, toolId: string) => { |
| 68 | + const client = getClient() |
| 69 | + await outputGet( |
| 70 | + client, |
| 71 | + getFormat(), |
| 72 | + `/api/v2/tools/${registryChain}/${registryAddr}/${toolId}`, |
| 73 | + ) |
| 74 | + }, |
| 75 | + ) |
| 76 | + |
| 77 | + cmd |
| 78 | + .command("list") |
| 79 | + .description("List registered tools with optional sorting and filtering") |
| 80 | + .option("--sort-by <sort>", "Sort order (newest, oldest)", "newest") |
| 81 | + .option( |
| 82 | + "--type <type>", |
| 83 | + "Filter by access type (open, nft_gated, token_gated, subscription, gated)", |
| 84 | + ) |
| 85 | + .option("--limit <limit>", "Number of results", "20") |
| 86 | + .option("--next <cursor>", "Pagination cursor") |
| 87 | + .action( |
| 88 | + async (options: { |
| 89 | + sortBy: string |
| 90 | + type?: string |
| 91 | + limit: string |
| 92 | + next?: string |
| 93 | + }) => { |
| 94 | + const client = getClient() |
| 95 | + await outputGet(client, getFormat(), "/api/v2/tools", { |
| 96 | + sort_by: options.sortBy, |
| 97 | + type: options.type, |
| 98 | + limit: parseIntOption(options.limit, "--limit"), |
| 99 | + "cursor.value": options.next, |
| 100 | + }) |
| 101 | + }, |
| 102 | + ) |
| 103 | + |
| 104 | + return cmd |
| 105 | +} |
0 commit comments