ai 3.0.20 → 3.0.22

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.
Files changed (63) hide show
  1. package/dist/index.d.mts +45 -354
  2. package/dist/index.d.ts +45 -354
  3. package/dist/index.js +161 -460
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +136 -430
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +6 -41
  8. package/react/dist/index.d.mts +1 -1
  9. package/react/dist/index.d.ts +1 -1
  10. package/react/dist/index.js +3 -3
  11. package/react/dist/index.js.map +1 -1
  12. package/react/dist/index.mjs +3 -3
  13. package/react/dist/index.mjs.map +1 -1
  14. package/rsc/dist/rsc-server.mjs +3 -3
  15. package/rsc/dist/rsc-server.mjs.map +1 -1
  16. package/solid/dist/index.d.mts +1 -1
  17. package/solid/dist/index.d.ts +1 -1
  18. package/solid/dist/index.js +3 -3
  19. package/solid/dist/index.js.map +1 -1
  20. package/solid/dist/index.mjs +3 -3
  21. package/solid/dist/index.mjs.map +1 -1
  22. package/svelte/dist/index.d.mts +1 -1
  23. package/svelte/dist/index.d.ts +1 -1
  24. package/svelte/dist/index.js +3 -3
  25. package/svelte/dist/index.js.map +1 -1
  26. package/svelte/dist/index.mjs +3 -3
  27. package/svelte/dist/index.mjs.map +1 -1
  28. package/vue/dist/index.d.mts +1 -1
  29. package/vue/dist/index.d.ts +1 -1
  30. package/vue/dist/index.js +3 -3
  31. package/vue/dist/index.js.map +1 -1
  32. package/vue/dist/index.mjs +3 -3
  33. package/vue/dist/index.mjs.map +1 -1
  34. package/anthropic/dist/index.d.mts +0 -403
  35. package/anthropic/dist/index.d.ts +0 -403
  36. package/anthropic/dist/index.js +0 -950
  37. package/anthropic/dist/index.js.map +0 -1
  38. package/anthropic/dist/index.mjs +0 -914
  39. package/anthropic/dist/index.mjs.map +0 -1
  40. package/google/dist/index.d.mts +0 -399
  41. package/google/dist/index.d.ts +0 -399
  42. package/google/dist/index.js +0 -954
  43. package/google/dist/index.js.map +0 -1
  44. package/google/dist/index.mjs +0 -918
  45. package/google/dist/index.mjs.map +0 -1
  46. package/mistral/dist/index.d.mts +0 -404
  47. package/mistral/dist/index.d.ts +0 -404
  48. package/mistral/dist/index.js +0 -921
  49. package/mistral/dist/index.js.map +0 -1
  50. package/mistral/dist/index.mjs +0 -885
  51. package/mistral/dist/index.mjs.map +0 -1
  52. package/openai/dist/index.d.mts +0 -468
  53. package/openai/dist/index.d.ts +0 -468
  54. package/openai/dist/index.js +0 -1334
  55. package/openai/dist/index.js.map +0 -1
  56. package/openai/dist/index.mjs +0 -1298
  57. package/openai/dist/index.mjs.map +0 -1
  58. package/spec/dist/index.d.mts +0 -780
  59. package/spec/dist/index.d.ts +0 -780
  60. package/spec/dist/index.js +0 -863
  61. package/spec/dist/index.js.map +0 -1
  62. package/spec/dist/index.mjs +0 -797
  63. package/spec/dist/index.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,362 +1,10 @@
1
+ import { LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1CallWarning } from '@ai-sdk/provider';
1
2
  import { z } from 'zod';
2
- import { JSONSchema7 } from 'json-schema';
3
3
  import { AssistantStream } from 'openai/lib/AssistantStream';
4
4
  import { Run } from 'openai/resources/beta/threads/runs/runs';
5
5
  import { ChatCompletionResponseChunk } from '@mistralai/mistralai';
6
6
  import { ServerResponse } from 'node:http';
7
7
 
