@tavily/ai-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +135 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alpha AI Technologies Inc dba Tavily.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# @tavily/ai-sdk
|
|
2
|
+
|
|
3
|
+
AI SDK tools for Tavily, built for Vercel's AI SDK v5.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Search**: Real-time web search optimized for AI applications
|
|
8
|
+
- **Extract**: Clean, structured content extraction from URLs
|
|
9
|
+
- **Crawl**: Intelligent website crawling at scale
|
|
10
|
+
- **Map**: Website structure discovery and mapping
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @tavily/ai-sdk
|
|
16
|
+
# or
|
|
17
|
+
pnpm install @tavily/ai-sdk
|
|
18
|
+
# or
|
|
19
|
+
yarn add @tavily/ai-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Prerequisites
|
|
23
|
+
|
|
24
|
+
You need a Tavily API key to use these tools. Get one at [tavily.com](https://tavily.com).
|
|
25
|
+
|
|
26
|
+
Set your API key as an environment variable:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
export TAVILY_API_KEY=tvly-your-api-key
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or pass it directly to the tool configuration.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Tavily Search
|
|
37
|
+
|
|
38
|
+
Search the web for real-time, AI-optimized information:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { tavilySearch } from "@tavily/ai-sdk";
|
|
42
|
+
import { generateText, gateway } from "ai";
|
|
43
|
+
|
|
44
|
+
const result = await generateText({
|
|
45
|
+
model: gateway("openai/gpt-5-mini"),
|
|
46
|
+
prompt: "What are the latest developments in quantum computing?",
|
|
47
|
+
tools: {
|
|
48
|
+
tavilySearch: tavilySearch({
|
|
49
|
+
searchDepth: "advanced",
|
|
50
|
+
includeAnswer: true,
|
|
51
|
+
maxResults: 5,
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Configuration Options:**
|
|
58
|
+
- `apiKey?: string` - Tavily API key (defaults to `TAVILY_API_KEY` env var)
|
|
59
|
+
- `searchDepth?: "basic" | "advanced"` - Search depth (default: "basic")
|
|
60
|
+
- `topic?: "general" | "news" | "finance"` - Search category (default: "general")
|
|
61
|
+
- `includeImages?: boolean` - Include images in results (default: false)
|
|
62
|
+
- `includeAnswer?: boolean` - Include AI-generated answer (default: false)
|
|
63
|
+
- `maxResults?: number` - Maximum results to return (default: 5)
|
|
64
|
+
- `includeImageDescriptions?: boolean` - Include AI-generated image descriptions
|
|
65
|
+
- `includeRawContent?: false | "markdown" | "text"` - Include raw content in specified format
|
|
66
|
+
- `includeDomains?: string[]` - List of domains to include in search
|
|
67
|
+
- `excludeDomains?: string[]` - List of domains to exclude from search
|
|
68
|
+
- `maxTokens?: number` - Maximum number of tokens in response
|
|
69
|
+
- `timeRange?: "year" | "month" | "week" | "day" | "y" | "m" | "w" | "d"` - Time range for results
|
|
70
|
+
- `chunksPerSource?: number` - Number of content chunks per source
|
|
71
|
+
- `country?: string` - Country code for localized results
|
|
72
|
+
- `startDate?: string` - Start date for results (YYYY-MM-DD format)
|
|
73
|
+
- `endDate?: string` - End date for results (YYYY-MM-DD format)
|
|
74
|
+
- `days?: number` - Number of days back to search (for news/finance topics)
|
|
75
|
+
- `autoParameters?: boolean` - Enable automatic parameter optimization
|
|
76
|
+
- `timeout?: number` - Request timeout in milliseconds
|
|
77
|
+
- `includeFavicon?: boolean` - Include favicon URLs in results
|
|
78
|
+
- `proxies?: { http?: string, https?: string }` - HTTP/HTTPS proxy configuration
|
|
79
|
+
- `apiBaseURL?: string` - Custom API base URL
|
|
80
|
+
|
|
81
|
+
### Tavily Extract
|
|
82
|
+
|
|
83
|
+
Extract clean, structured content from URLs:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { tavilyExtract } from "@tavily/ai-sdk";
|
|
87
|
+
import { generateText, gateway } from "ai";
|
|
88
|
+
|
|
89
|
+
const result = await generateText({
|
|
90
|
+
model: gateway("openai/gpt-5-mini"),
|
|
91
|
+
prompt: "Extract and summarize the content from https://tavily.com",
|
|
92
|
+
tools: {
|
|
93
|
+
tavilyExtract: tavilyExtract(),
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Configuration Options:**
|
|
99
|
+
- `apiKey?: string` - Tavily API key (defaults to `TAVILY_API_KEY` env var)
|
|
100
|
+
- `includeImages?: boolean` - Include images in extracted content (default: false)
|
|
101
|
+
- `extractDepth?: "basic" | "advanced"` - Extraction depth (default: "basic")
|
|
102
|
+
- `format?: "markdown" | "text"` - Output format (default: "markdown")
|
|
103
|
+
- `timeout?: number` - Request timeout in milliseconds
|
|
104
|
+
- `includeFavicon?: boolean` - Include favicon URLs in results
|
|
105
|
+
- `proxies?: { http?: string, https?: string }` - HTTP/HTTPS proxy configuration
|
|
106
|
+
- `apiBaseURL?: string` - Custom API base URL
|
|
107
|
+
|
|
108
|
+
**Input Parameters (for AI agent):**
|
|
109
|
+
- `urls: string[]` - Array of URLs to extract content from (required)
|
|
110
|
+
- `extractDepth?: "basic" | "advanced"` - Override extraction depth per call
|
|
111
|
+
|
|
112
|
+
### Tavily Crawl
|
|
113
|
+
|
|
114
|
+
Crawl websites to discover and extract content from multiple pages:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { tavilyCrawl } from "@tavily/ai-sdk";
|
|
118
|
+
import { generateText, gateway } from "ai";
|
|
119
|
+
|
|
120
|
+
const result = await generateText({
|
|
121
|
+
model: gateway("openai/gpt-5-mini"),
|
|
122
|
+
prompt: "Crawl tavily.com and tell me about their integrations",
|
|
123
|
+
tools: {
|
|
124
|
+
tavilyCrawl: tavilyCrawl(),
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Configuration Options:**
|
|
130
|
+
- `apiKey?: string` - Tavily API key (defaults to `TAVILY_API_KEY` env var)
|
|
131
|
+
- `maxDepth?: number` - Maximum crawl depth (1-5, default: 1)
|
|
132
|
+
- `maxBreadth?: number` - Maximum pages per depth level (1-100, default: 20)
|
|
133
|
+
- `limit?: number` - Maximum total pages to crawl (default: 50)
|
|
134
|
+
- `extractDepth?: "basic" | "advanced"` - Content extraction depth
|
|
135
|
+
- `instructions?: string` - Natural language crawling instructions
|
|
136
|
+
- `selectPaths?: string[]` - Path patterns to include (e.g., `["/blog/*"]`)
|
|
137
|
+
- `selectDomains?: string[]` - Domains to include
|
|
138
|
+
- `excludePaths?: string[]` - Path patterns to exclude (e.g., `["/admin/*"]`)
|
|
139
|
+
- `excludeDomains?: string[]` - Domains to exclude
|
|
140
|
+
- `allowExternal?: boolean` - Allow crawling external domains (default: false)
|
|
141
|
+
- `includeImages?: boolean` - Include images in extracted content
|
|
142
|
+
- `format?: "markdown" | "text"` - Output format (default: "markdown")
|
|
143
|
+
- `timeout?: number` - Request timeout in milliseconds
|
|
144
|
+
- `includeFavicon?: boolean` - Include favicon URLs in results
|
|
145
|
+
- `proxies?: { http?: string, https?: string }` - HTTP/HTTPS proxy configuration
|
|
146
|
+
- `apiBaseURL?: string` - Custom API base URL
|
|
147
|
+
|
|
148
|
+
**Input Parameters (for AI agent):**
|
|
149
|
+
- `url: string` - Base URL to start crawling from (required)
|
|
150
|
+
- `maxDepth?: number` - Override maximum crawl depth per call
|
|
151
|
+
- `extractDepth?: "basic" | "advanced"` - Override extraction depth per call
|
|
152
|
+
- `instructions?: string` - Override or specify crawling instructions per call
|
|
153
|
+
- `allowExternal?: boolean` - Override external domain crawling setting per call
|
|
154
|
+
|
|
155
|
+
### Tavily Map
|
|
156
|
+
|
|
157
|
+
Map website structure to understand site architecture:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { tavilyMap } from "@tavily/ai-sdk";
|
|
161
|
+
import { generateText, gateway } from "ai";
|
|
162
|
+
|
|
163
|
+
const result = await generateText({
|
|
164
|
+
model: gateway("openai/gpt-5-mini"),
|
|
165
|
+
prompt: "Map the structure of tavily.com",
|
|
166
|
+
tools: {
|
|
167
|
+
tavilyMap: tavilyMap(),
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Configuration Options:**
|
|
173
|
+
- `apiKey?: string` - Tavily API key (defaults to `TAVILY_API_KEY` env var)
|
|
174
|
+
- `maxDepth?: number` - Maximum mapping depth (1-5, default: 1)
|
|
175
|
+
- `maxBreadth?: number` - Maximum pages per depth level (1-100, default: 20)
|
|
176
|
+
- `limit?: number` - Maximum total pages to map (default: 50)
|
|
177
|
+
- `instructions?: string` - Natural language mapping instructions
|
|
178
|
+
- `selectPaths?: string[]` - Path patterns to include (e.g., `["/docs/*"]`)
|
|
179
|
+
- `selectDomains?: string[]` - Domains to include
|
|
180
|
+
- `excludePaths?: string[]` - Path patterns to exclude (e.g., `["/api/*"]`)
|
|
181
|
+
- `excludeDomains?: string[]` - Domains to exclude
|
|
182
|
+
- `allowExternal?: boolean` - Allow mapping external domains (default: false)
|
|
183
|
+
- `timeout?: number` - Request timeout in milliseconds
|
|
184
|
+
- `proxies?: { http?: string, https?: string }` - HTTP/HTTPS proxy configuration
|
|
185
|
+
- `apiBaseURL?: string` - Custom API base URL
|
|
186
|
+
|
|
187
|
+
**Input Parameters (for AI agent):**
|
|
188
|
+
- `url: string` - Base URL to start mapping from (required)
|
|
189
|
+
- `maxDepth?: number` - Override maximum mapping depth per call
|
|
190
|
+
- `instructions?: string` - Override or specify mapping instructions per call
|
|
191
|
+
- `allowExternal?: boolean` - Override external domain mapping setting per call
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## Using Multiple Tools Together
|
|
195
|
+
|
|
196
|
+
You can combine multiple Tavily tools in a single AI agent:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import {
|
|
200
|
+
tavilySearch,
|
|
201
|
+
tavilyExtract,
|
|
202
|
+
tavilyCrawl,
|
|
203
|
+
tavilyMap
|
|
204
|
+
} from "@tavily/ai-sdk";
|
|
205
|
+
import { generateText, gateway } from "ai";
|
|
206
|
+
|
|
207
|
+
const result = await generateText({
|
|
208
|
+
model: gateway("openai/gpt-5-mini"),
|
|
209
|
+
prompt: "Research the company at tavily.com - search for news, map their site, and extract key pages",
|
|
210
|
+
tools: {
|
|
211
|
+
tavilySearch: tavilySearch({ searchDepth: "advanced" }),
|
|
212
|
+
tavilyExtract: tavilyExtract(),
|
|
213
|
+
tavilyCrawl: tavilyCrawl(),
|
|
214
|
+
tavilyMap: tavilyMap(),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Development
|
|
220
|
+
|
|
221
|
+
### Setup
|
|
222
|
+
|
|
223
|
+
1. Clone the repository
|
|
224
|
+
2. Install dependencies:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npm install
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
3. Create a `.env` file:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
TAVILY_API_KEY=tvly-your-api-key
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## API Reference
|
|
237
|
+
|
|
238
|
+
For detailed API documentation, visit [docs.tavily.com](https://docs.tavily.com).
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT
|
|
243
|
+
|
|
244
|
+
## Support
|
|
245
|
+
|
|
246
|
+
- Documentation: [docs.tavily.com](https://docs.tavily.com)
|
|
247
|
+
- Support: [help.tavily.com](https://help.tavily.com)
|
|
248
|
+
- Issues: [GitHub Issues](https://github.com/tavily-ai/ai-sdk/issues)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
import * as _tavily_core from '@tavily/core';
|
|
3
|
+
import { TavilyClientOptions, TavilySearchOptions as TavilySearchOptions$1, TavilyExtractOptions as TavilyExtractOptions$1, TavilyCrawlOptions as TavilyCrawlOptions$1, TavilyMapOptions as TavilyMapOptions$1 } from '@tavily/core';
|
|
4
|
+
|
|
5
|
+
type TavilySearchOptions = TavilyClientOptions & Partial<TavilySearchOptions$1>;
|
|
6
|
+
/**
|
|
7
|
+
* Tavily Search tool for AI SDK
|
|
8
|
+
* Performs web searches optimized for AI applications with real-time, contextual information
|
|
9
|
+
*/
|
|
10
|
+
declare const tavilySearch: (options?: TavilySearchOptions) => ai.Tool<{
|
|
11
|
+
query: string;
|
|
12
|
+
searchDepth?: "basic" | "advanced" | undefined;
|
|
13
|
+
timeRange?: "year" | "month" | "week" | "day" | "y" | "m" | "w" | "d" | undefined;
|
|
14
|
+
}, _tavily_core.TavilySearchResponse>;
|
|
15
|
+
|
|
16
|
+
type TavilyExtractOptions = TavilyClientOptions & Partial<TavilyExtractOptions$1>;
|
|
17
|
+
/**
|
|
18
|
+
* Tavily Extract tool for AI SDK
|
|
19
|
+
* Extracts structured content from specified URLs with AI-optimized parsing
|
|
20
|
+
*/
|
|
21
|
+
declare const tavilyExtract: (options?: TavilyExtractOptions) => ai.Tool<{
|
|
22
|
+
urls: string[];
|
|
23
|
+
extractDepth?: "basic" | "advanced" | undefined;
|
|
24
|
+
}, _tavily_core.TavilyExtractResponse>;
|
|
25
|
+
|
|
26
|
+
type TavilyCrawlOptions = TavilyClientOptions & Partial<TavilyCrawlOptions$1>;
|
|
27
|
+
/**
|
|
28
|
+
* Tavily Crawl tool for AI SDK
|
|
29
|
+
* Crawls a website starting from a base URL to discover and extract content from multiple pages
|
|
30
|
+
*/
|
|
31
|
+
declare const tavilyCrawl: (options?: TavilyCrawlOptions) => ai.Tool<{
|
|
32
|
+
url: string;
|
|
33
|
+
maxDepth?: number | undefined;
|
|
34
|
+
extractDepth?: "basic" | "advanced" | undefined;
|
|
35
|
+
instructions?: string | undefined;
|
|
36
|
+
allowExternal?: boolean | undefined;
|
|
37
|
+
}, _tavily_core.TavilyCrawlResponse>;
|
|
38
|
+
|
|
39
|
+
type TavilyMapOptions = TavilyClientOptions & Partial<TavilyMapOptions$1>;
|
|
40
|
+
/**
|
|
41
|
+
* Tavily Map tool for AI SDK
|
|
42
|
+
* Maps the structure of a website to discover and organize its pages and hierarchy
|
|
43
|
+
*/
|
|
44
|
+
declare const tavilyMap: (options?: TavilyMapOptions) => ai.Tool<{
|
|
45
|
+
url: string;
|
|
46
|
+
maxDepth?: number | undefined;
|
|
47
|
+
instructions?: string | undefined;
|
|
48
|
+
allowExternal?: boolean | undefined;
|
|
49
|
+
}, _tavily_core.TavilyMapResponse>;
|
|
50
|
+
|
|
51
|
+
export { tavilyCrawl, tavilyExtract, tavilyMap, tavilySearch };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/tools/tavily-search.ts
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { tavily } from "@tavily/core";
|
|
5
|
+
var tavilySearch = (options = {}) => {
|
|
6
|
+
const client = tavily(options);
|
|
7
|
+
const inputSchema = z.object({
|
|
8
|
+
query: z.string().describe("The search query to look up on the web"),
|
|
9
|
+
searchDepth: z.enum(["basic", "advanced"]).optional().describe(
|
|
10
|
+
"The depth of the search - 'basic' for quick results, 'advanced' for comprehensive search"
|
|
11
|
+
),
|
|
12
|
+
timeRange: z.enum(["year", "month", "week", "day", "y", "m", "w", "d"]).optional().describe("Time range for search results")
|
|
13
|
+
});
|
|
14
|
+
return tool({
|
|
15
|
+
description: "Search the web for real-time information using Tavily's AI-optimized search engine. Returns relevant sources, snippets, and optional AI-generated answers.",
|
|
16
|
+
inputSchema,
|
|
17
|
+
execute: async ({
|
|
18
|
+
query,
|
|
19
|
+
searchDepth: inputSearchDepth,
|
|
20
|
+
timeRange: inputTimeRange
|
|
21
|
+
}) => {
|
|
22
|
+
return await client.search(query, {
|
|
23
|
+
...options,
|
|
24
|
+
searchDepth: inputSearchDepth ?? options.searchDepth,
|
|
25
|
+
timeRange: inputTimeRange ?? options.timeRange
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/tools/tavily-extract.ts
|
|
32
|
+
import { tool as tool2 } from "ai";
|
|
33
|
+
import { z as z2 } from "zod";
|
|
34
|
+
import { tavily as tavily2 } from "@tavily/core";
|
|
35
|
+
var tavilyExtract = (options = {}) => {
|
|
36
|
+
const client = tavily2(options);
|
|
37
|
+
const inputSchema = z2.object({
|
|
38
|
+
urls: z2.array(z2.string()).describe("Array of URLs to extract content from"),
|
|
39
|
+
extractDepth: z2.enum(["basic", "advanced"]).optional().describe(
|
|
40
|
+
"Extraction depth - 'basic' for main content, 'advanced' for comprehensive extraction (default: 'basic')"
|
|
41
|
+
)
|
|
42
|
+
});
|
|
43
|
+
return tool2({
|
|
44
|
+
description: "Extract clean, structured content from one or more URLs. Returns parsed content in markdown or text format, optimized for AI consumption.",
|
|
45
|
+
inputSchema,
|
|
46
|
+
execute: async ({
|
|
47
|
+
urls,
|
|
48
|
+
extractDepth: inputExtractDepth
|
|
49
|
+
}) => {
|
|
50
|
+
return await client.extract(urls, {
|
|
51
|
+
...options,
|
|
52
|
+
extractDepth: inputExtractDepth ?? options.extractDepth
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/tools/tavily-crawl.ts
|
|
59
|
+
import { tool as tool3 } from "ai";
|
|
60
|
+
import { z as z3 } from "zod";
|
|
61
|
+
import { tavily as tavily3 } from "@tavily/core";
|
|
62
|
+
var tavilyCrawl = (options = {}) => {
|
|
63
|
+
const client = tavily3(options);
|
|
64
|
+
const inputSchema = z3.object({
|
|
65
|
+
url: z3.string().describe("The base URL to start crawling from"),
|
|
66
|
+
maxDepth: z3.number().min(1).max(5).optional().describe(
|
|
67
|
+
"Maximum depth to crawl (number of link hops from the base URL, default: 1)"
|
|
68
|
+
),
|
|
69
|
+
extractDepth: z3.enum(["basic", "advanced"]).optional().describe("Extraction depth for page content (default: 'basic')"),
|
|
70
|
+
instructions: z3.string().optional().describe(
|
|
71
|
+
"Optional instructions to guide the crawler (e.g., 'only crawl blog posts', 'focus on product pages')"
|
|
72
|
+
),
|
|
73
|
+
allowExternal: z3.boolean().optional().describe("Whether to allow crawling external domains (default: false)")
|
|
74
|
+
});
|
|
75
|
+
return tool3({
|
|
76
|
+
description: "Crawl a website starting from a base URL to discover and extract content from multiple pages. Intelligently traverses links and extracts structured data at scale.",
|
|
77
|
+
inputSchema,
|
|
78
|
+
execute: async ({
|
|
79
|
+
url,
|
|
80
|
+
maxDepth: inputMaxDepth,
|
|
81
|
+
extractDepth: inputExtractDepth,
|
|
82
|
+
instructions: inputInstructions,
|
|
83
|
+
allowExternal: inputAllowExternal
|
|
84
|
+
}) => {
|
|
85
|
+
return await client.crawl(url, {
|
|
86
|
+
...options,
|
|
87
|
+
maxDepth: inputMaxDepth ?? options.maxDepth,
|
|
88
|
+
extractDepth: inputExtractDepth ?? options.extractDepth,
|
|
89
|
+
instructions: inputInstructions ?? options.instructions,
|
|
90
|
+
allowExternal: inputAllowExternal ?? options.allowExternal
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/tools/tavily-map.ts
|
|
97
|
+
import { tool as tool4 } from "ai";
|
|
98
|
+
import { z as z4 } from "zod";
|
|
99
|
+
import { tavily as tavily4 } from "@tavily/core";
|
|
100
|
+
var tavilyMap = (options = {}) => {
|
|
101
|
+
const client = tavily4(options);
|
|
102
|
+
const inputSchema = z4.object({
|
|
103
|
+
url: z4.string().describe("The base URL to start mapping from"),
|
|
104
|
+
maxDepth: z4.number().min(1).max(5).optional().describe(
|
|
105
|
+
"Maximum depth to map (number of link hops from the base URL, default: 1)"
|
|
106
|
+
),
|
|
107
|
+
instructions: z4.string().optional().describe(
|
|
108
|
+
"Optional instructions to guide the mapping (e.g., 'focus on documentation pages', 'skip API references')"
|
|
109
|
+
),
|
|
110
|
+
allowExternal: z4.boolean().optional().describe("Whether to allow mapping external domains (default: false)")
|
|
111
|
+
});
|
|
112
|
+
return tool4({
|
|
113
|
+
description: "Map the structure of a website starting from a base URL. Discovers pages, links, and site hierarchy without extracting full content. Ideal for understanding site architecture.",
|
|
114
|
+
inputSchema,
|
|
115
|
+
execute: async ({
|
|
116
|
+
url,
|
|
117
|
+
maxDepth: inputMaxDepth,
|
|
118
|
+
instructions: inputInstructions,
|
|
119
|
+
allowExternal: inputAllowExternal
|
|
120
|
+
}) => {
|
|
121
|
+
return await client.map(url, {
|
|
122
|
+
...options,
|
|
123
|
+
maxDepth: inputMaxDepth ?? options.maxDepth,
|
|
124
|
+
instructions: inputInstructions ?? options.instructions,
|
|
125
|
+
allowExternal: inputAllowExternal ?? options.allowExternal
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
export {
|
|
131
|
+
tavilyCrawl,
|
|
132
|
+
tavilyExtract,
|
|
133
|
+
tavilyMap,
|
|
134
|
+
tavilySearch
|
|
135
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tavily/ai-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tavily AI SDK tools - Search, Extract, Crawl, and Map",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
20
|
+
"prepublishOnly": "pnpm build"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"ai",
|
|
24
|
+
"ai-sdk",
|
|
25
|
+
"tools",
|
|
26
|
+
"tavily",
|
|
27
|
+
"search",
|
|
28
|
+
"web-search",
|
|
29
|
+
"crawl",
|
|
30
|
+
"extract"
|
|
31
|
+
],
|
|
32
|
+
"author": "Tavily",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"packageManager": "pnpm@10.8.0",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@ai-sdk/openai": "^2.0.71",
|
|
37
|
+
"@types/node": "^24.10.1",
|
|
38
|
+
"dotenv": "^17.2.3",
|
|
39
|
+
"tsup": "^8.5.0",
|
|
40
|
+
"tsx": "^4.20.6",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@tavily/core": "*"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"ai": "^5.0.0",
|
|
48
|
+
"zod": "^4.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|