ai 5.1.0-beta.2 → 5.1.0-beta.21

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,164 @@
1
1
  # ai
2
2
 
3
+ ## 5.1.0-beta.21
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [ef62178]
8
+ - @ai-sdk/gateway@1.1.0-beta.15
9
+
10
+ ## 5.1.0-beta.20
11
+
12
+ ### Patch Changes
13
+
14
+ - 846e80e: fix(ai): bind functions for v2 -> v3 adapter
15
+ - Updated dependencies [a90dca6]
16
+ - @ai-sdk/gateway@1.1.0-beta.14
17
+
18
+ ## 5.1.0-beta.19
19
+
20
+ ### Patch Changes
21
+
22
+ - aa0515c: feat(ai): move Agent to stable
23
+ - e7d9b00: feat(agent): add optional name property to agent
24
+ - b1aeea7: feat(ai): set default stopWhen on Agent to stepCountIs(20)
25
+
26
+ ## 5.1.0-beta.18
27
+
28
+ ### Patch Changes
29
+
30
+ - 0adc679: feat(provider): shared spec v3
31
+ - 9b8d17e: fix(agent): move provider options to main agent config
32
+ - Updated dependencies [0adc679]
33
+ - Updated dependencies [2b0caef]
34
+ - @ai-sdk/provider-utils@3.1.0-beta.6
35
+ - @ai-sdk/provider@2.1.0-beta.4
36
+ - @ai-sdk/gateway@1.1.0-beta.13
37
+
38
+ ## 5.1.0-beta.17
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies [e6bfe91]
43
+ - @ai-sdk/gateway@1.1.0-beta.12
44
+
45
+ ## 5.1.0-beta.16
46
+
47
+ ### Patch Changes
48
+
49
+ - 14ca35d: feat: add support for v2 specs
50
+ - Updated dependencies [636e614]
51
+ - @ai-sdk/gateway@1.1.0-beta.11
52
+
53
+ ## 5.1.0-beta.15
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [9f6149e]
58
+ - @ai-sdk/gateway@1.1.0-beta.10
59
+
60
+ ## 5.1.0-beta.14
61
+
62
+ ### Patch Changes
63
+
64
+ - 7c3c216: fixed docs and exported NoSpeechGeneratedError
65
+ - 8dac895: feat: `LanguageModelV3`
66
+ - e0d1ea9: fix(ai): align logic of text-end with reasoning-end
67
+ - 10c1322: fix: moved dependency `@ai-sdk/test-server` to devDependencies
68
+ - Updated dependencies [8dac895]
69
+ - @ai-sdk/provider-utils@3.1.0-beta.5
70
+ - @ai-sdk/provider@2.1.0-beta.3
71
+ - @ai-sdk/gateway@1.1.0-beta.9
72
+
73
+ ## 5.1.0-beta.13
74
+
75
+ ### Patch Changes
76
+
77
+ - 1c2a4c1: fix(ai): remove outdated jsdoc param descriptions
78
+
79
+ ## 5.1.0-beta.12
80
+
81
+ ### Patch Changes
82
+
83
+ - Updated dependencies [c823faf]
84
+ - @ai-sdk/gateway@1.1.0-beta.8
85
+
86
+ ## 5.1.0-beta.11
87
+
88
+ ### Patch Changes
89
+
90
+ - 4616b86: chore: update zod peer depenedency version
91
+ - Updated dependencies [4616b86]
92
+ - @ai-sdk/provider-utils@3.1.0-beta.4
93
+ - @ai-sdk/gateway@1.1.0-beta.7
94
+
95
+ ## 5.1.0-beta.10
96
+
97
+ ### Patch Changes
98
+
99
+ - 8c98371: Extend addToolResult to support error results
100
+
101
+ ## 5.1.0-beta.9
102
+
103
+ ### Patch Changes
104
+
105
+ - ed329cb: feat: `Provider-V3`
106
+ - 177b475: fix(ai): download files when intermediate file cannot be downloaded
107
+ - 522f6b8: feat: `ImageModelV3`
108
+ - Updated dependencies [aaf5ebf]
109
+ - Updated dependencies [ed329cb]
110
+ - Updated dependencies [522f6b8]
111
+ - @ai-sdk/gateway@1.1.0-beta.6
112
+ - @ai-sdk/provider@2.1.0-beta.2
113
+ - @ai-sdk/provider-utils@3.1.0-beta.3
114
+
115
+ ## 5.1.0-beta.8
116
+
117
+ ### Patch Changes
118
+
119
+ - 7eca093: fix(ai): update `uiMessageChunkSchema` to satisfy the `UIMessageChunk` type
120
+
121
+ ## 5.1.0-beta.7
122
+
123
+ ### Patch Changes
124
+
125
+ - 5a4e732: Export `parseJsonEventStream` and `uiMessageChunkSchema` from "ai" package
126
+
127
+ ## 5.1.0-beta.6
128
+
129
+ ### Patch Changes
130
+
131
+ - 0c4822d: feat: `EmbeddingModelV3`
132
+ - Updated dependencies [5d21222]
133
+ - Updated dependencies [0c4822d]
134
+ - Updated dependencies [1cad0ab]
135
+ - @ai-sdk/gateway@1.1.0-beta.5
136
+ - @ai-sdk/provider@2.1.0-beta.1
137
+ - @ai-sdk/provider-utils@3.1.0-beta.2
138
+
139
+ ## 5.1.0-beta.5
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [7ccb36f]
144
+ - Updated dependencies [6c766ef]
145
+ - @ai-sdk/gateway@1.1.0-beta.4
146
+
147
+ ## 5.1.0-beta.4
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies [ea9ca31]
152
+ - @ai-sdk/gateway@1.1.0-beta.3
153
+
154
+ ## 5.1.0-beta.3
155
+
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [3e83633]
159
+ - Updated dependencies [f83903d]
160
+ - @ai-sdk/gateway@1.1.0-beta.2
161
+
3
162
  ## 5.1.0-beta.2