8
- /**
9
- A tool has a name, a description, and a set of parameters.
10
-
11
- Note: this is **not** the user-facing tool definition. The AI SDK methods will
12
- map the user-facing tool definitions to this format.
13
- */
14
- type LanguageModelV1FunctionTool = {
15
- /**
16
- The type of the tool. Only functions for now, but this gives us room to
17
- add more specific tool types in the future and use a discriminated union.
18
- */
19
- type: 'function';
20
- /**
21
- The name of the tool. Unique within this model call.
22
- */
23
- name: string;
24
- description?: string;
25
- parameters: JSONSchema7;
26
- };
27
-
28
- type LanguageModelV1CallSettings = {
29
- /**
30
- * Maximum number of tokens to generate.
31
- */
32
- maxTokens?: number;
33
- /**
34
- * Temperature setting. This is a number between 0 (almost no randomness) and
35
- * 1 (very random).
36
- *
37
- * Different LLM providers have different temperature
38
- * scales, so they'd need to map it (without mapping, the same temperature has
39
- * different effects on different models). The provider can also chose to map
40
- * this to topP, potentially even using a custom setting on their model.
41
- *
42
- * Note: This is an example of a setting that requires a clear specification of
43
- * the semantics.
44
- */
45
- temperature?: number;
46
- /**
47
- * Nucleus sampling. This is a number between 0 and 1.
48
- *
49
- * E.g. 0.1 would mean that only tokens with the top 10% probability mass
50
- * are considered.
51
- *
52
- * It is recommended to set either `temperature` or `topP`, but not both.
53
- */
54
- topP?: number;
55
- /**
56
- * Presence penalty setting. It affects the likelihood of the model to
57
- * repeat information that is already in the prompt.
58
- *
59
- * The presence penalty is a number between -1 (increase repetition)
60
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
61
- */
62
- presencePenalty?: number;
63
- /**
64
- * Frequency penalty setting. It affects the likelihood of the model
65
- * to repeatedly use the same words or phrases.
66
- *
67
- * The frequency penalty is a number between -1 (increase repetition)
68
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
69
- */
70
- frequencyPenalty?: number;
71
- /**
72
- * The seed (integer) to use for random sampling. If set and supported
73
- * by the model, calls will generate deterministic results.
74
- */
75
- seed?: number;
76
- /**
77
- * Abort signal for cancelling the operation.
78
- */
79
- abortSignal?: AbortSignal;
80
- };
81
-
82
- /**
83
- A prompt is a list of messages.
84
-
85
- Note: Not all models and prompt formats support multi-modal inputs and
86
- tool calls. The validation happens at runtime.
87
-
88
- Note: This is not a user-facing prompt. The AI SDK methods will map the
89
- user-facing prompt types such as chat or instruction prompts to this format.
90
- */
91
- type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
92
- type LanguageModelV1Message = {
93
- role: 'system';
94
- content: string;
95
- } | {
96
- role: 'user';
97
- content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
98
- } | {
99
- role: 'assistant';
100
- content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
101
- } | {
102
- role: 'tool';
103
- content: Array<LanguageModelV1ToolResultPart>;
104
- };
105
- /**
106
- Text content part of a prompt. It contains a string of text.
107
- */
108
- interface LanguageModelV1TextPart {
109
- type: 'text';
110
- /**
111
- The text content.
112
- */
113
- text: string;
114
- }
115
- /**
116
- Image content part of a prompt. It contains an image.
117
- */
118
- interface LanguageModelV1ImagePart {
119
- type: 'image';
120
- /**
121
- Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
122
- */
123
- image: Uint8Array | URL;
124
- /**
125
- Optional mime type of the image.
126
- */
127
- mimeType?: string;
128
- }
129
- /**
130
- Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
131
- */
132
- interface LanguageModelV1ToolCallPart {
133
- type: 'tool-call';
134
- /**
135
- ID of the tool call. This ID is used to match the tool call with the tool result.
136
- */
137
- toolCallId: string;
138
- /**
139
- Name of the tool that is being called.
140
- */
141
- toolName: string;
142
- /**
143
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
144
- */
145
- args: unknown;
146
- }
147
- /**
148
- Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
149
- */
150
- interface LanguageModelV1ToolResultPart {
151
- type: 'tool-result';
152
- /**
153
- ID of the tool call that this result is associated with.
154
- */
155
- toolCallId: string;
156
- /**
157
- Name of the tool that generated this result.
158
- */
159
- toolName: string;
160
- /**
161
- Result of the tool call. This is a JSON-serializable object.
162
- */
163
- result: unknown;
164
- /**
165
- Optional flag if the result is an error or an error message.
166
- */
167
- isError?: boolean;
168
- }
169
-
170
- type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
171
- /**
172
- * Whether the user provided the input as messages or as
173
- * a prompt. This can help guide non-chat models in the
174
- * expansion, bc different expansions can be needed for
175
- * chat/non-chat use cases.
176
- */
177
- inputFormat: 'messages' | 'prompt';
178
- /**
179
- * The mode affects the behavior of the language model. It is required to
180
- * support provider-independent streaming and generation of structured objects.
181
- * The model can take this information and e.g. configure json mode, the correct
182
- * low level grammar, etc. It can also be used to optimize the efficiency of the
183
- * streaming, e.g. tool-delta stream parts are only needed in the
184
- * object-tool mode.
185
- */
186
- mode: {
187
- type: 'regular';
188
- tools?: Array<LanguageModelV1FunctionTool>;
189
- } | {
190
- type: 'object-json';
191
- } | {
192
- type: 'object-grammar';
193
- schema: JSONSchema7;
194
- } | {
195
- type: 'object-tool';
196
- tool: LanguageModelV1FunctionTool;
197
- };
198
- /**
199
- * A language mode prompt is a standardized prompt type.
200
- *
201
- * Note: This is **not** the user-facing prompt. The AI SDK methods will map the
202
- * user-facing prompt types such as chat or instruction prompts to this format.
203
- * That approach allows us to evolve the user facing prompts without breaking
204
- * the language model interface.
205
- */
206
- prompt: LanguageModelV1Prompt;
207
- };
208
-
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 LanguageModelV1CallWarning = {
214
- type: 'unsupported-setting';
215
- setting: keyof LanguageModelV1CallSettings;
216
- } | {
217
- type: 'other';
218
- message: string;
219
- };
220
-
221
- type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
222
-
223
- type LanguageModelV1FunctionToolCall = {
224
- toolCallType: 'function';
225
- toolCallId: string;
226
- toolName: string;
227
- /**
228
- * Stringified JSON object with the tool call arguments. Must match the
229
- * parameters schema of the tool.
230
- */
231
- args: string;
232
- };
233
-
234
- /**
235
- * Experimental: Specification for a language model that implements the language model
236
- * interface version 1.
237
- */
238
- type LanguageModelV1 = {
239
- /**
240
- * The language model must specify which language model interface
241
- * version it implements. This will allow us to evolve the language
242
- * model interface and retain backwards compatibility. The different
243
- * implementation versions can be handled as a discriminated union
244
- * on our side.
245
- */
246
- readonly specificationVersion: 'v1';
247
- /**
248
- * Name of the provider for logging purposes.
249
- */
250
- readonly provider: string;
251
- /**
252
- * Provider-specific model ID for logging purposes.
253
- */
254
- readonly modelId: string;
255
- /**
256
- * Default object generation mode that should be used with this model when
257
- * no mode is specified. Should be the mode with the best results for this
258
- * model. `undefined` can be returned if object generation is not supported.
259
- *
260
- * This is needed to generate the best objects possible w/o requiring the
261
- * user to explicitly specify the object generation mode.
262
- */
263
- readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
264
- /**
265
- * Generates a language model output (non-streaming).
266
- *
267
- * Naming: "do" prefix to prevent accidental direct usage of the method
268
- * by the user.
269
- */
270
- doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
271
- /**
272
- * Text that the model has generated. Can be undefined if the model
273
- * has only generated tool calls.
274
- */
275
- text?: string;
276
- /**
277
- * Tool calls that the model has generated. Can be undefined if the
278
- * model has only generated text.
279
- */
280
- toolCalls?: Array<LanguageModelV1FunctionToolCall>;
281
- /**
282
- * Finish reason.
283
- */
284
- finishReason: LanguageModelV1FinishReason;
285
- /**
286
- * Usage information.
287
- */
288
- usage: {
289
- promptTokens: number;
290
- completionTokens: number;
291
- };
292
- /**
293
- * Raw prompt and setting information for observability provider integration.
294
- */
295
- rawCall: {
296
- /**
297
- * Raw prompt after expansion and conversion to the format that the
298
- * provider uses to send the information to their API.
299
- */
300
- rawPrompt: unknown;
301
- /**
302
- * Raw settings that are used for the API call. Includes provider-specific
303
- * settings.
304
- */
305
- rawSettings: Record<string, unknown>;
306
- };
307
- warnings?: LanguageModelV1CallWarning[];
308
- }>;
309
- /**
310
- * Generates a language model output (streaming).
311
- *
312
- * Naming: "do" prefix to prevent accidental direct usage of the method
313
- * by the user.
314
- *
315
- * @return A stream of higher-level language model output parts.
316
- */
317
- doStream(options: LanguageModelV1CallOptions): PromiseLike<{
318
- stream: ReadableStream<LanguageModelV1StreamPart>;
319
- /**
320
- * Raw prompt and setting information for observability provider integration.
321
- */
322
- rawCall: {
323
- /**
324
- * Raw prompt after expansion and conversion to the format that the
325
- * provider uses to send the information to their API.
326
- */
327
- rawPrompt: unknown;
328
- /**
329
- * Raw settings that are used for the API call. Includes provider-specific
330
- * settings.
331
- */
332
- rawSettings: Record<string, unknown>;
333
- };
334
- warnings?: LanguageModelV1CallWarning[];
335
- }>;
336
- };
337
- type LanguageModelV1StreamPart = {
338
- type: 'text-delta';
339
- textDelta: string;
340
- } | ({
341
- type: 'tool-call';
342
- } & LanguageModelV1FunctionToolCall) | {
343
- type: 'tool-call-delta';
344
- toolCallType: 'function';
345
- toolCallId: string;
346
- toolName: string;
347
- argsTextDelta: string;
348
- } | {
349
- type: 'finish';
350
- finishReason: LanguageModelV1FinishReason;
351
- usage: {
352
- promptTokens: number;
353
- completionTokens: number;
354
- };
355
- } | {
356
- type: 'error';
357
- error: unknown;
358
- };
359
-
360
8
  type TokenUsage = {
361
9
  promptTokens: number;
362
10
  completionTokens: number;
@@ -1035,6 +683,12 @@ declare class StreamTextResult<TOOLS extends Record<string, ExperimentalTool>> {
1035
683
  @returns an `AIStream` object.
1036
684
  */
1037
685
  toAIStream(callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
686
+ /**
687
+ Creates a simple text stream response.
688
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
689
+ Non-text-delta events are ignored.
690
+ */
691
+ toTextStreamResponse(init?: ResponseInit): Response;
1038
692
  }
1039
693
 
1040
694
  interface FunctionCall {
@@ -1341,6 +995,13 @@ declare const toolCallStreamPart: StreamPart<'7', 'tool_calls', {
1341
995
  tool_calls: ToolCall[];
1342
996
  }>;
1343
997
  declare const messageAnnotationsStreamPart: StreamPart<'8', 'message_annotations', Array<JSONValue>>;
998
+ type StreamParts = typeof textStreamPart | typeof functionCallStreamPart | typeof dataStreamPart | typeof errorStreamPart | typeof assistantMessageStreamPart | typeof assistantControlDataStreamPart | typeof dataMessageStreamPart | typeof toolCallStreamPart | typeof messageAnnotationsStreamPart;
999
+ /**
1000
+ * Maps the type of a stream part to its value type.
1001
+ */
1002
+ type StreamPartValueType = {
1003
+ [P in StreamParts as P['name']]: ReturnType<P['parse']>['value'];
1004
+ };
1344
1005
  type StreamPartType = ReturnType<typeof textStreamPart.parse> | ReturnType<typeof functionCallStreamPart.parse> | ReturnType<typeof dataStreamPart.parse> | ReturnType<typeof errorStreamPart.parse> | ReturnType<typeof assistantMessageStreamPart.parse> | ReturnType<typeof assistantControlDataStreamPart.parse> | ReturnType<typeof dataMessageStreamPart.parse> | ReturnType<typeof toolCallStreamPart.parse> | ReturnType<typeof messageAnnotationsStreamPart.parse>;
1345
1006
  /**
1346
1007
  * The map of prefixes for data in the stream
@@ -1375,12 +1036,42 @@ declare const StreamStringPrefixes: {
1375
1036
  readonly tool_calls: "7";
1376
1037
  readonly message_annotations: "8";
1377
1038
  };
1039
+ /**
1040
+ Parses a stream part from a string.
1041
+
1042
+ @param line The string to parse.
1043
+ @returns The parsed stream part.
1044
+ @throws An error if the string cannot be parsed.
1045
+ */
1046
+ declare const parseStreamPart: (line: string) => StreamPartType;
1047
+ /**
1048
+ Prepends a string with a prefix from the `StreamChunkPrefixes`, JSON-ifies it,
1049
+ and appends a new line.
1050
+
1051
+ It ensures type-safety for the part type and value.
1052
+ */
1053
+ declare function formatStreamPart<T extends keyof StreamPartValueType>(type: T, value: StreamPartValueType[T]): StreamString;
1378
1054
 
1379
1055
  /**
1380
1056
  * Generates a 7-character random string to use for IDs. Not secure.
1381
1057
  */
1382
1058
  declare const generateId: (size?: number | undefined) => string;
1383
1059
 
1060
+ /**
1061
+ Converts a ReadableStreamDefaultReader into an async generator that yields
1062
+ StreamPart objects.
1063
+
1064
+ @param reader
1065
+ Reader for the stream to read from.
1066
+ @param isAborted
1067
+ Optional function that returns true if the request has been aborted.
1068
+ If the function returns true, the generator will stop reading the stream.
1069
+ If the function is not provided, the generator will not stop reading the stream.
1070
+ */
1071
+ declare function readDataStream(reader: ReadableStreamDefaultReader<Uint8Array>, { isAborted, }?: {
1072
+ isAborted?: () => boolean;
1073
+ }): AsyncGenerator<StreamPartType>;
1074
+
1384
1075
  declare function createChunkDecoder(): (chunk: Uint8Array | undefined) => string;
1385
1076
  declare function createChunkDecoder(complex: false): (chunk: Uint8Array | undefined) => string;
1386
1077
  declare function createChunkDecoder(complex: true): (chunk: Uint8Array | undefined) => StreamPartType[];
@@ -2072,4 +1763,4 @@ declare function streamToResponse(res: ReadableStream, response: ServerResponse,
2072
1763
  status?: number;
2073
1764
  }): void;
2074
1765
 
2075
- export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage, AssistantResponse, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataContent, DataMessage, DeepPartial, ErrorStreamPart, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamData, StreamObjectResult, StreamString, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, Tool, ToolCall, ToolCallHandler, ToolCallPart, ToolCallPayload, ToolChoice, ToolContent, ToolResultPart, UseChatOptions, UseCompletionOptions, UserContent, convertDataContentToBase64String, convertDataContentToUint8Array, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, isStreamStringEqualToType, generateId as nanoid, readableFromAsyncIterable, streamToResponse, tool, trimStartOfStreamHelper };
1766
+ export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage, AssistantResponse, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataContent, DataMessage, DeepPartial, ErrorStreamPart, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamData, StreamObjectResult, StreamPart, StreamString, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, Tool, ToolCall, ToolCallHandler, ToolCallPart, ToolCallPayload, ToolChoice, ToolContent, ToolResultPart, UseChatOptions, UseCompletionOptions, UserContent, convertDataContentToBase64String, convertDataContentToUint8Array, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, formatStreamPart, generateId, isStreamStringEqualToType, generateId as nanoid, parseStreamPart, readDataStream, readableFromAsyncIterable, streamToResponse, tool, trimStartOfStreamHelper };