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