4
163
 
5
164
  ### Patch Changes
package/README.md CHANGED
@@ -2,65 +2,169 @@
2
2
 
3
3
  # AI SDK
4
4
 
5
- The [AI SDK](https://ai-sdk.dev/docs) is a TypeScript toolkit designed to help you build AI-powered applications using popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.
5
+ The [AI SDK](https://ai-sdk.dev/docs) is a TypeScript toolkit designed to help you build AI-powered applications and agents using popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.
6
6
 
7
7
  To learn more about how to use the AI SDK, check out our [API Reference](https://ai-sdk.dev/docs/reference) and [Documentation](https://ai-sdk.dev/docs).
8
8
 
9
9
  ## Installation
10
10
 
11
- You will need Node.js 18+ and pnpm installed on your local development machine.
11
+ You will need Node.js 18+ and npm (or another package manager) installed on your local development machine.
12
12
 
13
13
  ```shell
14
14
  npm install ai
15
15
  ```
16
16
 
17
- ## Usage
18
-
19
- ### AI SDK Core
17
+ ## Unified Provider Architecture
20
18
 
21
- The [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core/overview) module provides a unified API to interact with model providers like [OpenAI](https://ai-sdk.dev/providers/ai-sdk-providers/openai), [Anthropic](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic), [Google](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai), and more.
22
-
23
- You will then install the model provider of your choice.
19
+ The AI SDK provides a [unified API](https://ai-sdk.dev/docs/foundations/providers-and-models) to interact with model providers like [OpenAI](https://ai-sdk.dev/providers/ai-sdk-providers/openai), [Anthropic](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic), [Google](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai), and [more](https://ai-sdk.dev/providers/ai-sdk-providers).
24
20
 
25
21
  ```shell
26
- npm install @ai-sdk/openai
22
+ npm install @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google
27
23
  ```
28
24
 
29
- ###### @/index.ts (Node.js Runtime)
25
+ Alternatively you can use the [Vercel AI Gateway](https://vercel.com/docs/ai-gateway).
26
+
27
+ ## Usage
28
+
29
+ ### Generating Text
30
30
 
31
31
  ```ts
32
32
  import { generateText } from 'ai';
33
- import { openai } from '@ai-sdk/openai'; // Ensure OPENAI_API_KEY environment variable is set
34
33
 
35
34
  const { text } = await generateText({
36
- model: openai('gpt-4o'),
37
- system: 'You are a friendly assistant!',
38
- prompt: 'Why is the sky blue?',
35
+ model: 'openai/gpt-5', // use Vercel AI Gateway
36
+ prompt: 'What is an agent?',
37
+ });
38
+ ```
39
+
40
+ ```ts
41
+ import { generateText } from 'ai';
42
+ import { openai } from '@ai-sdk/openai';
43
+
44
+ const { text } = await generateText({
45
+ model: openai('gpt-5'), // use OpenAI Responses API
46
+ prompt: 'What is an agent?',
47
+ });
48
+ ```
49
+
50
+ ### Generating Structured Data
51
+
52
+ ```ts
53
+ import { generateObject } from 'ai';
54
+ import { z } from 'zod';
55
+
56
+ const { object } = await generateObject({
57
+ model: 'openai/gpt-4.1',
58
+ schema: z.object({
59
+ recipe: z.object({
60
+ name: z.string(),
61
+ ingredients: z.array(z.object({ name: z.string(), amount: z.string() })),
62
+ steps: z.array(z.string()),
63
+ }),
64
+ }),
65
+ prompt: 'Generate a lasagna recipe.',
39
66
  });
67
+ ```
68
+
69
+ ### Agents
40
70
 
41
- console.log(text);
71
+ ```ts
72
+ import { Agent } from 'ai';
73
+
74
+ const sandboxAgent = new Agent({
75
+ model: 'openai/gpt-5-codex',
76
+ system: 'You are an agent with access to a shell environment.',
77
+ tools: {
78
+ local_shell: openai.tools.localShell({
79
+ execute: async ({ action }) => {
80
+ const [cmd, ...args] = action.command;
81
+ const sandbox = await getSandbox(); // Vercel Sandbox
82
+ const command = await sandbox.runCommand({ cmd, args });
83
+ return { output: await command.stdout() };
84
+ },
85
+ }),
86
+ },
87
+ });
42
88
  ```
43
89
 
44
- ### AI SDK UI
90
+ ### UI Integration
45
91
 
46
92
  The [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, and Vue.
47
93
 
48
- You need to install the package for your framework:
94
+ You need to install the package for your framework, e.g.:
49
95
 
50
96
  ```shell
51
97
  npm install @ai-sdk/react
52
98
  ```
53
99
 
54
- ###### @/app/page.tsx (Next.js App Router)
100
+ #### Agent @/agent/image-generation-agent.ts
101
+
102
+ ```ts
103
+ import { openai } from '@ai-sdk/openai';
104
+ import { Agent, InferAgentUIMessage } from 'ai';
105
+
106
+ export const imageGenerationAgent = new Agent({
107
+ model: openai('gpt-5'),
108
+ tools: {
109
+ image_generation: openai.tools.imageGeneration({
110
+ partialImages: 3,
111
+ }),
112
+ },
113
+ });
114
+
115
+ export type ImageGenerationAgentMessage = InferAgentUIMessage<
116
+ typeof imageGenerationAgent
117
+ >;
118
+ ```
119
+
120
+ #### Route (Next.js App Router) @/app/api/chat/route.ts
121
+
122
+ ```tsx
123
+ import { imageGenerationAgent } from '@/agent/image-generation-agent';
124
+ import { validateUIMessages } from 'ai';
125
+
126
+ export async function POST(req: Request) {
127
+ const { messages } = await req.json();
128
+
129
+ return imageGenerationAgent.respond({
130
+ messages: await validateUIMessages({ messages }),
131
+ });
132
+ }
133
+ ```
134
+
135
+ #### UI Component for Tool @/component/image-generation-view.tsx
136
+
137
+ ```tsx
138
+ import { openai } from '@ai-sdk/openai';
139
+ import { UIToolInvocation } from 'ai';
140
+
141
+ export default function ImageGenerationView({
142
+ invocation,
143
+ }: {
144
+ invocation: UIToolInvocation<ReturnType<typeof openai.tools.imageGeneration>>;
145
+ }) {
146
+ switch (invocation.state) {
147
+ case 'input-available':
148
+ return <div>Generating image...</div>;
149
+ case 'output-available':
150
+ return <img src={`data:image/png;base64,${invocation.output.result}`} />;
151
+ }
152
+ }
153
+ ```
154
+
155
+ #### Page @/app/page.tsx
55
156
 
56
157
  ```tsx
57
158
  'use client';
58
159
 
59
- import { useState } from 'react';
160
+ import { ImageGenerationAgentMessage } from '@/agent/image-generation-agent';
161
+ import ImageGenerationView from '@/component/image-generation-view';
60
162
  import { useChat } from '@ai-sdk/react';
61
163
 
62
164
  export default function Page() {
63
- const { messages, status, sendMessage } = useChat();
165
+ const { messages, status, sendMessage } =
166
+ useChat<ImageGenerationAgentMessage>();
167
+
64
168
  const [input, setInput] = useState('');
65
169
  const handleSubmit = e => {
66
170
  e.preventDefault();
@@ -76,9 +180,9 @@ export default function Page() {
76
180
  {message.parts.map((part, index) => {
77
181
  switch (part.type) {
78
182
  case 'text':
79
- return <span key={index}>{part.text}</span>;
80
-
81
- // other cases can handle images, tool calls, etc
183
+ return <div key={index}>{part.text}</div>;
184
+ case 'tool-image_generation':
185
+ return <ImageGenerationView key={index} invocation={part} />;
82
186
  }
83
187
  })}
84
188
  </div>
@@ -87,7 +191,6 @@ export default function Page() {
87
191
  <form onSubmit={handleSubmit}>
88
192
  <input
89
193
  value={input}
90
- placeholder="Send a message..."
91
194
  onChange={e => setInput(e.target.value)}
92
195
  disabled={status !== 'ready'}
93
196
  />
@@ -97,28 +200,9 @@ export default function Page() {
97
200
  }
98
201
  ```
99
202
 
100
- ###### @/app/api/chat/route.ts (Next.js App Router)
101
-
102
- ```ts
103
- import { streamText } from 'ai';
104
- import { openai } from '@ai-sdk/openai';
105
-
106
- export async function POST(req: Request) {
107
- const { messages } = await req.json();
108
-
109
- const result = streamText({
110
- model: openai('gpt-4o'),
111
- system: 'You are a helpful assistant.',
112
- messages,
113
- });
114
-
115
- return result.toUIMessageStreamResponse();
116
- }
117
- ```
118
-
119
203
  ## Templates
120
204
 
121
- We've built [templates](https://vercel.com/templates?type=ai) that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.
205
+ We've built [templates](https://ai-sdk.dev/docs/introduction#templates) that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.
122
206
 
123
207
  ## Community
124
208