ai 5.0.0-canary.17 → 5.0.0-canary.18
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 +19 -0
- package/README.md +4 -4
- package/dist/index.d.mts +39 -87
- package/dist/index.d.ts +39 -87
- package/dist/index.js +177 -166
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -166
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -44
- package/dist/internal/index.d.ts +6 -44
- package/dist/internal/index.js +12 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +12 -19
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +2 -2
- package/dist/mcp-stdio/index.d.ts +2 -2
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 5.0.0-canary.18
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- c60f895: chore (ai): remove useChat keepLastMessageOnError
|
8
|
+
- a662dea: chore (ai): remove sendExtraMessageFields
|
9
|
+
|
10
|
+
### Patch Changes
|
11
|
+
|
12
|
+
- a571d6e: chore(provider-utils): move ToolResultContent to provider-utils
|
13
|
+
- 332167b: chore (ai): move maxSteps into UseChatOptions
|
14
|
+
- a8c8bd5: feat(embed-many): respect supportsParallelCalls & concurrency
|
15
|
+
- Updated dependencies [a571d6e]
|
16
|
+
- Updated dependencies [a8c8bd5]
|
17
|
+
- Updated dependencies [7979f7f]
|
18
|
+
- Updated dependencies [41fa418]
|
19
|
+
- @ai-sdk/provider-utils@3.0.0-canary.15
|
20
|
+
- @ai-sdk/provider@2.0.0-canary.14
|
21
|
+
|
3
22
|
## 5.0.0-canary.17
|
4
23
|
|
5
24
|
### Major Changes
|
package/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
# AI SDK
|
4
4
|
|
5
|
-
The [AI SDK](https://sdk.
|
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.
|
6
6
|
|
7
|
-
To learn more about how to use the AI SDK, check out our [API Reference](https://sdk.
|
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
|
|
@@ -18,7 +18,7 @@ npm install ai
|
|
18
18
|
|
19
19
|
### AI SDK Core
|
20
20
|
|
21
|
-
The [AI SDK Core](https://sdk.
|
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
22
|
|
23
23
|
You will then install the model provider of your choice.
|
24
24
|
|
@@ -43,7 +43,7 @@ console.log(text);
|
|
43
43
|
|
44
44
|
### AI SDK UI
|
45
45
|
|
46
|
-
The [AI SDK UI](https://sdk.
|
46
|
+
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
47
|
|
48
48
|
You need to install the package for your framework:
|
49
49
|
|
package/dist/index.d.mts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { ToolCall, ToolResult, FetchFunction, Schema,
|
2
|
-
export {
|
1
|
+
import { ToolCall, ToolResult, FetchFunction, ToolResultContent, Schema, IdGenerator as IdGenerator$1 } from '@ai-sdk/provider-utils';
|
2
|
+
export { IdGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
|
3
3
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
4
|
-
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
4
|
+
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
5
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
6
6
|
import { ServerResponse } from 'node:http';
|
7
7
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
@@ -221,19 +221,15 @@ type TranscriptionModelResponseMetadata = {
|
|
221
221
|
/**
|
222
222
|
Represents the number of tokens used in a prompt and completion.
|
223
223
|
*/
|
224
|
-
type LanguageModelUsage
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
/**
|
230
|
-
The number of tokens used in the completion.
|
231
|
-
*/
|
232
|
-
completionTokens: number;
|
224
|
+
type LanguageModelUsage = LanguageModelV2Usage;
|
225
|
+
/**
|
226
|
+
Represents the number of tokens used in an embedding.
|
227
|
+
*/
|
228
|
+
type EmbeddingModelUsage = {
|
233
229
|
/**
|
234
|
-
The
|
230
|
+
The number of tokens used in the embedding.
|
235
231
|
*/
|
236
|
-
|
232
|
+
tokens: number;
|
237
233
|
};
|
238
234
|
|
239
235
|
type IdGenerator = () => string;
|
@@ -415,12 +411,6 @@ type ChatRequestOptions = {
|
|
415
411
|
};
|
416
412
|
type UseChatOptions = {
|
417
413
|
/**
|
418
|
-
Keeps the last message when an error happens. Defaults to `true`.
|
419
|
-
|
420
|
-
@deprecated This option will be removed in the next major release.
|
421
|
-
*/
|
422
|
-
keepLastMessageOnError?: boolean;
|
423
|
-
/**
|
424
414
|
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
425
415
|
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
426
416
|
*/
|
@@ -461,7 +451,7 @@ type UseChatOptions = {
|
|
461
451
|
* @param options.finishReason The finish reason of the message.
|
462
452
|
*/
|
463
453
|
onFinish?: (message: UIMessage, options: {
|
464
|
-
usage: LanguageModelUsage
|
454
|
+
usage: LanguageModelUsage;
|
465
455
|
finishReason: LanguageModelV2FinishReason;
|
466
456
|
}) => void;
|
467
457
|
/**
|
@@ -497,12 +487,6 @@ type UseChatOptions = {
|
|
497
487
|
*/
|
498
488
|
body?: object;
|
499
489
|
/**
|
500
|
-
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
501
|
-
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
502
|
-
* handle the extra fields before forwarding the request to the AI service.
|
503
|
-
*/
|
504
|
-
sendExtraMessageFields?: boolean;
|
505
|
-
/**
|
506
490
|
Streaming protocol that is used. Defaults to `data`.
|
507
491
|
*/
|
508
492
|
streamProtocol?: 'data' | 'text';
|
@@ -511,6 +495,15 @@ type UseChatOptions = {
|
|
511
495
|
or to provide a custom fetch implementation for e.g. testing.
|
512
496
|
*/
|
513
497
|
fetch?: FetchFunction;
|
498
|
+
/**
|
499
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
500
|
+
Must be at least 1.
|
501
|
+
|
502
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
503
|
+
|
504
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
505
|
+
*/
|
506
|
+
maxSteps?: number;
|
514
507
|
};
|
515
508
|
type UseCompletionOptions = {
|
516
509
|
/**
|
@@ -578,42 +571,14 @@ type UseCompletionOptions = {
|
|
578
571
|
fetch?: FetchFunction;
|
579
572
|
};
|
580
573
|
|
581
|
-
/**
|
582
|
-
Represents the number of tokens used in a prompt and completion.
|
583
|
-
*/
|
584
|
-
type LanguageModelUsage = {
|
585
|
-
/**
|
586
|
-
The number of tokens used in the prompt.
|
587
|
-
*/
|
588
|
-
promptTokens: number;
|
589
|
-
/**
|
590
|
-
The number of tokens used in the completion.
|
591
|
-
*/
|
592
|
-
completionTokens: number;
|
593
|
-
/**
|
594
|
-
The total number of tokens used (promptTokens + completionTokens).
|
595
|
-
*/
|
596
|
-
totalTokens: number;
|
597
|
-
};
|
598
|
-
/**
|
599
|
-
Represents the number of tokens used in an embedding.
|
600
|
-
*/
|
601
|
-
type EmbeddingModelUsage = {
|
602
|
-
/**
|
603
|
-
The number of tokens used in the embedding.
|
604
|
-
*/
|
605
|
-
tokens: number;
|
606
|
-
};
|
607
|
-
|
608
574
|
declare const getOriginalFetch$1: () => typeof fetch;
|
609
|
-
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController,
|
575
|
+
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, getCurrentDate, requestType, }: {
|
610
576
|
api: string;
|
611
577
|
body: Record<string, any>;
|
612
578
|
streamProtocol: 'data' | 'text' | undefined;
|
613
579
|
credentials: RequestCredentials | undefined;
|
614
580
|
headers: HeadersInit | undefined;
|
615
581
|
abortController: (() => AbortController | null) | undefined;
|
616
|
-
restoreMessagesOnFailure: () => void;
|
617
582
|
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
618
583
|
onUpdate: (options: {
|
619
584
|
message: UIMessage;
|
@@ -667,17 +632,11 @@ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, Da
|
|
667
632
|
argsTextDelta: string;
|
668
633
|
}>, DataStreamPart<"d", "finish_message", {
|
669
634
|
finishReason: LanguageModelV2FinishReason;
|
670
|
-
usage?:
|
671
|
-
promptTokens: number;
|
672
|
-
completionTokens: number;
|
673
|
-
};
|
635
|
+
usage?: LanguageModelV2Usage;
|
674
636
|
}>, DataStreamPart<"e", "finish_step", {
|
675
637
|
isContinued: boolean;
|
676
638
|
finishReason: LanguageModelV2FinishReason;
|
677
|
-
usage?:
|
678
|
-
promptTokens: number;
|
679
|
-
completionTokens: number;
|
680
|
-
};
|
639
|
+
usage?: LanguageModelV2Usage;
|
681
640
|
}>, DataStreamPart<"f", "start_step", {
|
682
641
|
messageId: string;
|
683
642
|
}>, DataStreamPart<"g", "reasoning", {
|
@@ -1064,7 +1023,7 @@ has a limit on how many embeddings can be generated in a single call.
|
|
1064
1023
|
|
1065
1024
|
@returns A result object that contains the embeddings, the value, and additional information.
|
1066
1025
|
*/
|
1067
|
-
declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
1026
|
+
declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
1068
1027
|
/**
|
1069
1028
|
The embedding model to use.
|
1070
1029
|
*/
|
@@ -1098,6 +1057,12 @@ declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, ab
|
|
1098
1057
|
functionality that can be fully encapsulated in the provider.
|
1099
1058
|
*/
|
1100
1059
|
providerOptions?: ProviderOptions;
|
1060
|
+
/**
|
1061
|
+
* Maximum number of concurrent requests.
|
1062
|
+
*
|
1063
|
+
* @default Infinity
|
1064
|
+
*/
|
1065
|
+
maxParallelCalls?: number;
|
1101
1066
|
}): Promise<EmbedManyResult<VALUE>>;
|
1102
1067
|
|
1103
1068
|
type CallSettings = {
|
@@ -1180,19 +1145,6 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
|
|
1180
1145
|
*/
|
1181
1146
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
1182
1147
|
|
1183
|
-
type ToolResultContent = Array<{
|
1184
|
-
type: 'text';
|
1185
|
-
text: string;
|
1186
|
-
} | {
|
1187
|
-
type: 'image';
|
1188
|
-
data: string;
|
1189
|
-
mediaType?: string;
|
1190
|
-
/**
|
1191
|
-
* @deprecated Use `mediaType` instead.
|
1192
|
-
*/
|
1193
|
-
mimeType?: string;
|
1194
|
-
}>;
|
1195
|
-
|
1196
1148
|
/**
|
1197
1149
|
Text content part of a prompt. It contains a string of text.
|
1198
1150
|
*/
|
@@ -1568,20 +1520,20 @@ declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
1568
1520
|
data?: unknown;
|
1569
1521
|
}>;
|
1570
1522
|
}, "strict", z.ZodTypeAny, {
|
1571
|
-
id: string | number;
|
1572
1523
|
error: {
|
1573
1524
|
code: number;
|
1574
1525
|
message: string;
|
1575
1526
|
data?: unknown;
|
1576
1527
|
};
|
1528
|
+
id: string | number;
|
1577
1529
|
jsonrpc: "2.0";
|
1578
1530
|
}, {
|
1579
|
-
id: string | number;
|
1580
1531
|
error: {
|
1581
1532
|
code: number;
|
1582
1533
|
message: string;
|
1583
1534
|
data?: unknown;
|
1584
1535
|
};
|
1536
|
+
id: string | number;
|
1585
1537
|
jsonrpc: "2.0";
|
1586
1538
|
}>;
|
1587
1539
|
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
@@ -1702,20 +1654,20 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
|
|
1702
1654
|
data?: unknown;
|
1703
1655
|
}>;
|
1704
1656
|
}, "strict", z.ZodTypeAny, {
|
1705
|
-
id: string | number;
|
1706
1657
|
error: {
|
1707
1658
|
code: number;
|
1708
1659
|
message: string;
|
1709
1660
|
data?: unknown;
|
1710
1661
|
};
|
1662
|
+
id: string | number;
|
1711
1663
|
jsonrpc: "2.0";
|
1712
1664
|
}, {
|
1713
|
-
id: string | number;
|
1714
1665
|
error: {
|
1715
1666
|
code: number;
|
1716
1667
|
message: string;
|
1717
1668
|
data?: unknown;
|
1718
1669
|
};
|
1670
|
+
id: string | number;
|
1719
1671
|
jsonrpc: "2.0";
|
1720
1672
|
}>]>;
|
1721
1673
|
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
@@ -3065,7 +3017,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
|
|
3065
3017
|
/**
|
3066
3018
|
Generate a unique ID for each message.
|
3067
3019
|
*/
|
3068
|
-
experimental_generateMessageId?:
|
3020
|
+
experimental_generateMessageId?: IdGenerator$1;
|
3069
3021
|
/**
|
3070
3022
|
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3071
3023
|
|
@@ -3125,7 +3077,7 @@ A function that attempts to repair a tool call that failed to parse.
|
|
3125
3077
|
* Internal. For test use only. May change without notice.
|
3126
3078
|
*/
|
3127
3079
|
_internal?: {
|
3128
|
-
generateId?:
|
3080
|
+
generateId?: IdGenerator$1;
|
3129
3081
|
currentDate?: () => Date;
|
3130
3082
|
};
|
3131
3083
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
@@ -3584,7 +3536,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
|
|
3584
3536
|
/**
|
3585
3537
|
Generate a unique ID for each message.
|
3586
3538
|
*/
|
3587
|
-
experimental_generateMessageId?:
|
3539
|
+
experimental_generateMessageId?: IdGenerator$1;
|
3588
3540
|
/**
|
3589
3541
|
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3590
3542
|
|
@@ -3655,7 +3607,7 @@ Internal. For test use only. May change without notice.
|
|
3655
3607
|
*/
|
3656
3608
|
_internal?: {
|
3657
3609
|
now?: () => number;
|
3658
|
-
generateId?:
|
3610
|
+
generateId?: IdGenerator$1;
|
3659
3611
|
currentDate?: () => Date;
|
3660
3612
|
};
|
3661
3613
|
}): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
|
@@ -4718,4 +4670,4 @@ declare class RetryError extends AISDKError {
|
|
4718
4670
|
static isInstance(error: unknown): error is RetryError;
|
4719
4671
|
}
|
4720
4672
|
|
4721
|
-
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile,
|
4673
|
+
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RequestOptions, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UIMessagePart, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, appendResponseMessages, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, formatDataStreamPart, generateObject, generateText, getTextFromDataUrl, getToolInvocations, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, modelMessageSchema, parseDataStreamPart, parsePartialJson, pipeDataStreamToResponse, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { ToolCall, ToolResult, FetchFunction, Schema,
|
2
|
-
export {
|
1
|
+
import { ToolCall, ToolResult, FetchFunction, ToolResultContent, Schema, IdGenerator as IdGenerator$1 } from '@ai-sdk/provider-utils';
|
2
|
+
export { IdGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
|
3
3
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
4
|
-
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
4
|
+
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
5
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
6
6
|
import { ServerResponse } from 'node:http';
|
7
7
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
@@ -221,19 +221,15 @@ type TranscriptionModelResponseMetadata = {
|
|
221
221
|
/**
|
222
222
|
Represents the number of tokens used in a prompt and completion.
|
223
223
|
*/
|
224
|
-
type LanguageModelUsage
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
/**
|
230
|
-
The number of tokens used in the completion.
|
231
|
-
*/
|
232
|
-
completionTokens: number;
|
224
|
+
type LanguageModelUsage = LanguageModelV2Usage;
|
225
|
+
/**
|
226
|
+
Represents the number of tokens used in an embedding.
|
227
|
+
*/
|
228
|
+
type EmbeddingModelUsage = {
|
233
229
|
/**
|
234
|
-
The
|
230
|
+
The number of tokens used in the embedding.
|
235
231
|
*/
|
236
|
-
|
232
|
+
tokens: number;
|
237
233
|
};
|
238
234
|
|
239
235
|
type IdGenerator = () => string;
|
@@ -415,12 +411,6 @@ type ChatRequestOptions = {
|
|
415
411
|
};
|
416
412
|
type UseChatOptions = {
|
417
413
|
/**
|
418
|
-
Keeps the last message when an error happens. Defaults to `true`.
|
419
|
-
|
420
|
-
@deprecated This option will be removed in the next major release.
|
421
|
-
*/
|
422
|
-
keepLastMessageOnError?: boolean;
|
423
|
-
/**
|
424
414
|
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
425
415
|
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
426
416
|
*/
|
@@ -461,7 +451,7 @@ type UseChatOptions = {
|
|
461
451
|
* @param options.finishReason The finish reason of the message.
|
462
452
|
*/
|
463
453
|
onFinish?: (message: UIMessage, options: {
|
464
|
-
usage: LanguageModelUsage
|
454
|
+
usage: LanguageModelUsage;
|
465
455
|
finishReason: LanguageModelV2FinishReason;
|
466
456
|
}) => void;
|
467
457
|
/**
|
@@ -497,12 +487,6 @@ type UseChatOptions = {
|
|
497
487
|
*/
|
498
488
|
body?: object;
|
499
489
|
/**
|
500
|
-
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
501
|
-
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
502
|
-
* handle the extra fields before forwarding the request to the AI service.
|
503
|
-
*/
|
504
|
-
sendExtraMessageFields?: boolean;
|
505
|
-
/**
|
506
490
|
Streaming protocol that is used. Defaults to `data`.
|
507
491
|
*/
|
508
492
|
streamProtocol?: 'data' | 'text';
|
@@ -511,6 +495,15 @@ type UseChatOptions = {
|
|
511
495
|
or to provide a custom fetch implementation for e.g. testing.
|
512
496
|
*/
|
513
497
|
fetch?: FetchFunction;
|
498
|
+
/**
|
499
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
500
|
+
Must be at least 1.
|
501
|
+
|
502
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
503
|
+
|
504
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
505
|
+
*/
|
506
|
+
maxSteps?: number;
|
514
507
|
};
|
515
508
|
type UseCompletionOptions = {
|
516
509
|
/**
|
@@ -578,42 +571,14 @@ type UseCompletionOptions = {
|
|
578
571
|
fetch?: FetchFunction;
|
579
572
|
};
|
580
573
|
|
581
|
-
/**
|
582
|
-
Represents the number of tokens used in a prompt and completion.
|
583
|
-
*/
|
584
|
-
type LanguageModelUsage = {
|
585
|
-
/**
|
586
|
-
The number of tokens used in the prompt.
|
587
|
-
*/
|
588
|
-
promptTokens: number;
|
589
|
-
/**
|
590
|
-
The number of tokens used in the completion.
|
591
|
-
*/
|
592
|
-
completionTokens: number;
|
593
|
-
/**
|
594
|
-
The total number of tokens used (promptTokens + completionTokens).
|
595
|
-
*/
|
596
|
-
totalTokens: number;
|
597
|
-
};
|
598
|
-
/**
|
599
|
-
Represents the number of tokens used in an embedding.
|
600
|
-
*/
|
601
|
-
type EmbeddingModelUsage = {
|
602
|
-
/**
|
603
|
-
The number of tokens used in the embedding.
|
604
|
-
*/
|
605
|
-
tokens: number;
|
606
|
-
};
|
607
|
-
|
608
574
|
declare const getOriginalFetch$1: () => typeof fetch;
|
609
|
-
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController,
|
575
|
+
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, getCurrentDate, requestType, }: {
|
610
576
|
api: string;
|
611
577
|
body: Record<string, any>;
|
612
578
|
streamProtocol: 'data' | 'text' | undefined;
|
613
579
|
credentials: RequestCredentials | undefined;
|
614
580
|
headers: HeadersInit | undefined;
|
615
581
|
abortController: (() => AbortController | null) | undefined;
|
616
|
-
restoreMessagesOnFailure: () => void;
|
617
582
|
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
618
583
|
onUpdate: (options: {
|
619
584
|
message: UIMessage;
|
@@ -667,17 +632,11 @@ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, Da
|
|
667
632
|
argsTextDelta: string;
|
668
633
|
}>, DataStreamPart<"d", "finish_message", {
|
669
634
|
finishReason: LanguageModelV2FinishReason;
|
670
|
-
usage?:
|
671
|
-
promptTokens: number;
|
672
|
-
completionTokens: number;
|
673
|
-
};
|
635
|
+
usage?: LanguageModelV2Usage;
|
674
636
|
}>, DataStreamPart<"e", "finish_step", {
|
675
637
|
isContinued: boolean;
|
676
638
|
finishReason: LanguageModelV2FinishReason;
|
677
|
-
usage?:
|
678
|
-
promptTokens: number;
|
679
|
-
completionTokens: number;
|
680
|
-
};
|
639
|
+
usage?: LanguageModelV2Usage;
|
681
640
|
}>, DataStreamPart<"f", "start_step", {
|
682
641
|
messageId: string;
|
683
642
|
}>, DataStreamPart<"g", "reasoning", {
|
@@ -1064,7 +1023,7 @@ has a limit on how many embeddings can be generated in a single call.
|
|
1064
1023
|
|
1065
1024
|
@returns A result object that contains the embeddings, the value, and additional information.
|
1066
1025
|
*/
|
1067
|
-
declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
1026
|
+
declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
1068
1027
|
/**
|
1069
1028
|
The embedding model to use.
|
1070
1029
|
*/
|
@@ -1098,6 +1057,12 @@ declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, ab
|
|
1098
1057
|
functionality that can be fully encapsulated in the provider.
|
1099
1058
|
*/
|
1100
1059
|
providerOptions?: ProviderOptions;
|
1060
|
+
/**
|
1061
|
+
* Maximum number of concurrent requests.
|
1062
|
+
*
|
1063
|
+
* @default Infinity
|
1064
|
+
*/
|
1065
|
+
maxParallelCalls?: number;
|
1101
1066
|
}): Promise<EmbedManyResult<VALUE>>;
|
1102
1067
|
|
1103
1068
|
type CallSettings = {
|
@@ -1180,19 +1145,6 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
|
|
1180
1145
|
*/
|
1181
1146
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
1182
1147
|
|
1183
|
-
type ToolResultContent = Array<{
|
1184
|
-
type: 'text';
|
1185
|
-
text: string;
|
1186
|
-
} | {
|
1187
|
-
type: 'image';
|
1188
|
-
data: string;
|
1189
|
-
mediaType?: string;
|
1190
|
-
/**
|
1191
|
-
* @deprecated Use `mediaType` instead.
|
1192
|
-
*/
|
1193
|
-
mimeType?: string;
|
1194
|
-
}>;
|
1195
|
-
|
1196
1148
|
/**
|
1197
1149
|
Text content part of a prompt. It contains a string of text.
|
1198
1150
|
*/
|
@@ -1568,20 +1520,20 @@ declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
1568
1520
|
data?: unknown;
|
1569
1521
|
}>;
|
1570
1522
|
}, "strict", z.ZodTypeAny, {
|
1571
|
-
id: string | number;
|
1572
1523
|
error: {
|
1573
1524
|
code: number;
|
1574
1525
|
message: string;
|
1575
1526
|
data?: unknown;
|
1576
1527
|
};
|
1528
|
+
id: string | number;
|
1577
1529
|
jsonrpc: "2.0";
|
1578
1530
|
}, {
|
1579
|
-
id: string | number;
|
1580
1531
|
error: {
|
1581
1532
|
code: number;
|
1582
1533
|
message: string;
|
1583
1534
|
data?: unknown;
|
1584
1535
|
};
|
1536
|
+
id: string | number;
|
1585
1537
|
jsonrpc: "2.0";
|
1586
1538
|
}>;
|
1587
1539
|
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
@@ -1702,20 +1654,20 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
|
|
1702
1654
|
data?: unknown;
|
1703
1655
|
}>;
|
1704
1656
|
}, "strict", z.ZodTypeAny, {
|
1705
|
-
id: string | number;
|
1706
1657
|
error: {
|
1707
1658
|
code: number;
|
1708
1659
|
message: string;
|
1709
1660
|
data?: unknown;
|
1710
1661
|
};
|
1662
|
+
id: string | number;
|
1711
1663
|
jsonrpc: "2.0";
|
1712
1664
|
}, {
|
1713
|
-
id: string | number;
|
1714
1665
|
error: {
|
1715
1666
|
code: number;
|
1716
1667
|
message: string;
|
1717
1668
|
data?: unknown;
|
1718
1669
|
};
|
1670
|
+
id: string | number;
|
1719
1671
|
jsonrpc: "2.0";
|
1720
1672
|
}>]>;
|
1721
1673
|
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
@@ -3065,7 +3017,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
|
|
3065
3017
|
/**
|
3066
3018
|
Generate a unique ID for each message.
|
3067
3019
|
*/
|
3068
|
-
experimental_generateMessageId?:
|
3020
|
+
experimental_generateMessageId?: IdGenerator$1;
|
3069
3021
|
/**
|
3070
3022
|
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3071
3023
|
|
@@ -3125,7 +3077,7 @@ A function that attempts to repair a tool call that failed to parse.
|
|
3125
3077
|
* Internal. For test use only. May change without notice.
|
3126
3078
|
*/
|
3127
3079
|
_internal?: {
|
3128
|
-
generateId?:
|
3080
|
+
generateId?: IdGenerator$1;
|
3129
3081
|
currentDate?: () => Date;
|
3130
3082
|
};
|
3131
3083
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
@@ -3584,7 +3536,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
|
|
3584
3536
|
/**
|
3585
3537
|
Generate a unique ID for each message.
|
3586
3538
|
*/
|
3587
|
-
experimental_generateMessageId?:
|
3539
|
+
experimental_generateMessageId?: IdGenerator$1;
|
3588
3540
|
/**
|
3589
3541
|
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3590
3542
|
|
@@ -3655,7 +3607,7 @@ Internal. For test use only. May change without notice.
|
|
3655
3607
|
*/
|
3656
3608
|
_internal?: {
|
3657
3609
|
now?: () => number;
|
3658
|
-
generateId?:
|
3610
|
+
generateId?: IdGenerator$1;
|
3659
3611
|
currentDate?: () => Date;
|
3660
3612
|
};
|
3661
3613
|
}): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
|
@@ -4718,4 +4670,4 @@ declare class RetryError extends AISDKError {
|
|
4718
4670
|
static isInstance(error: unknown): error is RetryError;
|
4719
4671
|
}
|
4720
4672
|
|
4721
|
-
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile,
|
4673
|
+
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RequestOptions, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UIMessagePart, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, appendResponseMessages, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, formatDataStreamPart, generateObject, generateText, getTextFromDataUrl, getToolInvocations, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, modelMessageSchema, parseDataStreamPart, parsePartialJson, pipeDataStreamToResponse, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
|