@zenning/ai 5.1.0 → 5.2.0

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,165 @@
1
1
  # ai
2
2
 
3
+ ## 5.1.0-beta.19
4
+
5
+ ### Patch Changes
6
+
7
+ - aa0515c: feat(ai): move Agent to stable
8
+ - e7d9b00: feat(agent): add optional name property to agent
9
+ - b1aeea7: feat(ai): set default stopWhen on Agent to stepCountIs(20)
10
+
11
+ ## 5.1.0-beta.18
12
+
13
+ ### Patch Changes
14
+
15
+ - 0adc679: feat(provider): shared spec v3
16
+ - 9b8d17e: fix(agent): move provider options to main agent config
17
+ - Updated dependencies [0adc679]
18
+ - Updated dependencies [2b0caef]
19
+ - @ai-sdk/provider-utils@3.1.0-beta.6
20
+ - @ai-sdk/provider@2.1.0-beta.4
21
+ - @ai-sdk/gateway@1.1.0-beta.13
22
+
23
+ ## 5.1.0-beta.17
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [e6bfe91]
28
+ - @ai-sdk/gateway@1.1.0-beta.12
29
+
30
+ ## 5.1.0-beta.16
31
+
32
+ ### Patch Changes
33
+
34
+ - 14ca35d: feat: add support for v2 specs
35
+ - Updated dependencies [636e614]
36
+ - @ai-sdk/gateway@1.1.0-beta.11
37
+
38
+ ## 5.1.0-beta.15
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies [9f6149e]
43
+ - @ai-sdk/gateway@1.1.0-beta.10
44
+
45
+ ## 5.1.0-beta.14
46
+
47
+ ### Patch Changes
48
+
49
+ - 7c3c216: fixed docs and exported NoSpeechGeneratedError
50
+ - 8dac895: feat: `LanguageModelV3`
51
+ - e0d1ea9: fix(ai): align logic of text-end with reasoning-end
52
+ - 10c1322: fix: moved dependency `@ai-sdk/test-server` to devDependencies
53
+ - Updated dependencies [8dac895]
54
+ - @ai-sdk/provider-utils@3.1.0-beta.5
55
+ - @ai-sdk/provider@2.1.0-beta.3
56
+ - @ai-sdk/gateway@1.1.0-beta.9
57
+
58
+ ## 5.1.0-beta.13
59
+
60
+ ### Patch Changes
61
+
62
+ - 1c2a4c1: fix(ai): remove outdated jsdoc param descriptions
63
+
64
+ ## 5.1.0-beta.12
65
+
66
+ ### Patch Changes
67
+
68
+ - Updated dependencies [c823faf]
69
+ - @ai-sdk/gateway@1.1.0-beta.8
70
+
71
+ ## 5.1.0-beta.11
72
+
73
+ ### Patch Changes
74
+
75
+ - 4616b86: chore: update zod peer depenedency version
76
+ - Updated dependencies [4616b86]
77
+ - @ai-sdk/provider-utils@3.1.0-beta.4
78
+ - @ai-sdk/gateway@1.1.0-beta.7
79
+
80
+ ## 5.1.0-beta.10
81
+
82
+ ### Patch Changes
83
+
84
+ - 8c98371: Extend addToolResult to support error results
85
+
86
+ ## 5.1.0-beta.9
87
+
88
+ ### Patch Changes
89
+
90
+ - ed329cb: feat: `Provider-V3`
91
+ - 177b475: fix(ai): download files when intermediate file cannot be downloaded
92
+ - 522f6b8: feat: `ImageModelV3`
93
+ - Updated dependencies [aaf5ebf]
94
+ - Updated dependencies [ed329cb]
95
+ - Updated dependencies [522f6b8]
96
+ - @ai-sdk/gateway@1.1.0-beta.6
97
+ - @ai-sdk/provider@2.1.0-beta.2
98
+ - @ai-sdk/provider-utils@3.1.0-beta.3
99
+
100
+ ## 5.1.0-beta.8
101
+
102
+ ### Patch Changes
103
+
104
+ - 7eca093: fix(ai): update `uiMessageChunkSchema` to satisfy the `UIMessageChunk` type
105
+
106
+ ## 5.1.0-beta.7
107
+
108
+ ### Patch Changes
109
+
110
+ - 5a4e732: Export `parseJsonEventStream` and `uiMessageChunkSchema` from "ai" package
111
+
112
+ ## 5.1.0-beta.6
113
+
114
+ ### Patch Changes
115
+
116
+ - 0c4822d: feat: `EmbeddingModelV3`
117
+ - Updated dependencies [5d21222]
118
+ - Updated dependencies [0c4822d]
119
+ - Updated dependencies [1cad0ab]
120
+ - @ai-sdk/gateway@1.1.0-beta.5
121
+ - @ai-sdk/provider@2.1.0-beta.1
122
+ - @ai-sdk/provider-utils@3.1.0-beta.2
123
+
124
+ ## 5.1.0-beta.5
125
+
126
+ ### Patch Changes
127
+
128
+ - Updated dependencies [7ccb36f]
129
+ - Updated dependencies [6c766ef]
130
+ - @ai-sdk/gateway@1.1.0-beta.4
131
+
132
+ ## 5.1.0-beta.4
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [ea9ca31]
137
+ - @ai-sdk/gateway@1.1.0-beta.3
138
+
139
+ ## 5.1.0-beta.3
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [3e83633]
144
+ - Updated dependencies [f83903d]
145
+ - @ai-sdk/gateway@1.1.0-beta.2
146
+
147
+ ## 5.1.0-beta.2
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies [953d0f2]
152
+ - Updated dependencies [cbb1d35]
153
+ - @ai-sdk/test-server@1.0.0-beta.0
154
+ - @ai-sdk/provider-utils@3.1.0-beta.1
155
+ - @ai-sdk/gateway@1.1.0-beta.1
156
+
157
+ ## 5.1.0-beta.1
158
+
159
+ ### Patch Changes
160
+
161
+ - a7f6f81: Add safeValidateUIMessages utility to validate UI messages without throwing, returning a success/failure result object like Zod’s safeParse
162
+
3
163
  ## 5.1.0-beta.0
4
164
 
5
165
  ### Minor 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