ai 6.0.315 → 6.0.317

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.317
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [90fad7b]
8
+ - @ai-sdk/gateway@3.0.223
9
+
10
+ ## 6.0.316
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [fe96bb3]
15
+ - @ai-sdk/gateway@3.0.222
16
+
3
17
  ## 6.0.315
4
18
 
5
19
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1335,7 +1335,7 @@ function detectMediaType({
1335
1335
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1336
1336
 
1337
1337
  // src/version.ts
1338
- var VERSION = true ? "6.0.315" : "0.0.0-test";
1338
+ var VERSION = true ? "6.0.317" : "0.0.0-test";
1339
1339
 
1340
1340
  // src/util/download/download.ts
1341
1341
  var download = async ({
package/dist/index.mjs CHANGED
@@ -1225,7 +1225,7 @@ import {
1225
1225
  } from "@ai-sdk/provider-utils";
1226
1226
 
1227
1227
  // src/version.ts
1228
- var VERSION = true ? "6.0.315" : "0.0.0-test";
1228
+ var VERSION = true ? "6.0.317" : "0.0.0-test";
1229
1229
 
1230
1230
  // src/util/download/download.ts
1231
1231
  var download = async ({
@@ -164,7 +164,7 @@ function detectMediaType({
164
164
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
165
165
 
166
166
  // src/version.ts
167
- var VERSION = true ? "6.0.315" : "0.0.0-test";
167
+ var VERSION = true ? "6.0.317" : "0.0.0-test";
168
168
 
169
169
  // src/util/download/download.ts
170
170
  var download = async ({
@@ -144,7 +144,7 @@ import {
144
144
  } from "@ai-sdk/provider-utils";
145
145
 
146
146
  // src/version.ts
147
- var VERSION = true ? "6.0.315" : "0.0.0-test";
147
+ var VERSION = true ? "6.0.317" : "0.0.0-test";
148
148
 
149
149
  // src/util/download/download.ts
150
150
  var download = async ({
@@ -27,8 +27,8 @@ Start by creating a new Next.js application. This command will create a new dire
27
27
  <div className="mb-4">
28
28
  <Note>
29
29
  Be sure to select yes when prompted to use the App Router and Tailwind CSS.
30
- If you are looking for the Next.js Pages Router quickstart guide, you can
31
- find it [here](/docs/getting-started/nextjs-pages-router).
30
+ If you are adding the AI SDK to an existing Pages Router application, follow
31
+ the [Pages Router guide](/docs/getting-started/nextjs-pages-router).
32
32
  </Note>
33
33
  </div>
34
34
 
@@ -293,7 +293,6 @@ In this updated code:
293
293
 
294
294
  1. You import the `tool` function from the `ai` package and `z` from `zod` for schema validation.
295
295
  2. You define a `tools` object with a `weather` tool. This tool:
296
-
297
296
  - Has a description that helps the model understand when to use it.
298
297
  - Defines `inputSchema` using a Zod schema, specifying that it requires a `location` string to execute this tool. The model will attempt to extract this input from the context of the conversation. If it can't, it will ask the user for the missing information.
299
298
  - Defines an `execute` function that simulates getting weather data (in this case, it returns a random temperature). This is an asynchronous function running on the server so you can fetch real data from an external API.
@@ -0,0 +1,313 @@
1
+ ---
2
+ title: Angular
3
+ description: Learn how to build your first agent with the AI SDK and Angular.
4
+ ---
5
+
6
+ # Angular Quickstart
7
+
8
+ The AI SDK is a powerful TypeScript library designed to help developers build AI-powered applications.
9
+
10
+ In this quickstart tutorial, you'll build a simple agent with a streaming chat user interface using Angular and an Express backend. Along the way, you'll learn key concepts and techniques that are fundamental to using the AI SDK in your own projects.
11
+
12
+ If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/prompt-engineering) and [HTTP Streaming](/docs/foundations/streaming), you can optionally read these documents first.
13
+
14
+ ## Prerequisites
15
+
16
+ To follow this quickstart, you'll need:
17
+
18
+ - Node.js 24.15+ (or another [version supported by Angular](https://angular.dev/reference/versions)) and pnpm installed on your local development machine.
19
+ - A [Vercel AI Gateway](https://vercel.com/ai-gateway) API key.
20
+
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
+
23
+ ## Set Up Your Application
24
+
25
+ Create a new Angular application using the Angular CLI:
26
+
27
+ <Snippet text="pnpm dlx @angular/cli@latest new my-ai-app --defaults --ssr=false --package-manager=pnpm" />
28
+
29
+ This creates a standalone Angular application. This guide uses client-side rendering, with a separate Express server for the chat API.
30
+
31
+ Navigate to the newly created directory:
32
+
33
+ <Snippet text="cd my-ai-app" />
34
+
35
+ ### Install Dependencies
36
+
37
+ Install `ai` and `@ai-sdk/angular`, the AI package and AI SDK's Angular bindings. You'll also install `express` for the backend, `dotenv` to load environment variables, and `zod` to define tool inputs.
38
+
39
+ <InstallPackages packages="ai@^6 @ai-sdk/angular@^2 express dotenv zod" />
40
+
41
+ Install the TypeScript runner and server type definitions:
42
+
43
+ <InstallPackages packages="tsx @types/express @types/node" dev />
44
+
45
+ <Note>
46
+ This guide uses the Vercel AI Gateway provider, which ships with the `ai`
47
+ package. You can access hundreds of models with one API key, or switch to
48
+ another [AI SDK provider](/providers/ai-sdk-providers).
49
+ </Note>
50
+
51
+ ### Configure Your AI Gateway API Key
52
+
53
+ Create a `.env` file in your project root:
54
+
55
+ ```env filename=".env"
56
+ AI_GATEWAY_API_KEY=xxxxxxxxx
57
+ ```
58
+
59
+ Replace `xxxxxxxxx` with your actual Vercel AI Gateway API key. The Express server loads this file using `dotenv`, and the AI SDK's Gateway provider reads `AI_GATEWAY_API_KEY` automatically. Keep the API key on the server and add `.env` to `.gitignore`.
60
+
61
+ ## Create an API Route
62
+
63
+ Create `server.ts` in your project root and add the following code:
64
+
65
+ ```ts filename="server.ts"
66
+ import { streamText, type UIMessage, convertToModelMessages } from 'ai';
67
+ __PROVIDER_IMPORT__;
68
+ import 'dotenv/config';
69
+ import express from 'express';
70
+
71
+ const app = express();
72
+ app.use(express.json());
73
+
74
+ app.post('/api/chat', async (req, res) => {
75
+ const { messages }: { messages: UIMessage[] } = req.body;
76
+
77
+ const result = streamText({
78
+ model: __MODEL__,
79
+ messages: await convertToModelMessages(messages),
80
+ });
81
+
82
+ await result.pipeUIMessageStreamToResponse(res);
83
+ });
84
+
85
+ app.listen(3000, '127.0.0.1', () => {
86
+ console.log('Chat API listening on http://127.0.0.1:3000');
87
+ });
88
+ ```
89
+
90
+ The server listens on `127.0.0.1` to keep the development API local to your machine. This creates a `POST /api/chat` endpoint. Let's take a look at what happens when it receives a request:
91
+
92
+ 1. `express.json()` parses the request body, which contains the conversation's `UIMessage` objects.
93
+ 2. [`convertToModelMessages`](/docs/reference/ai-sdk-ui/convert-to-model-messages) converts those UI messages to the format expected by the model.
94
+ 3. [`streamText`](/docs/reference/ai-sdk-core/stream-text) calls the model through AI Gateway.
95
+ 4. `result.pipeUIMessageStreamToResponse` converts the model's output to the UI message stream format and writes it to the Express response as server-sent events.
96
+
97
+ ### Configure the Development Proxy
98
+
99
+ Create `proxy.conf.json` in your project root:
100
+
101
+ ```json filename="proxy.conf.json"
102
+ {
103
+ "/api/**": {
104
+ "target": "http://127.0.0.1:3000"
105
+ }
106
+ }
107
+ ```
108
+
109
+ When you start Angular with this proxy configuration, requests to `/api/chat` are forwarded to the Express server. The browser can use the relative `/api/chat` URL, which is also the default endpoint for the AI SDK's `Chat` class.
110
+
111
+ <Note>
112
+ This proxy is for local development. When deploying, route `/api/chat` to your
113
+ backend, or configure a different API URL using
114
+ [`DefaultChatTransport`](/docs/ai-sdk-ui/transport).
115
+ </Note>
116
+
117
+ ## Choosing a Provider
118
+
119
+ 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.
120
+
121
+ 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). You can select a model using a string in your server's configuration:
122
+
123
+ ```ts
124
+ model: __MODEL__;
125
+ ```
126
+
127
+ To use a provider directly, install its package and create a provider instance. Learn more about [provider management](/docs/ai-sdk-core/provider-management#global-provider-configuration).
128
+
129
+ ## Wire Up the UI
130
+
131
+ The `@ai-sdk/angular` package provides a `Chat` class that manages messages, streams responses, and exposes the current request status. Its state is backed by Angular signals, so the template updates as new content arrives.
132
+
133
+ Replace `src/app/app.ts` with the following component:
134
+
135
+ ```ts filename="src/app/app.ts"
136
+ import { JsonPipe } from '@angular/common';
137
+ import { Component, signal } from '@angular/core';
138
+ import { Chat } from '@ai-sdk/angular';
139
+
140
+ @Component({
141
+ selector: 'app-root',
142
+ imports: [JsonPipe],
143
+ template: `
144
+ <main>
145
+ @for (message of chat.messages; track message.id) {
146
+ <div>
147
+ <strong>{{ message.role === 'user' ? 'User' : 'AI' }}:</strong>
148
+ @for (part of message.parts; track $index) {
149
+ @if (part.type === 'text') {
150
+ <p style="white-space: pre-wrap">{{ part.text }}</p>
151
+ } @else if (part.type.startsWith('tool-')) {
152
+ <pre>{{ part | json }}</pre>
153
+ }
154
+ }
155
+ </div>
156
+ }
157
+
158
+ @if (chat.status === 'submitted') {
159
+ <p>Waiting for a response...</p>
160
+ }
161
+
162
+ @if (chat.error; as error) {
163
+ <p role="alert">{{ error.message }}</p>
164
+ }
165
+
166
+ <form (submit)="sendMessage($event)">
167
+ <label for="message">Your message</label>
168
+ <input
169
+ id="message"
170
+ #messageInput
171
+ [value]="input()"
172
+ (input)="input.set(messageInput.value)"
173
+ />
174
+ <button
175
+ type="submit"
176
+ [disabled]="
177
+ chat.status === 'submitted' || chat.status === 'streaming'
178
+ "
179
+ >
180
+ Send
181
+ </button>
182
+ @if (chat.status === 'submitted' || chat.status === 'streaming') {
183
+ <button type="button" (click)="chat.stop()">Stop</button>
184
+ }
185
+ </form>
186
+ </main>
187
+ `,
188
+ })
189
+ export class App {
190
+ readonly chat = new Chat({});
191
+ readonly input = signal('');
192
+
193
+ sendMessage(event: Event) {
194
+ event.preventDefault();
195
+ const text = this.input().trim();
196
+
197
+ if (
198
+ !text ||
199
+ this.chat.status === 'submitted' ||
200
+ this.chat.status === 'streaming'
201
+ ) {
202
+ return;
203
+ }
204
+
205
+ this.chat.sendMessage({ text });
206
+ this.input.set('');
207
+ }
208
+ }
209
+ ```
210
+
211
+ <Note>
212
+ Older Angular projects may name the root component file `app.component.ts` and
213
+ its class `AppComponent`. If you are using an existing project, keep its file
214
+ and class names so the imports in `src/main.ts` continue to work.
215
+ </Note>
216
+
217
+ The component creates one `Chat` instance and uses its reactive properties:
218
+
219
+ - `messages` contains the conversation. Each message has a `role` and an ordered array of `parts`.
220
+ - `sendMessage` sends a user message to `/api/chat` and streams the response into `messages`.
221
+ - `status` indicates whether the chat is ready, submitted, streaming, or in an error state.
222
+ - `error` contains the latest request error.
223
+ - `stop` cancels the current response.
224
+
225
+ Read these properties as `chat.messages`, `chat.status`, and `chat.error`; the `Chat` class manages the underlying signals. The input field uses a separate Angular signal, which is read with `input()`.
226
+
227
+ The template renders text parts as they arrive and uses Angular's `JsonPipe` to display tool calls and results, which you'll add next.
228
+
229
+ ## Running Your Application
230
+
231
+ In one terminal, start the Express backend from your project root:
232
+
233
+ <Snippet text="pnpm exec tsx watch server.ts" />
234
+
235
+ In a second terminal, start the Angular development server from the same directory:
236
+
237
+ <Snippet text="pnpm exec ng serve --proxy-config proxy.conf.json" />
238
+
239
+ Open [http://localhost:4200](http://localhost:4200), enter a message, and watch the response stream into the chat interface.
240
+
241
+ <Note>
242
+ If you change `proxy.conf.json`, restart the Angular development server so it
243
+ picks up the new configuration.
244
+ </Note>
245
+
246
+ ## Enhance Your Chatbot with Tools
247
+
248
+ [Tools](/docs/ai-sdk-core/tools-and-tool-calling) let a model request actions such as looking up the weather. The server executes the action and returns the result to the model.
249
+
250
+ Replace `server.ts` with the following code to add a weather tool:
251
+
252
+ ```ts filename="server.ts"
253
+ import {
254
+ streamText,
255
+ type UIMessage,
256
+ convertToModelMessages,
257
+ tool,
258
+ stepCountIs,
259
+ } from 'ai';
260
+ __PROVIDER_IMPORT__;
261
+ import 'dotenv/config';
262
+ import express from 'express';
263
+ import * as z4 from 'zod/v4';
264
+
265
+ const app = express();
266
+ app.use(express.json());
267
+
268
+ app.post('/api/chat', async (req, res) => {
269
+ const { messages }: { messages: UIMessage[] } = req.body;
270
+
271
+ const result = streamText({
272
+ model: __MODEL__,
273
+ messages: await convertToModelMessages(messages),
274
+ stopWhen: stepCountIs(5),
275
+ tools: {
276
+ weather: tool({
277
+ description: 'Get the weather in a location (fahrenheit)',
278
+ inputSchema: z4.object({
279
+ location: z4.string().describe('The location to get the weather for'),
280
+ }),
281
+ execute: async ({ location }) => {
282
+ const temperature = Math.round(Math.random() * (90 - 32) + 32);
283
+ return { location, temperature };
284
+ },
285
+ }),
286
+ },
287
+ });
288
+
289
+ await result.pipeUIMessageStreamToResponse(res);
290
+ });
291
+
292
+ app.listen(3000, '127.0.0.1', () => {
293
+ console.log('Chat API listening on http://127.0.0.1:3000');
294
+ });
295
+ ```
296
+
297
+ The `weather` tool has a description, an input schema, and an `execute` function. The model uses the description to decide when to call the tool and the schema to generate its input. The server then executes the function and returns its result.
298
+
299
+ This example returns a simulated temperature. You can replace the function with a call to a weather API to return real data.
300
+
301
+ ### Enabling Multi-Step Tool Calls
302
+
303
+ By default, a generation stops after one step. Setting `stopWhen: stepCountIs(5)` allows the model to continue after receiving a tool result, for up to five steps. It can use the returned weather data to answer the original question.
304
+
305
+ Ask "What's the weather in San Francisco?" in your chat interface. The template displays the `tool-weather` part as JSON, followed by the model's text response. No frontend changes are required: the `Chat` class already handles tool parts in the UI message stream.
306
+
307
+ ## Where to Go Next
308
+
309
+ You've built an Angular chat interface that streams responses, calls tools, and uses their results in multi-step generations.
310
+
311
+ - Explore the [Angular example](https://github.com/vercel/ai/tree/main/examples/angular) for chat, completion, and structured output examples.
312
+ - Learn more about [AI SDK UI](/docs/ai-sdk-ui/overview) and [tools and tool calling](/docs/ai-sdk-core/tools-and-tool-calling).
313
+ - Use the [transport API](/docs/ai-sdk-ui/transport) to connect your Angular frontend to an existing backend.
@@ -1,40 +1,32 @@
1
1
  ---
2
2
  title: Next.js Pages Router
3
- description: Learn how to build your first agent with the AI SDK and Next.js Pages Router.
3
+ description: Add an agent with a streaming chat interface to an existing Next.js Pages Router application.
4
4
  ---
5
5
 
6
- # Next.js Pages Router Quickstart
6
+ # Next.js Pages Router Guide
7
7
 
8
- The AI SDK is a powerful TypeScript library designed to help developers build AI-powered applications.
8
+ This guide shows how to add an agent with a streaming chat user interface to an existing Next.js Pages Router application.
9
9
 
10
- In this quickstart tutorial, you'll build a simple agent with a streaming chat user interface. Along the way, you'll learn key concepts and techniques that are fundamental to using the AI SDK in your own projects.
10
+ <Note>
11
+ For new applications, we recommend the [Next.js App Router
12
+ quickstart](/docs/getting-started/nextjs-app-router).
13
+ </Note>
11
14
 
12
15
  If you are unfamiliar with the concepts of [Prompt Engineering](/docs/advanced/prompt-engineering) and [HTTP Streaming](/docs/foundations/streaming), you can optionally read these documents first.
13
16
 
14
17
  ## Prerequisites
15
18
 
16
- To follow this quickstart, you'll need:
19
+ To follow this guide, you'll need:
17
20
 
21
+ - An existing Next.js 13+ application using the Pages Router.
18
22
  - Node.js 18+ and pnpm installed on your local development machine.
19
23
  - A [ Vercel AI Gateway ](https://vercel.com/ai-gateway) API key.
20
24
 
21
25
  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
26
 
23
- ## Setup Your Application
24
-
25
- Start by creating a new Next.js application. This command will create a new directory named `my-ai-app` and set up a basic Next.js application inside it.
27
+ ## Set Up Your Application
26
28
 
27
- <Note>
28
- Be sure to select no when prompted to use the App Router. If you are looking
29
- for the Next.js App Router quickstart guide, you can find it
30
- [here](/docs/getting-started/nextjs-app-router).
31
- </Note>
32
-
33
- <Snippet text="pnpm create next-app@latest my-ai-app" />
34
-
35
- Navigate to the newly created directory:
36
-
37
- <Snippet text="cd my-ai-app" />
29
+ Open a terminal in the root directory of your existing Next.js Pages Router application.
38
30
 
39
31
  ### Install dependencies
40
32
 
@@ -124,7 +116,7 @@ This Route Handler creates a POST request endpoint at `/api/chat`.
124
116
 
125
117
  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.
126
118
 
127
- 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
+ This guide 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:
128
120
 
129
121
  ```ts
130
122
  model: __MODEL__;
@@ -288,7 +280,6 @@ In this updated code:
288
280
 
289
281
  1. You import the `tool` function from the `ai` package and `z` from `zod` for schema validation.
290
282
  2. You define a `tools` object with a `weather` tool. This tool:
291
-
292
283
  - Has a description that helps the model understand when to use it.
293
284
  - Defines `inputSchema` using a Zod schema, specifying that it requires a `location` string to execute this tool. The model will attempt to extract this input from the context of the conversation. If it can't, it will ask the user for the missing information.
294
285
  - Defines an `execute` function that simulates getting weather data (in this case, it returns a random temperature). This is an asynchronous function running on the server so you can fetch real data from an external API.
@@ -9,6 +9,8 @@ The following guides are intended to provide you with an introduction to some of
9
9
 
10
10
  <QuickstartFrameworkCards />
11
11
 
12
+ [Using an existing Next.js Pages Router app?](/docs/getting-started/nextjs-pages-router)
13
+
12
14
  ## Backend Framework Examples
13
15
 
14
16
  You can also use [AI SDK Core](/docs/ai-sdk-core/overview) and [AI SDK UI](/docs/ai-sdk-ui/overview) with the following backend frameworks:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "6.0.315",
3
+ "version": "6.0.317",
4
4
  "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.",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@opentelemetry/api": "^1.9.0",
48
- "@ai-sdk/gateway": "3.0.221",
48
+ "@ai-sdk/gateway": "3.0.223",
49
49
  "@ai-sdk/provider": "3.0.19",
50
50
  "@ai-sdk/provider-utils": "4.0.62"
51
51
  },
@@ -58,7 +58,7 @@
58
58
  "tsx": "^4.19.2",
59
59
  "typescript": "5.8.3",
60
60
  "zod": "3.25.76",
61
- "@ai-sdk/google": "3.0.138",
61
+ "@ai-sdk/google": "3.0.139",
62
62
  "@ai-sdk/test-server": "1.0.6",
63
63
  "@vercel/ai-tsconfig": "0.0.0"
64
64
  },