ai 7.0.145 → 7.0.147
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 +22 -0
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +10 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/01-overview.mdx +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +2 -2
- package/docs/02-foundations/03-prompts.mdx +3 -3
- package/docs/02-foundations/04-tools.mdx +2 -2
- package/docs/02-getting-started/00-choosing-a-provider.mdx +1 -1
- package/docs/02-getting-started/02-nextjs-app-router.mdx +4 -4
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +4 -4
- package/docs/02-getting-started/04-svelte.mdx +3 -3
- package/docs/02-getting-started/05-nuxt.mdx +3 -3
- package/docs/02-getting-started/06-nodejs.mdx +2 -2
- package/docs/02-getting-started/07-expo.mdx +4 -4
- package/docs/02-getting-started/08-tanstack-start.mdx +4 -4
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +1 -1
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +29 -2
- package/docs/03-ai-sdk-core/18-tools.mdx +137 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +1 -1
- package/docs/03-ai-sdk-core/41-skill-uploads.mdx +24 -10
- package/docs/03-ai-sdk-core/index.mdx +6 -0
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +1 -1
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +8 -8
- package/docs/03-ai-sdk-harnesses/06-workflow-utilities.mdx +12 -0
- package/docs/03-ai-sdk-harnesses/07-ui.mdx +2 -2
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +2 -2
- package/docs/05-ai-sdk-rsc/01-overview.mdx +1 -1
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +1 -1
- package/docs/06-advanced/01-prompt-engineering.mdx +1 -1
- package/docs/06-advanced/03-backpressure.mdx +1 -1
- package/docs/06-advanced/10-vercel-deployment-guide.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +18 -13
- package/docs/07-reference/01-ai-sdk-core/14-upload-skill.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +1 -1
- package/docs/08-migration-guides/index.mdx +12 -12
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +1 -1
- package/package.json +12 -12
- package/src/decide/decide-events.ts +6 -0
- package/src/decide/decide.ts +13 -0
- package/src/generate-text/output.ts +1 -1
- package/src/generate-text/prune-messages.ts +91 -32
- package/src/generate-text/tool-call.ts +1 -1
- package/src/generate-text/tool-error.ts +1 -1
- package/src/generate-text/tool-execution-events.ts +2 -2
- package/src/generate-text/tool-output-denied.ts +1 -1
- package/src/generate-text/tool-result.ts +1 -1
- package/src/ui/process-ui-message-stream.ts +1 -0
|
@@ -40,4 +40,4 @@ However, it's crucial to understand LLMs' limitations. When asked about less kno
|
|
|
40
40
|
|
|
41
41
|
An **embedding model** is used to convert complex data (like words or images) into a dense vector (a list of numbers) representation, known as an embedding. Unlike generative models, embedding models do not generate new text or data. Instead, they provide representations of semantic and syntactic relationships between entities that can be used as input for other models or other natural language processing tasks.
|
|
42
42
|
|
|
43
|
-
In the next section, you will learn about the difference between
|
|
43
|
+
In the next section, you will learn about the difference between model providers and models, and which ones are available in the AI SDK.
|
|
@@ -9,7 +9,7 @@ Companies such as OpenAI and Anthropic (providers) offer access to a range of la
|
|
|
9
9
|
|
|
10
10
|
Each provider typically has its own unique method for interfacing with their models, complicating the process of switching providers and increasing the risk of vendor lock-in.
|
|
11
11
|
|
|
12
|
-
To solve these challenges, AI SDK Core offers a standardized approach to interacting with LLMs through a [language model specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/
|
|
12
|
+
To solve these challenges, AI SDK Core offers a standardized approach to interacting with LLMs through a [language model specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/v4) that abstracts differences between providers. This unified interface allows you to switch between providers with ease while using the same API for all providers.
|
|
13
13
|
|
|
14
14
|
Here is an overview of the AI SDK Provider Architecture:
|
|
15
15
|
|
|
@@ -56,7 +56,7 @@ You can also use the [OpenAI Compatible provider](/providers/openai-compatible-p
|
|
|
56
56
|
- [LM Studio](/providers/openai-compatible-providers/lmstudio)
|
|
57
57
|
- [Heroku](/providers/openai-compatible-providers/heroku)
|
|
58
58
|
|
|
59
|
-
Our [language model specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/
|
|
59
|
+
Our [language model specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/v4) is published as an open-source package, which you can use to create [custom providers](/providers/community-providers/custom-providers).
|
|
60
60
|
|
|
61
61
|
The open-source community has created the following providers:
|
|
62
62
|
|
|
@@ -58,7 +58,7 @@ System messages in `prompt` or `messages` are rejected by default; use the `inst
|
|
|
58
58
|
const result = await generateText({
|
|
59
59
|
model: __MODEL__,
|
|
60
60
|
instructions:
|
|
61
|
-
`You help
|
|
61
|
+
`You help plan travel itineraries. ` +
|
|
62
62
|
`Respond to the users' request with a list ` +
|
|
63
63
|
`of the best stops to make in their destination.`,
|
|
64
64
|
prompt:
|
|
@@ -481,7 +481,7 @@ const result = await generateText({
|
|
|
481
481
|
});
|
|
482
482
|
```
|
|
483
483
|
|
|
484
|
-
### Tool
|
|
484
|
+
### Tool Messages
|
|
485
485
|
|
|
486
486
|
<Note>
|
|
487
487
|
[Tools](/docs/foundations/tools) (also known as function calling) are programs
|
|
@@ -616,7 +616,7 @@ const result = await generateText({
|
|
|
616
616
|
model: __MODEL__,
|
|
617
617
|
allowSystemInMessages: true,
|
|
618
618
|
messages: [
|
|
619
|
-
{ role: 'system', content: 'You help
|
|
619
|
+
{ role: 'system', content: 'You help plan travel itineraries.' },
|
|
620
620
|
{
|
|
621
621
|
role: 'user',
|
|
622
622
|
content:
|
|
@@ -34,7 +34,7 @@ A tool consists of three properties:
|
|
|
34
34
|
|
|
35
35
|
If the LLM decides to use a tool, it will generate a tool call.
|
|
36
36
|
Tools with an `execute` function are run automatically when these calls are generated.
|
|
37
|
-
The output of the tool calls
|
|
37
|
+
The output of the tool calls is returned using tool result objects.
|
|
38
38
|
|
|
39
39
|
You can automatically pass tool results back to the LLM
|
|
40
40
|
using [multi-step calls](/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls-using-stopwhen) with `streamText` and `generateText`.
|
|
@@ -150,7 +150,7 @@ const result = await generateText({
|
|
|
150
150
|
|
|
151
151
|
## Schemas
|
|
152
152
|
|
|
153
|
-
Schemas are used to define and validate the [tool input](/docs/ai-sdk-core/tools-and-tool-calling),
|
|
153
|
+
Schemas are used to define and validate the [tool input](/docs/ai-sdk-core/tools-and-tool-calling), tool outputs, and structured output generation.
|
|
154
154
|
|
|
155
155
|
The AI SDK supports the following schemas:
|
|
156
156
|
|
|
@@ -80,7 +80,7 @@ See [available providers](/providers/ai-sdk-providers) for setup instructions fo
|
|
|
80
80
|
|
|
81
81
|
## Custom Providers
|
|
82
82
|
|
|
83
|
-
You can build your own provider to integrate any service with the AI SDK. The AI SDK provides a [Language Model Specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/
|
|
83
|
+
You can build your own provider to integrate any service with the AI SDK. The AI SDK provides a [Language Model Specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/v4) that ensures compatibility across providers.
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
86
|
import { generateText } from 'ai';
|
|
@@ -16,7 +16,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
16
16
|
To follow this quickstart, you'll need:
|
|
17
17
|
|
|
18
18
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
19
|
-
- A [
|
|
19
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
20
20
|
|
|
21
21
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
22
22
|
|
|
@@ -40,7 +40,7 @@ Navigate to the newly created directory:
|
|
|
40
40
|
|
|
41
41
|
### Install dependencies
|
|
42
42
|
|
|
43
|
-
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [
|
|
43
|
+
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [Vercel AI Gateway provider](/providers/ai-sdk-providers/ai-gateway) ships with the `ai` package. You'll also install `zod`, a schema validation library used for defining tool inputs.
|
|
44
44
|
|
|
45
45
|
<Note>
|
|
46
46
|
This guide uses the Vercel AI Gateway provider so you can access hundreds of
|
|
@@ -109,7 +109,7 @@ This Route Handler creates a POST request endpoint at `/api/chat`.
|
|
|
109
109
|
|
|
110
110
|
## Choosing a Provider
|
|
111
111
|
|
|
112
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
112
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
113
113
|
|
|
114
114
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
115
115
|
|
|
@@ -149,7 +149,7 @@ Pick the approach that best matches how you want to manage providers across your
|
|
|
149
149
|
|
|
150
150
|
## Wire up the UI
|
|
151
151
|
|
|
152
|
-
Now that you have a Route Handler that can query an LLM, it's time to
|
|
152
|
+
Now that you have a Route Handler that can query an LLM, it's time to set up your frontend. The AI SDK's [UI](/docs/ai-sdk-ui) package abstracts the complexity of a chat interface into one hook, [`useChat`](/docs/reference/ai-sdk-ui/use-chat).
|
|
153
153
|
|
|
154
154
|
Update your root page (`app/page.tsx`) with the following code to show a list of chat messages and provide a user message input:
|
|
155
155
|
|
|
@@ -16,7 +16,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
16
16
|
To follow this quickstart, you'll need:
|
|
17
17
|
|
|
18
18
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
19
|
-
- A [
|
|
19
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
20
20
|
|
|
21
21
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
22
22
|
|
|
@@ -38,7 +38,7 @@ Navigate to the newly created directory:
|
|
|
38
38
|
|
|
39
39
|
### Install dependencies
|
|
40
40
|
|
|
41
|
-
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [
|
|
41
|
+
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [Vercel AI Gateway provider](/providers/ai-sdk-providers/ai-gateway) ships with the `ai` package. You'll also install `zod`, a schema validation library used for defining tool inputs.
|
|
42
42
|
|
|
43
43
|
<Note>
|
|
44
44
|
This guide uses the Vercel AI Gateway provider so you can access hundreds of
|
|
@@ -113,7 +113,7 @@ This Route Handler creates a POST request endpoint at `/api/chat`.
|
|
|
113
113
|
|
|
114
114
|
## Choosing a Provider
|
|
115
115
|
|
|
116
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
116
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
117
117
|
|
|
118
118
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
119
119
|
|
|
@@ -153,7 +153,7 @@ Pick the approach that best matches how you want to manage providers across your
|
|
|
153
153
|
|
|
154
154
|
## Wire up the UI
|
|
155
155
|
|
|
156
|
-
Now that you have an API route that can query an LLM, it's time to set up your frontend. The AI SDK's [
|
|
156
|
+
Now that you have an API route that can query an LLM, it's time to set up your frontend. The AI SDK's [UI](/docs/ai-sdk-ui) package abstracts the complexity of a chat interface into one hook, [`useChat`](/docs/reference/ai-sdk-ui/use-chat).
|
|
157
157
|
|
|
158
158
|
Update your root page (`pages/index.tsx`) with the following code to show a list of chat messages and provide a user message input:
|
|
159
159
|
|
|
@@ -16,7 +16,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
16
16
|
To follow this quickstart, you'll need:
|
|
17
17
|
|
|
18
18
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
19
|
-
- A [
|
|
19
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
20
20
|
|
|
21
21
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
22
22
|
|
|
@@ -32,7 +32,7 @@ Navigate to the newly created directory:
|
|
|
32
32
|
|
|
33
33
|
### Install Dependencies
|
|
34
34
|
|
|
35
|
-
Install `ai` and `@ai-sdk/svelte`, the AI package and AI SDK's Svelte bindings. The AI SDK's [
|
|
35
|
+
Install `ai` and `@ai-sdk/svelte`, the AI package and AI SDK's Svelte bindings. The AI SDK's [Vercel AI Gateway provider](/providers/ai-sdk-providers/ai-gateway) ships with the `ai` package. You'll also install `zod`, a schema validation library used for defining tool inputs.
|
|
36
36
|
|
|
37
37
|
<Note>
|
|
38
38
|
This guide uses the Vercel AI Gateway provider so you can access hundreds of
|
|
@@ -112,7 +112,7 @@ Let's take a look at what is happening in this code:
|
|
|
112
112
|
|
|
113
113
|
## Choosing a Provider
|
|
114
114
|
|
|
115
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
115
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
116
116
|
|
|
117
117
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
118
118
|
|
|
@@ -16,7 +16,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
16
16
|
To follow this quickstart, you'll need:
|
|
17
17
|
|
|
18
18
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
19
|
-
- A [
|
|
19
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
20
20
|
|
|
21
21
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
22
22
|
|
|
@@ -120,7 +120,7 @@ Let's take a look at what is happening in this code:
|
|
|
120
120
|
|
|
121
121
|
## Choosing a Provider
|
|
122
122
|
|
|
123
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
123
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
124
124
|
|
|
125
125
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
126
126
|
|
|
@@ -154,7 +154,7 @@ model: openai('gpt-6-astra');
|
|
|
154
154
|
|
|
155
155
|
## Wire up the UI
|
|
156
156
|
|
|
157
|
-
Now that you have an API route that can query an LLM, it's time to set up your frontend. The AI SDK's [
|
|
157
|
+
Now that you have an API route that can query an LLM, it's time to set up your frontend. The AI SDK's [UI](/docs/ai-sdk-ui/overview) package abstracts the complexity of a chat interface into one hook, [`useChat`](/docs/reference/ai-sdk-ui/use-chat).
|
|
158
158
|
|
|
159
159
|
Update your root page (`pages/index.vue`) with the following code to show a list of chat messages and provide a user message input:
|
|
160
160
|
|
|
@@ -16,7 +16,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
16
16
|
To follow this quickstart, you'll need:
|
|
17
17
|
|
|
18
18
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
19
|
-
- A [
|
|
19
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
20
20
|
|
|
21
21
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
22
22
|
|
|
@@ -133,7 +133,7 @@ You should see a prompt in your terminal. Test it out by entering a message and
|
|
|
133
133
|
|
|
134
134
|
## Choosing a Provider
|
|
135
135
|
|
|
136
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
136
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
137
137
|
|
|
138
138
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
139
139
|
|
|
@@ -14,7 +14,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
14
14
|
To follow this quickstart, you'll need:
|
|
15
15
|
|
|
16
16
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
17
|
-
- A [
|
|
17
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
18
18
|
|
|
19
19
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
20
20
|
|
|
@@ -32,7 +32,7 @@ Navigate to the newly created directory:
|
|
|
32
32
|
|
|
33
33
|
### Install dependencies
|
|
34
34
|
|
|
35
|
-
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [
|
|
35
|
+
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [Vercel AI Gateway provider](/providers/ai-sdk-providers/ai-gateway) ships with the `ai` package. You'll also install `zod`, a schema validation library used for defining tool inputs.
|
|
36
36
|
|
|
37
37
|
<Note>
|
|
38
38
|
This guide uses the Vercel AI Gateway provider so you can access hundreds of
|
|
@@ -112,7 +112,7 @@ This API route creates a POST request endpoint at `/api/chat`.
|
|
|
112
112
|
|
|
113
113
|
## Choosing a Provider
|
|
114
114
|
|
|
115
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
115
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
116
116
|
|
|
117
117
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
118
118
|
|
|
@@ -152,7 +152,7 @@ Pick the approach that best matches how you want to manage providers across your
|
|
|
152
152
|
|
|
153
153
|
## Wire up the UI
|
|
154
154
|
|
|
155
|
-
Now that you have an API route that can query an LLM, it's time to
|
|
155
|
+
Now that you have an API route that can query an LLM, it's time to set up your frontend. The AI SDK's [UI](/docs/ai-sdk-ui) package abstracts the complexity of a chat interface into one hook, [`useChat`](/docs/reference/ai-sdk-ui/use-chat).
|
|
156
156
|
|
|
157
157
|
Update your root page (`app/(tabs)/index.tsx`) with the following code to show a list of chat messages and provide a user message input:
|
|
158
158
|
|
|
@@ -16,7 +16,7 @@ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/p
|
|
|
16
16
|
To follow this quickstart, you'll need:
|
|
17
17
|
|
|
18
18
|
- Node.js 22+ and pnpm installed on your local development machine.
|
|
19
|
-
- A [
|
|
19
|
+
- A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
|
|
20
20
|
|
|
21
21
|
If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website.
|
|
22
22
|
|
|
@@ -32,7 +32,7 @@ Navigate to the newly created directory:
|
|
|
32
32
|
|
|
33
33
|
### Install dependencies
|
|
34
34
|
|
|
35
|
-
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [
|
|
35
|
+
Install `ai` and `@ai-sdk/react`, the AI package and AI SDK's React hooks. The AI SDK's [Vercel AI Gateway provider](/providers/ai-sdk-providers/ai-gateway) ships with the `ai` package. You'll also install `zod`, a schema validation library used for defining tool inputs.
|
|
36
36
|
|
|
37
37
|
<Note>
|
|
38
38
|
This guide uses the Vercel AI Gateway provider so you can access hundreds of
|
|
@@ -108,7 +108,7 @@ This Route Handler creates a POST request endpoint at `/api/chat`.
|
|
|
108
108
|
|
|
109
109
|
## Choosing a Provider
|
|
110
110
|
|
|
111
|
-
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [
|
|
111
|
+
The AI SDK supports dozens of model providers through [first-party](/providers/ai-sdk-providers), [OpenAI-compatible](/providers/openai-compatible-providers), and [community](/providers/community-providers) packages.
|
|
112
112
|
|
|
113
113
|
This quickstart uses the [Vercel AI Gateway](https://vercel.com/ai-gateway) provider, which is the default [global provider](/docs/ai-sdk-core/provider-management#global-provider-configuration). This means you can access models using a simple string in the model configuration:
|
|
114
114
|
|
|
@@ -148,7 +148,7 @@ Pick the approach that best matches how you want to manage providers across your
|
|
|
148
148
|
|
|
149
149
|
## Wire up the UI
|
|
150
150
|
|
|
151
|
-
Now that you have a Route Handler that can query an LLM, it's time to
|
|
151
|
+
Now that you have a Route Handler that can query an LLM, it's time to set up your frontend. The AI SDK's [UI](/docs/ai-sdk-ui) package abstracts the complexity of a chat interface into one hook, [`useChat`](/docs/reference/ai-sdk-ui/use-chat).
|
|
152
152
|
|
|
153
153
|
Update your index route (`src/routes/index.tsx`) with the following code to show a list of chat messages and provide a user message input:
|
|
154
154
|
|
|
@@ -11,7 +11,7 @@ For example, you might want to extract information from text, classify data, or
|
|
|
11
11
|
Many language models are capable of generating structured data, often defined as using "JSON modes" or "tools".
|
|
12
12
|
However, you need to manually provide schemas and then validate the generated data as LLMs can produce incorrect or incomplete structured data.
|
|
13
13
|
|
|
14
|
-
The AI SDK
|
|
14
|
+
The AI SDK standardizes structured object generation across model providers
|
|
15
15
|
using the `output` property on [`generateText`](/docs/reference/ai-sdk-core/generate-text)
|
|
16
16
|
and [`streamText`](/docs/reference/ai-sdk-core/stream-text).
|
|
17
17
|
You can use [Zod schemas](/docs/reference/ai-sdk-core/zod-schema), [Valibot](/docs/reference/ai-sdk-core/valibot-schema), or [JSON schemas](/docs/reference/ai-sdk-core/json-schema) to specify the shape of the data that you want,
|
|
@@ -210,6 +210,33 @@ tokens are invalid.
|
|
|
210
210
|
|
|
211
211
|
### OAuth Authorization Server Validation
|
|
212
212
|
|
|
213
|
+
Pre-registered confidential clients must be bound to their authorization server
|
|
214
|
+
before starting OAuth. Set `issuer` on the credentials returned by
|
|
215
|
+
`clientInformation()` to the issuer of the server that registered the client:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
clientInformation() {
|
|
219
|
+
return {
|
|
220
|
+
client_id: process.env.OAUTH_CLIENT_ID!,
|
|
221
|
+
client_secret: process.env.OAUTH_CLIENT_SECRET!,
|
|
222
|
+
issuer: 'https://accounts.example.com',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The issuer must exactly match the discovered issuer. The SDK rejects a mismatch
|
|
228
|
+
before redirecting or sending credentials, even if a stored authorization flow
|
|
229
|
+
pin names the discovered server. Dynamic client registration attaches this
|
|
230
|
+
binding automatically.
|
|
231
|
+
|
|
232
|
+
Existing complete authorization server bindings on credentials, stored tokens,
|
|
233
|
+
or `authorizationServerInformation()` are also supported. Without a binding,
|
|
234
|
+
a pre-registered client secret or custom `addClientAuthentication` handler is
|
|
235
|
+
rejected, even when `validateAuthorizationServerURL` accepts the selected server.
|
|
236
|
+
Approving a server does not establish that the credentials belong to it.
|
|
237
|
+
Do not derive the credential issuer from the MCP server's metadata; configure it
|
|
238
|
+
from the client's registration.
|
|
239
|
+
|
|
213
240
|
When using MCP OAuth in server-side applications, the MCP server can advertise
|
|
214
241
|
the OAuth authorization server to use. If you connect to MCP servers outside
|
|
215
242
|
your control, implement `validateAuthorizationServerURL` on your
|
|
@@ -237,8 +264,8 @@ const myOAuthClientProvider = {
|
|
|
237
264
|
```
|
|
238
265
|
|
|
239
266
|
This hook is called before the SDK fetches authorization server metadata, so a
|
|
240
|
-
rejected URL is not requested.
|
|
241
|
-
|
|
267
|
+
rejected URL is not requested. The hook is an optional additional restriction;
|
|
268
|
+
it does not replace the credential binding required for confidential clients.
|
|
242
269
|
|
|
243
270
|
### OAuth Callback Issuer Validation
|
|
244
271
|
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Tools
|
|
3
|
+
description: Use first-party AI SDK tools to add capabilities to agents and applications.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tools
|
|
7
|
+
|
|
8
|
+
The AI SDK provides first-party tools for agents and applications. Each tool
|
|
9
|
+
includes its input schema, model-facing description, and
|
|
10
|
+
execution logic, ready to use with `generateText`, `streamText`, or `ToolLoopAgent`.
|
|
11
|
+
These tools work with any model that supports function calling.
|
|
12
|
+
|
|
13
|
+
Install tools from their individual `@ai-sdk/tool-*` packages.
|
|
14
|
+
|
|
15
|
+
For defining your own tools and configuring tool execution, see
|
|
16
|
+
[Tools and Tool Calling](/docs/ai-sdk-core/tools-and-tool-calling).
|
|
17
|
+
|
|
18
|
+
## Bash Tool
|
|
19
|
+
|
|
20
|
+
`experimental_createBashTool` lets agents run Bash commands to search, analyze, and transform files.
|
|
21
|
+
Supply an `Experimental_SandboxSession` to choose where commands run. Use
|
|
22
|
+
`@ai-sdk/sandbox-just-bash` for an in-memory environment,
|
|
23
|
+
`@ai-sdk/sandbox-vercel` for Vercel Sandbox, or your own implementation.
|
|
24
|
+
The tool has no direct dependency on either runtime.
|
|
25
|
+
|
|
26
|
+
### Installation
|
|
27
|
+
|
|
28
|
+
Install the tool and the sandbox adapter you want to use. The following examples
|
|
29
|
+
use just-bash:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pnpm add ai @ai-sdk/tool-bash @ai-sdk/sandbox-just-bash
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Requires Node.js 22.13 or newer.
|
|
36
|
+
|
|
37
|
+
### Usage
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createJustBashNetworkSandboxSession } from '@ai-sdk/sandbox-just-bash';
|
|
41
|
+
import { experimental_createBashTool as createBashTool } from '@ai-sdk/tool-bash';
|
|
42
|
+
import { generateText, isStepCount } from 'ai';
|
|
43
|
+
|
|
44
|
+
const session = await createJustBashNetworkSandboxSession();
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const sandbox = session.restricted();
|
|
48
|
+
await sandbox.writeTextFile({
|
|
49
|
+
path: 'notes.txt',
|
|
50
|
+
content: 'Apples: 10\nPears: 20\n',
|
|
51
|
+
});
|
|
52
|
+
const bash = await createBashTool({ sandbox });
|
|
53
|
+
|
|
54
|
+
const result = await generateText({
|
|
55
|
+
model, // Your configured model with function calling support.
|
|
56
|
+
tools: { bash },
|
|
57
|
+
stopWhen: isStepCount(5),
|
|
58
|
+
prompt: 'Read notes.txt and write a summary to summary.txt.',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log(result.text);
|
|
62
|
+
console.log(await sandbox.readTextFile({ path: 'summary.txt' }));
|
|
63
|
+
} finally {
|
|
64
|
+
await session.destroy();
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Vercel Sandbox
|
|
69
|
+
|
|
70
|
+
Install `@ai-sdk/sandbox-vercel` and `@vercel/sandbox` to use an existing native
|
|
71
|
+
Vercel Sandbox. Wrap it with the adapter before passing it to the tool:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { createVercelSandboxSessionFromNativeSandbox } from '@ai-sdk/sandbox-vercel';
|
|
75
|
+
import { experimental_createBashTool as createBashTool } from '@ai-sdk/tool-bash';
|
|
76
|
+
import { Sandbox } from '@vercel/sandbox';
|
|
77
|
+
|
|
78
|
+
const nativeSandbox = await Sandbox.create();
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const sandbox = createVercelSandboxSessionFromNativeSandbox(nativeSandbox);
|
|
82
|
+
await sandbox.writeTextFile({
|
|
83
|
+
path: 'notes.txt',
|
|
84
|
+
content: 'Hello from Vercel Sandbox',
|
|
85
|
+
});
|
|
86
|
+
const bash = await createBashTool({ sandbox });
|
|
87
|
+
|
|
88
|
+
// Use bash with generateText, streamText, or ToolLoopAgent here.
|
|
89
|
+
} finally {
|
|
90
|
+
await nativeSandbox.stop();
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
You can also create a managed session with
|
|
95
|
+
`createVercelNetworkSandboxSession()` from `@ai-sdk/sandbox-vercel` and pass
|
|
96
|
+
`session.restricted()`. For an existing native just-bash `Sandbox`, use
|
|
97
|
+
`createJustBashSandboxSessionFromNativeSandbox()` from `@ai-sdk/sandbox-just-bash`.
|
|
98
|
+
Raw runtime instances need their respective adapters; a custom
|
|
99
|
+
`Experimental_SandboxSession` can be passed directly.
|
|
100
|
+
|
|
101
|
+
### Options
|
|
102
|
+
|
|
103
|
+
`experimental_createBashTool()` requires an options object:
|
|
104
|
+
|
|
105
|
+
| Option | Type | Description |
|
|
106
|
+
| ------------------ | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
107
|
+
| `sandbox` | `Experimental_SandboxSession` | Required session for command execution and file operations. |
|
|
108
|
+
| `workingDirectory` | `string` | Optional absolute starting directory for each command, created if needed. When omitted, uses the sandbox's default directory. |
|
|
109
|
+
| `maxOutputLength` | `number` | Positive integer limiting characters retained from each output stream before a truncation notice. Defaults to `30000`. |
|
|
110
|
+
|
|
111
|
+
The model calls the tool with `{ command: string }` and receives
|
|
112
|
+
`{ stdout, stderr, exitCode }`. Nonzero exit codes are returned so the model can
|
|
113
|
+
inspect failures and recover. AI SDK cancellation is forwarded to the session.
|
|
114
|
+
Output truncation happens after execution and does not limit execution memory or
|
|
115
|
+
duration.
|
|
116
|
+
|
|
117
|
+
### Files and lifecycle
|
|
118
|
+
|
|
119
|
+
Commands use the sandbox's default working directory unless `workingDirectory`
|
|
120
|
+
is provided. Without an override, creating the tool runs no setup commands.
|
|
121
|
+
Seed files through `sandbox.writeTextFile({ path, content })` before running the
|
|
122
|
+
tool. With an explicit working directory, use absolute paths to write files there.
|
|
123
|
+
|
|
124
|
+
The sandbox controls which files commands can access. Available programs, network
|
|
125
|
+
access, shell state, and persistence depend on the supplied sandbox. Its
|
|
126
|
+
description is included in the tool's instructions.
|
|
127
|
+
|
|
128
|
+
Tools using the same session share files. Creating a tool does not reset existing
|
|
129
|
+
files or create a new sandbox. Use separate sessions for independent workflows.
|
|
130
|
+
The caller creates, reconnects, and destroys the sandbox.
|
|
131
|
+
|
|
132
|
+
`experimental_createBashTool()` returns the tool directly, ready to use as `tools: { bash }`.
|
|
133
|
+
Use the supplied sandbox's `readTextFile({ path })` to read generated text files;
|
|
134
|
+
it returns `null` if the file is missing. Relative read paths depend on the
|
|
135
|
+
sandbox adapter; just-bash resolves them against its default directory. With an
|
|
136
|
+
explicit working directory, use absolute paths to read files from that directory.
|
|
137
|
+
The same session provides other file operations.
|
|
@@ -14,7 +14,7 @@ that providers can load, e.g. in sandboxed container environments.
|
|
|
14
14
|
|
|
15
15
|
In the AI SDK, the uploaded skill is identified by a `ProviderReference` — a
|
|
16
16
|
`Record<string, string>` mapping provider names to provider-specific identifiers.
|
|
17
|
-
This concept is used for other provider
|
|
17
|
+
This concept is used for other provider-specific asset references too, such as
|
|
18
18
|
uploaded media files.
|
|
19
19
|
|
|
20
20
|
```ts
|
|
@@ -30,7 +30,7 @@ const { providerReference } = await uploadSkill({
|
|
|
30
30
|
files: [
|
|
31
31
|
{
|
|
32
32
|
path: 'my-skill/SKILL.md',
|
|
33
|
-
|
|
33
|
+
data: readFileSync('./SKILL.md'),
|
|
34
34
|
},
|
|
35
35
|
],
|
|
36
36
|
displayTitle: 'My Skill',
|
|
@@ -57,16 +57,16 @@ As a shorthand, you can pass a provider instance directly to `api` instead of ca
|
|
|
57
57
|
```ts highlight="2"
|
|
58
58
|
const { providerReference } = await uploadSkill({
|
|
59
59
|
api: anthropic, // shorthand for anthropic.skills()
|
|
60
|
-
files: [{ path: 'my-skill/SKILL.md',
|
|
60
|
+
files: [{ path: 'my-skill/SKILL.md', data: readFileSync('./SKILL.md') }],
|
|
61
61
|
displayTitle: 'My Skill',
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
## Skill Files
|
|
66
66
|
|
|
67
|
-
A skill is composed of one or more files, each with a relative `path` and `
|
|
68
|
-
|
|
69
|
-
base64-encoded string:
|
|
67
|
+
A skill is composed of one or more files, each with a relative `path` and `data`.
|
|
68
|
+
|
|
69
|
+
File content can be provided as a `Uint8Array` (for example, from `fs.readFileSync`) or as a base64-encoded string. Alternatively, `data` can be provided as a tagged object with either `type: 'text'` or `type: 'data'` to explicitly specify the content format:
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
const { providerReference } = await uploadSkill({
|
|
@@ -74,11 +74,25 @@ const { providerReference } = await uploadSkill({
|
|
|
74
74
|
files: [
|
|
75
75
|
{
|
|
76
76
|
path: 'my-skill/SKILL.md',
|
|
77
|
-
|
|
77
|
+
data: readFileSync('./SKILL.md'), // Uint8Array
|
|
78
78
|
},
|
|
79
79
|
{
|
|
80
80
|
path: 'my-skill/helper.py',
|
|
81
|
-
|
|
81
|
+
data: readFileSync('./helper.py'),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
path: 'my-skill/data.json',
|
|
85
|
+
data: {
|
|
86
|
+
type: 'data',
|
|
87
|
+
data: Buffer.from(JSON.stringify({ foo: 'bar' })).toString('base64'),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
path: 'my-skill/README.txt',
|
|
92
|
+
data: {
|
|
93
|
+
type: 'text',
|
|
94
|
+
text: 'This is a skill for demonstrating skill uploads.',
|
|
95
|
+
},
|
|
82
96
|
},
|
|
83
97
|
],
|
|
84
98
|
});
|
|
@@ -123,11 +137,11 @@ merge the references:
|
|
|
123
137
|
const [openaiUpload, anthropicUpload] = await Promise.all([
|
|
124
138
|
uploadSkill({
|
|
125
139
|
api: openai.skills(),
|
|
126
|
-
files: [{ path: 'my-skill/SKILL.md',
|
|
140
|
+
files: [{ path: 'my-skill/SKILL.md', data: skillSource }],
|
|
127
141
|
}),
|
|
128
142
|
uploadSkill({
|
|
129
143
|
api: anthropic.skills(),
|
|
130
|
-
files: [{ path: 'my-skill/SKILL.md',
|
|
144
|
+
files: [{ path: 'my-skill/SKILL.md', data: skillSource }],
|
|
131
145
|
displayTitle: 'My Skill',
|
|
132
146
|
}),
|
|
133
147
|
]);
|
|
@@ -28,6 +28,12 @@ description: Learn about AI SDK Core.
|
|
|
28
28
|
description: 'Learn how to do tool calling with AI SDK Core.',
|
|
29
29
|
href: '/docs/ai-sdk-core/tools-and-tool-calling',
|
|
30
30
|
},
|
|
31
|
+
{
|
|
32
|
+
title: 'Tools',
|
|
33
|
+
description:
|
|
34
|
+
'Add capabilities to agents and applications with first-party AI SDK tools.',
|
|
35
|
+
href: '/docs/ai-sdk-core/tools',
|
|
36
|
+
},
|
|
31
37
|
{
|
|
32
38
|
title: 'Tool Search',
|
|
33
39
|
description:
|
|
@@ -15,7 +15,7 @@ Install the core harness package, a harness adapter, and a sandbox adapter:
|
|
|
15
15
|
|
|
16
16
|
<InstallPackages packages="@ai-sdk/harness @ai-sdk/harness-claude-code @ai-sdk/sandbox-vercel" />
|
|
17
17
|
|
|
18
|
-
Bridge-backed harnesses such as Claude Code and Codex require using real network sandbox
|
|
18
|
+
Bridge-backed harnesses such as Claude Code and Codex require using a real network sandbox
|
|
19
19
|
like `@ai-sdk/sandbox-vercel`. Host-runtime harnesses such as Pi can also run with
|
|
20
20
|
`@ai-sdk/sandbox-just-bash` because they do not need a sandbox-exposed port.
|
|
21
21
|
|