ai 3.3.7 → 3.3.9
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/dist/index.d.mts +94 -4
- package/dist/index.d.ts +94 -4
- package/dist/index.js +72 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/prompts/dist/index.d.mts +13 -2
- package/prompts/dist/index.d.ts +13 -2
- package/prompts/dist/index.js.map +1 -1
- package/prompts/dist/index.mjs.map +1 -1
- package/rsc/dist/index.d.ts +97 -49
- package/rsc/dist/rsc-server.d.mts +97 -49
- package/rsc/dist/rsc-server.mjs +41 -13
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs.map +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1 } from '@ai-sdk/provider';
|
1
|
+
import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1 } from '@ai-sdk/provider';
|
2
2
|
import { ReactNode } from 'react';
|
3
3
|
import { z } from 'zod';
|
4
4
|
import OpenAI from 'openai';
|
@@ -176,6 +176,60 @@ type CallSettings = {
|
|
176
176
|
headers?: Record<string, string | undefined>;
|
177
177
|
};
|
178
178
|
|
179
|
+
/**
|
180
|
+
Represents the number of tokens used in a prompt and completion.
|
181
|
+
*/
|
182
|
+
type CompletionTokenUsage = {
|
183
|
+
/**
|
184
|
+
The number of tokens used in the prompt.
|
185
|
+
*/
|
186
|
+
promptTokens: number;
|
187
|
+
/**
|
188
|
+
The number of tokens used in the completion.
|
189
|
+
*/
|
190
|
+
completionTokens: number;
|
191
|
+
/**
|
192
|
+
The total number of tokens used (promptTokens + completionTokens).
|
193
|
+
*/
|
194
|
+
totalTokens: number;
|
195
|
+
};
|
196
|
+
|
197
|
+
/**
|
198
|
+
Reason why a language model finished generating a response.
|
199
|
+
|
200
|
+
Can be one of the following:
|
201
|
+
- `stop`: model generated stop sequence
|
202
|
+
- `length`: model generated maximum number of tokens
|
203
|
+
- `content-filter`: content filter violation stopped the model
|
204
|
+
- `tool-calls`: model triggered tool calls
|
205
|
+
- `error`: model stopped because of an error
|
206
|
+
- `other`: model stopped for other reasons
|
207
|
+
*/
|
208
|
+
type FinishReason = LanguageModelV1FinishReason;
|
209
|
+
/**
|
210
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
211
|
+
some settings might not be supported, which can lead to suboptimal results.
|
212
|
+
*/
|
213
|
+
type CallWarning = LanguageModelV1CallWarning;
|
214
|
+
/**
|
215
|
+
Additional provider-specific metadata. They are passed through
|
216
|
+
to the provider from the AI SDK and enable provider-specific
|
217
|
+
functionality that can be fully encapsulated in the provider.
|
218
|
+
*/
|
219
|
+
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
220
|
+
/**
|
221
|
+
Tool choice for the generation. It supports the following settings:
|
222
|
+
|
223
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
224
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
225
|
+
- `none`: the model must not call tools
|
226
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
227
|
+
*/
|
228
|
+
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
229
|
+
type: 'tool';
|
230
|
+
toolName: keyof TOOLS;
|
231
|
+
};
|
232
|
+
|
179
233
|
/**
|
180
234
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
181
235
|
*/
|
@@ -190,6 +244,12 @@ interface TextPart {
|
|
190
244
|
The text content.
|
191
245
|
*/
|
192
246
|
text: string;
|
247
|
+
/**
|
248
|
+
Additional provider-specific metadata. They are passed through
|
249
|
+
to the provider from the AI SDK and enable provider-specific
|
250
|
+
functionality that can be fully encapsulated in the provider.
|
251
|
+
*/
|
252
|
+
experimental_providerMetadata?: ProviderMetadata;
|
193
253
|
}
|
194
254
|
/**
|
195
255
|
Image content part of a prompt. It contains an image.
|
@@ -207,6 +267,12 @@ interface ImagePart {
|
|
207
267
|
Optional mime type of the image.
|
208
268
|
*/
|
209
269
|
mimeType?: string;
|
270
|
+
/**
|
271
|
+
Additional provider-specific metadata. They are passed through
|
272
|
+
to the provider from the AI SDK and enable provider-specific
|
273
|
+
functionality that can be fully encapsulated in the provider.
|
274
|
+
*/
|
275
|
+
experimental_providerMetadata?: ProviderMetadata;
|
210
276
|
}
|
211
277
|
/**
|
212
278
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
@@ -247,6 +313,12 @@ interface ToolResultPart {
|
|
247
313
|
Optional flag if the result is an error or an error message.
|
248
314
|
*/
|
249
315
|
isError?: boolean;
|
316
|
+
/**
|
317
|
+
Additional provider-specific metadata. They are passed through
|
318
|
+
to the provider from the AI SDK and enable provider-specific
|
319
|
+
functionality that can be fully encapsulated in the provider.
|
320
|
+
*/
|
321
|
+
experimental_providerMetadata?: ProviderMetadata;
|
250
322
|
}
|
251
323
|
|
252
324
|
/**
|
@@ -264,6 +336,12 @@ type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage |
|
|
264
336
|
type CoreSystemMessage = {
|
265
337
|
role: 'system';
|
266
338
|
content: string;
|
339
|
+
/**
|
340
|
+
Additional provider-specific metadata. They are passed through
|
341
|
+
to the provider from the AI SDK and enable provider-specific
|
342
|
+
functionality that can be fully encapsulated in the provider.
|
343
|
+
*/
|
344
|
+
experimental_providerMetadata?: ProviderMetadata;
|
267
345
|
};
|
268
346
|
/**
|
269
347
|
A user message. It can contain text or a combination of text and images.
|
@@ -271,6 +349,12 @@ A user message. It can contain text or a combination of text and images.
|
|
271
349
|
type CoreUserMessage = {
|
272
350
|
role: 'user';
|
273
351
|
content: UserContent;
|
352
|
+
/**
|
353
|
+
Additional provider-specific metadata. They are passed through
|
354
|
+
to the provider from the AI SDK and enable provider-specific
|
355
|
+
functionality that can be fully encapsulated in the provider.
|
356
|
+
*/
|
357
|
+
experimental_providerMetadata?: ProviderMetadata;
|
274
358
|
};
|
275
359
|
/**
|
276
360
|
Content of a user message. It can be a string or an array of text and image parts.
|
@@ -282,6 +366,12 @@ An assistant message. It can contain text, tool calls, or a combination of text
|
|
282
366
|
type CoreAssistantMessage = {
|
283
367
|
role: 'assistant';
|
284
368
|
content: AssistantContent;
|
369
|
+
/**
|
370
|
+
Additional provider-specific metadata. They are passed through
|
371
|
+
to the provider from the AI SDK and enable provider-specific
|
372
|
+
functionality that can be fully encapsulated in the provider.
|
373
|
+
*/
|
374
|
+
experimental_providerMetadata?: ProviderMetadata;
|
285
375
|
};
|
286
376
|
/**
|
287
377
|
Content of an assistant message. It can be a string or an array of text and tool call parts.
|
@@ -293,6 +383,12 @@ A tool message. It contains the result of one or more tool calls.
|
|
293
383
|
type CoreToolMessage = {
|
294
384
|
role: 'tool';
|
295
385
|
content: ToolContent;
|
386
|
+
/**
|
387
|
+
Additional provider-specific metadata. They are passed through
|
388
|
+
to the provider from the AI SDK and enable provider-specific
|
389
|
+
functionality that can be fully encapsulated in the provider.
|
390
|
+
*/
|
391
|
+
experimental_providerMetadata?: ProviderMetadata;
|
296
392
|
};
|
297
393
|
/**
|
298
394
|
Content of a tool message. It is an array of tool result parts.
|
@@ -317,54 +413,6 @@ type Prompt = {
|
|
317
413
|
messages?: Array<CoreMessage>;
|
318
414
|
};
|
319
415
|
|
320
|
-
/**
|
321
|
-
Represents the number of tokens used in a prompt and completion.
|
322
|
-
*/
|
323
|
-
type CompletionTokenUsage = {
|
324
|
-
/**
|
325
|
-
The number of tokens used in the prompt.
|
326
|
-
*/
|
327
|
-
promptTokens: number;
|
328
|
-
/**
|
329
|
-
The number of tokens used in the completion.
|
330
|
-
*/
|
331
|
-
completionTokens: number;
|
332
|
-
/**
|
333
|
-
The total number of tokens used (promptTokens + completionTokens).
|
334
|
-
*/
|
335
|
-
totalTokens: number;
|
336
|
-
};
|
337
|
-
|
338
|
-
/**
|
339
|
-
Reason why a language model finished generating a response.
|
340
|
-
|
341
|
-
Can be one of the following:
|
342
|
-
- `stop`: model generated stop sequence
|
343
|
-
- `length`: model generated maximum number of tokens
|
344
|
-
- `content-filter`: content filter violation stopped the model
|
345
|
-
- `tool-calls`: model triggered tool calls
|
346
|
-
- `error`: model stopped because of an error
|
347
|
-
- `other`: model stopped for other reasons
|
348
|
-
*/
|
349
|
-
type FinishReason = LanguageModelV1FinishReason;
|
350
|
-
/**
|
351
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
352
|
-
some settings might not be supported, which can lead to suboptimal results.
|
353
|
-
*/
|
354
|
-
type CallWarning = LanguageModelV1CallWarning;
|
355
|
-
/**
|
356
|
-
Tool choice for the generation. It supports the following settings:
|
357
|
-
|
358
|
-
- `auto` (default): the model can choose whether and which tools to call.
|
359
|
-
- `required`: the model must call a tool. It can choose which tool to call.
|
360
|
-
- `none`: the model must not call tools
|
361
|
-
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
362
|
-
*/
|
363
|
-
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
364
|
-
type: 'tool';
|
365
|
-
toolName: keyof TOOLS;
|
366
|
-
};
|
367
|
-
|
368
416
|
type Streamable$1 = ReactNode | Promise<ReactNode>;
|
369
417
|
type Renderer$1<T extends Array<any>> = (...args: T) => Streamable$1 | Generator<Streamable$1, Streamable$1, void> | AsyncGenerator<Streamable$1, Streamable$1, void>;
|
370
418
|
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -449,13 +449,18 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
449
449
|
const role = message.role;
|
450
450
|
switch (role) {
|
451
451
|
case "system": {
|
452
|
-
return {
|
452
|
+
return {
|
453
|
+
role: "system",
|
454
|
+
content: message.content,
|
455
|
+
providerMetadata: message.experimental_providerMetadata
|
456
|
+
};
|
453
457
|
}
|
454
458
|
case "user": {
|
455
459
|
if (typeof message.content === "string") {
|
456
460
|
return {
|
457
461
|
role: "user",
|
458
|
-
content: [{ type: "text", text: message.content }]
|
462
|
+
content: [{ type: "text", text: message.content }],
|
463
|
+
providerMetadata: message.experimental_providerMetadata
|
459
464
|
};
|
460
465
|
}
|
461
466
|
return {
|
@@ -465,7 +470,11 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
465
470
|
var _a8, _b, _c;
|
466
471
|
switch (part.type) {
|
467
472
|
case "text": {
|
468
|
-
return
|
473
|
+
return {
|
474
|
+
type: "text",
|
475
|
+
text: part.text,
|
476
|
+
providerMetadata: part.experimental_providerMetadata
|
477
|
+
};
|
469
478
|
}
|
470
479
|
case "image": {
|
471
480
|
if (part.image instanceof URL) {
|
@@ -473,14 +482,16 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
473
482
|
return {
|
474
483
|
type: "image",
|
475
484
|
image: part.image,
|
476
|
-
mimeType: part.mimeType
|
485
|
+
mimeType: part.mimeType,
|
486
|
+
providerMetadata: part.experimental_providerMetadata
|
477
487
|
};
|
478
488
|
} else {
|
479
489
|
const downloadedImage = downloadedImages[part.image.toString()];
|
480
490
|
return {
|
481
491
|
type: "image",
|
482
492
|
image: downloadedImage.data,
|
483
|
-
mimeType: (_a8 = part.mimeType) != null ? _a8 : downloadedImage.mimeType
|
493
|
+
mimeType: (_a8 = part.mimeType) != null ? _a8 : downloadedImage.mimeType,
|
494
|
+
providerMetadata: part.experimental_providerMetadata
|
484
495
|
};
|
485
496
|
}
|
486
497
|
}
|
@@ -494,14 +505,16 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
494
505
|
return {
|
495
506
|
type: "image",
|
496
507
|
image: url,
|
497
|
-
mimeType: part.mimeType
|
508
|
+
mimeType: part.mimeType,
|
509
|
+
providerMetadata: part.experimental_providerMetadata
|
498
510
|
};
|
499
511
|
} else {
|
500
512
|
const downloadedImage = downloadedImages[part.image];
|
501
513
|
return {
|
502
514
|
type: "image",
|
503
515
|
image: downloadedImage.data,
|
504
|
-
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType
|
516
|
+
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
517
|
+
providerMetadata: part.experimental_providerMetadata
|
505
518
|
};
|
506
519
|
}
|
507
520
|
}
|
@@ -515,7 +528,8 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
515
528
|
return {
|
516
529
|
type: "image",
|
517
530
|
image: convertDataContentToUint8Array(base64Content),
|
518
|
-
mimeType
|
531
|
+
mimeType,
|
532
|
+
providerMetadata: part.experimental_providerMetadata
|
519
533
|
};
|
520
534
|
} catch (error) {
|
521
535
|
throw new Error(
|
@@ -538,19 +552,22 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
538
552
|
return {
|
539
553
|
type: "image",
|
540
554
|
image: imageUint8,
|
541
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8)
|
555
|
+
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
556
|
+
providerMetadata: part.experimental_providerMetadata
|
542
557
|
};
|
543
558
|
}
|
544
559
|
}
|
545
560
|
}
|
546
|
-
)
|
561
|
+
),
|
562
|
+
providerMetadata: message.experimental_providerMetadata
|
547
563
|
};
|
548
564
|
}
|
549
565
|
case "assistant": {
|
550
566
|
if (typeof message.content === "string") {
|
551
567
|
return {
|
552
568
|
role: "assistant",
|
553
|
-
content: [{ type: "text", text: message.content }]
|
569
|
+
content: [{ type: "text", text: message.content }],
|
570
|
+
providerMetadata: message.experimental_providerMetadata
|
554
571
|
};
|
555
572
|
}
|
556
573
|
return {
|
@@ -558,11 +575,22 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
558
575
|
content: message.content.filter(
|
559
576
|
// remove empty text parts:
|
560
577
|
(part) => part.type !== "text" || part.text !== ""
|
561
|
-
)
|
578
|
+
),
|
579
|
+
providerMetadata: message.experimental_providerMetadata
|
562
580
|
};
|
563
581
|
}
|
564
582
|
case "tool": {
|
565
|
-
return
|
583
|
+
return {
|
584
|
+
role: "tool",
|
585
|
+
content: message.content.map((part) => ({
|
586
|
+
type: "tool-result",
|
587
|
+
toolCallId: part.toolCallId,
|
588
|
+
toolName: part.toolName,
|
589
|
+
result: part.result,
|
590
|
+
providerMetadata: part.experimental_providerMetadata
|
591
|
+
})),
|
592
|
+
providerMetadata: message.experimental_providerMetadata
|
593
|
+
};
|
566
594
|
}
|
567
595
|
default: {
|
568
596
|
const _exhaustiveCheck = role;
|