| name | description | metadata | ||||
|---|---|---|---|---|---|---|
regxa-ai-tool |
Integrates regxa's packageTool into AI applications built with the Vercel AI SDK. Provides structured package registry queries (info, versions, dependencies, maintainers, bulk lookups) as a tool for LLM agents. Use when building AI apps that need to query npm, PyPI, crates.io, or other registries. Do not use for direct CLI usage or non-AI integrations. |
|
regxa exports a ready-made packageTool compatible with the Vercel AI SDK. It gives AI agents structured access to package registry data across npm, PyPI, crates.io, RubyGems, Packagist, and Arch Linux.
npm install regxa ai @ai-sdk/openai # or any AI SDK providerImport packageTool from regxa/ai and pass it to the AI SDK:
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { packageTool } from "regxa/ai";
const result = await generateText({
model: openai("gpt-4o"),
tools: { package: packageTool },
prompt: "What are the dependencies of flask 3.1.1?",
});The tool handles PURL construction, API calls, normalization, and error handling internally.
The tool accepts a discriminated union input with these operations:
{ "operation": "package", "purl": "pkg:npm/lodash" }Returns: name, description, licenses, repository, latest version, keywords.
{ "operation": "versions", "purl": "pkg:cargo/serde" }Returns: version numbers, publish dates, integrity hashes, status (yanked/deprecated).
{ "operation": "dependencies", "purl": "pkg:pypi/flask@3.1.1" }Returns: dependency names, version constraints, scope (runtime/dev/test/build), optional flag.
Note: The PURL must include a version. Without it, the tool returns an error.
{ "operation": "maintainers", "purl": "pkg:gem/rails" }Returns: login, name, email, role for each maintainer.
{ "operation": "bulk-packages", "purls": ["pkg:npm/lodash", "pkg:cargo/serde"], "concurrency": 10 }Returns: map of PURL to package metadata. Fetches up to 50 PURLs concurrently (default concurrency: 15). Failed lookups are silently omitted.
The tool works with streamText as well:
import { streamText } from "ai";
import { packageTool } from "regxa/ai";
const result = streamText({
model: openai("gpt-4o"),
tools: { package: packageTool },
prompt: "Compare the latest versions of express and fastify",
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}Read references/purl-cheatsheet.md for the PURL format details and ecosystem-specific examples.
The tool handles errors internally and returns them as structured error objects:
- Package not found: Returns error with ecosystem and package name
- Invalid PURL: Returns parse error with details
- Unknown ecosystem: Returns list of supported ecosystems
- Rate limiting: The HTTP client retries automatically with exponential backoff
If the tool call fails at the AI SDK level, the agent receives the error message and can self-correct (e.g., fix PURL format, try a different ecosystem).