ai 7.0.150 → 7.0.152
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/CHANGELOG.md +14 -0
- package/dist/index.js +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-ai-sdk-core/18-tools.mdx +181 -9
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.152
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a706678]
|
|
8
|
+
- @ai-sdk/gateway@4.0.125
|
|
9
|
+
|
|
10
|
+
## 7.0.151
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [1bf6d85]
|
|
15
|
+
- @ai-sdk/gateway@4.0.124
|
|
16
|
+
|
|
3
17
|
## 7.0.150
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.js
CHANGED
package/dist/internal/index.js
CHANGED
|
@@ -28,9 +28,7 @@ The tool has no direct dependency on either runtime.
|
|
|
28
28
|
Install the tool and the sandbox adapter you want to use. The following examples
|
|
29
29
|
use just-bash:
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
pnpm add ai @ai-sdk/tool-bash @ai-sdk/sandbox-just-bash
|
|
33
|
-
```
|
|
31
|
+
<InstallPackages packages="ai @ai-sdk/tool-bash @ai-sdk/sandbox-just-bash" />
|
|
34
32
|
|
|
35
33
|
Requires Node.js 22.13 or newer.
|
|
36
34
|
|
|
@@ -102,12 +100,36 @@ Raw runtime instances need their respective adapters; a custom
|
|
|
102
100
|
|
|
103
101
|
`experimental_createBashTool()` requires an options object:
|
|
104
102
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
<PropertiesTable
|
|
104
|
+
content={[
|
|
105
|
+
{
|
|
106
|
+
name: 'sandbox',
|
|
107
|
+
type: 'Experimental_SandboxSession',
|
|
108
|
+
description: 'Session for command execution and file operations.',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'workingDirectory',
|
|
112
|
+
type: 'string',
|
|
113
|
+
isOptional: true,
|
|
114
|
+
description:
|
|
115
|
+
"Absolute starting directory for each command, created if needed. When omitted, uses the sandbox's default directory.",
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'maxOutputLength',
|
|
119
|
+
type: 'number',
|
|
120
|
+
isOptional: true,
|
|
121
|
+
description:
|
|
122
|
+
'Positive integer limiting characters retained from each output stream before a truncation notice. Defaults to `30000`.',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'timeout',
|
|
126
|
+
type: 'number',
|
|
127
|
+
isOptional: true,
|
|
128
|
+
description:
|
|
129
|
+
'Timeout per command execution, in milliseconds (integer from `1` to `2147483647`). No tool-level timeout by default.',
|
|
130
|
+
},
|
|
131
|
+
]}
|
|
132
|
+
/>
|
|
111
133
|
|
|
112
134
|
The model calls the tool with `{ command: string }` and receives
|
|
113
135
|
`{ stdout, stderr, exitCode }`. Nonzero exit codes are returned so the model can
|
|
@@ -154,3 +176,153 @@ it returns `null` if the file is missing. Relative read paths depend on the
|
|
|
154
176
|
sandbox adapter; just-bash resolves them against its default directory. With an
|
|
155
177
|
explicit working directory, use absolute paths to read files from that directory.
|
|
156
178
|
The same session provides other file operations.
|
|
179
|
+
|
|
180
|
+
## Web Fetch Tool
|
|
181
|
+
|
|
182
|
+
`experimental_createWebFetchTool` lets agents read web pages and documents by URL.
|
|
183
|
+
|
|
184
|
+
### Installation
|
|
185
|
+
|
|
186
|
+
<InstallPackages packages="ai @ai-sdk/tool-web-fetch" />
|
|
187
|
+
|
|
188
|
+
Requires Node.js 22.13 or newer.
|
|
189
|
+
|
|
190
|
+
### Usage
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { experimental_createWebFetchTool as createWebFetchTool } from '@ai-sdk/tool-web-fetch';
|
|
194
|
+
import { generateText, isStepCount } from 'ai';
|
|
195
|
+
|
|
196
|
+
const result = await generateText({
|
|
197
|
+
model, // Your configured model with function calling support.
|
|
198
|
+
tools: { webFetch: createWebFetchTool() },
|
|
199
|
+
stopWhen: isStepCount(5),
|
|
200
|
+
prompt: 'Summarize https://ai-sdk.dev/docs/introduction.',
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Options
|
|
205
|
+
|
|
206
|
+
`experimental_createWebFetchTool()` accepts an optional options object:
|
|
207
|
+
|
|
208
|
+
<PropertiesTable
|
|
209
|
+
content={[
|
|
210
|
+
{
|
|
211
|
+
name: 'allowedDomains',
|
|
212
|
+
type: 'string[]',
|
|
213
|
+
isOptional: true,
|
|
214
|
+
description:
|
|
215
|
+
"Only fetch from these domains and their subdomains, e.g. `['example.com']`. List a subdomain such as `docs.example.com` to allow only that subdomain. Also applies to redirects. Cannot be combined with `blockedDomains`.",
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'blockedDomains',
|
|
219
|
+
type: 'string[]',
|
|
220
|
+
isOptional: true,
|
|
221
|
+
description:
|
|
222
|
+
'Never fetch from these domains or their subdomains. Also applies to redirects.',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: 'requireUrlInUserMessage',
|
|
226
|
+
type: 'boolean',
|
|
227
|
+
isOptional: true,
|
|
228
|
+
description:
|
|
229
|
+
'Only fetch URLs that appear in user messages. URLs in instructions, system messages, assistant messages, and tool results are not included. Defaults to `false`.',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'maxLength',
|
|
233
|
+
type: 'number',
|
|
234
|
+
isOptional: true,
|
|
235
|
+
description:
|
|
236
|
+
'Maximum characters returned per call. Longer content can be read with `offset`. Defaults to `50000`.',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: 'maxBytes',
|
|
240
|
+
type: 'number',
|
|
241
|
+
isOptional: true,
|
|
242
|
+
description: 'Maximum response size in bytes. Defaults to 10 MiB.',
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: 'timeout',
|
|
246
|
+
type: 'number',
|
|
247
|
+
isOptional: true,
|
|
248
|
+
description:
|
|
249
|
+
'Timeout in milliseconds for fetching each URL, including redirects. Defaults to `30000`.',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'fetch',
|
|
253
|
+
type: 'FetchFunction',
|
|
254
|
+
isOptional: true,
|
|
255
|
+
description:
|
|
256
|
+
'Custom fetch implementation, for example to route requests through a proxy. It must validate resolved addresses itself.',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'defuddleOptions',
|
|
260
|
+
type: 'DefuddleOptions',
|
|
261
|
+
isOptional: true,
|
|
262
|
+
description:
|
|
263
|
+
'Options for the [defuddle](https://github.com/kepano/defuddle) HTML content extractor, such as `contentSelector`.',
|
|
264
|
+
},
|
|
265
|
+
]}
|
|
266
|
+
/>
|
|
267
|
+
|
|
268
|
+
The model calls the tool with `{ url: string, offset?: number }` and receives
|
|
269
|
+
one of the following results:
|
|
270
|
+
|
|
271
|
+
- `{ type: 'document', url, finalUrl, contentType, title?, content, offset, totalLength, nextOffset? }`
|
|
272
|
+
for HTML and text.
|
|
273
|
+
- `{ type: 'error', url, errorCode, message, statusCode? }` when fetching fails.
|
|
274
|
+
|
|
275
|
+
Errors are returned so the model can recover, for example by trying another URL.
|
|
276
|
+
The model receives documents as text with the URL, title, and content type,
|
|
277
|
+
followed by the content. AI SDK cancellation aborts the request.
|
|
278
|
+
|
|
279
|
+
`experimental_createWebFetchTool()` returns the tool directly, ready to use as `tools: { webFetch }`.
|
|
280
|
+
|
|
281
|
+
### Content handling
|
|
282
|
+
|
|
283
|
+
Requests prefer markdown using the `Accept: text/markdown` header, which many
|
|
284
|
+
documentation sites support. Otherwise, HTML pages are converted to markdown
|
|
285
|
+
with [defuddle](https://github.com/kepano/defuddle), which removes navigation,
|
|
286
|
+
footers, and other boilerplate. Text formats such as plain text, JSON, XML, and
|
|
287
|
+
CSV are returned as is. PDFs, images, audio, video, and other binary formats
|
|
288
|
+
are not supported.
|
|
289
|
+
|
|
290
|
+
JavaScript is not executed. Pages that render their content in the browser may
|
|
291
|
+
return little or no content, in which case the model is told that the page may
|
|
292
|
+
require JavaScript.
|
|
293
|
+
|
|
294
|
+
The extractor sometimes selects the wrong part of a page. If you fetch pages
|
|
295
|
+
with a known structure, set `defuddleOptions.contentSelector` to choose the main
|
|
296
|
+
content element:
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
const webFetch = createWebFetchTool({
|
|
300
|
+
defuddleOptions: { contentSelector: 'article' },
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Content longer than `maxLength` is truncated. The model is told to call the tool
|
|
305
|
+
again with `offset` to continue reading. Converted documents are cached for a
|
|
306
|
+
few minutes per tool instance, so reading at an offset does not fetch the page
|
|
307
|
+
again.
|
|
308
|
+
|
|
309
|
+
### Security
|
|
310
|
+
|
|
311
|
+
The tool makes GET requests without cookies or credentials, and rejects URLs
|
|
312
|
+
that contain credentials. Each request and redirect is validated against
|
|
313
|
+
private and reserved addresses such as `localhost` and cloud metadata
|
|
314
|
+
endpoints. On Node.js, resolved DNS addresses are validated at connect time to
|
|
315
|
+
prevent DNS rebinding. On other runtimes, only the URL is validated, so restrict
|
|
316
|
+
network egress at the platform level. A custom `fetch` must provide equivalent
|
|
317
|
+
validation. See [Secure URL Fetching](/docs/advanced/secure-url-fetching).
|
|
318
|
+
|
|
319
|
+
Fetched content is untrusted and can contain prompt injections. When an agent
|
|
320
|
+
has access to private data, a model could also be instructed to send that data
|
|
321
|
+
to another site, for example in a URL query string. Restrict fetching with
|
|
322
|
+
`allowedDomains`, enable `requireUrlInUserMessage` so only URLs from user
|
|
323
|
+
messages can be fetched, or require [tool approval](/docs/ai-sdk-core/tools-and-tool-calling#tool-execution-approval).
|
|
324
|
+
|
|
325
|
+
`requireUrlInUserMessage` ignores URLs in tool results because the model can
|
|
326
|
+
place arbitrary text there, for example through tool inputs that are reflected
|
|
327
|
+
in outputs. As a result, the model cannot follow links from search results or
|
|
328
|
+
fetched pages in this mode.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.152",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ai-sdk/gateway": "4.0.
|
|
45
|
+
"@ai-sdk/gateway": "4.0.125",
|
|
46
46
|
"@ai-sdk/provider": "4.0.33",
|
|
47
47
|
"@ai-sdk/provider-utils": "5.0.67"
|
|
48
48
|
},
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@ai-sdk/google": "4.0.104",
|
|
53
53
|
"@ai-sdk/groq": "4.0.69",
|
|
54
54
|
"@ai-sdk/huggingface": "2.0.77",
|
|
55
|
-
"@ai-sdk/moonshotai": "3.0.
|
|
55
|
+
"@ai-sdk/moonshotai": "3.0.77",
|
|
56
56
|
"@ai-sdk/openai": "4.0.101",
|
|
57
57
|
"@ai-sdk/test-server": "2.0.4",
|
|
58
58
|
"@ai-sdk/xai": "5.0.29",
|