@parallel-web/ai-sdk-tools 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/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @parallel-web/ai-sdk-tools
2
+
3
+ AI-SDK tools for Parallel Web with support for Vercel's AI-SDK v4 and v5.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install ai @parallel-web/ai-sdk-tools
9
+ # or
10
+ pnpm add ai @parallel-web/ai-sdk-tools
11
+ # or
12
+ yarn add ai @parallel-web/ai-sdk-tools
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Add `PARALLEL_API_KEY` obtained from [Parallel Platform](https://platform.parallel.ai/settings?tab=api-keys) to your environment variables.
18
+
19
+ ### Search Tool
20
+
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
+ ### Extract Tool
24
+
25
+ `extractTool` uses [Parallel's extract API](https://docs.parallel.ai/api-reference/search-and-extract-api-beta/extract) to extract a web-page's content, for a given objective.
26
+
27
+
28
+ ### With AI SDK v5 (Default exports)
29
+
30
+ ```typescript
31
+ import { openai } from '@ai-sdk/openai';
32
+ import { streamText, type Tool } from 'ai';
33
+ import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools';
34
+
35
+ const result = streamText({
36
+ model: openai('gpt-4o'),
37
+ messages: [
38
+ { role: 'user', content: 'What are the latest developments in AI?' }
39
+ ],
40
+ tools: {
41
+ 'web-search': searchTool as Tool,
42
+ 'web-extract': extractTool as Tool,
43
+ },
44
+ toolChoice: 'auto',
45
+ });
46
+
47
+ // Stream the response
48
+ return result.toDataStreamResponse();
49
+ ```
50
+
51
+ ### With AI SDK v4
52
+
53
+ ```typescript
54
+ import { openai } from '@ai-sdk/openai';
55
+ import { streamText, type Tool } from 'ai';
56
+ import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools/v4';
57
+
58
+ const result = streamText({
59
+ model: openai('gpt-4o'),
60
+ messages: [
61
+ { role: 'user', content: 'What are the latest developments in AI?' }
62
+ ],
63
+ tools: {
64
+ 'web-search': searchTool as Tool,
65
+ 'web-extract': extractTool as Tool,
66
+ },
67
+ toolChoice: 'auto',
68
+ });
69
+
70
+ // Stream the response
71
+ return result.toDataStreamResponse();
72
+ ```
73
+
74
+
75
+ ### Custom Tools
76
+
77
+ You can create custom tools that wrap the Parallel Web API:
78
+
79
+ **For AI SDK v5:**
80
+ ```typescript
81
+ import { tool, generateText } from 'ai';
82
+ import { openai } from '@ai-sdk/openai';
83
+ import { z } from 'zod';
84
+ import { Parallel } from 'parallel-web';
85
+
86
+ const parallel = new Parallel({
87
+ apiKey: process.env.PARALLEL_API_KEY,
88
+ });
89
+
90
+ const webSearch = tool({
91
+ description: 'Use this tool to search the web.',
92
+ inputSchema: z.object({ // v5 uses inputSchema
93
+ searchQueries: z.array(z.string()).describe("Search queries"),
94
+ usersQuestion: z.string().describe("The user's question"),
95
+ }),
96
+ execute: async ({ searchQueries, usersQuestion }) => {
97
+ const search = await parallel.beta.search({
98
+ objective: usersQuestion,
99
+ search_queries: searchQueries,
100
+ max_results: 3,
101
+ max_chars_per_result: 1000,
102
+ });
103
+ return search.results;
104
+ },
105
+ });
106
+ ```
107
+
108
+ **For AI SDK v4:**
109
+ ```typescript
110
+ import { tool } from 'ai';
111
+ import { z } from 'zod';
112
+ import { Parallel } from 'parallel-web';
113
+
114
+ const parallel = new Parallel({
115
+ apiKey: process.env.PARALLEL_API_KEY,
116
+ });
117
+
118
+ const webSearch = tool({
119
+ description: 'Use this tool to search the web.',
120
+ parameters: z.object({ // v4 uses parameters
121
+ searchQueries: z.array(z.string()).describe("Search queries"),
122
+ usersQuestion: z.string().describe("The user's question"),
123
+ }),
124
+ execute: async ({ searchQueries, usersQuestion }) => {
125
+ const search = await parallel.beta.search({
126
+ objective: usersQuestion,
127
+ search_queries: searchQueries,
128
+ max_results: 3,
129
+ max_chars_per_result: 1000,
130
+ });
131
+ return search.results;
132
+ },
133
+ });
134
+ ```
135
+
136
+
137
+ **Note:** This package includes both AI SDK v4 and v5 support via package aliases.
138
+
139
+ ## Version Compatibility
140
+
141
+ **This package supports both AI SDK v4 and v5.**
142
+
143
+ Using npm package aliases, we bundle both `ai@4.x` and `ai@5.x` within the same package, providing compatibility for both versions.
144
+
145
+ ### Choose Your Version
146
+
147
+ - **AI SDK v5 (Default/Recommended)**
148
+ ```typescript
149
+ import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools';
150
+ // or explicitly
151
+ import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools/v5';
152
+ ```
153
+
154
+ - **AI SDK v4**
155
+ ```typescript
156
+ import { searchTool, extractTool } from '@parallel-web/ai-sdk-tools/v4';
157
+ ```
158
+
159
+ ### How It Works
160
+
161
+ The package uses npm package aliases to install both versions:
162
+ - `ai-v4`: Maps to `ai@^4.0.0` (uses `parameters` API)
163
+ - `ai-v5`: Maps to `ai@^5.0.0` (uses `inputSchema` API)
164
+
165
+ Each version has its own implementation that imports from the appropriate aliased package, ensuring compatibility with both SDK versions.
166
+
167
+
package/dist/index.cjs ADDED
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+
3
+ var aiV5 = require('ai-v5');
4
+ var zod = require('zod');
5
+ var parallelWeb = require('parallel-web');
6
+
7
+ // src/v5/tools/search.ts
8
+ var _parallelClient = null;
9
+ var parallelClient = new Proxy({}, {
10
+ get(_target, prop) {
11
+ if (!_parallelClient) {
12
+ _parallelClient = new parallelWeb.Parallel({
13
+ apiKey: process.env["PARALLEL_API_KEY"]
14
+ });
15
+ }
16
+ return _parallelClient[prop];
17
+ }
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
+ }
34
+ var search = async (searchArgs, { abortSignal }) => {
35
+ return await parallelClient.beta.search(
36
+ {
37
+ ...searchArgs
38
+ },
39
+ {
40
+ signal: abortSignal
41
+ // headers: { 'parallel-beta': 'search-extract-2025-10-10' },
42
+ }
43
+ );
44
+ };
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({
66
+ objective: zod.z.string().describe(
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.`
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"),
83
+ search_queries: zod.z.array(zod.z.string()).optional().describe(
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.`
88
+ ),
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.`
115
+ ),
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.`
119
+ ),
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
+ )
126
+ }),
127
+ execute: async function({ ...args }, { abortSignal }) {
128
+ const results = await parallelClient.beta.extract(
129
+ { ...args },
130
+ {
131
+ signal: abortSignal,
132
+ headers: { "parallel-beta": "search-extract-2025-10-10" }
133
+ }
134
+ );
135
+ return {
136
+ searchParams: args,
137
+ answer: results
138
+ };
139
+ }
140
+ });
141
+
142
+ exports.extractTool = extractTool;
143
+ exports.searchTool = searchTool;
144
+ //# sourceMappingURL=index.cjs.map
145
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/v5/tools/search.ts","../src/v5/tools/extract.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,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAIA,oBAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB;AAAA,OACvC,CAAA;AAAA,IACH;AACA,IAAA,OAAQ,gBAAwB,IAAI,CAAA;AAAA,EACtC;AACF,CAAC,CAAA;;;ACRD,SAAS,gBACP,WAAA,EACgE;AAChE,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,UAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,CAAA,EAAG,oBAAA,EAAsB,IAAA,EAAM;AAAA,IACvD,KAAK,SAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,EAAA,EAAI,oBAAA,EAAsB,GAAA,EAAK;AAAA,IACvD,KAAK,aAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,CAAA,EAAG,oBAAA,EAAsB,GAAA,EAAM;AAAA,IACvD,KAAK,MAAA;AAAA,IACL;AACE,MAAA,OAAO,EAAE,WAAA,EAAa,EAAA,EAAI,oBAAA,EAAsB,IAAA,EAAK;AAAA;AAE3D;AAEA,IAAM,MAAA,GAAS,OACb,UAAA,EACA,EAAE,aAAY,KACX;AACH,EAAA,OAAO,MAAM,eAAe,IAAA,CAAK,MAAA;AAAA,IAC/B;AAAA,MACE,GAAG;AAAA,KACL;AAAA,IACA;AAAA,MAC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;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"]}
@@ -0,0 +1,15 @@
1
+ import { Tool } from 'ai-v5';
2
+
3
+ /**
4
+ * Search tool for Parallel Web (AI SDK v5)
5
+ */
6
+
7
+ declare const searchTool: Tool;
8
+
9
+ /**
10
+ * Extract tool for Parallel Web (AI SDK v5)
11
+ */
12
+
13
+ declare const extractTool: Tool;
14
+
15
+ export { extractTool, searchTool };
@@ -0,0 +1,15 @@
1
+ import { Tool } from 'ai-v5';
2
+
3
+ /**
4
+ * Search tool for Parallel Web (AI SDK v5)
5
+ */
6
+
7
+ declare const searchTool: Tool;
8
+
9
+ /**
10
+ * Extract tool for Parallel Web (AI SDK v5)
11
+ */
12
+
13
+ declare const extractTool: Tool;
14
+
15
+ export { extractTool, searchTool };
package/dist/index.js ADDED
@@ -0,0 +1,142 @@
1
+ import { tool } from 'ai-v5';
2
+ import { z } from 'zod';
3
+ import { Parallel } from 'parallel-web';
4
+
5
+ // src/v5/tools/search.ts
6
+ var _parallelClient = null;
7
+ var parallelClient = new Proxy({}, {
8
+ get(_target, prop) {
9
+ if (!_parallelClient) {
10
+ _parallelClient = new Parallel({
11
+ apiKey: process.env["PARALLEL_API_KEY"]
12
+ });
13
+ }
14
+ return _parallelClient[prop];
15
+ }
16
+ });
17
+
18
+ // src/v5/tools/search.ts
19
+ function getSearchParams(search_type) {
20
+ switch (search_type) {
21
+ case "targeted":
22
+ return { max_results: 5, max_chars_per_result: 16e3 };
23
+ case "general":
24
+ return { max_results: 10, max_chars_per_result: 9e3 };
25
+ case "single_page":
26
+ return { max_results: 2, max_chars_per_result: 3e4 };
27
+ case "list":
28
+ default:
29
+ return { max_results: 20, max_chars_per_result: 1500 };
30
+ }
31
+ }
32
+ var search = async (searchArgs, { abortSignal }) => {
33
+ return await parallelClient.beta.search(
34
+ {
35
+ ...searchArgs
36
+ },
37
+ {
38
+ signal: abortSignal
39
+ // headers: { 'parallel-beta': 'search-extract-2025-10-10' },
40
+ }
41
+ );
42
+ };
43
+ var searchTool = tool({
44
+ description: `Use the web_search_parallel tool to access information from the web. The
45
+ web_search_parallel tool returns ranked, extended web excerpts optimized for LLMs.
46
+ Intelligently scale the number of web_search_parallel tool calls to get more information
47
+ when needed, from a single call for simple factual questions to five or more calls for
48
+ complex research questions.
49
+
50
+ * Keep queries concise - 1-6 words for best results. Start broad with very short
51
+ queries and medium context, then add words to narrow results or use high context
52
+ if needed.
53
+ * Include broader context about what the search is trying to accomplish in the
54
+ \`objective\` field. This helps the search engine understand the user's intent and
55
+ provide relevant results and excerpts.
56
+ * Never repeat similar search queries - make every query unique. If initial results are
57
+ insufficient, reformulate queries to obtain new and better results.
58
+
59
+ How to use:
60
+ - For simple queries, a one-shot call to depth is usually sufficient.
61
+ - For complex multi-hop queries, first try to use breadth to narrow down sources. Then
62
+ use other search types with include_domains to get more detailed results.`,
63
+ inputSchema: z.object({
64
+ objective: z.string().describe(
65
+ `Natural-language description of what the web research goal
66
+ is. Specify the broad intent of the search query here. Also include any source or
67
+ freshness guidance here. Limit to 200 characters. This should reflect the end goal so
68
+ that the tool can better understand the intent and return the best results. Do not
69
+ dump long texts.`
70
+ ),
71
+ search_type: z.enum(["list", "general", "single_page", "targeted"]).describe(
72
+ `Can be "list", "general", "single_page" or "targeted".
73
+ "list" should be used for searching for data broadly, like aggregating data or
74
+ considering multiple sources or doing broad initial research. "targeted" should be
75
+ used for searching for data from a specific source set. "general" is a catch all case
76
+ if there is no specific use case from list or targeted. "single_page" extracts data
77
+ from a single page - extremely targeted. If there is a specific webpage you want the
78
+ data from, use "single_page" and mention the URL in the objective.
79
+ Use search_type appropriately.`
80
+ ).optional().default("list"),
81
+ search_queries: z.array(z.string()).optional().describe(
82
+ `(optional) List of keyword search queries of 1-6
83
+ words, which may include search operators. The search queries should be related to the
84
+ objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
85
+ ideal.`
86
+ ),
87
+ include_domains: z.array(z.string()).optional().describe(`(optional) List of valid URL domains to explicitly
88
+ focus on for the search. This will restrict all search results to only include results
89
+ from the provided list. This is useful when you want to only use a specific set of
90
+ sources. example: ["google.com", "wikipedia.org"]. Maximum 10 entries.`)
91
+ }),
92
+ execute: async function({ ...args }, { abortSignal }) {
93
+ const results = await search(
94
+ { ...args, ...getSearchParams(args.search_type) },
95
+ { abortSignal }
96
+ );
97
+ return {
98
+ searchParams: args,
99
+ answer: results
100
+ };
101
+ }
102
+ });
103
+ var extractTool = tool({
104
+ description: `Purpose: Fetch and extract relevant content from specific web URLs.
105
+
106
+ Ideal Use Cases:
107
+ - Extracting content from specific URLs you've already identified
108
+ - Exploring URLs returned by a web search in greater depth`,
109
+ inputSchema: z.object({
110
+ objective: z.string().describe(
111
+ `Natural-language description of what information you're looking for from the URLs.
112
+ Limit to 200 characters.`
113
+ ),
114
+ urls: z.array(z.string()).describe(
115
+ `List of URLs to extract content from. Must be valid
116
+ HTTP/HTTPS URLs. Maximum 10 URLs per request.`
117
+ ),
118
+ search_queries: z.array(z.string()).optional().describe(
119
+ `(optional) List of keyword search queries of 1-6
120
+ words, which may include search operators. The search queries should be related to the
121
+ objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
122
+ ideal.`
123
+ )
124
+ }),
125
+ execute: async function({ ...args }, { abortSignal }) {
126
+ const results = await parallelClient.beta.extract(
127
+ { ...args },
128
+ {
129
+ signal: abortSignal,
130
+ headers: { "parallel-beta": "search-extract-2025-10-10" }
131
+ }
132
+ );
133
+ return {
134
+ searchParams: args,
135
+ answer: results
136
+ };
137
+ }
138
+ });
139
+
140
+ export { extractTool, searchTool };
141
+ //# sourceMappingURL=index.js.map
142
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/v5/tools/search.ts","../src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A,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AAAA,MACpB,CAAA;AAAA,yBAAA;AAAA,KAEF;AAAA,IAEA,MAAMA,CAAAA,CAAE,KAAA,CAAMA,CAAAA,CAAE,MAAA,EAAQ,CAAA,CAAE,QAAA;AAAA,MACxB,CAAA;AAAA,6CAAA;AAAA,KAEF;AAAA,IACA,cAAA,EAAgBA,EACb,KAAA,CAAMA,CAAAA,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.js","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/v4.cjs ADDED
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+
3
+ var aiV4 = require('ai-v4');
4
+ var zod = require('zod');
5
+ var parallelWeb = require('parallel-web');
6
+
7
+ // src/v4/tools/search.ts
8
+ var _parallelClient = null;
9
+ var parallelClient = new Proxy({}, {
10
+ get(_target, prop) {
11
+ if (!_parallelClient) {
12
+ _parallelClient = new parallelWeb.Parallel({
13
+ apiKey: process.env["PARALLEL_API_KEY"]
14
+ });
15
+ }
16
+ return _parallelClient[prop];
17
+ }
18
+ });
19
+
20
+ // src/v4/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
+ }
34
+ var search = async (searchArgs, { abortSignal }) => {
35
+ return await parallelClient.beta.search(
36
+ {
37
+ ...searchArgs
38
+ },
39
+ {
40
+ signal: abortSignal
41
+ // headers: { 'parallel-beta': 'search-extract-2025-10-10' },
42
+ }
43
+ );
44
+ };
45
+ var searchTool = aiV4.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
+ parameters: zod.z.object({
66
+ objective: zod.z.string().describe(
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.`
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"),
83
+ search_queries: zod.z.array(zod.z.string()).optional().describe(
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.`
88
+ ),
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 = aiV4.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
+ parameters: 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.`
115
+ ),
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.`
119
+ ),
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
+ )
126
+ }),
127
+ execute: async function({ ...args }, { abortSignal }) {
128
+ const results = await parallelClient.beta.extract(
129
+ { ...args },
130
+ {
131
+ signal: abortSignal,
132
+ headers: { "parallel-beta": "search-extract-2025-10-10" }
133
+ }
134
+ );
135
+ return {
136
+ searchParams: args,
137
+ answer: results
138
+ };
139
+ }
140
+ });
141
+
142
+ exports.extractTool = extractTool;
143
+ exports.searchTool = searchTool;
144
+ //# sourceMappingURL=v4.cjs.map
145
+ //# sourceMappingURL=v4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/v4/tools/search.ts","../src/v4/tools/extract.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,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAIA,oBAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB;AAAA,OACvC,CAAA;AAAA,IACH;AACA,IAAA,OAAQ,gBAAwB,IAAI,CAAA;AAAA,EACtC;AACF,CAAC,CAAA;;;ACRD,SAAS,gBACP,WAAA,EACgE;AAChE,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,UAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa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AE,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":"v4.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 v4)\n */\n\nimport { tool, type Tool as ToolV4 } from 'ai-v4';\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: ToolV4 = 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 parameters: 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 (\n { ...args },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\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 v4)\n */\n\nimport { tool, type Tool as ToolV4 } from 'ai-v4';\nimport { z } from 'zod';\nimport { parallelClient } from '../../client.js';\n\nexport const extractTool: ToolV4 = 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 parameters: 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 (\n { ...args },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\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/v4.d.cts ADDED
@@ -0,0 +1,15 @@
1
+ import { Tool } from 'ai-v4';
2
+
3
+ /**
4
+ * Search tool for Parallel Web (AI SDK v4)
5
+ */
6
+
7
+ declare const searchTool: Tool;
8
+
9
+ /**
10
+ * Extract tool for Parallel Web (AI SDK v4)
11
+ */
12
+
13
+ declare const extractTool: Tool;
14
+
15
+ export { extractTool, searchTool };
package/dist/v4.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Tool } from 'ai-v4';
2
+
3
+ /**
4
+ * Search tool for Parallel Web (AI SDK v4)
5
+ */
6
+
7
+ declare const searchTool: Tool;
8
+
9
+ /**
10
+ * Extract tool for Parallel Web (AI SDK v4)
11
+ */
12
+
13
+ declare const extractTool: Tool;
14
+
15
+ export { extractTool, searchTool };
package/dist/v4.js ADDED
@@ -0,0 +1,142 @@
1
+ import { tool } from 'ai-v4';
2
+ import { z } from 'zod';
3
+ import { Parallel } from 'parallel-web';
4
+
5
+ // src/v4/tools/search.ts
6
+ var _parallelClient = null;
7
+ var parallelClient = new Proxy({}, {
8
+ get(_target, prop) {
9
+ if (!_parallelClient) {
10
+ _parallelClient = new Parallel({
11
+ apiKey: process.env["PARALLEL_API_KEY"]
12
+ });
13
+ }
14
+ return _parallelClient[prop];
15
+ }
16
+ });
17
+
18
+ // src/v4/tools/search.ts
19
+ function getSearchParams(search_type) {
20
+ switch (search_type) {
21
+ case "targeted":
22
+ return { max_results: 5, max_chars_per_result: 16e3 };
23
+ case "general":
24
+ return { max_results: 10, max_chars_per_result: 9e3 };
25
+ case "single_page":
26
+ return { max_results: 2, max_chars_per_result: 3e4 };
27
+ case "list":
28
+ default:
29
+ return { max_results: 20, max_chars_per_result: 1500 };
30
+ }
31
+ }
32
+ var search = async (searchArgs, { abortSignal }) => {
33
+ return await parallelClient.beta.search(
34
+ {
35
+ ...searchArgs
36
+ },
37
+ {
38
+ signal: abortSignal
39
+ // headers: { 'parallel-beta': 'search-extract-2025-10-10' },
40
+ }
41
+ );
42
+ };
43
+ var searchTool = tool({
44
+ description: `Use the web_search_parallel tool to access information from the web. The
45
+ web_search_parallel tool returns ranked, extended web excerpts optimized for LLMs.
46
+ Intelligently scale the number of web_search_parallel tool calls to get more information
47
+ when needed, from a single call for simple factual questions to five or more calls for
48
+ complex research questions.
49
+
50
+ * Keep queries concise - 1-6 words for best results. Start broad with very short
51
+ queries and medium context, then add words to narrow results or use high context
52
+ if needed.
53
+ * Include broader context about what the search is trying to accomplish in the
54
+ \`objective\` field. This helps the search engine understand the user's intent and
55
+ provide relevant results and excerpts.
56
+ * Never repeat similar search queries - make every query unique. If initial results are
57
+ insufficient, reformulate queries to obtain new and better results.
58
+
59
+ How to use:
60
+ - For simple queries, a one-shot call to depth is usually sufficient.
61
+ - For complex multi-hop queries, first try to use breadth to narrow down sources. Then
62
+ use other search types with include_domains to get more detailed results.`,
63
+ parameters: z.object({
64
+ objective: z.string().describe(
65
+ `Natural-language description of what the web research goal
66
+ is. Specify the broad intent of the search query here. Also include any source or
67
+ freshness guidance here. Limit to 200 characters. This should reflect the end goal so
68
+ that the tool can better understand the intent and return the best results. Do not
69
+ dump long texts.`
70
+ ),
71
+ search_type: z.enum(["list", "general", "single_page", "targeted"]).describe(
72
+ `Can be "list", "general", "single_page" or "targeted".
73
+ "list" should be used for searching for data broadly, like aggregating data or
74
+ considering multiple sources or doing broad initial research. "targeted" should be
75
+ used for searching for data from a specific source set. "general" is a catch all case
76
+ if there is no specific use case from list or targeted. "single_page" extracts data
77
+ from a single page - extremely targeted. If there is a specific webpage you want the
78
+ data from, use "single_page" and mention the URL in the objective.
79
+ Use search_type appropriately.`
80
+ ).optional().default("list"),
81
+ search_queries: z.array(z.string()).optional().describe(
82
+ `(optional) List of keyword search queries of 1-6
83
+ words, which may include search operators. The search queries should be related to the
84
+ objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
85
+ ideal.`
86
+ ),
87
+ include_domains: z.array(z.string()).optional().describe(`(optional) List of valid URL domains to explicitly
88
+ focus on for the search. This will restrict all search results to only include results
89
+ from the provided list. This is useful when you want to only use a specific set of
90
+ sources. example: ["google.com", "wikipedia.org"]. Maximum 10 entries.`)
91
+ }),
92
+ execute: async function({ ...args }, { abortSignal }) {
93
+ const results = await search(
94
+ { ...args, ...getSearchParams(args.search_type) },
95
+ { abortSignal }
96
+ );
97
+ return {
98
+ searchParams: args,
99
+ answer: results
100
+ };
101
+ }
102
+ });
103
+ var extractTool = tool({
104
+ description: `Purpose: Fetch and extract relevant content from specific web URLs.
105
+
106
+ Ideal Use Cases:
107
+ - Extracting content from specific URLs you've already identified
108
+ - Exploring URLs returned by a web search in greater depth`,
109
+ parameters: z.object({
110
+ objective: z.string().describe(
111
+ `Natural-language description of what information you're looking for from the URLs.
112
+ Limit to 200 characters.`
113
+ ),
114
+ urls: z.array(z.string()).describe(
115
+ `List of URLs to extract content from. Must be valid
116
+ HTTP/HTTPS URLs. Maximum 10 URLs per request.`
117
+ ),
118
+ search_queries: z.array(z.string()).optional().describe(
119
+ `(optional) List of keyword search queries of 1-6
120
+ words, which may include search operators. The search queries should be related to the
121
+ objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
122
+ ideal.`
123
+ )
124
+ }),
125
+ execute: async function({ ...args }, { abortSignal }) {
126
+ const results = await parallelClient.beta.extract(
127
+ { ...args },
128
+ {
129
+ signal: abortSignal,
130
+ headers: { "parallel-beta": "search-extract-2025-10-10" }
131
+ }
132
+ );
133
+ return {
134
+ searchParams: args,
135
+ answer: results
136
+ };
137
+ }
138
+ });
139
+
140
+ export { extractTool, searchTool };
141
+ //# sourceMappingURL=v4.js.map
142
+ //# sourceMappingURL=v4.js.map
package/dist/v4.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/v4/tools/search.ts","../src/v4/tools/extract.ts"],"names":["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,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAI,QAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB;AAAA,OACvC,CAAA;AAAA,IACH;AACA,IAAA,OAAQ,gBAAwB,IAAI,CAAA;AAAA,EACtC;AACF,CAAC,CAAA;;;ACRD,SAAS,gBACP,WAAA,EACgE;AAChE,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,UAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,CAAA,EAAG,oBAAA,EAAsB,IAAA,EAAM;AAAA,IACvD,KAAK,SAAA;AACH,MAAA,OAAO,EAAE,WAAA,EA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2BAAA;AAA4B;AAC1D,KACF;AAEA,IAAA,OAAO;AAAA,MACL,YAAA,EAAc,IAAA;AAAA,MACd,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AACF,CAAC","file":"v4.js","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 v4)\n */\n\nimport { tool, type Tool as ToolV4 } from 'ai-v4';\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: ToolV4 = 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 parameters: 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 (\n { ...args },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\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 v4)\n */\n\nimport { tool, type Tool as ToolV4 } from 'ai-v4';\nimport { z } from 'zod';\nimport { parallelClient } from '../../client.js';\n\nexport const extractTool: ToolV4 = 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 parameters: 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 (\n { ...args },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\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/v5.cjs ADDED
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+
3
+ var aiV5 = require('ai-v5');
4
+ var zod = require('zod');
5
+ var parallelWeb = require('parallel-web');
6
+
7
+ // src/v5/tools/search.ts
8
+ var _parallelClient = null;
9
+ var parallelClient = new Proxy({}, {
10
+ get(_target, prop) {
11
+ if (!_parallelClient) {
12
+ _parallelClient = new parallelWeb.Parallel({
13
+ apiKey: process.env["PARALLEL_API_KEY"]
14
+ });
15
+ }
16
+ return _parallelClient[prop];
17
+ }
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
+ }
34
+ var search = async (searchArgs, { abortSignal }) => {
35
+ return await parallelClient.beta.search(
36
+ {
37
+ ...searchArgs
38
+ },
39
+ {
40
+ signal: abortSignal
41
+ // headers: { 'parallel-beta': 'search-extract-2025-10-10' },
42
+ }
43
+ );
44
+ };
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({
66
+ objective: zod.z.string().describe(
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.`
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"),
83
+ search_queries: zod.z.array(zod.z.string()).optional().describe(
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.`
88
+ ),
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.`
115
+ ),
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.`
119
+ ),
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
+ )
126
+ }),
127
+ execute: async function({ ...args }, { abortSignal }) {
128
+ const results = await parallelClient.beta.extract(
129
+ { ...args },
130
+ {
131
+ signal: abortSignal,
132
+ headers: { "parallel-beta": "search-extract-2025-10-10" }
133
+ }
134
+ );
135
+ return {
136
+ searchParams: args,
137
+ answer: results
138
+ };
139
+ }
140
+ });
141
+
142
+ exports.extractTool = extractTool;
143
+ exports.searchTool = searchTool;
144
+ //# sourceMappingURL=v5.cjs.map
145
+ //# sourceMappingURL=v5.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/v5/tools/search.ts","../src/v5/tools/extract.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,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAIA,oBAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB;AAAA,OACvC,CAAA;AAAA,IACH;AACA,IAAA,OAAQ,gBAAwB,IAAI,CAAA;AAAA,EACtC;AACF,CAAC,CAAA;;;ACRD,SAAS,gBACP,WAAA,EACgE;AAChE,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,UAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,CAAA,EAAG,oBAAA,EAAsB,IAAA,EAAM;AAAA,IACvD,KAAK,SAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,EAAA,EAAI,oBAAA,EAAsB,GAAA,EAAK;AAAA,IACvD,KAAK,aAAA;AACH,MAAA,OAAO,EAAE,WAAA,EAAa,CAAA,EAAG,oBAAA,EAAsB,GAAA,EAAM;AAAA,IACvD,KAAK,MAAA;AAAA,IACL;AACE,MAAA,OAAO,EAAE,WAAA,EAAa,EAAA,EAAI,oBAAA,EAAsB,IAAA,EAAK;AAAA;AAE3D;AAEA,IAAM,MAAA,GAAS,OACb,UAAA,EACA,EAAE,aAAY,KACX;AACH,EAAA,OAAO,MAAM,eAAe,IAAA,CAAK,MAAA;AAAA,IAC/B;AAAA,MACE,GAAG;AAAA,KACL;AAAA,IACA;AAAA,MACE,MAAA,EAAQ;AAAA;AAAA;AAEV,GACF;AACF,CAAA;AAEO,IAA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AAA,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":"v5.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/v5.d.cts ADDED
@@ -0,0 +1,2 @@
1
+ export { extractTool, searchTool } from './index.cjs';
2
+ import 'ai-v5';
package/dist/v5.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { extractTool, searchTool } from './index.js';
2
+ import 'ai-v5';
package/dist/v5.js ADDED
@@ -0,0 +1,142 @@
1
+ import { tool } from 'ai-v5';
2
+ import { z } from 'zod';
3
+ import { Parallel } from 'parallel-web';
4
+
5
+ // src/v5/tools/search.ts
6
+ var _parallelClient = null;
7
+ var parallelClient = new Proxy({}, {
8
+ get(_target, prop) {
9
+ if (!_parallelClient) {
10
+ _parallelClient = new Parallel({
11
+ apiKey: process.env["PARALLEL_API_KEY"]
12
+ });
13
+ }
14
+ return _parallelClient[prop];
15
+ }
16
+ });
17
+
18
+ // src/v5/tools/search.ts
19
+ function getSearchParams(search_type) {
20
+ switch (search_type) {
21
+ case "targeted":
22
+ return { max_results: 5, max_chars_per_result: 16e3 };
23
+ case "general":
24
+ return { max_results: 10, max_chars_per_result: 9e3 };
25
+ case "single_page":
26
+ return { max_results: 2, max_chars_per_result: 3e4 };
27
+ case "list":
28
+ default:
29
+ return { max_results: 20, max_chars_per_result: 1500 };
30
+ }
31
+ }
32
+ var search = async (searchArgs, { abortSignal }) => {
33
+ return await parallelClient.beta.search(
34
+ {
35
+ ...searchArgs
36
+ },
37
+ {
38
+ signal: abortSignal
39
+ // headers: { 'parallel-beta': 'search-extract-2025-10-10' },
40
+ }
41
+ );
42
+ };
43
+ var searchTool = tool({
44
+ description: `Use the web_search_parallel tool to access information from the web. The
45
+ web_search_parallel tool returns ranked, extended web excerpts optimized for LLMs.
46
+ Intelligently scale the number of web_search_parallel tool calls to get more information
47
+ when needed, from a single call for simple factual questions to five or more calls for
48
+ complex research questions.
49
+
50
+ * Keep queries concise - 1-6 words for best results. Start broad with very short
51
+ queries and medium context, then add words to narrow results or use high context
52
+ if needed.
53
+ * Include broader context about what the search is trying to accomplish in the
54
+ \`objective\` field. This helps the search engine understand the user's intent and
55
+ provide relevant results and excerpts.
56
+ * Never repeat similar search queries - make every query unique. If initial results are
57
+ insufficient, reformulate queries to obtain new and better results.
58
+
59
+ How to use:
60
+ - For simple queries, a one-shot call to depth is usually sufficient.
61
+ - For complex multi-hop queries, first try to use breadth to narrow down sources. Then
62
+ use other search types with include_domains to get more detailed results.`,
63
+ inputSchema: z.object({
64
+ objective: z.string().describe(
65
+ `Natural-language description of what the web research goal
66
+ is. Specify the broad intent of the search query here. Also include any source or
67
+ freshness guidance here. Limit to 200 characters. This should reflect the end goal so
68
+ that the tool can better understand the intent and return the best results. Do not
69
+ dump long texts.`
70
+ ),
71
+ search_type: z.enum(["list", "general", "single_page", "targeted"]).describe(
72
+ `Can be "list", "general", "single_page" or "targeted".
73
+ "list" should be used for searching for data broadly, like aggregating data or
74
+ considering multiple sources or doing broad initial research. "targeted" should be
75
+ used for searching for data from a specific source set. "general" is a catch all case
76
+ if there is no specific use case from list or targeted. "single_page" extracts data
77
+ from a single page - extremely targeted. If there is a specific webpage you want the
78
+ data from, use "single_page" and mention the URL in the objective.
79
+ Use search_type appropriately.`
80
+ ).optional().default("list"),
81
+ search_queries: z.array(z.string()).optional().describe(
82
+ `(optional) List of keyword search queries of 1-6
83
+ words, which may include search operators. The search queries should be related to the
84
+ objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
85
+ ideal.`
86
+ ),
87
+ include_domains: z.array(z.string()).optional().describe(`(optional) List of valid URL domains to explicitly
88
+ focus on for the search. This will restrict all search results to only include results
89
+ from the provided list. This is useful when you want to only use a specific set of
90
+ sources. example: ["google.com", "wikipedia.org"]. Maximum 10 entries.`)
91
+ }),
92
+ execute: async function({ ...args }, { abortSignal }) {
93
+ const results = await search(
94
+ { ...args, ...getSearchParams(args.search_type) },
95
+ { abortSignal }
96
+ );
97
+ return {
98
+ searchParams: args,
99
+ answer: results
100
+ };
101
+ }
102
+ });
103
+ var extractTool = tool({
104
+ description: `Purpose: Fetch and extract relevant content from specific web URLs.
105
+
106
+ Ideal Use Cases:
107
+ - Extracting content from specific URLs you've already identified
108
+ - Exploring URLs returned by a web search in greater depth`,
109
+ inputSchema: z.object({
110
+ objective: z.string().describe(
111
+ `Natural-language description of what information you're looking for from the URLs.
112
+ Limit to 200 characters.`
113
+ ),
114
+ urls: z.array(z.string()).describe(
115
+ `List of URLs to extract content from. Must be valid
116
+ HTTP/HTTPS URLs. Maximum 10 URLs per request.`
117
+ ),
118
+ search_queries: z.array(z.string()).optional().describe(
119
+ `(optional) List of keyword search queries of 1-6
120
+ words, which may include search operators. The search queries should be related to the
121
+ objective. Limited to 5 entries of 200 characters each. Usually 1-3 queries are
122
+ ideal.`
123
+ )
124
+ }),
125
+ execute: async function({ ...args }, { abortSignal }) {
126
+ const results = await parallelClient.beta.extract(
127
+ { ...args },
128
+ {
129
+ signal: abortSignal,
130
+ headers: { "parallel-beta": "search-extract-2025-10-10" }
131
+ }
132
+ );
133
+ return {
134
+ searchParams: args,
135
+ answer: results
136
+ };
137
+ }
138
+ });
139
+
140
+ export { extractTool, searchTool };
141
+ //# sourceMappingURL=v5.js.map
142
+ //# sourceMappingURL=v5.js.map
package/dist/v5.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/v5/tools/search.ts","../src/v5/tools/extract.ts"],"names":["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,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAI,QAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB;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AA,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":"v5.js","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/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@parallel-web/ai-sdk-tools",
3
+ "version": "0.1.0",
4
+ "description": "AI SDK tools for Parallel Web",
5
+ "author": "Parallel Web",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ },
17
+ "./v4": {
18
+ "types": "./dist/v4.d.ts",
19
+ "import": "./dist/v4.js",
20
+ "require": "./dist/v4.cjs"
21
+ },
22
+ "./v5": {
23
+ "types": "./dist/v5.d.ts",
24
+ "import": "./dist/v5.js",
25
+ "require": "./dist/v5.cjs"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsup",
34
+ "dev": "tsup --watch",
35
+ "test": "vitest run",
36
+ "typecheck": "tsc --noEmit",
37
+ "clean": "rm -rf dist"
38
+ },
39
+ "keywords": [
40
+ "ai",
41
+ "sdk",
42
+ "tools",
43
+ "parallel"
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/parallel-web/npm-packages",
48
+ "directory": "packages/ai-sdk-tools"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "dependencies": {
54
+ "ai-v4": "npm:ai@^4.0.0",
55
+ "ai-v5": "npm:ai@^5.0.0",
56
+ "parallel-web": "^0.2.1",
57
+ "zod": "^3.23.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^20.0.0"
61
+ }
62
+ }