@parallel-web/ai-sdk-tools 0.1.1-canary.023f473 → 0.1.1-canary.776023d
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/README.md +121 -27
- package/dist/index.cjs +102 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -76
- package/dist/index.d.ts +9 -76
- package/dist/index.js +101 -17
- package/dist/index.js.map +1 -1
- package/dist/v4.cjs +145 -0
- package/dist/v4.cjs.map +1 -0
- package/dist/v4.d.cts +15 -0
- package/dist/v4.d.ts +15 -0
- package/dist/v4.js +142 -0
- package/dist/v4.js.map +1 -0
- package/dist/v5.cjs +145 -0
- package/dist/v5.cjs.map +1 -0
- package/dist/v5.d.cts +2 -0
- package/dist/v5.d.ts +2 -0
- package/dist/v5.js +142 -0
- package/dist/v5.js.map +1 -0
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
# @parallel-web/ai-sdk-tools
|
|
2
2
|
|
|
3
|
-
AI
|
|
3
|
+
AI-SDK tools for Parallel Web with support for Vercel's AI-SDK v4 and v5.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @parallel-web/ai-sdk-tools
|
|
8
|
+
npm install ai @parallel-web/ai-sdk-tools
|
|
9
9
|
# or
|
|
10
|
-
pnpm add @parallel-web/ai-sdk-tools
|
|
10
|
+
pnpm add ai @parallel-web/ai-sdk-tools
|
|
11
11
|
# or
|
|
12
|
-
yarn add @parallel-web/ai-sdk-tools
|
|
12
|
+
yarn add ai @parallel-web/ai-sdk-tools
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
Add `PARALLEL_API_KEY` obtained from [Parallel Platform](https://platform.parallel.ai/settings?tab=api-keys) to your environment variables.
|
|
18
18
|
|
|
19
|
-
###
|
|
19
|
+
### Search Tool
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
`searchTool` uses [Parallel's web search API](https://docs.parallel.ai/api-reference/search-api/search) to get fresh relevant search results.
|
|
22
|
+
|
|
23
|
+
### With AI SDK v5 (Recommended)
|
|
22
24
|
|
|
23
25
|
```typescript
|
|
24
26
|
import { openai } from '@ai-sdk/openai';
|
|
25
|
-
import { streamText } from 'ai';
|
|
26
|
-
import { searchTool } from '@parallel-web/ai-sdk-tools';
|
|
27
|
+
import { streamText, type Tool } from 'ai';
|
|
28
|
+
import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools';
|
|
27
29
|
|
|
28
30
|
const result = streamText({
|
|
29
31
|
model: openai('gpt-4o'),
|
|
@@ -31,7 +33,8 @@ const result = streamText({
|
|
|
31
33
|
{ role: 'user', content: 'What are the latest developments in AI?' }
|
|
32
34
|
],
|
|
33
35
|
tools: {
|
|
34
|
-
'web-search': searchTool,
|
|
36
|
+
'web-search': searchTool as Tool,
|
|
37
|
+
'web-extract': extractTool as Tool,
|
|
35
38
|
},
|
|
36
39
|
toolChoice: 'auto',
|
|
37
40
|
});
|
|
@@ -40,29 +43,120 @@ const result = streamText({
|
|
|
40
43
|
return result.toDataStreamResponse();
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
###
|
|
46
|
+
### With AI SDK v4
|
|
44
47
|
|
|
45
48
|
```typescript
|
|
46
49
|
import { openai } from '@ai-sdk/openai';
|
|
47
|
-
import { streamText,
|
|
48
|
-
import { searchTool } from '@parallel-web/ai-sdk-tools';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
import { streamText, type Tool } from 'ai';
|
|
51
|
+
import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools/v4';
|
|
52
|
+
|
|
53
|
+
const result = streamText({
|
|
54
|
+
model: openai('gpt-4o'),
|
|
55
|
+
messages: [
|
|
56
|
+
{ role: 'user', content: 'What are the latest developments in AI?' }
|
|
57
|
+
],
|
|
58
|
+
tools: {
|
|
59
|
+
'web-search': searchTool as Tool,
|
|
60
|
+
'web-extract': extractTool as Tool,
|
|
61
|
+
},
|
|
62
|
+
toolChoice: 'auto',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Stream the response
|
|
66
|
+
return result.toDataStreamResponse();
|
|
64
67
|
```
|
|
65
68
|
|
|
66
69
|
|
|
70
|
+
### Custom Tools
|
|
71
|
+
|
|
72
|
+
You can create custom tools that wrap the Parallel Web API:
|
|
73
|
+
|
|
74
|
+
**For AI SDK v5:**
|
|
75
|
+
```typescript
|
|
76
|
+
import { tool, generateText } from 'ai';
|
|
77
|
+
import { openai } from '@ai-sdk/openai';
|
|
78
|
+
import { z } from 'zod';
|
|
79
|
+
import { Parallel } from 'parallel-web';
|
|
80
|
+
|
|
81
|
+
const parallel = new Parallel({
|
|
82
|
+
apiKey: process.env.PARALLEL_API_KEY,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const webSearch = tool({
|
|
86
|
+
description: 'Use this tool to search the web.',
|
|
87
|
+
inputSchema: z.object({ // v5 uses inputSchema
|
|
88
|
+
searchQueries: z.array(z.string()).describe("Search queries"),
|
|
89
|
+
usersQuestion: z.string().describe("The user's question"),
|
|
90
|
+
}),
|
|
91
|
+
execute: async ({ searchQueries, usersQuestion }) => {
|
|
92
|
+
const search = await parallel.beta.search({
|
|
93
|
+
objective: usersQuestion,
|
|
94
|
+
search_queries: searchQueries,
|
|
95
|
+
max_results: 3,
|
|
96
|
+
max_chars_per_result: 1000,
|
|
97
|
+
});
|
|
98
|
+
return search.results;
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**For AI SDK v4:**
|
|
104
|
+
```typescript
|
|
105
|
+
import { tool } from 'ai';
|
|
106
|
+
import { z } from 'zod';
|
|
107
|
+
import { Parallel } from 'parallel-web';
|
|
108
|
+
|
|
109
|
+
const parallel = new Parallel({
|
|
110
|
+
apiKey: process.env.PARALLEL_API_KEY,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const webSearch = tool({
|
|
114
|
+
description: 'Use this tool to search the web.',
|
|
115
|
+
parameters: z.object({ // v4 uses parameters
|
|
116
|
+
searchQueries: z.array(z.string()).describe("Search queries"),
|
|
117
|
+
usersQuestion: z.string().describe("The user's question"),
|
|
118
|
+
}),
|
|
119
|
+
execute: async ({ searchQueries, usersQuestion }) => {
|
|
120
|
+
const search = await parallel.beta.search({
|
|
121
|
+
objective: usersQuestion,
|
|
122
|
+
search_queries: searchQueries,
|
|
123
|
+
max_results: 3,
|
|
124
|
+
max_chars_per_result: 1000,
|
|
125
|
+
});
|
|
126
|
+
return search.results;
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
**Note:** This package includes both AI SDK v4 and v5 support via package aliases.
|
|
133
|
+
|
|
134
|
+
## Version Compatibility
|
|
135
|
+
|
|
136
|
+
**This package supports both AI SDK v4 and v5.**
|
|
137
|
+
|
|
138
|
+
Using npm package aliases, we bundle both `ai@4.x` and `ai@5.x` within the same package, providing compatibility for both versions.
|
|
139
|
+
|
|
140
|
+
### Choose Your Version
|
|
141
|
+
|
|
142
|
+
- **AI SDK v5 (Default/Recommended)**
|
|
143
|
+
```typescript
|
|
144
|
+
import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools';
|
|
145
|
+
// or explicitly
|
|
146
|
+
import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools/v5';
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- **AI SDK v4**
|
|
150
|
+
```typescript
|
|
151
|
+
import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools/v4';
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### How It Works
|
|
155
|
+
|
|
156
|
+
The package uses npm package aliases to install both versions:
|
|
157
|
+
- `ai-v4`: Maps to `ai@^4.0.0` (uses `parameters` API)
|
|
158
|
+
- `ai-v5`: Maps to `ai@^5.0.0` (uses `inputSchema` API)
|
|
159
|
+
|
|
160
|
+
Each version has its own implementation that imports from the appropriate aliased package, ensuring compatibility with both SDK versions.
|
|
67
161
|
|
|
68
162
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var ai = require('ai');
|
|
3
|
+
var aiV5 = require('ai-v5');
|
|
5
4
|
var zod = require('zod');
|
|
5
|
+
var parallelWeb = require('parallel-web');
|
|
6
6
|
|
|
7
|
-
// src/
|
|
7
|
+
// src/v5/tools/search.ts
|
|
8
8
|
var _parallelClient = null;
|
|
9
9
|
var parallelClient = new Proxy({}, {
|
|
10
10
|
get(_target, prop) {
|
|
@@ -16,6 +16,21 @@ var parallelClient = new Proxy({}, {
|
|
|
16
16
|
return _parallelClient[prop];
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
|
|
20
|
+
// src/v5/tools/search.ts
|
|
21
|
+
function getSearchParams(search_type) {
|
|
22
|
+
switch (search_type) {
|
|
23
|
+
case "targeted":
|
|
24
|
+
return { max_results: 5, max_chars_per_result: 16e3 };
|
|
25
|
+
case "general":
|
|
26
|
+
return { max_results: 10, max_chars_per_result: 9e3 };
|
|
27
|
+
case "single_page":
|
|
28
|
+
return { max_results: 2, max_chars_per_result: 3e4 };
|
|
29
|
+
case "list":
|
|
30
|
+
default:
|
|
31
|
+
return { max_results: 20, max_chars_per_result: 1500 };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
19
34
|
var search = async (searchArgs, { abortSignal }) => {
|
|
20
35
|
return await parallelClient.beta.search(
|
|
21
36
|
{
|
|
@@ -23,31 +38,100 @@ var search = async (searchArgs, { abortSignal }) => {
|
|
|
23
38
|
},
|
|
24
39
|
{
|
|
25
40
|
signal: abortSignal
|
|
41
|
+
// headers: { 'parallel-beta': 'search-extract-2025-10-10' },
|
|
26
42
|
}
|
|
27
43
|
);
|
|
28
44
|
};
|
|
29
|
-
var searchTool =
|
|
30
|
-
description:
|
|
31
|
-
|
|
45
|
+
var searchTool = aiV5.tool({
|
|
46
|
+
description: `Use the web_search_parallel tool to access information from the web. The
|
|
47
|
+
web_search_parallel tool returns ranked, extended web excerpts optimized for LLMs.
|
|
48
|
+
Intelligently scale the number of web_search_parallel tool calls to get more information
|
|
49
|
+
when needed, from a single call for simple factual questions to five or more calls for
|
|
50
|
+
complex research questions.
|
|
51
|
+
|
|
52
|
+
* Keep queries concise - 1-6 words for best results. Start broad with very short
|
|
53
|
+
queries and medium context, then add words to narrow results or use high context
|
|
54
|
+
if needed.
|
|
55
|
+
* Include broader context about what the search is trying to accomplish in the
|
|
56
|
+
\`objective\` field. This helps the search engine understand the user's intent and
|
|
57
|
+
provide relevant results and excerpts.
|
|
58
|
+
* Never repeat similar search queries - make every query unique. If initial results are
|
|
59
|
+
insufficient, reformulate queries to obtain new and better results.
|
|
60
|
+
|
|
61
|
+
How to use:
|
|
62
|
+
- For simple queries, a one-shot call to depth is usually sufficient.
|
|
63
|
+
- For complex multi-hop queries, first try to use breadth to narrow down sources. Then
|
|
64
|
+
use other search types with include_domains to get more detailed results.`,
|
|
65
|
+
inputSchema: zod.z.object({
|
|
32
66
|
objective: zod.z.string().describe(
|
|
33
|
-
|
|
67
|
+
`Natural-language description of what the web research goal
|
|
68
|
+
is. Specify the broad intent of the search query here. Also include any source or
|
|
69
|
+
freshness guidance here. Limit to 200 characters. This should reflect the end goal so
|
|
70
|
+
that the tool can better understand the intent and return the best results. Do not
|
|
71
|
+
dump long texts.`
|
|
34
72
|
),
|
|
73
|
+
search_type: zod.z.enum(["list", "general", "single_page", "targeted"]).describe(
|
|
74
|
+
`Can be "list", "general", "single_page" or "targeted".
|
|
75
|
+
"list" should be used for searching for data broadly, like aggregating data or
|
|
76
|
+
considering multiple sources or doing broad initial research. "targeted" should be
|
|
77
|
+
used for searching for data from a specific source set. "general" is a catch all case
|
|
78
|
+
if there is no specific use case from list or targeted. "single_page" extracts data
|
|
79
|
+
from a single page - extremely targeted. If there is a specific webpage you want the
|
|
80
|
+
data from, use "single_page" and mention the URL in the objective.
|
|
81
|
+
Use search_type appropriately.`
|
|
82
|
+
).optional().default("list"),
|
|
35
83
|
search_queries: zod.z.array(zod.z.string()).optional().describe(
|
|
36
|
-
|
|
84
|
+
`(optional) List of keyword search queries of 1-6
|
|
85
|
+
words, which may include search operators. The search queries should be related to the
|
|
86
|
+
objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
|
|
87
|
+
ideal.`
|
|
37
88
|
),
|
|
38
|
-
|
|
39
|
-
|
|
89
|
+
include_domains: zod.z.array(zod.z.string()).optional().describe(`(optional) List of valid URL domains to explicitly
|
|
90
|
+
focus on for the search. This will restrict all search results to only include results
|
|
91
|
+
from the provided list. This is useful when you want to only use a specific set of
|
|
92
|
+
sources. example: ["google.com", "wikipedia.org"]. Maximum 10 entries.`)
|
|
93
|
+
}),
|
|
94
|
+
execute: async function({ ...args }, { abortSignal }) {
|
|
95
|
+
const results = await search(
|
|
96
|
+
{ ...args, ...getSearchParams(args.search_type) },
|
|
97
|
+
{ abortSignal }
|
|
98
|
+
);
|
|
99
|
+
return {
|
|
100
|
+
searchParams: args,
|
|
101
|
+
answer: results
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
var extractTool = aiV5.tool({
|
|
106
|
+
description: `Purpose: Fetch and extract relevant content from specific web URLs.
|
|
107
|
+
|
|
108
|
+
Ideal Use Cases:
|
|
109
|
+
- Extracting content from specific URLs you've already identified
|
|
110
|
+
- Exploring URLs returned by a web search in greater depth`,
|
|
111
|
+
inputSchema: zod.z.object({
|
|
112
|
+
objective: zod.z.string().describe(
|
|
113
|
+
`Natural-language description of what information you're looking for from the URLs.
|
|
114
|
+
Limit to 200 characters.`
|
|
40
115
|
),
|
|
41
|
-
|
|
42
|
-
|
|
116
|
+
urls: zod.z.array(zod.z.string()).describe(
|
|
117
|
+
`List of URLs to extract content from. Must be valid
|
|
118
|
+
HTTP/HTTPS URLs. Maximum 10 URLs per request.`
|
|
43
119
|
),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
120
|
+
search_queries: zod.z.array(zod.z.string()).optional().describe(
|
|
121
|
+
`(optional) List of keyword search queries of 1-6
|
|
122
|
+
words, which may include search operators. The search queries should be related to the
|
|
123
|
+
objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
|
|
124
|
+
ideal.`
|
|
125
|
+
)
|
|
48
126
|
}),
|
|
49
127
|
execute: async function({ ...args }, { abortSignal }) {
|
|
50
|
-
const results = await
|
|
128
|
+
const results = await parallelClient.beta.extract(
|
|
129
|
+
{ ...args },
|
|
130
|
+
{
|
|
131
|
+
signal: abortSignal,
|
|
132
|
+
headers: { "parallel-beta": "search-extract-2025-10-10" }
|
|
133
|
+
}
|
|
134
|
+
);
|
|
51
135
|
return {
|
|
52
136
|
searchParams: args,
|
|
53
137
|
answer: results
|
|
@@ -55,7 +139,7 @@ var searchTool = ai.tool({
|
|
|
55
139
|
}
|
|
56
140
|
});
|
|
57
141
|
|
|
58
|
-
exports.
|
|
142
|
+
exports.extractTool = extractTool;
|
|
59
143
|
exports.searchTool = searchTool;
|
|
60
144
|
//# sourceMappingURL=index.cjs.map
|
|
61
145
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/tools/search.ts"],"names":["Parallel","tool","z"],"mappings":";;;;;;;AAMA,IAAI,eAAA,GAAmC,IAAA;AAEhC,IAAM,cAAA,GAAiB,IAAI,KAAA,CAAM,EAAC,EAAe;AAAA,EACtD,GAAA,CAAI,SAAS,IAAA,EAAM;AACjB,IAAA,IAAI,CAAC,eAAA,EAAi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KAChB;AAEA,IAAA,OAAO;AAAA,MACL,YAAA,EAAc,IAAA;AAAA,MACd,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AACF,CAAC;ACrGM,IAAM,cAAsBD,SAAAA,CAAK;AAAA,EACtC,WAAA,EAAa,CAAA;;AAAA;AAAA;AAAA,0DAAA,CAAA;AAAA,EAKb,WAAA,EAAaC,MAAE,MAAA,CAAO;AAAA,IACpB,SAAA,EAAWA,KAAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AAAA,MACpB,CAAA;AAAA,yBAAA;AAAA,KAEF;AAAA,IAEA,MAAMA,KAAAA,CAAE,KAAA,CAAMA,KAAAA,CAAE,MAAA,EAAQ,CAAA,CAAE,QAAA;AAAA,MACxB,CAAA;AAAA,6CAAA;AAAA,KAEF;AAAA,IACA,cAAA,EAAgBA,MACb,KAAA,CAAMA,KAAAA,CAAE,QAAQ,CAAA,CAChB,UAAS,CACT,QAAA;AAAA,MACC,CAAA;AAAA;AAAA;AAAA,OAAA;AAAA;AAIF,GACH,CAAA;AAAA,EAED,OAAA,EAAS,eAAgB,EAAE,GAAG,MAAK,EAAG,EAAE,aAAY,EAAG;AACrD,IAAA,MAAM,OAAA,GAAU,MAAM,cAAA,CAAe,IAAA,CAAK,OAAA;AAAA,MACxC,EAAE,GAAG,IAAA,EAAK;AAAA,MACV;AAAA,QACE,MAAA,EAAQ,WAAA;AAAA,QACR,OAAA,EAAS,EAAE,eAAA,EAAiB,2BAAA;AAA4B;AAC1D,KACF;AAEA,IAAA,OAAO;AAAA,MACL,YAAA,EAAc,IAAA;AAAA,MACd,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AACF,CAAC","file":"index.cjs","sourcesContent":["/**\n * Shared Parallel Web client instance\n */\n\nimport { Parallel } from 'parallel-web';\n\nlet _parallelClient: Parallel | null = null;\n\nexport const parallelClient = new Proxy({} as Parallel, {\n get(_target, prop) {\n if (!_parallelClient) {\n _parallelClient = new Parallel({\n apiKey: process.env['PARALLEL_API_KEY'],\n });\n }\n return (_parallelClient as any)[prop];\n },\n});\n","/**\n * Search tool for Parallel Web (AI SDK v5)\n */\n\nimport { tool, type Tool as ToolV5 } from 'ai-v5';\nimport { z } from 'zod';\nimport { BetaSearchParams } from 'parallel-web/resources/beta/beta.mjs';\nimport { parallelClient } from '../../client.js';\n\nfunction getSearchParams(\n search_type: 'list' | 'targeted' | 'general' | 'single_page'\n): Pick<BetaSearchParams, 'max_results' | 'max_chars_per_result'> {\n switch (search_type) {\n case 'targeted':\n return { max_results: 5, max_chars_per_result: 16000 };\n case 'general':\n return { max_results: 10, max_chars_per_result: 9000 };\n case 'single_page':\n return { max_results: 2, max_chars_per_result: 30000 };\n case 'list':\n default:\n return { max_results: 20, max_chars_per_result: 1500 };\n }\n}\n\nconst search = async (\n searchArgs: BetaSearchParams,\n { abortSignal }: { abortSignal: AbortSignal | undefined }\n) => {\n return await parallelClient.beta.search(\n {\n ...searchArgs,\n },\n {\n signal: abortSignal,\n // headers: { 'parallel-beta': 'search-extract-2025-10-10' },\n }\n );\n};\n\nexport const searchTool: ToolV5 = tool({\n description: `Use the web_search_parallel tool to access information from the web. The\nweb_search_parallel tool returns ranked, extended web excerpts optimized for LLMs.\nIntelligently scale the number of web_search_parallel tool calls to get more information\nwhen needed, from a single call for simple factual questions to five or more calls for\ncomplex research questions.\n\n* Keep queries concise - 1-6 words for best results. Start broad with very short\n queries and medium context, then add words to narrow results or use high context\n if needed.\n* Include broader context about what the search is trying to accomplish in the\n \\`objective\\` field. This helps the search engine understand the user's intent and\n provide relevant results and excerpts.\n* Never repeat similar search queries - make every query unique. If initial results are\n insufficient, reformulate queries to obtain new and better results.\n\nHow to use:\n- For simple queries, a one-shot call to depth is usually sufficient.\n- For complex multi-hop queries, first try to use breadth to narrow down sources. Then\nuse other search types with include_domains to get more detailed results.`,\n inputSchema: z.object({\n objective: z.string().describe(\n `Natural-language description of what the web research goal\n is. Specify the broad intent of the search query here. Also include any source or\n freshness guidance here. Limit to 200 characters. This should reflect the end goal so\n that the tool can better understand the intent and return the best results. Do not\n dump long texts.`\n ),\n search_type: z\n .enum(['list', 'general', 'single_page', 'targeted'])\n .describe(\n `Can be \"list\", \"general\", \"single_page\" or \"targeted\".\n \"list\" should be used for searching for data broadly, like aggregating data or\n considering multiple sources or doing broad initial research. \"targeted\" should be\n used for searching for data from a specific source set. \"general\" is a catch all case\n if there is no specific use case from list or targeted. \"single_page\" extracts data\n from a single page - extremely targeted. If there is a specific webpage you want the\n data from, use \"single_page\" and mention the URL in the objective.\n Use search_type appropriately.`\n )\n .optional()\n .default('list'),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(\n `(optional) List of keyword search queries of 1-6\n words, which may include search operators. The search queries should be related to the\n objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are\n ideal.`\n ),\n include_domains: z.array(z.string()).optional()\n .describe(`(optional) List of valid URL domains to explicitly\n focus on for the search. This will restrict all search results to only include results\n from the provided list. This is useful when you want to only use a specific set of\n sources. example: [\"google.com\", \"wikipedia.org\"]. Maximum 10 entries.`),\n }),\n\n execute: async function ({ ...args }, { abortSignal }) {\n const results = await search(\n { ...args, ...getSearchParams(args.search_type) },\n { abortSignal }\n );\n\n return {\n searchParams: args,\n answer: results,\n };\n },\n});\n","/**\n * Extract tool for Parallel Web (AI SDK v5)\n */\n\nimport { tool, type Tool as ToolV5 } from 'ai-v5';\nimport { z } from 'zod';\nimport { parallelClient } from '../../client.js';\n\nexport const extractTool: ToolV5 = tool({\n description: `Purpose: Fetch and extract relevant content from specific web URLs.\n\nIdeal Use Cases:\n- Extracting content from specific URLs you've already identified\n- Exploring URLs returned by a web search in greater depth`,\n inputSchema: z.object({\n objective: z.string().describe(\n `Natural-language description of what information you're looking for from the URLs. \n Limit to 200 characters.`\n ),\n\n urls: z.array(z.string()).describe(\n `List of URLs to extract content from. Must be valid\nHTTP/HTTPS URLs. Maximum 10 URLs per request.`\n ),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(\n `(optional) List of keyword search queries of 1-6\n words, which may include search operators. The search queries should be related to the\n objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are\n ideal.`\n ),\n }),\n\n execute: async function ({ ...args }, { abortSignal }) {\n const results = await parallelClient.beta.extract(\n { ...args },\n {\n signal: abortSignal,\n headers: { 'parallel-beta': 'search-extract-2025-10-10' },\n }\n );\n\n return {\n searchParams: args,\n answer: results,\n };\n },\n});\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,82 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as ai from 'ai';
|
|
3
|
-
import * as parallel_web_resources_beta_beta_mjs from 'parallel-web/resources/beta/beta.mjs';
|
|
4
|
-
import { z } from 'zod';
|
|
1
|
+
import { Tool } from 'ai-v5';
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
|
-
*
|
|
4
|
+
* Search tool for Parallel Web (AI SDK v5)
|
|
8
5
|
*/
|
|
9
6
|
|
|
10
|
-
declare const
|
|
7
|
+
declare const searchTool: Tool;
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
source_policy: z.ZodOptional<z.ZodObject<{
|
|
18
|
-
include_domains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
19
|
-
exclude_domains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
20
|
-
}, "strip", z.ZodTypeAny, {
|
|
21
|
-
include_domains?: string[] | undefined;
|
|
22
|
-
exclude_domains?: string[] | undefined;
|
|
23
|
-
}, {
|
|
24
|
-
include_domains?: string[] | undefined;
|
|
25
|
-
exclude_domains?: string[] | undefined;
|
|
26
|
-
}>>;
|
|
27
|
-
}, "strip", z.ZodTypeAny, {
|
|
28
|
-
objective: string;
|
|
29
|
-
search_queries?: string[] | undefined;
|
|
30
|
-
processor?: "pro" | "base" | undefined;
|
|
31
|
-
max_results?: number | undefined;
|
|
32
|
-
source_policy?: {
|
|
33
|
-
include_domains?: string[] | undefined;
|
|
34
|
-
exclude_domains?: string[] | undefined;
|
|
35
|
-
} | undefined;
|
|
36
|
-
}, {
|
|
37
|
-
objective: string;
|
|
38
|
-
search_queries?: string[] | undefined;
|
|
39
|
-
processor?: "pro" | "base" | undefined;
|
|
40
|
-
max_results?: number | undefined;
|
|
41
|
-
source_policy?: {
|
|
42
|
-
include_domains?: string[] | undefined;
|
|
43
|
-
exclude_domains?: string[] | undefined;
|
|
44
|
-
} | undefined;
|
|
45
|
-
}>, {
|
|
46
|
-
searchParams: {
|
|
47
|
-
objective: string;
|
|
48
|
-
search_queries?: string[] | undefined;
|
|
49
|
-
processor?: "pro" | "base" | undefined;
|
|
50
|
-
max_results?: number | undefined;
|
|
51
|
-
source_policy?: {
|
|
52
|
-
include_domains?: string[] | undefined;
|
|
53
|
-
exclude_domains?: string[] | undefined;
|
|
54
|
-
} | undefined;
|
|
55
|
-
};
|
|
56
|
-
answer: parallel_web_resources_beta_beta_mjs.SearchResult;
|
|
57
|
-
}> & {
|
|
58
|
-
execute: (args: {
|
|
59
|
-
objective: string;
|
|
60
|
-
search_queries?: string[] | undefined;
|
|
61
|
-
processor?: "pro" | "base" | undefined;
|
|
62
|
-
max_results?: number | undefined;
|
|
63
|
-
source_policy?: {
|
|
64
|
-
include_domains?: string[] | undefined;
|
|
65
|
-
exclude_domains?: string[] | undefined;
|
|
66
|
-
} | undefined;
|
|
67
|
-
}, options: ai.ToolExecutionOptions) => PromiseLike<{
|
|
68
|
-
searchParams: {
|
|
69
|
-
objective: string;
|
|
70
|
-
search_queries?: string[] | undefined;
|
|
71
|
-
processor?: "pro" | "base" | undefined;
|
|
72
|
-
max_results?: number | undefined;
|
|
73
|
-
source_policy?: {
|
|
74
|
-
include_domains?: string[] | undefined;
|
|
75
|
-
exclude_domains?: string[] | undefined;
|
|
76
|
-
} | undefined;
|
|
77
|
-
};
|
|
78
|
-
answer: parallel_web_resources_beta_beta_mjs.SearchResult;
|
|
79
|
-
}>;
|
|
80
|
-
};
|
|
9
|
+
/**
|
|
10
|
+
* Extract tool for Parallel Web (AI SDK v5)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
declare const extractTool: Tool;
|
|
81
14
|
|
|
82
|
-
export {
|
|
15
|
+
export { extractTool, searchTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as ai from 'ai';
|
|
3
|
-
import * as parallel_web_resources_beta_beta_mjs from 'parallel-web/resources/beta/beta.mjs';
|
|
4
|
-
import { z } from 'zod';
|
|
1
|
+
import { Tool } from 'ai-v5';
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
|
-
*
|
|
4
|
+
* Search tool for Parallel Web (AI SDK v5)
|
|
8
5
|
*/
|
|
9
6
|
|
|
10
|
-
declare const
|
|
7
|
+
declare const searchTool: Tool;
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
source_policy: z.ZodOptional<z.ZodObject<{
|
|
18
|
-
include_domains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
19
|
-
exclude_domains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
20
|
-
}, "strip", z.ZodTypeAny, {
|
|
21
|
-
include_domains?: string[] | undefined;
|
|
22
|
-
exclude_domains?: string[] | undefined;
|
|
23
|
-
}, {
|
|
24
|
-
include_domains?: string[] | undefined;
|
|
25
|
-
exclude_domains?: string[] | undefined;
|
|
26
|
-
}>>;
|
|
27
|
-
}, "strip", z.ZodTypeAny, {
|
|
28
|
-
objective: string;
|
|
29
|
-
search_queries?: string[] | undefined;
|
|
30
|
-
processor?: "pro" | "base" | undefined;
|
|
31
|
-
max_results?: number | undefined;
|
|
32
|
-
source_policy?: {
|
|
33
|
-
include_domains?: string[] | undefined;
|
|
34
|
-
exclude_domains?: string[] | undefined;
|
|
35
|
-
} | undefined;
|
|
36
|
-
}, {
|
|
37
|
-
objective: string;
|
|
38
|
-
search_queries?: string[] | undefined;
|
|
39
|
-
processor?: "pro" | "base" | undefined;
|
|
40
|
-
max_results?: number | undefined;
|
|
41
|
-
source_policy?: {
|
|
42
|
-
include_domains?: string[] | undefined;
|
|
43
|
-
exclude_domains?: string[] | undefined;
|
|
44
|
-
} | undefined;
|
|
45
|
-
}>, {
|
|
46
|
-
searchParams: {
|
|
47
|
-
objective: string;
|
|
48
|
-
search_queries?: string[] | undefined;
|
|
49
|
-
processor?: "pro" | "base" | undefined;
|
|
50
|
-
max_results?: number | undefined;
|
|
51
|
-
source_policy?: {
|
|
52
|
-
include_domains?: string[] | undefined;
|
|
53
|
-
exclude_domains?: string[] | undefined;
|
|
54
|
-
} | undefined;
|
|
55
|
-
};
|
|
56
|
-
answer: parallel_web_resources_beta_beta_mjs.SearchResult;
|
|
57
|
-
}> & {
|
|
58
|
-
execute: (args: {
|
|
59
|
-
objective: string;
|
|
60
|
-
search_queries?: string[] | undefined;
|
|
61
|
-
processor?: "pro" | "base" | undefined;
|
|
62
|
-
max_results?: number | undefined;
|
|
63
|
-
source_policy?: {
|
|
64
|
-
include_domains?: string[] | undefined;
|
|
65
|
-
exclude_domains?: string[] | undefined;
|
|
66
|
-
} | undefined;
|
|
67
|
-
}, options: ai.ToolExecutionOptions) => PromiseLike<{
|
|
68
|
-
searchParams: {
|
|
69
|
-
objective: string;
|
|
70
|
-
search_queries?: string[] | undefined;
|
|
71
|
-
processor?: "pro" | "base" | undefined;
|
|
72
|
-
max_results?: number | undefined;
|
|
73
|
-
source_policy?: {
|
|
74
|
-
include_domains?: string[] | undefined;
|
|
75
|
-
exclude_domains?: string[] | undefined;
|
|
76
|
-
} | undefined;
|
|
77
|
-
};
|
|
78
|
-
answer: parallel_web_resources_beta_beta_mjs.SearchResult;
|
|
79
|
-
}>;
|
|
80
|
-
};
|
|
9
|
+
/**
|
|
10
|
+
* Extract tool for Parallel Web (AI SDK v5)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
declare const extractTool: Tool;
|
|
81
14
|
|
|
82
|
-
export {
|
|
15
|
+
export { extractTool, searchTool };
|