ai 5.1.0-beta.9 → 6.0.0-beta.30

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,179 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.0-beta.30
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7b1b1b1]
8
+ - @ai-sdk/gateway@2.0.0-beta.21
9
+
10
+ ## 6.0.0-beta.29
11
+
12
+ ### Major Changes
13
+
14
+ - dee8b05: ai SDK 6 beta
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [dee8b05]
19
+ - @ai-sdk/gateway@2.0.0-beta.20
20
+ - @ai-sdk/provider@3.0.0-beta.6
21
+ - @ai-sdk/provider-utils@4.0.0-beta.10
22
+
23
+ ## 5.1.0-beta.28
24
+
25
+ ### Patch Changes
26
+
27
+ - 521c537: feat(ai): Tool.needsApproval can be a function
28
+ - Updated dependencies [521c537]
29
+ - @ai-sdk/provider-utils@3.1.0-beta.9
30
+ - @ai-sdk/gateway@1.1.0-beta.19
31
+
32
+ ## 5.1.0-beta.27
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [e06565c]
37
+ - @ai-sdk/provider-utils@3.1.0-beta.8
38
+ - @ai-sdk/gateway@1.1.0-beta.18
39
+
40
+ ## 5.1.0-beta.26
41
+
42
+ ### Patch Changes
43
+
44
+ - c99da05: feat(ai): add onFinish to Agent
45
+
46
+ ## 5.1.0-beta.25
47
+
48
+ ### Patch Changes
49
+
50
+ - 457f1c6: feat(ai): onFinish callback for generateText
51
+
52
+ ## 5.1.0-beta.24
53
+
54
+ ### Patch Changes
55
+
56
+ - 90e5bdd: chore(ai): restructure agent files
57
+
58
+ ## 5.1.0-beta.23
59
+
60
+ ### Patch Changes
61
+
62
+ - Updated dependencies [1d8ea2c]
63
+ - @ai-sdk/gateway@1.1.0-beta.17
64
+
65
+ ## 5.1.0-beta.22
66
+
67
+ ### Patch Changes
68
+
69
+ - 046aa3b: feat(provider): speech model v3 spec
70
+ - e8109d3: feat: tool execution approval
71
+ - a5e152d: fix(ai): back version support for V2 providers
72
+ - 21e20c0: feat(provider): transcription model v3 spec
73
+ - Updated dependencies [046aa3b]
74
+ - Updated dependencies [e8109d3]
75
+ - @ai-sdk/provider@2.1.0-beta.5
76
+ - @ai-sdk/provider-utils@3.1.0-beta.7
77
+ - @ai-sdk/gateway@1.1.0-beta.16
78
+
79
+ ## 5.1.0-beta.21
80
+
81
+ ### Patch Changes
82
+
83
+ - Updated dependencies [ef62178]
84
+ - @ai-sdk/gateway@1.1.0-beta.15
85
+
86
+ ## 5.1.0-beta.20
87
+
88
+ ### Patch Changes
89
+
90
+ - 846e80e: fix(ai): bind functions for v2 -> v3 adapter
91
+ - Updated dependencies [a90dca6]
92
+ - @ai-sdk/gateway@1.1.0-beta.14
93
+
94
+ ## 5.1.0-beta.19
95
+
96
+ ### Patch Changes
97
+
98
+ - aa0515c: feat(ai): move Agent to stable
99
+ - e7d9b00: feat(agent): add optional name property to agent
100
+ - b1aeea7: feat(ai): set default stopWhen on Agent to stepCountIs(20)
101
+
102
+ ## 5.1.0-beta.18
103
+
104
+ ### Patch Changes
105
+
106
+ - 0adc679: feat(provider): shared spec v3
107
+ - 9b8d17e: fix(agent): move provider options to main agent config
108
+ - Updated dependencies [0adc679]
109
+ - Updated dependencies [2b0caef]
110
+ - @ai-sdk/provider-utils@3.1.0-beta.6
111
+ - @ai-sdk/provider@2.1.0-beta.4
112
+ - @ai-sdk/gateway@1.1.0-beta.13
113
+
114
+ ## 5.1.0-beta.17
115
+
116
+ ### Patch Changes
117
+
118
+ - Updated dependencies [e6bfe91]
119
+ - @ai-sdk/gateway@1.1.0-beta.12
120
+
121
+ ## 5.1.0-beta.16
122
+
123
+ ### Patch Changes
124
+
125
+ - 14ca35d: feat: add support for v2 specs
126
+ - Updated dependencies [636e614]
127
+ - @ai-sdk/gateway@1.1.0-beta.11
128
+
129
+ ## 5.1.0-beta.15
130
+
131
+ ### Patch Changes
132
+
133
+ - Updated dependencies [9f6149e]
134
+ - @ai-sdk/gateway@1.1.0-beta.10
135
+
136
+ ## 5.1.0-beta.14
137
+
138
+ ### Patch Changes
139
+
140
+ - 7c3c216: fixed docs and exported NoSpeechGeneratedError
141
+ - 8dac895: feat: `LanguageModelV3`
142
+ - e0d1ea9: fix(ai): align logic of text-end with reasoning-end
143
+ - 10c1322: fix: moved dependency `@ai-sdk/test-server` to devDependencies
144
+ - Updated dependencies [8dac895]
145
+ - @ai-sdk/provider-utils@3.1.0-beta.5
146
+ - @ai-sdk/provider@2.1.0-beta.3
147
+ - @ai-sdk/gateway@1.1.0-beta.9
148
+
149
+ ## 5.1.0-beta.13
150
+
151
+ ### Patch Changes
152
+
153
+ - 1c2a4c1: fix(ai): remove outdated jsdoc param descriptions
154
+
155
+ ## 5.1.0-beta.12
156
+
157
+ ### Patch Changes
158
+
159
+ - Updated dependencies [c823faf]
160
+ - @ai-sdk/gateway@1.1.0-beta.8
161
+
162
+ ## 5.1.0-beta.11
163
+
164
+ ### Patch Changes
165
+
166
+ - 4616b86: chore: update zod peer depenedency version
167
+ - Updated dependencies [4616b86]
168
+ - @ai-sdk/provider-utils@3.1.0-beta.4
169
+ - @ai-sdk/gateway@1.1.0-beta.7
170
+
171
+ ## 5.1.0-beta.10
172
+
173
+ ### Patch Changes
174
+
175
+ - 8c98371: Extend addToolResult to support error results
176
+
3
177
  ## 5.1.0-beta.9
4
178
 
5
179
  ### 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