A TypeScript package template for building and publishing AI SDK tools.
npm install ai-sdk-tool-as-package-templateimport { getWeather } from "ai-sdk-tool-as-package-template"; import { generateText, gateway } from "ai"; const result = await generateText({ model: gateway("openai/gpt-4o-mini"), prompt: "What's the weather like in San Francisco?", tools: { getWeather: getWeather({ unit: "celsius" }), }, });You can configure options for your tool. The example implementation, getWeather tool, accepts an optional configuration object:
type WeatherToolOptions = { unit?: "fahrenheit" | "celsius"; };- Clone the repository
- Install dependencies:
pnpm install- Create a
.envfile:
cp .env.example .env- Add your Vercel AI Gateway (or other preferred provider) API key to
.env
Test your tool locally:
pnpm testBuild the package:
pnpm buildBefore publishing, update the package name in package.json to your desired package name.
The package automatically builds before publishing:
pnpm publish. ├── src/ │ ├── tools/ │ │ └── weather.ts # Example weather tool implementation │ ├── index.ts # Your tool exports │ └── test.ts # Test script ├── dist/ # Build output (generated) ├── package.json ├── tsconfig.json └── README.md MIT