ai 7.0.86 → 7.0.88
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 +13 -0
- package/dist/index.d.ts +127 -44
- package/dist/index.js +527 -455
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +9 -4
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +2 -1
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +7 -0
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +6 -2
- package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +35 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +34 -6
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-choice-violation-error.mdx +38 -0
- package/docs/07-reference/05-ai-sdk-errors/index.mdx +1 -0
- package/package.json +5 -5
- package/src/batch/batch-types.ts +47 -7
- package/src/batch/batch.ts +43 -20
- package/src/error/index.ts +1 -0
- package/src/error/tool-choice-violation-error.ts +80 -0
- package/src/generate-text/generate-text.ts +25 -1
- package/src/ui/process-ui-message-stream.ts +4 -7
- package/src/ui/ui-messages.ts +10 -0
- package/src/ui/validate-ui-messages.ts +10 -0
- package/src/ui-message-stream/ui-message-chunks.ts +2 -0
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type ProviderOptions,
|
|
16
16
|
type ToolSet,
|
|
17
17
|
} from '@ai-sdk/provider-utils';
|
|
18
|
-
import { NoOutputGeneratedError } from '../error';
|
|
18
|
+
import { NoOutputGeneratedError, ToolChoiceViolationError } from '../error';
|
|
19
19
|
import { logWarnings } from '../logger/log-warnings';
|
|
20
20
|
import { resolveLanguageModel } from '../model/resolve-model';
|
|
21
21
|
import type { ModelMessage } from '../prompt';
|
|
@@ -1073,6 +1073,7 @@ export async function generateText<
|
|
|
1073
1073
|
}),
|
|
1074
1074
|
),
|
|
1075
1075
|
);
|
|
1076
|
+
|
|
1076
1077
|
const toolApprovalRequests: Record<
|
|
1077
1078
|
string,
|
|
1078
1079
|
ToolApprovalRequestOutput<TOOLS>
|
|
@@ -1132,6 +1133,29 @@ export async function generateText<
|
|
|
1132
1133
|
],
|
|
1133
1134
|
});
|
|
1134
1135
|
|
|
1136
|
+
const enforcedToolChoice =
|
|
1137
|
+
stepToolChoice.type === 'required' ||
|
|
1138
|
+
stepToolChoice.type === 'tool'
|
|
1139
|
+
? stepToolChoice
|
|
1140
|
+
: undefined;
|
|
1141
|
+
|
|
1142
|
+
if (
|
|
1143
|
+
enforcedToolChoice != null &&
|
|
1144
|
+
!stepToolCalls.some(
|
|
1145
|
+
toolCall =>
|
|
1146
|
+
enforcedToolChoice.type === 'required' ||
|
|
1147
|
+
toolCall.toolName === enforcedToolChoice.toolName,
|
|
1148
|
+
)
|
|
1149
|
+
) {
|
|
1150
|
+
throw new ToolChoiceViolationError({
|
|
1151
|
+
toolChoice: enforcedToolChoice,
|
|
1152
|
+
finishReason: currentModelResponse.finishReason.unified,
|
|
1153
|
+
provider: stepModel.provider,
|
|
1154
|
+
modelId: stepModel.modelId,
|
|
1155
|
+
content: currentModelResponse.content,
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1135
1159
|
// notify the tools that the tool calls are available:
|
|
1136
1160
|
for (const toolCall of stepToolCalls) {
|
|
1137
1161
|
if (toolCall.invalid) {
|
|
@@ -748,6 +748,9 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
748
748
|
toolInvocation.state = 'approval-requested';
|
|
749
749
|
toolInvocation.approval = {
|
|
750
750
|
id: chunk.approvalId,
|
|
751
|
+
...(chunk.approvalDescriptor != null
|
|
752
|
+
? { descriptor: chunk.approvalDescriptor }
|
|
753
|
+
: {}),
|
|
751
754
|
...(chunk.reason != null
|
|
752
755
|
? { requestReason: chunk.reason }
|
|
753
756
|
: {}),
|
|
@@ -771,16 +774,10 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
771
774
|
|
|
772
775
|
toolInvocation.state = 'approval-responded';
|
|
773
776
|
toolInvocation.approval = {
|
|
777
|
+
...approval,
|
|
774
778
|
id: chunk.approvalId,
|
|
775
779
|
approved: chunk.approved,
|
|
776
|
-
...(approval.requestReason != null
|
|
777
|
-
? { requestReason: approval.requestReason }
|
|
778
|
-
: {}),
|
|
779
780
|
...(chunk.reason != null ? { reason: chunk.reason } : {}),
|
|
780
|
-
...(approval.isAutomatic === true ? { isAutomatic: true } : {}),
|
|
781
|
-
...(approval.signature != null
|
|
782
|
-
? { signature: approval.signature }
|
|
783
|
-
: {}),
|
|
784
781
|
};
|
|
785
782
|
if (chunk.providerExecuted != null) {
|
|
786
783
|
toolInvocation.providerExecuted = chunk.providerExecuted;
|
package/src/ui/ui-messages.ts
CHANGED
|
@@ -319,6 +319,7 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
319
319
|
approval: {
|
|
320
320
|
id: string;
|
|
321
321
|
approved?: never;
|
|
322
|
+
descriptor?: unknown;
|
|
322
323
|
requestReason?: string;
|
|
323
324
|
reason?: never;
|
|
324
325
|
isAutomatic?: boolean;
|
|
@@ -334,6 +335,7 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
334
335
|
approval: {
|
|
335
336
|
id: string;
|
|
336
337
|
approved: boolean;
|
|
338
|
+
descriptor?: unknown;
|
|
337
339
|
requestReason?: string;
|
|
338
340
|
reason?: string;
|
|
339
341
|
isAutomatic?: boolean;
|
|
@@ -351,6 +353,7 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
351
353
|
approval?: {
|
|
352
354
|
id: string;
|
|
353
355
|
approved: true;
|
|
356
|
+
descriptor?: unknown;
|
|
354
357
|
requestReason?: string;
|
|
355
358
|
reason?: string;
|
|
356
359
|
isAutomatic?: boolean;
|
|
@@ -368,6 +371,7 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
368
371
|
approval?: {
|
|
369
372
|
id: string;
|
|
370
373
|
approved: true;
|
|
374
|
+
descriptor?: unknown;
|
|
371
375
|
requestReason?: string;
|
|
372
376
|
reason?: string;
|
|
373
377
|
isAutomatic?: boolean;
|
|
@@ -383,6 +387,7 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
383
387
|
approval: {
|
|
384
388
|
id: string;
|
|
385
389
|
approved: false;
|
|
390
|
+
descriptor?: unknown;
|
|
386
391
|
requestReason?: string;
|
|
387
392
|
reason?: string;
|
|
388
393
|
isAutomatic?: boolean;
|
|
@@ -442,6 +447,7 @@ export type DynamicToolUIPart = {
|
|
|
442
447
|
approval: {
|
|
443
448
|
id: string;
|
|
444
449
|
approved?: never;
|
|
450
|
+
descriptor?: unknown;
|
|
445
451
|
requestReason?: string;
|
|
446
452
|
reason?: never;
|
|
447
453
|
isAutomatic?: boolean;
|
|
@@ -457,6 +463,7 @@ export type DynamicToolUIPart = {
|
|
|
457
463
|
approval: {
|
|
458
464
|
id: string;
|
|
459
465
|
approved: boolean;
|
|
466
|
+
descriptor?: unknown;
|
|
460
467
|
requestReason?: string;
|
|
461
468
|
reason?: string;
|
|
462
469
|
isAutomatic?: boolean;
|
|
@@ -474,6 +481,7 @@ export type DynamicToolUIPart = {
|
|
|
474
481
|
approval?: {
|
|
475
482
|
id: string;
|
|
476
483
|
approved: true;
|
|
484
|
+
descriptor?: unknown;
|
|
477
485
|
requestReason?: string;
|
|
478
486
|
reason?: string;
|
|
479
487
|
isAutomatic?: boolean;
|
|
@@ -490,6 +498,7 @@ export type DynamicToolUIPart = {
|
|
|
490
498
|
approval?: {
|
|
491
499
|
id: string;
|
|
492
500
|
approved: true;
|
|
501
|
+
descriptor?: unknown;
|
|
493
502
|
requestReason?: string;
|
|
494
503
|
reason?: string;
|
|
495
504
|
isAutomatic?: boolean;
|
|
@@ -505,6 +514,7 @@ export type DynamicToolUIPart = {
|
|
|
505
514
|
approval: {
|
|
506
515
|
id: string;
|
|
507
516
|
approved: false;
|
|
517
|
+
descriptor?: unknown;
|
|
508
518
|
requestReason?: string;
|
|
509
519
|
reason?: string;
|
|
510
520
|
isAutomatic?: boolean;
|
|
@@ -153,6 +153,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
153
153
|
approval: z.object({
|
|
154
154
|
id: z.string(),
|
|
155
155
|
approved: z.never().optional(),
|
|
156
|
+
descriptor: z.unknown().optional(),
|
|
156
157
|
requestReason: z.string().optional(),
|
|
157
158
|
reason: z.never().optional(),
|
|
158
159
|
isAutomatic: z.boolean().optional(),
|
|
@@ -173,6 +174,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
173
174
|
approval: z.object({
|
|
174
175
|
id: z.string(),
|
|
175
176
|
approved: z.boolean(),
|
|
177
|
+
descriptor: z.unknown().optional(),
|
|
176
178
|
requestReason: z.string().optional(),
|
|
177
179
|
reason: z.string().optional(),
|
|
178
180
|
isAutomatic: z.boolean().optional(),
|
|
@@ -196,6 +198,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
196
198
|
.object({
|
|
197
199
|
id: z.string(),
|
|
198
200
|
approved: z.literal(true),
|
|
201
|
+
descriptor: z.unknown().optional(),
|
|
199
202
|
requestReason: z.string().optional(),
|
|
200
203
|
reason: z.string().optional(),
|
|
201
204
|
isAutomatic: z.boolean().optional(),
|
|
@@ -220,6 +223,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
220
223
|
.object({
|
|
221
224
|
id: z.string(),
|
|
222
225
|
approved: z.literal(true),
|
|
226
|
+
descriptor: z.unknown().optional(),
|
|
223
227
|
requestReason: z.string().optional(),
|
|
224
228
|
reason: z.string().optional(),
|
|
225
229
|
isAutomatic: z.boolean().optional(),
|
|
@@ -241,6 +245,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
241
245
|
approval: z.object({
|
|
242
246
|
id: z.string(),
|
|
243
247
|
approved: z.literal(false),
|
|
248
|
+
descriptor: z.unknown().optional(),
|
|
244
249
|
requestReason: z.string().optional(),
|
|
245
250
|
reason: z.string().optional(),
|
|
246
251
|
isAutomatic: z.boolean().optional(),
|
|
@@ -284,6 +289,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
284
289
|
approval: z.object({
|
|
285
290
|
id: z.string(),
|
|
286
291
|
approved: z.never().optional(),
|
|
292
|
+
descriptor: z.unknown().optional(),
|
|
287
293
|
requestReason: z.string().optional(),
|
|
288
294
|
reason: z.never().optional(),
|
|
289
295
|
isAutomatic: z.boolean().optional(),
|
|
@@ -303,6 +309,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
303
309
|
approval: z.object({
|
|
304
310
|
id: z.string(),
|
|
305
311
|
approved: z.boolean(),
|
|
312
|
+
descriptor: z.unknown().optional(),
|
|
306
313
|
requestReason: z.string().optional(),
|
|
307
314
|
reason: z.string().optional(),
|
|
308
315
|
isAutomatic: z.boolean().optional(),
|
|
@@ -325,6 +332,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
325
332
|
.object({
|
|
326
333
|
id: z.string(),
|
|
327
334
|
approved: z.literal(true),
|
|
335
|
+
descriptor: z.unknown().optional(),
|
|
328
336
|
requestReason: z.string().optional(),
|
|
329
337
|
reason: z.string().optional(),
|
|
330
338
|
isAutomatic: z.boolean().optional(),
|
|
@@ -348,6 +356,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
348
356
|
.object({
|
|
349
357
|
id: z.string(),
|
|
350
358
|
approved: z.literal(true),
|
|
359
|
+
descriptor: z.unknown().optional(),
|
|
351
360
|
requestReason: z.string().optional(),
|
|
352
361
|
reason: z.string().optional(),
|
|
353
362
|
isAutomatic: z.boolean().optional(),
|
|
@@ -368,6 +377,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
368
377
|
approval: z.object({
|
|
369
378
|
id: z.string(),
|
|
370
379
|
approved: z.literal(false),
|
|
380
|
+
descriptor: z.unknown().optional(),
|
|
371
381
|
requestReason: z.string().optional(),
|
|
372
382
|
reason: z.string().optional(),
|
|
373
383
|
isAutomatic: z.boolean().optional(),
|
|
@@ -85,6 +85,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
85
85
|
type: z.literal('tool-approval-request'),
|
|
86
86
|
approvalId: z.string(),
|
|
87
87
|
toolCallId: z.string(),
|
|
88
|
+
approvalDescriptor: z.unknown().optional(),
|
|
88
89
|
reason: z.string().optional(),
|
|
89
90
|
isAutomatic: z.boolean().optional(),
|
|
90
91
|
signature: z.string().optional(),
|
|
@@ -299,6 +300,7 @@ export type UIMessageChunk<
|
|
|
299
300
|
type: 'tool-approval-request';
|
|
300
301
|
approvalId: string;
|
|
301
302
|
toolCallId: string;
|
|
303
|
+
approvalDescriptor?: unknown;
|
|
302
304
|
reason?: string;
|
|
303
305
|
isAutomatic?: boolean;
|
|
304
306
|
signature?: string;
|