ai 3.4.10 → 3.4.12
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 +17 -0
- package/README.md +0 -109
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/svelte/dist/index.d.mts +2 -0
- package/svelte/dist/index.d.ts +2 -0
- package/svelte/dist/index.js +7 -0
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +7 -0
- package/svelte/dist/index.mjs.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 3.4.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- a23da5b: feat (ai/core): forward abort signal to tools
|
8
|
+
|
9
|
+
## 3.4.11
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- caedcda: feat (ai/ui): add setData helper to useChat
|
14
|
+
- Updated dependencies [caedcda]
|
15
|
+
- @ai-sdk/svelte@0.0.52
|
16
|
+
- @ai-sdk/react@0.0.63
|
17
|
+
- @ai-sdk/solid@0.0.50
|
18
|
+
- @ai-sdk/vue@0.0.55
|
19
|
+
|
3
20
|
## 3.4.10
|
4
21
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
@@ -101,115 +101,6 @@ export async function POST(req: Request) {
|
|
101
101
|
}
|
102
102
|
```
|
103
103
|
|
104
|
-
### AI SDK RSC
|
105
|
-
|
106
|
-
The [AI SDK RSC](https://sdk.vercel.ai/docs/ai-sdk-rsc/overview) module provides an alternative API that also helps you build chatbots and generative user interfaces for frameworks that support [React Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components) (RSC).
|
107
|
-
|
108
|
-
This API leverages the benefits of [Streaming](https://nextjs.org/docs/app/building-your-application/rendering/server-components#streaming) and [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations) offered by RSC, thus improving the developer experience of managing states between server/client and building generative user interfaces.
|
109
|
-
|
110
|
-
###### @/app/actions.tsx (Next.js App Router)
|
111
|
-
|
112
|
-
```tsx
|
113
|
-
import { streamUI } from 'ai/rsc';
|
114
|
-
import { z } from 'zod';
|
115
|
-
|
116
|
-
async function submitMessage() {
|
117
|
-
'use server';
|
118
|
-
|
119
|
-
const stream = await streamUI({
|
120
|
-
model: openai('gpt-4-turbo'),
|
121
|
-
messages: [
|
122
|
-
{ role: 'system', content: 'You are a friendly bot!' },
|
123
|
-
{ role: 'user', content: input },
|
124
|
-
],
|
125
|
-
text: ({ content, done }) => {
|
126
|
-
return <div>{content}</div>;
|
127
|
-
},
|
128
|
-
tools: {
|
129
|
-
deploy: {
|
130
|
-
description: 'Deploy repository to vercel',
|
131
|
-
parameters: z.object({
|
132
|
-
repositoryName: z
|
133
|
-
.string()
|
134
|
-
.describe('The name of the repository, example: vercel/ai-chatbot'),
|
135
|
-
}),
|
136
|
-
generate: async function* ({ repositoryName }) {
|
137
|
-
yield <div>Cloning repository {repositoryName}...</div>;
|
138
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
139
|
-
yield <div>Building repository {repositoryName}...</div>;
|
140
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
141
|
-
return <div>{repositoryName} deployed!</div>;
|
142
|
-
},
|
143
|
-
},
|
144
|
-
},
|
145
|
-
});
|
146
|
-
|
147
|
-
return {
|
148
|
-
ui: stream.value,
|
149
|
-
};
|
150
|
-
}
|
151
|
-
```
|
152
|
-
|
153
|
-
###### @/app/ai.ts (Next.js App Router)
|
154
|
-
|
155
|
-
```tsx
|
156
|
-
import { createAI } from 'ai/rsc';
|
157
|
-
import { submitMessage } from '@/app/actions';
|
158
|
-
|
159
|
-
export const AI = createAI({
|
160
|
-
initialAIState: {},
|
161
|
-
initialUIState: {},
|
162
|
-
actions: {
|
163
|
-
submitMessage,
|
164
|
-
},
|
165
|
-
});
|
166
|
-
```
|
167
|
-
|
168
|
-
###### @/app/layout.tsx (Next.js App Router)
|
169
|
-
|
170
|
-
```tsx
|
171
|
-
import { ReactNode } from 'react';
|
172
|
-
import { AI } from '@/app/ai';
|
173
|
-
|
174
|
-
export default function Layout({ children }: { children: ReactNode }) {
|
175
|
-
<AI>{children}</AI>;
|
176
|
-
}
|
177
|
-
```
|
178
|
-
|
179
|
-
###### @/app/page.tsx (Next.js App Router)
|
180
|
-
|
181
|
-
```tsx
|
182
|
-
'use client';
|
183
|
-
|
184
|
-
import { useActions } from 'ai/rsc';
|
185
|
-
import { ReactNode, useState } from 'react';
|
186
|
-
|
187
|
-
export default function Page() {
|
188
|
-
const [input, setInput] = useState('');
|
189
|
-
const [messages, setMessages] = useState<ReactNode[]>([]);
|
190
|
-
const { submitMessage } = useActions();
|
191
|
-
|
192
|
-
return (
|
193
|
-
<div>
|
194
|
-
<input
|
195
|
-
value={input}
|
196
|
-
onChange={event => {
|
197
|
-
setInput(event.target.value);
|
198
|
-
}}
|
199
|
-
/>
|
200
|
-
<button
|
201
|
-
onClick={async () => {
|
202
|
-
const { ui } = await submitMessage(input);
|
203
|
-
setMessages(currentMessages => [...currentMessages, ui]);
|
204
|
-
}}
|
205
|
-
>
|
206
|
-
Submit
|
207
|
-
</button>
|
208
|
-
</div>
|
209
|
-
);
|
210
|
-
}
|
211
|
-
```
|
212
|
-
|
213
104
|
## Templates
|
214
105
|
|
215
106
|
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.
|
package/dist/index.d.mts
CHANGED
@@ -1233,8 +1233,13 @@ interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
|
|
1233
1233
|
/**
|
1234
1234
|
An async function that is called with the arguments from the tool call and produces a result.
|
1235
1235
|
If not provided, the tool will not be executed automatically.
|
1236
|
+
|
1237
|
+
@args is the input of the tool call.
|
1238
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
1236
1239
|
*/
|
1237
|
-
execute?: (args: inferParameters<PARAMETERS
|
1240
|
+
execute?: (args: inferParameters<PARAMETERS>, options: {
|
1241
|
+
abortSignal?: AbortSignal;
|
1242
|
+
}) => PromiseLike<RESULT>;
|
1238
1243
|
}
|
1239
1244
|
/**
|
1240
1245
|
Helper function for inferring the execute args of a tool.
|
package/dist/index.d.ts
CHANGED
@@ -1233,8 +1233,13 @@ interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
|
|
1233
1233
|
/**
|
1234
1234
|
An async function that is called with the arguments from the tool call and produces a result.
|
1235
1235
|
If not provided, the tool will not be executed automatically.
|
1236
|
+
|
1237
|
+
@args is the input of the tool call.
|
1238
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
1236
1239
|
*/
|
1237
|
-
execute?: (args: inferParameters<PARAMETERS
|
1240
|
+
execute?: (args: inferParameters<PARAMETERS>, options: {
|
1241
|
+
abortSignal?: AbortSignal;
|
1242
|
+
}) => PromiseLike<RESULT>;
|
1238
1243
|
}
|
1239
1244
|
/**
|
1240
1245
|
Helper function for inferring the execute args of a tool.
|
package/dist/index.js
CHANGED
@@ -3337,7 +3337,8 @@ async function generateText({
|
|
3337
3337
|
toolCalls: currentToolCalls,
|
3338
3338
|
tools,
|
3339
3339
|
tracer,
|
3340
|
-
telemetry
|
3340
|
+
telemetry,
|
3341
|
+
abortSignal
|
3341
3342
|
});
|
3342
3343
|
const currentUsage = calculateLanguageModelUsage(
|
3343
3344
|
currentModelResponse.usage
|
@@ -3467,7 +3468,8 @@ async function executeTools({
|
|
3467
3468
|
toolCalls,
|
3468
3469
|
tools,
|
3469
3470
|
tracer,
|
3470
|
-
telemetry
|
3471
|
+
telemetry,
|
3472
|
+
abortSignal
|
3471
3473
|
}) {
|
3472
3474
|
const toolResults = await Promise.all(
|
3473
3475
|
toolCalls.map(async (toolCall) => {
|
@@ -3493,7 +3495,7 @@ async function executeTools({
|
|
3493
3495
|
}),
|
3494
3496
|
tracer,
|
3495
3497
|
fn: async (span) => {
|
3496
|
-
const result2 = await tool2.execute(toolCall.args);
|
3498
|
+
const result2 = await tool2.execute(toolCall.args, { abortSignal });
|
3497
3499
|
try {
|
3498
3500
|
span.setAttributes(
|
3499
3501
|
selectTelemetryAttributes({
|
@@ -3703,7 +3705,8 @@ function runToolsTransformation({
|
|
3703
3705
|
generatorStream,
|
3704
3706
|
toolCallStreaming,
|
3705
3707
|
tracer,
|
3706
|
-
telemetry
|
3708
|
+
telemetry,
|
3709
|
+
abortSignal
|
3707
3710
|
}) {
|
3708
3711
|
let canClose = false;
|
3709
3712
|
const outstandingToolCalls = /* @__PURE__ */ new Set();
|
@@ -3789,7 +3792,7 @@ function runToolsTransformation({
|
|
3789
3792
|
}
|
3790
3793
|
}),
|
3791
3794
|
tracer,
|
3792
|
-
fn: async (span) => tool2.execute(toolCall.args).then(
|
3795
|
+
fn: async (span) => tool2.execute(toolCall.args, { abortSignal }).then(
|
3793
3796
|
(result) => {
|
3794
3797
|
toolResultsStreamController.enqueue({
|
3795
3798
|
...toolCall,
|
@@ -4010,7 +4013,8 @@ async function streamText({
|
|
4010
4013
|
generatorStream: stream2,
|
4011
4014
|
toolCallStreaming,
|
4012
4015
|
tracer,
|
4013
|
-
telemetry
|
4016
|
+
telemetry,
|
4017
|
+
abortSignal
|
4014
4018
|
}),
|
4015
4019
|
warnings: warnings2,
|
4016
4020
|
rawResponse: rawResponse2
|