@parallel-web/ai-sdk-tools 0.2.0 → 0.2.1
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 +5 -1
- package/dist/index.cjs +17 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -60,7 +60,9 @@ return result.toUIMessageStreamResponse();
|
|
|
60
60
|
|
|
61
61
|
## Factory Functions
|
|
62
62
|
|
|
63
|
-
For more control over the tool configuration, use the factory functions to create tools with custom defaults
|
|
63
|
+
For more control over the tool configuration, use the factory functions to create tools with custom defaults.
|
|
64
|
+
|
|
65
|
+
> **Note:** Both factory functions accept an optional `apiKey` parameter. If not provided, they fall back to the `PARALLEL_API_KEY` environment variable.
|
|
64
66
|
|
|
65
67
|
### createSearchTool
|
|
66
68
|
|
|
@@ -72,6 +74,7 @@ import { createSearchTool } from '@parallel-web/ai-sdk-tools';
|
|
|
72
74
|
const myCustomSearchTool = createSearchTool({
|
|
73
75
|
mode: 'one-shot', // 'one-shot' returns more comprehensive results and longer excerpts to answer questions from a single response.
|
|
74
76
|
max_results: 5, // Limit to 5 results
|
|
77
|
+
apiKey: 'your-api-key', // Optional: pass an API key, falls back to PARALLEL_API_KEY env variable
|
|
75
78
|
});
|
|
76
79
|
```
|
|
77
80
|
|
|
@@ -87,6 +90,7 @@ const myExtractTool = createExtractTool({
|
|
|
87
90
|
excerpts: {
|
|
88
91
|
max_chars_per_result: 10000,
|
|
89
92
|
},
|
|
93
|
+
apiKey: 'your-api-key', // Optional: pass an API key, falls back to PARALLEL_API_KEY env variable
|
|
90
94
|
});
|
|
91
95
|
```
|
|
92
96
|
|
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,7 @@ var parallelClient = new Proxy({}, {
|
|
|
12
12
|
_parallelClient = new parallelWeb.Parallel({
|
|
13
13
|
apiKey: process.env["PARALLEL_API_KEY"],
|
|
14
14
|
defaultHeaders: {
|
|
15
|
-
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.
|
|
15
|
+
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.1"}`
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
}
|
|
@@ -52,6 +52,7 @@ var defaultSearchDescription = `Purpose: Perform web searches and return results
|
|
|
52
52
|
Use the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`;
|
|
53
53
|
function createSearchTool(options = {}) {
|
|
54
54
|
const {
|
|
55
|
+
apiKey,
|
|
55
56
|
mode: defaultMode = "agentic",
|
|
56
57
|
max_results,
|
|
57
58
|
excerpts,
|
|
@@ -59,6 +60,12 @@ function createSearchTool(options = {}) {
|
|
|
59
60
|
fetch_policy,
|
|
60
61
|
description = defaultSearchDescription
|
|
61
62
|
} = options;
|
|
63
|
+
const client = apiKey ? new parallelWeb.Parallel({
|
|
64
|
+
apiKey,
|
|
65
|
+
defaultHeaders: {
|
|
66
|
+
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.1"}`
|
|
67
|
+
}
|
|
68
|
+
}) : parallelClient;
|
|
62
69
|
return ai.tool({
|
|
63
70
|
description,
|
|
64
71
|
inputSchema: zod.z.object({
|
|
@@ -66,7 +73,7 @@ function createSearchTool(options = {}) {
|
|
|
66
73
|
search_queries: zod.z.array(zod.z.string()).optional().describe(searchQueriesDescription)
|
|
67
74
|
}),
|
|
68
75
|
execute: async function({ objective, search_queries }, { abortSignal }) {
|
|
69
|
-
return await
|
|
76
|
+
return await client.beta.search(
|
|
70
77
|
{
|
|
71
78
|
objective,
|
|
72
79
|
search_queries,
|
|
@@ -114,11 +121,18 @@ Ideal Use Cases:
|
|
|
114
121
|
- Exploring URLs returned by a web search in greater depth`;
|
|
115
122
|
function createExtractTool(options = {}) {
|
|
116
123
|
const {
|
|
124
|
+
apiKey,
|
|
117
125
|
excerpts,
|
|
118
126
|
full_content,
|
|
119
127
|
fetch_policy,
|
|
120
128
|
description = defaultExtractDescription
|
|
121
129
|
} = options;
|
|
130
|
+
const client = apiKey ? new parallelWeb.Parallel({
|
|
131
|
+
apiKey,
|
|
132
|
+
defaultHeaders: {
|
|
133
|
+
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.1"}`
|
|
134
|
+
}
|
|
135
|
+
}) : parallelClient;
|
|
122
136
|
return ai.tool({
|
|
123
137
|
description,
|
|
124
138
|
inputSchema: zod.z.object({
|
|
@@ -126,7 +140,7 @@ function createExtractTool(options = {}) {
|
|
|
126
140
|
objective: zod.z.string().optional().describe(objectiveDescription2)
|
|
127
141
|
}),
|
|
128
142
|
execute: async function({ urls, objective }, { abortSignal }) {
|
|
129
|
-
return await
|
|
143
|
+
return await client.beta.extract(
|
|
130
144
|
{
|
|
131
145
|
urls,
|
|
132
146
|
objective,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/tools/search.ts","../src/tools/extract.ts"],"names":["Parallel","tool","z","objectiveDescription"],"mappings":";;;;;;;AAQA,IAAI,eAAA,GAAmC,IAAA;AAEhC,IAAM,cAAA,GAAiB,IAAI,KAAA,CAAM,EAAC,EAAe;AAAA,EACtD,GAAA,CAAI,SAAS,IAAA,EAAsB;AACjC,IAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAIA,oBAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB,CAAA;AAAA,QACtC,cAAA,EAAgB;AAAA,UACd,wBAAA,EAA0B,mCAAmC,OAA8B,CAAA;AAAA;AAC7F,OACD,CAAA;AAAA,IACH;AACA,IAAA,OAAO,gBAAgB,IAAI,CAAA;AAAA,EAC7B;AACF,CAAC,CAAA;;;AC4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F;AAAA,MACA;AAAA,QACE,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,EACF;AACF,CAAC;AAED,IAAM,yBAAA,GAA4B,CAAA;;AAAA;AAAA;AAAA,0DAAA,CAAA;AAoB3B,SAAS,iBAAA,CAAkB,OAAA,GAAoC,EAAC,EAAG;AACxE,EAAA,MAAM;AAAA,IACJ,QAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA,GAAc;AAAA,GAChB,GAAI,OAAA;AAEJ,EAAA,OAAOF,OAAAA,CAAK;AAAA,IACV,WAAA;AAAA,IACA,WAAA,EAAaC,MAAE,MAAA,CAAO;AAAA,MACpB,IAAA,EAAMA,MAAE,KAAA,CAAMA,KAAAA,CAAE,QAAQ,CAAA,CAAE,SAAS,eAAe,CAAA;AAAA,MAClD,WAAWA,KAAAA,CAAE,MAAA,GAAS,QAAA,EAAS,CAAE,SAASC,qBAAoB;AAAA,KAC/D,CAAA;AAAA,IAED,OAAA,EAAS,eACP,EAAE,IAAA,EAAM,WAAU,EAClB,EAAE,aAAY,EACd;AACA,MAAA,OAAO,MAAM,eAAe,IAAA,CAAK,OAAA;AAAA,QAC/B;AAAA,UACE,IAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,UACA,YAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA;AAAA,UACE,MAAA,EAAQ;AAAA;AACV,OACF;AAAA,IACF;AAAA,GACD,CAAA;AACH","file":"index.cjs","sourcesContent":["/**\n * Shared Parallel Web client instance\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { Parallel } from 'parallel-web';\n\nlet _parallelClient: Parallel | null = null;\n\nexport const parallelClient = new Proxy({} as Parallel, {\n get(_target, prop: keyof Parallel) {\n if (!_parallelClient) {\n _parallelClient = new Parallel({\n apiKey: process.env['PARALLEL_API_KEY'],\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n });\n }\n return _parallelClient[prop];\n },\n});\n","/**\n * Search tool for Parallel Web\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport type { SourcePolicy } from 'parallel-web/resources/shared.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom search tool with code-supplied defaults.\n */\nexport interface CreateSearchToolOptions {\n /**\n * Default mode for search. 'agentic' returns concise, token-efficient results\n * for multi-step workflows. 'one-shot' returns comprehensive results with\n * longer excerpts. Defaults to 'agentic'.\n */\n mode?: 'agentic' | 'one-shot';\n\n /**\n * Maximum number of search results to return. Defaults to 10.\n */\n max_results?: number;\n\n /**\n * Excerpt settings for controlling excerpt length.\n */\n excerpts?: ExcerptSettings;\n\n /**\n * Source policy for controlling which domains to include/exclude and freshness.\n */\n source_policy?: SourcePolicy | null;\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst objectiveDescription = `Natural-language description of what the web search is trying to find.\nTry to make the search objective atomic, looking for a specific piece of information. May include guidance about preferred sources or freshness.`;\n\nconst searchQueriesDescription = `(optional) List of keyword search queries of 1-6 words, which may include search operators. The search queries should be related to the objective. Limited to 5 entries of 200 characters each.`;\n\nconst modeDescription = `Presets default values for different use cases. \"one-shot\" returns more comprehensive results and longer excerpts to answer questions from a single response, while \"agentic\" returns more concise, token-efficient results for use in an agentic loop. Defaults to \"agentic\".`;\n\n/**\n * Search tool that mirrors the MCP web_search_preview tool.\n * Takes objective and optional search_queries/mode, returns raw search response.\n */\nexport const searchTool = tool({\n description: `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n mode: z\n .enum(['agentic', 'one-shot'])\n .optional()\n .default('agentic')\n .describe(modeDescription),\n }),\n\n execute: async function (\n { objective, search_queries, mode },\n { abortSignal }\n ) {\n return await parallelClient.beta.search(\n {\n objective,\n search_queries,\n mode,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultSearchDescription = `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`;\n\n/**\n * Factory function to create a search tool with custom defaults.\n *\n * Use this when you want to set defaults for mode, max_results, excerpts,\n * source_policy, or fetch_policy in your code, so the LLM only needs to\n * provide objective and search_queries.\n *\n * @example\n * ```ts\n * const mySearchTool = createSearchTool({\n * mode: 'one-shot',\n * max_results: 5,\n * excerpts: { max_chars_per_result: 5000 },\n * });\n * ```\n */\nexport function createSearchTool(options: CreateSearchToolOptions = {}) {\n const {\n mode: defaultMode = 'agentic',\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n description = defaultSearchDescription,\n } = options;\n\n return tool({\n description,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n }),\n\n execute: async function ({ objective, search_queries }, { abortSignal }) {\n return await parallelClient.beta.search(\n {\n objective,\n search_queries,\n mode: defaultMode,\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n","/**\n * Extract tool for Parallel Web\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n BetaExtractParams,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom extract tool with code-supplied defaults.\n */\nexport interface CreateExtractToolOptions {\n /**\n * Include excerpts from each URL relevant to the search objective and queries.\n * Can be a boolean or ExcerptSettings object. Defaults to true.\n */\n excerpts?: boolean | ExcerptSettings;\n\n /**\n * Include full content from each URL. Can be a boolean or FullContentSettings object.\n * Defaults to false.\n */\n full_content?: BetaExtractParams['full_content'];\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst urlsDescription = `List of URLs to extract content from. Must be valid HTTP/HTTPS URLs. Maximum 10 URLs per request.`;\n\nconst objectiveDescription = `Natural-language description of what information you're looking for from the URLs.`;\n\n/**\n * Extract tool that mirrors the MCP web_fetch tool.\n * Takes urls and optional objective, returns raw extract response.\n */\nexport const extractTool = 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 urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await parallelClient.beta.extract(\n {\n urls,\n objective,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultExtractDescription = `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\n/**\n * Factory function to create an extract tool with custom defaults.\n *\n * Use this when you want to set defaults for excerpts, full_content, or\n * fetch_policy in your code, so the LLM only needs to provide urls and objective.\n *\n * @example\n * ```ts\n * const myExtractTool = createExtractTool({\n * excerpts: { max_chars_per_result: 5000 },\n * full_content: true,\n * });\n * ```\n */\nexport function createExtractTool(options: CreateExtractToolOptions = {}) {\n const {\n excerpts,\n full_content,\n fetch_policy,\n description = defaultExtractDescription,\n } = options;\n\n return tool({\n description,\n inputSchema: z.object({\n urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await parallelClient.beta.extract(\n {\n urls,\n objective,\n excerpts,\n full_content,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/tools/search.ts","../src/tools/extract.ts"],"names":["Parallel","tool","z","objectiveDescription"],"mappings":";;;;;;;AAQA,IAAI,eAAA,GAAmC,IAAA;AAEhC,IAAM,cAAA,GAAiB,IAAI,KAAA,CAAM,EAAC,EAAe;AAAA,EACtD,GAAA,CAAI,SAAS,IAAA,EAAsB;AACjC,IAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAIA,oBAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB,CAAA;AAAA,QACtC,cAAA,EAAgB;AAAA,UACd,wBAAA,EAA0B,mCAAmC,OAA8B,CAAA;AAAA;AAC7F,OACD,CAAA;AAAA,IACH;AACA,IAAA,OAAO,gBAAgB,IAAI,CAAA;AAAA,EAC7B;AACF,CAAC,CAAA;;;ACqCD,IAAM,oBAAA,GAAuB,CAAA;AAAA,gJAAA,CAAA;AAG7B,IAAM,wBAAA,GAA2B,CAAA,+LAAA,CAAA;AAEjC,IAAM,eAAA,GAAkB,CAAA,8QAAA,CAAA;AAMjB,IAAM,aAAaC,OAAA,CAAK;AAAA,EAC7B,WAAA,EAAa,CAAA;;AAAA,iJAAA,CAAA;AAAA,EAGb,WAAA,EAAaC,MAAE,MAAA,CAAO;AAAA,IACpB,SAAA,EAAWA,KAAA,CAAE,MAAA,EAAO,CAAE,SAAS,oBAAoB,CAAA;AAAA,IACnD,cAAA,EAAgBA,KAAA,CACb,KAAA,CAAMA,KAAA,CAAE,MAAA,EAAQ,CAAA,CAChB,QAAA,EAAS,CACT,QAAA,CAAS,wBAAwB,CAAA;AA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AA;AAAA,IACA,WAAA,GAAc;AAAA,GAChB,GAAI,OAAA;AAEJ,EAAA,MAAM,MAAA,GAAS,MAAA,GACX,IAAIH,oBAAAA,CAAS;AAAA,IACX,MAAA;AAAA,IACA,cAAA,EAAgB;AAAA,MACd,wBAAA,EAA0B,mCAAmC,OAA8B,CAAA;AAAA;AAC7F,GACD,CAAA,GACD,cAAA;AAEJ,EAAA,OAAOC,OAAAA,CAAK;AAAA,IACV,WAAA;AAAA,IACA,WAAA,EAAaC,MAAE,MAAA,CAAO;AAAA,MACpB,IAAA,EAAMA,MAAE,KAAA,CAAMA,KAAAA,CAAE,QAAQ,CAAA,CAAE,SAAS,eAAe,CAAA;AAAA,MAClD,WAAWA,KAAAA,CAAE,MAAA,GAAS,QAAA,EAAS,CAAE,SAASC,qBAAoB;AAAA,KAC/D,CAAA;AAAA,IAED,OAAA,EAAS,eACP,EAAE,IAAA,EAAM,WAAU,EAClB,EAAE,aAAY,EACd;AACA,MAAA,OAAO,MAAM,OAAO,IAAA,CAAK,OAAA;AAAA,QACvB;AAAA,UACE,IAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,UACA,YAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA;AAAA,UACE,MAAA,EAAQ;AAAA;AACV,OACF;AAAA,IACF;AAAA,GACD,CAAA;AACH","file":"index.cjs","sourcesContent":["/**\n * Shared Parallel Web client instance\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { Parallel } from 'parallel-web';\n\nlet _parallelClient: Parallel | null = null;\n\nexport const parallelClient = new Proxy({} as Parallel, {\n get(_target, prop: keyof Parallel) {\n if (!_parallelClient) {\n _parallelClient = new Parallel({\n apiKey: process.env['PARALLEL_API_KEY'],\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n });\n }\n return _parallelClient[prop];\n },\n});\n","/**\n * Search tool for Parallel Web\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { Parallel } from 'parallel-web';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport type { SourcePolicy } from 'parallel-web/resources/shared.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom search tool with code-supplied defaults.\n */\nexport interface CreateSearchToolOptions {\n /**\n * API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY\n * environment variable.\n */\n apiKey?: string;\n\n /**\n * Default mode for search. 'agentic' returns concise, token-efficient results\n * for multi-step workflows. 'one-shot' returns comprehensive results with\n * longer excerpts. Defaults to 'agentic'.\n */\n mode?: 'agentic' | 'one-shot';\n\n /**\n * Maximum number of search results to return. Defaults to 10.\n */\n max_results?: number;\n\n /**\n * Excerpt settings for controlling excerpt length.\n */\n excerpts?: ExcerptSettings;\n\n /**\n * Source policy for controlling which domains to include/exclude and freshness.\n */\n source_policy?: SourcePolicy | null;\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst objectiveDescription = `Natural-language description of what the web search is trying to find.\nTry to make the search objective atomic, looking for a specific piece of information. May include guidance about preferred sources or freshness.`;\n\nconst searchQueriesDescription = `(optional) List of keyword search queries of 1-6 words, which may include search operators. The search queries should be related to the objective. Limited to 5 entries of 200 characters each.`;\n\nconst modeDescription = `Presets default values for different use cases. \"one-shot\" returns more comprehensive results and longer excerpts to answer questions from a single response, while \"agentic\" returns more concise, token-efficient results for use in an agentic loop. Defaults to \"agentic\".`;\n\n/**\n * Search tool that mirrors the MCP web_search_preview tool.\n * Takes objective and optional search_queries/mode, returns raw search response.\n */\nexport const searchTool = tool({\n description: `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n mode: z\n .enum(['agentic', 'one-shot'])\n .optional()\n .default('agentic')\n .describe(modeDescription),\n }),\n\n execute: async function (\n { objective, search_queries, mode },\n { abortSignal }\n ) {\n return await parallelClient.beta.search(\n {\n objective,\n search_queries,\n mode,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultSearchDescription = `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`;\n\n/**\n * Factory function to create a search tool with custom defaults.\n *\n * Use this when you want to set defaults for mode, max_results, excerpts,\n * source_policy, or fetch_policy in your code, so the LLM only needs to\n * provide objective and search_queries.\n *\n * @example\n * ```ts\n * const mySearchTool = createSearchTool({\n * mode: 'one-shot',\n * max_results: 5,\n * excerpts: { max_chars_per_result: 5000 },\n * });\n * ```\n */\nexport function createSearchTool(options: CreateSearchToolOptions = {}) {\n const {\n apiKey,\n mode: defaultMode = 'agentic',\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n description = defaultSearchDescription,\n } = options;\n\n const client = apiKey\n ? new Parallel({\n apiKey,\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n })\n : parallelClient;\n\n return tool({\n description,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n }),\n\n execute: async function ({ objective, search_queries }, { abortSignal }) {\n return await client.beta.search(\n {\n objective,\n search_queries,\n mode: defaultMode,\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n","/**\n * Extract tool for Parallel Web\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { Parallel } from 'parallel-web';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n BetaExtractParams,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom extract tool with code-supplied defaults.\n */\nexport interface CreateExtractToolOptions {\n /**\n * API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY\n * environment variable.\n */\n apiKey?: string;\n\n /**\n * Include excerpts from each URL relevant to the search objective and queries.\n * Can be a boolean or ExcerptSettings object. Defaults to true.\n */\n excerpts?: boolean | ExcerptSettings;\n\n /**\n * Include full content from each URL. Can be a boolean or FullContentSettings object.\n * Defaults to false.\n */\n full_content?: BetaExtractParams['full_content'];\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst urlsDescription = `List of URLs to extract content from. Must be valid HTTP/HTTPS URLs. Maximum 10 URLs per request.`;\n\nconst objectiveDescription = `Natural-language description of what information you're looking for from the URLs.`;\n\n/**\n * Extract tool that mirrors the MCP web_fetch tool.\n * Takes urls and optional objective, returns raw extract response.\n */\nexport const extractTool = 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 urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await parallelClient.beta.extract(\n {\n urls,\n objective,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultExtractDescription = `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\n/**\n * Factory function to create an extract tool with custom defaults.\n *\n * Use this when you want to set defaults for excerpts, full_content, or\n * fetch_policy in your code, so the LLM only needs to provide urls and objective.\n *\n * @example\n * ```ts\n * const myExtractTool = createExtractTool({\n * excerpts: { max_chars_per_result: 5000 },\n * full_content: true,\n * });\n * ```\n */\nexport function createExtractTool(options: CreateExtractToolOptions = {}) {\n const {\n apiKey,\n excerpts,\n full_content,\n fetch_policy,\n description = defaultExtractDescription,\n } = options;\n\n const client = apiKey\n ? new Parallel({\n apiKey,\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n })\n : parallelClient;\n\n return tool({\n description,\n inputSchema: z.object({\n urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await client.beta.extract(\n {\n urls,\n objective,\n excerpts,\n full_content,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import
|
|
2
|
+
import { Parallel } from 'parallel-web';
|
|
3
3
|
import { ExcerptSettings, FetchPolicy, BetaExtractParams } from 'parallel-web/resources/beta/beta.mjs';
|
|
4
4
|
import { SourcePolicy } from 'parallel-web/resources/shared.mjs';
|
|
5
5
|
|
|
@@ -7,6 +7,11 @@ import { SourcePolicy } from 'parallel-web/resources/shared.mjs';
|
|
|
7
7
|
* Options for creating a custom search tool with code-supplied defaults.
|
|
8
8
|
*/
|
|
9
9
|
interface CreateSearchToolOptions {
|
|
10
|
+
/**
|
|
11
|
+
* API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY
|
|
12
|
+
* environment variable.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
10
15
|
/**
|
|
11
16
|
* Default mode for search. 'agentic' returns concise, token-efficient results
|
|
12
17
|
* for multi-step workflows. 'one-shot' returns comprehensive results with
|
|
@@ -42,7 +47,7 @@ declare const searchTool: ai.Tool<{
|
|
|
42
47
|
objective: string;
|
|
43
48
|
mode: "agentic" | "one-shot";
|
|
44
49
|
search_queries?: string[] | undefined;
|
|
45
|
-
},
|
|
50
|
+
}, Parallel.Beta.SearchResult>;
|
|
46
51
|
/**
|
|
47
52
|
* Factory function to create a search tool with custom defaults.
|
|
48
53
|
*
|
|
@@ -62,12 +67,17 @@ declare const searchTool: ai.Tool<{
|
|
|
62
67
|
declare function createSearchTool(options?: CreateSearchToolOptions): ai.Tool<{
|
|
63
68
|
objective: string;
|
|
64
69
|
search_queries?: string[] | undefined;
|
|
65
|
-
},
|
|
70
|
+
}, Parallel.Beta.SearchResult>;
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
73
|
* Options for creating a custom extract tool with code-supplied defaults.
|
|
69
74
|
*/
|
|
70
75
|
interface CreateExtractToolOptions {
|
|
76
|
+
/**
|
|
77
|
+
* API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY
|
|
78
|
+
* environment variable.
|
|
79
|
+
*/
|
|
80
|
+
apiKey?: string;
|
|
71
81
|
/**
|
|
72
82
|
* Include excerpts from each URL relevant to the search objective and queries.
|
|
73
83
|
* Can be a boolean or ExcerptSettings object. Defaults to true.
|
|
@@ -94,7 +104,7 @@ interface CreateExtractToolOptions {
|
|
|
94
104
|
declare const extractTool: ai.Tool<{
|
|
95
105
|
urls: string[];
|
|
96
106
|
objective?: string | undefined;
|
|
97
|
-
},
|
|
107
|
+
}, Parallel.Beta.ExtractResponse>;
|
|
98
108
|
/**
|
|
99
109
|
* Factory function to create an extract tool with custom defaults.
|
|
100
110
|
*
|
|
@@ -112,6 +122,6 @@ declare const extractTool: ai.Tool<{
|
|
|
112
122
|
declare function createExtractTool(options?: CreateExtractToolOptions): ai.Tool<{
|
|
113
123
|
urls: string[];
|
|
114
124
|
objective?: string | undefined;
|
|
115
|
-
},
|
|
125
|
+
}, Parallel.Beta.ExtractResponse>;
|
|
116
126
|
|
|
117
127
|
export { type CreateExtractToolOptions, type CreateSearchToolOptions, createExtractTool, createSearchTool, extractTool, searchTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import
|
|
2
|
+
import { Parallel } from 'parallel-web';
|
|
3
3
|
import { ExcerptSettings, FetchPolicy, BetaExtractParams } from 'parallel-web/resources/beta/beta.mjs';
|
|
4
4
|
import { SourcePolicy } from 'parallel-web/resources/shared.mjs';
|
|
5
5
|
|
|
@@ -7,6 +7,11 @@ import { SourcePolicy } from 'parallel-web/resources/shared.mjs';
|
|
|
7
7
|
* Options for creating a custom search tool with code-supplied defaults.
|
|
8
8
|
*/
|
|
9
9
|
interface CreateSearchToolOptions {
|
|
10
|
+
/**
|
|
11
|
+
* API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY
|
|
12
|
+
* environment variable.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
10
15
|
/**
|
|
11
16
|
* Default mode for search. 'agentic' returns concise, token-efficient results
|
|
12
17
|
* for multi-step workflows. 'one-shot' returns comprehensive results with
|
|
@@ -42,7 +47,7 @@ declare const searchTool: ai.Tool<{
|
|
|
42
47
|
objective: string;
|
|
43
48
|
mode: "agentic" | "one-shot";
|
|
44
49
|
search_queries?: string[] | undefined;
|
|
45
|
-
},
|
|
50
|
+
}, Parallel.Beta.SearchResult>;
|
|
46
51
|
/**
|
|
47
52
|
* Factory function to create a search tool with custom defaults.
|
|
48
53
|
*
|
|
@@ -62,12 +67,17 @@ declare const searchTool: ai.Tool<{
|
|
|
62
67
|
declare function createSearchTool(options?: CreateSearchToolOptions): ai.Tool<{
|
|
63
68
|
objective: string;
|
|
64
69
|
search_queries?: string[] | undefined;
|
|
65
|
-
},
|
|
70
|
+
}, Parallel.Beta.SearchResult>;
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
73
|
* Options for creating a custom extract tool with code-supplied defaults.
|
|
69
74
|
*/
|
|
70
75
|
interface CreateExtractToolOptions {
|
|
76
|
+
/**
|
|
77
|
+
* API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY
|
|
78
|
+
* environment variable.
|
|
79
|
+
*/
|
|
80
|
+
apiKey?: string;
|
|
71
81
|
/**
|
|
72
82
|
* Include excerpts from each URL relevant to the search objective and queries.
|
|
73
83
|
* Can be a boolean or ExcerptSettings object. Defaults to true.
|
|
@@ -94,7 +104,7 @@ interface CreateExtractToolOptions {
|
|
|
94
104
|
declare const extractTool: ai.Tool<{
|
|
95
105
|
urls: string[];
|
|
96
106
|
objective?: string | undefined;
|
|
97
|
-
},
|
|
107
|
+
}, Parallel.Beta.ExtractResponse>;
|
|
98
108
|
/**
|
|
99
109
|
* Factory function to create an extract tool with custom defaults.
|
|
100
110
|
*
|
|
@@ -112,6 +122,6 @@ declare const extractTool: ai.Tool<{
|
|
|
112
122
|
declare function createExtractTool(options?: CreateExtractToolOptions): ai.Tool<{
|
|
113
123
|
urls: string[];
|
|
114
124
|
objective?: string | undefined;
|
|
115
|
-
},
|
|
125
|
+
}, Parallel.Beta.ExtractResponse>;
|
|
116
126
|
|
|
117
127
|
export { type CreateExtractToolOptions, type CreateSearchToolOptions, createExtractTool, createSearchTool, extractTool, searchTool };
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var parallelClient = new Proxy({}, {
|
|
|
10
10
|
_parallelClient = new Parallel({
|
|
11
11
|
apiKey: process.env["PARALLEL_API_KEY"],
|
|
12
12
|
defaultHeaders: {
|
|
13
|
-
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.
|
|
13
|
+
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.1"}`
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -50,6 +50,7 @@ var defaultSearchDescription = `Purpose: Perform web searches and return results
|
|
|
50
50
|
Use the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`;
|
|
51
51
|
function createSearchTool(options = {}) {
|
|
52
52
|
const {
|
|
53
|
+
apiKey,
|
|
53
54
|
mode: defaultMode = "agentic",
|
|
54
55
|
max_results,
|
|
55
56
|
excerpts,
|
|
@@ -57,6 +58,12 @@ function createSearchTool(options = {}) {
|
|
|
57
58
|
fetch_policy,
|
|
58
59
|
description = defaultSearchDescription
|
|
59
60
|
} = options;
|
|
61
|
+
const client = apiKey ? new Parallel({
|
|
62
|
+
apiKey,
|
|
63
|
+
defaultHeaders: {
|
|
64
|
+
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.1"}`
|
|
65
|
+
}
|
|
66
|
+
}) : parallelClient;
|
|
60
67
|
return tool({
|
|
61
68
|
description,
|
|
62
69
|
inputSchema: z.object({
|
|
@@ -64,7 +71,7 @@ function createSearchTool(options = {}) {
|
|
|
64
71
|
search_queries: z.array(z.string()).optional().describe(searchQueriesDescription)
|
|
65
72
|
}),
|
|
66
73
|
execute: async function({ objective, search_queries }, { abortSignal }) {
|
|
67
|
-
return await
|
|
74
|
+
return await client.beta.search(
|
|
68
75
|
{
|
|
69
76
|
objective,
|
|
70
77
|
search_queries,
|
|
@@ -112,11 +119,18 @@ Ideal Use Cases:
|
|
|
112
119
|
- Exploring URLs returned by a web search in greater depth`;
|
|
113
120
|
function createExtractTool(options = {}) {
|
|
114
121
|
const {
|
|
122
|
+
apiKey,
|
|
115
123
|
excerpts,
|
|
116
124
|
full_content,
|
|
117
125
|
fetch_policy,
|
|
118
126
|
description = defaultExtractDescription
|
|
119
127
|
} = options;
|
|
128
|
+
const client = apiKey ? new Parallel({
|
|
129
|
+
apiKey,
|
|
130
|
+
defaultHeaders: {
|
|
131
|
+
"X-Tool-Calling-Package": `npm:@parallel-web/ai-sdk-tools/v${"0.2.1"}`
|
|
132
|
+
}
|
|
133
|
+
}) : parallelClient;
|
|
120
134
|
return tool({
|
|
121
135
|
description,
|
|
122
136
|
inputSchema: z.object({
|
|
@@ -124,7 +138,7 @@ function createExtractTool(options = {}) {
|
|
|
124
138
|
objective: z.string().optional().describe(objectiveDescription2)
|
|
125
139
|
}),
|
|
126
140
|
execute: async function({ urls, objective }, { abortSignal }) {
|
|
127
|
-
return await
|
|
141
|
+
return await client.beta.extract(
|
|
128
142
|
{
|
|
129
143
|
urls,
|
|
130
144
|
objective,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/tools/search.ts","../src/tools/extract.ts"],"names":["objectiveDescription","tool","z"],"mappings":";;;;;AAQA,IAAI,eAAA,GAAmC,IAAA;AAEhC,IAAM,cAAA,GAAiB,IAAI,KAAA,CAAM,EAAC,EAAe;AAAA,EACtD,GAAA,CAAI,SAAS,IAAA,EAAsB;AACjC,IAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,MAAA,eAAA,GAAkB,IAAI,QAAA,CAAS;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,kBAAkB,CAAA;AAAA,QACtC,cAAA,EAAgB;AAAA,UACd,wBAAA,EAA0B,mCAAmC,OAA8B,CAAA;AAAA;AAC7F,OACD,CAAA;AAAA,IACH;AACA,IAAA,OAAO,gBAAgB,IAAI,CAAA;AAAA,EAC7B;AACF,CAAC,CAAA;;;AC4BD,IAAM,oBAAA,GAAuB,CAAA;AAAA,gJAAA,CAAA;AAG7B,IAAM,wBAAA,GAA2B,CAAA,+LAAA,CAAA;AAEjC,IAAM,eAAA,GAAkB,CAAA,8QAAA,CAAA;AAMjB,IAAM,aAAa,IAAA,CAAK;AAAA,EAC7B,WAAA,EAAa,CAAA;;AAAA,iJAAA,CAAA;AAAA,EAGb,WAAA,EAAa,EAAE,MAAA,CAAO;AAAA,IACpB,SAAA,EAAW,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,oBAAoB,CAAA;AA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A;AAAA,IACA,WAAA,EAAaC,EAAE,MAAA,CAAO;AAAA,MACpB,IAAA,EAAMA,EAAE,KAAA,CAAMA,CAAAA,CAAE,QAAQ,CAAA,CAAE,SAAS,eAAe,CAAA;AAAA,MAClD,WAAWA,CAAAA,CAAE,MAAA,GAAS,QAAA,EAAS,CAAE,SAASF,qBAAoB;AAAA,KAC/D,CAAA;AAAA,IAED,OAAA,EAAS,eACP,EAAE,IAAA,EAAM,WAAU,EAClB,EAAE,aAAY,EACd;AACA,MAAA,OAAO,MAAM,eAAe,IAAA,CAAK,OAAA;AAAA,QAC/B;AAAA,UACE,IAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,UACA,YAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA;AAAA,UACE,MAAA,EAAQ;AAAA;AACV,OACF;AAAA,IACF;AAAA,GACD,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * Shared Parallel Web client instance\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { Parallel } from 'parallel-web';\n\nlet _parallelClient: Parallel | null = null;\n\nexport const parallelClient = new Proxy({} as Parallel, {\n get(_target, prop: keyof Parallel) {\n if (!_parallelClient) {\n _parallelClient = new Parallel({\n apiKey: process.env['PARALLEL_API_KEY'],\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n });\n }\n return _parallelClient[prop];\n },\n});\n","/**\n * Search tool for Parallel Web\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport type { SourcePolicy } from 'parallel-web/resources/shared.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom search tool with code-supplied defaults.\n */\nexport interface CreateSearchToolOptions {\n /**\n * Default mode for search. 'agentic' returns concise, token-efficient results\n * for multi-step workflows. 'one-shot' returns comprehensive results with\n * longer excerpts. Defaults to 'agentic'.\n */\n mode?: 'agentic' | 'one-shot';\n\n /**\n * Maximum number of search results to return. Defaults to 10.\n */\n max_results?: number;\n\n /**\n * Excerpt settings for controlling excerpt length.\n */\n excerpts?: ExcerptSettings;\n\n /**\n * Source policy for controlling which domains to include/exclude and freshness.\n */\n source_policy?: SourcePolicy | null;\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst objectiveDescription = `Natural-language description of what the web search is trying to find.\nTry to make the search objective atomic, looking for a specific piece of information. May include guidance about preferred sources or freshness.`;\n\nconst searchQueriesDescription = `(optional) List of keyword search queries of 1-6 words, which may include search operators. The search queries should be related to the objective. Limited to 5 entries of 200 characters each.`;\n\nconst modeDescription = `Presets default values for different use cases. \"one-shot\" returns more comprehensive results and longer excerpts to answer questions from a single response, while \"agentic\" returns more concise, token-efficient results for use in an agentic loop. Defaults to \"agentic\".`;\n\n/**\n * Search tool that mirrors the MCP web_search_preview tool.\n * Takes objective and optional search_queries/mode, returns raw search response.\n */\nexport const searchTool = tool({\n description: `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n mode: z\n .enum(['agentic', 'one-shot'])\n .optional()\n .default('agentic')\n .describe(modeDescription),\n }),\n\n execute: async function (\n { objective, search_queries, mode },\n { abortSignal }\n ) {\n return await parallelClient.beta.search(\n {\n objective,\n search_queries,\n mode,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultSearchDescription = `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`;\n\n/**\n * Factory function to create a search tool with custom defaults.\n *\n * Use this when you want to set defaults for mode, max_results, excerpts,\n * source_policy, or fetch_policy in your code, so the LLM only needs to\n * provide objective and search_queries.\n *\n * @example\n * ```ts\n * const mySearchTool = createSearchTool({\n * mode: 'one-shot',\n * max_results: 5,\n * excerpts: { max_chars_per_result: 5000 },\n * });\n * ```\n */\nexport function createSearchTool(options: CreateSearchToolOptions = {}) {\n const {\n mode: defaultMode = 'agentic',\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n description = defaultSearchDescription,\n } = options;\n\n return tool({\n description,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n }),\n\n execute: async function ({ objective, search_queries }, { abortSignal }) {\n return await parallelClient.beta.search(\n {\n objective,\n search_queries,\n mode: defaultMode,\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n","/**\n * Extract tool for Parallel Web\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n BetaExtractParams,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom extract tool with code-supplied defaults.\n */\nexport interface CreateExtractToolOptions {\n /**\n * Include excerpts from each URL relevant to the search objective and queries.\n * Can be a boolean or ExcerptSettings object. Defaults to true.\n */\n excerpts?: boolean | ExcerptSettings;\n\n /**\n * Include full content from each URL. Can be a boolean or FullContentSettings object.\n * Defaults to false.\n */\n full_content?: BetaExtractParams['full_content'];\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst urlsDescription = `List of URLs to extract content from. Must be valid HTTP/HTTPS URLs. Maximum 10 URLs per request.`;\n\nconst objectiveDescription = `Natural-language description of what information you're looking for from the URLs.`;\n\n/**\n * Extract tool that mirrors the MCP web_fetch tool.\n * Takes urls and optional objective, returns raw extract response.\n */\nexport const extractTool = 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 urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await parallelClient.beta.extract(\n {\n urls,\n objective,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultExtractDescription = `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\n/**\n * Factory function to create an extract tool with custom defaults.\n *\n * Use this when you want to set defaults for excerpts, full_content, or\n * fetch_policy in your code, so the LLM only needs to provide urls and objective.\n *\n * @example\n * ```ts\n * const myExtractTool = createExtractTool({\n * excerpts: { max_chars_per_result: 5000 },\n * full_content: true,\n * });\n * ```\n */\nexport function createExtractTool(options: CreateExtractToolOptions = {}) {\n const {\n excerpts,\n full_content,\n fetch_policy,\n description = defaultExtractDescription,\n } = options;\n\n return tool({\n description,\n inputSchema: z.object({\n urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await parallelClient.beta.extract(\n {\n urls,\n objective,\n excerpts,\n full_content,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/tools/search.ts","../src/tools/extract.ts"],"names":["Parallel","objectiveDescription","tool","z"],"mappings":";;;;;AAQA,IAAI,eAAA,GAAmC,IAAA;AAEhC,IAAM,cAAA,GAAiB,IAAI,KAAA,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CAAE,QAAQ,CAAA,CAAE,SAAS,eAAe,CAAA;AAAA,MAClD,WAAWA,CAAAA,CAAE,MAAA,GAAS,QAAA,EAAS,CAAE,SAASF,qBAAoB;AAAA,KAC/D,CAAA;AAAA,IAED,OAAA,EAAS,eACP,EAAE,IAAA,EAAM,WAAU,EAClB,EAAE,aAAY,EACd;AACA,MAAA,OAAO,MAAM,OAAO,IAAA,CAAK,OAAA;AAAA,QACvB;AAAA,UACE,IAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,UACA,YAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA;AAAA,UACE,MAAA,EAAQ;AAAA;AACV,OACF;AAAA,IACF;AAAA,GACD,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * Shared Parallel Web client instance\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { Parallel } from 'parallel-web';\n\nlet _parallelClient: Parallel | null = null;\n\nexport const parallelClient = new Proxy({} as Parallel, {\n get(_target, prop: keyof Parallel) {\n if (!_parallelClient) {\n _parallelClient = new Parallel({\n apiKey: process.env['PARALLEL_API_KEY'],\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n });\n }\n return _parallelClient[prop];\n },\n});\n","/**\n * Search tool for Parallel Web\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { Parallel } from 'parallel-web';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport type { SourcePolicy } from 'parallel-web/resources/shared.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom search tool with code-supplied defaults.\n */\nexport interface CreateSearchToolOptions {\n /**\n * API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY\n * environment variable.\n */\n apiKey?: string;\n\n /**\n * Default mode for search. 'agentic' returns concise, token-efficient results\n * for multi-step workflows. 'one-shot' returns comprehensive results with\n * longer excerpts. Defaults to 'agentic'.\n */\n mode?: 'agentic' | 'one-shot';\n\n /**\n * Maximum number of search results to return. Defaults to 10.\n */\n max_results?: number;\n\n /**\n * Excerpt settings for controlling excerpt length.\n */\n excerpts?: ExcerptSettings;\n\n /**\n * Source policy for controlling which domains to include/exclude and freshness.\n */\n source_policy?: SourcePolicy | null;\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst objectiveDescription = `Natural-language description of what the web search is trying to find.\nTry to make the search objective atomic, looking for a specific piece of information. May include guidance about preferred sources or freshness.`;\n\nconst searchQueriesDescription = `(optional) List of keyword search queries of 1-6 words, which may include search operators. The search queries should be related to the objective. Limited to 5 entries of 200 characters each.`;\n\nconst modeDescription = `Presets default values for different use cases. \"one-shot\" returns more comprehensive results and longer excerpts to answer questions from a single response, while \"agentic\" returns more concise, token-efficient results for use in an agentic loop. Defaults to \"agentic\".`;\n\n/**\n * Search tool that mirrors the MCP web_search_preview tool.\n * Takes objective and optional search_queries/mode, returns raw search response.\n */\nexport const searchTool = tool({\n description: `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n mode: z\n .enum(['agentic', 'one-shot'])\n .optional()\n .default('agentic')\n .describe(modeDescription),\n }),\n\n execute: async function (\n { objective, search_queries, mode },\n { abortSignal }\n ) {\n return await parallelClient.beta.search(\n {\n objective,\n search_queries,\n mode,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultSearchDescription = `Purpose: Perform web searches and return results in an LLM-friendly format.\n\nUse the web search tool to search the web and access information from the web. The tool returns ranked, extended web excerpts optimized for LLMs.`;\n\n/**\n * Factory function to create a search tool with custom defaults.\n *\n * Use this when you want to set defaults for mode, max_results, excerpts,\n * source_policy, or fetch_policy in your code, so the LLM only needs to\n * provide objective and search_queries.\n *\n * @example\n * ```ts\n * const mySearchTool = createSearchTool({\n * mode: 'one-shot',\n * max_results: 5,\n * excerpts: { max_chars_per_result: 5000 },\n * });\n * ```\n */\nexport function createSearchTool(options: CreateSearchToolOptions = {}) {\n const {\n apiKey,\n mode: defaultMode = 'agentic',\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n description = defaultSearchDescription,\n } = options;\n\n const client = apiKey\n ? new Parallel({\n apiKey,\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n })\n : parallelClient;\n\n return tool({\n description,\n inputSchema: z.object({\n objective: z.string().describe(objectiveDescription),\n search_queries: z\n .array(z.string())\n .optional()\n .describe(searchQueriesDescription),\n }),\n\n execute: async function ({ objective, search_queries }, { abortSignal }) {\n return await client.beta.search(\n {\n objective,\n search_queries,\n mode: defaultMode,\n max_results,\n excerpts,\n source_policy,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n","/**\n * Extract tool for Parallel Web\n */\n\ndeclare const __PACKAGE_VERSION__: string;\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { Parallel } from 'parallel-web';\nimport type {\n ExcerptSettings,\n FetchPolicy,\n BetaExtractParams,\n} from 'parallel-web/resources/beta/beta.mjs';\nimport { parallelClient } from '../client.js';\n\n/**\n * Options for creating a custom extract tool with code-supplied defaults.\n */\nexport interface CreateExtractToolOptions {\n /**\n * API key for Parallel Web. If not provided, falls back to PARALLEL_API_KEY\n * environment variable.\n */\n apiKey?: string;\n\n /**\n * Include excerpts from each URL relevant to the search objective and queries.\n * Can be a boolean or ExcerptSettings object. Defaults to true.\n */\n excerpts?: boolean | ExcerptSettings;\n\n /**\n * Include full content from each URL. Can be a boolean or FullContentSettings object.\n * Defaults to false.\n */\n full_content?: BetaExtractParams['full_content'];\n\n /**\n * Fetch policy for controlling cached vs fresh content.\n */\n fetch_policy?: FetchPolicy | null;\n\n /**\n * Custom tool description. If not provided, uses the default description.\n */\n description?: string;\n}\n\nconst urlsDescription = `List of URLs to extract content from. Must be valid HTTP/HTTPS URLs. Maximum 10 URLs per request.`;\n\nconst objectiveDescription = `Natural-language description of what information you're looking for from the URLs.`;\n\n/**\n * Extract tool that mirrors the MCP web_fetch tool.\n * Takes urls and optional objective, returns raw extract response.\n */\nexport const extractTool = 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 urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await parallelClient.beta.extract(\n {\n urls,\n objective,\n },\n {\n signal: abortSignal,\n }\n );\n },\n});\n\nconst defaultExtractDescription = `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\n/**\n * Factory function to create an extract tool with custom defaults.\n *\n * Use this when you want to set defaults for excerpts, full_content, or\n * fetch_policy in your code, so the LLM only needs to provide urls and objective.\n *\n * @example\n * ```ts\n * const myExtractTool = createExtractTool({\n * excerpts: { max_chars_per_result: 5000 },\n * full_content: true,\n * });\n * ```\n */\nexport function createExtractTool(options: CreateExtractToolOptions = {}) {\n const {\n apiKey,\n excerpts,\n full_content,\n fetch_policy,\n description = defaultExtractDescription,\n } = options;\n\n const client = apiKey\n ? new Parallel({\n apiKey,\n defaultHeaders: {\n 'X-Tool-Calling-Package': `npm:@parallel-web/ai-sdk-tools/v${__PACKAGE_VERSION__ ?? '0.0.0'}`,\n },\n })\n : parallelClient;\n\n return tool({\n description,\n inputSchema: z.object({\n urls: z.array(z.string()).describe(urlsDescription),\n objective: z.string().optional().describe(objectiveDescription),\n }),\n\n execute: async function (\n { urls, objective }: { urls: string[]; objective?: string },\n { abortSignal }: { abortSignal?: AbortSignal }\n ) {\n return await client.beta.extract(\n {\n urls,\n objective,\n excerpts,\n full_content,\n fetch_policy,\n },\n {\n signal: abortSignal,\n }\n );\n },\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parallel-web/ai-sdk-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "AI SDK tools for Parallel Web",
|
|
5
5
|
"author": "Parallel Web",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "https://github.com/parallel-web/parallel-npm-packages",
|
|
37
|
+
"url": "git+https://github.com/parallel-web/parallel-npm-packages.git",
|
|
38
38
|
"directory": "packages/ai-sdk-tools"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|