ai 5.0.0-canary.2 → 5.0.0-canary.20

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 (51) hide show
  1. package/CHANGELOG.md +305 -0
  2. package/README.md +4 -4
  3. package/dist/index.d.mts +3246 -2586
  4. package/dist/index.d.ts +3246 -2586
  5. package/dist/index.js +4080 -3409
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +4748 -4084
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/internal/index.d.mts +473 -0
  10. package/dist/internal/index.d.ts +473 -0
  11. package/dist/internal/index.js +957 -0
  12. package/dist/internal/index.js.map +1 -0
  13. package/dist/internal/index.mjs +930 -0
  14. package/dist/internal/index.mjs.map +1 -0
  15. package/{mcp-stdio/dist → dist/mcp-stdio}/index.js +5 -8
  16. package/dist/mcp-stdio/index.js.map +1 -0
  17. package/{mcp-stdio/dist → dist/mcp-stdio}/index.mjs +5 -20
  18. package/dist/mcp-stdio/index.mjs.map +1 -0
  19. package/{test/dist → dist/test}/index.d.mts +23 -24
  20. package/{test/dist → dist/test}/index.d.ts +23 -24
  21. package/{test/dist → dist/test}/index.js +39 -16
  22. package/dist/test/index.js.map +1 -0
  23. package/{test/dist → dist/test}/index.mjs +38 -15
  24. package/dist/test/index.mjs.map +1 -0
  25. package/internal.d.ts +1 -0
  26. package/mcp-stdio.d.ts +1 -0
  27. package/package.json +32 -49
  28. package/test.d.ts +1 -0
  29. package/mcp-stdio/create-child-process.test.ts +0 -92
  30. package/mcp-stdio/create-child-process.ts +0 -21
  31. package/mcp-stdio/dist/index.js.map +0 -1
  32. package/mcp-stdio/dist/index.mjs.map +0 -1
  33. package/mcp-stdio/get-environment.ts +0 -43
  34. package/mcp-stdio/index.ts +0 -4
  35. package/mcp-stdio/mcp-stdio-transport.test.ts +0 -262
  36. package/mcp-stdio/mcp-stdio-transport.ts +0 -157
  37. package/rsc/dist/index.d.ts +0 -813
  38. package/rsc/dist/index.mjs +0 -18
  39. package/rsc/dist/rsc-client.d.mts +0 -1
  40. package/rsc/dist/rsc-client.mjs +0 -18
  41. package/rsc/dist/rsc-client.mjs.map +0 -1
  42. package/rsc/dist/rsc-server.d.mts +0 -748
  43. package/rsc/dist/rsc-server.mjs +0 -2142
  44. package/rsc/dist/rsc-server.mjs.map +0 -1
  45. package/rsc/dist/rsc-shared.d.mts +0 -101
  46. package/rsc/dist/rsc-shared.mjs +0 -308
  47. package/rsc/dist/rsc-shared.mjs.map +0 -1
  48. package/test/dist/index.js.map +0 -1
  49. package/test/dist/index.mjs.map +0 -1
  50. package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.mts +8 -8
  51. package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.ts +8 -8
@@ -0,0 +1,473 @@
1
+ import { ToolResultContent, Schema } from '@ai-sdk/provider-utils';
2
+ export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';
3
+ import { SharedV2ProviderOptions, LanguageModelV2Prompt, JSONValue, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice } from '@ai-sdk/provider';
4
+ import { z } from 'zod';
5
+
6
+ declare function download({ url }: {
7
+ url: URL;
8
+ }): Promise<{
9
+ data: Uint8Array;
10
+ mediaType: string | undefined;
11
+ }>;
12
+
13
+ /**
14
+ Additional provider-specific options.
15
+
16
+ They are passed through to the provider from the AI SDK and enable
17
+ provider-specific functionality that can be fully encapsulated in the provider.
18
+ */
19
+ type ProviderOptions = SharedV2ProviderOptions;
20
+
21
+ /**
22
+ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
23
+ */
24
+ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
25
+
26
+ /**
27
+ Text content part of a prompt. It contains a string of text.
28
+ */
29
+ interface TextPart {
30
+ type: 'text';
31
+ /**
32
+ The text content.
33
+ */
34
+ text: string;
35
+ /**
36
+ Additional provider-specific metadata. They are passed through
37
+ to the provider from the AI SDK and enable provider-specific
38
+ functionality that can be fully encapsulated in the provider.
39
+ */
40
+ providerOptions?: ProviderOptions;
41
+ }
42
+ /**
43
+ Image content part of a prompt. It contains an image.
44
+ */
45
+ interface ImagePart {
46
+ type: 'image';
47
+ /**
48
+ Image data. Can either be:
49
+
50
+ - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
51
+ - URL: a URL that points to the image
52
+ */
53
+ image: DataContent | URL;
54
+ /**
55
+ Optional IANA media type of the image.
56
+
57
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
58
+ */
59
+ mediaType?: string;
60
+ /**
61
+ Additional provider-specific metadata. They are passed through
62
+ to the provider from the AI SDK and enable provider-specific
63
+ functionality that can be fully encapsulated in the provider.
64
+ */
65
+ providerOptions?: ProviderOptions;
66
+ }
67
+ /**
68
+ File content part of a prompt. It contains a file.
69
+ */
70
+ interface FilePart {
71
+ type: 'file';
72
+ /**
73
+ File data. Can either be:
74
+
75
+ - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
76
+ - URL: a URL that points to the image
77
+ */
78
+ data: DataContent | URL;
79
+ /**
80
+ Optional filename of the file.
81
+ */
82
+ filename?: string;
83
+ /**
84
+ IANA media type of the file.
85
+
86
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
87
+ */
88
+ mediaType: string;
89
+ /**
90
+ Additional provider-specific metadata. They are passed through
91
+ to the provider from the AI SDK and enable provider-specific
92
+ functionality that can be fully encapsulated in the provider.
93
+ */
94
+ providerOptions?: ProviderOptions;
95
+ }
96
+ /**
97
+ * Reasoning content part of a prompt. It contains a reasoning.
98
+ */
99
+ interface ReasoningPart {
100
+ type: 'reasoning';
101
+ /**
102
+ The reasoning text.
103
+ */
104
+ text: string;
105
+ /**
106
+ Additional provider-specific metadata. They are passed through
107
+ to the provider from the AI SDK and enable provider-specific
108
+ functionality that can be fully encapsulated in the provider.
109
+ */
110
+ providerOptions?: ProviderOptions;
111
+ }
112
+ /**
113
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
114
+ */
115
+ interface ToolCallPart {
116
+ type: 'tool-call';
117
+ /**
118
+ ID of the tool call. This ID is used to match the tool call with the tool result.
119
+ */
120
+ toolCallId: string;
121
+ /**
122
+ Name of the tool that is being called.
123
+ */
124
+ toolName: string;
125
+ /**
126
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
127
+ */
128
+ args: unknown;
129
+ /**
130
+ Additional provider-specific metadata. They are passed through
131
+ to the provider from the AI SDK and enable provider-specific
132
+ functionality that can be fully encapsulated in the provider.
133
+ */
134
+ providerOptions?: ProviderOptions;
135
+ }
136
+ /**
137
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
138
+ */
139
+ interface ToolResultPart {
140
+ type: 'tool-result';
141
+ /**
142
+ ID of the tool call that this result is associated with.
143
+ */
144
+ toolCallId: string;
145
+ /**
146
+ Name of the tool that generated this result.
147
+ */
148
+ toolName: string;
149
+ /**
150
+ Result of the tool call. This is a JSON-serializable object.
151
+ */
152
+ result: unknown;
153
+ /**
154
+ Multi-part content of the tool result. Only for tools that support multipart results.
155
+ */
156
+ experimental_content?: ToolResultContent;
157
+ /**
158
+ Optional flag if the result is an error or an error message.
159
+ */
160
+ isError?: boolean;
161
+ /**
162
+ Additional provider-specific metadata. They are passed through
163
+ to the provider from the AI SDK and enable provider-specific
164
+ functionality that can be fully encapsulated in the provider.
165
+ */
166
+ providerOptions?: ProviderOptions;
167
+ }
168
+
169
+ /**
170
+ A system message. It can contain system information.
171
+
172
+ Note: using the "system" part of the prompt is strongly preferred
173
+ to increase the resilience against prompt injection attacks,
174
+ and because not all providers support several system messages.
175
+ */
176
+ type SystemModelMessage = {
177
+ role: 'system';
178
+ content: string;
179
+ /**
180
+ Additional provider-specific metadata. They are passed through
181
+ to the provider from the AI SDK and enable provider-specific
182
+ functionality that can be fully encapsulated in the provider.
183
+ */
184
+ providerOptions?: ProviderOptions;
185
+ };
186
+ /**
187
+ A user message. It can contain text or a combination of text and images.
188
+ */
189
+ type UserModelMessage = {
190
+ role: 'user';
191
+ content: UserContent;
192
+ /**
193
+ Additional provider-specific metadata. They are passed through
194
+ to the provider from the AI SDK and enable provider-specific
195
+ functionality that can be fully encapsulated in the provider.
196
+ */
197
+ providerOptions?: ProviderOptions;
198
+ };
199
+ /**
200
+ Content of a user message. It can be a string or an array of text and image parts.
201
+ */
202
+ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
203
+ /**
204
+ An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
205
+ */
206
+ type AssistantModelMessage = {
207
+ role: 'assistant';
208
+ content: AssistantContent;
209
+ /**
210
+ Additional provider-specific metadata. They are passed through
211
+ to the provider from the AI SDK and enable provider-specific
212
+ functionality that can be fully encapsulated in the provider.
213
+ */
214
+ providerOptions?: ProviderOptions;
215
+ };
216
+ /**
217
+ Content of an assistant message.
218
+ It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
219
+ */
220
+ type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart>;
221
+ /**
222
+ A tool message. It contains the result of one or more tool calls.
223
+ */
224
+ type ToolModelMessage = {
225
+ role: 'tool';
226
+ content: ToolContent;
227
+ /**
228
+ Additional provider-specific metadata. They are passed through
229
+ to the provider from the AI SDK and enable provider-specific
230
+ functionality that can be fully encapsulated in the provider.
231
+ */
232
+ providerOptions?: ProviderOptions;
233
+ };
234
+ /**
235
+ Content of a tool message. It is an array of tool result parts.
236
+ */
237
+ type ToolContent = Array<ToolResultPart>;
238
+ /**
239
+ A message that can be used in the `messages` field of a prompt.
240
+ It can be a user message, an assistant message, or a tool message.
241
+ */
242
+ type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
243
+
244
+ /**
245
+ Prompt part of the AI function options.
246
+ It contains a system message, a simple text prompt, or a list of messages.
247
+ */
248
+ type Prompt = {
249
+ /**
250
+ System message to include in the prompt. Can be used with `prompt` or `messages`.
251
+ */
252
+ system?: string;
253
+ /**
254
+ A prompt. It can be either a text prompt or a list of messages.
255
+
256
+ You can either use `prompt` or `messages` but not both.
257
+ */
258
+ prompt?: string | Array<ModelMessage>;
259
+ /**
260
+ A list of messages.
261
+
262
+ You can either use `prompt` or `messages` but not both.
263
+ */
264
+ messages?: Array<ModelMessage>;
265
+ };
266
+
267
+ type StandardizedPrompt = {
268
+ /**
269
+ * System message.
270
+ */
271
+ system?: string;
272
+ /**
273
+ * Messages.
274
+ */
275
+ messages: ModelMessage[];
276
+ };
277
+ declare function standardizePrompt(prompt: Prompt): Promise<StandardizedPrompt>;
278
+
279
+ declare function convertToLanguageModelPrompt({ prompt, supportedUrls, downloadImplementation, }: {
280
+ prompt: StandardizedPrompt;
281
+ supportedUrls: Record<string, RegExp[]>;
282
+ downloadImplementation?: typeof download;
283
+ }): Promise<LanguageModelV2Prompt>;
284
+
285
+ type CallSettings = {
286
+ /**
287
+ Maximum number of tokens to generate.
288
+ */
289
+ maxOutputTokens?: number;
290
+ /**
291
+ Temperature setting. This is a number between 0 (almost no randomness) and
292
+ 1 (very random).
293
+
294
+ It is recommended to set either `temperature` or `topP`, but not both.
295
+ Use `null` to use the provider's default temperature.
296
+
297
+ @default 0
298
+ */
299
+ temperature?: number | null;
300
+ /**
301
+ Nucleus sampling. This is a number between 0 and 1.
302
+
303
+ E.g. 0.1 would mean that only tokens with the top 10% probability mass
304
+ are considered.
305
+
306
+ It is recommended to set either `temperature` or `topP`, but not both.
307
+ */
308
+ topP?: number;
309
+ /**
310
+ Only sample from the top K options for each subsequent token.
311
+
312
+ Used to remove "long tail" low probability responses.
313
+ Recommended for advanced use cases only. You usually only need to use temperature.
314
+ */
315
+ topK?: number;
316
+ /**
317
+ Presence penalty setting. It affects the likelihood of the model to
318
+ repeat information that is already in the prompt.
319
+
320
+ The presence penalty is a number between -1 (increase repetition)
321
+ and 1 (maximum penalty, decrease repetition). 0 means no penalty.
322
+ */
323
+ presencePenalty?: number;
324
+ /**
325
+ Frequency penalty setting. It affects the likelihood of the model
326
+ to repeatedly use the same words or phrases.
327
+
328
+ The frequency penalty is a number between -1 (increase repetition)
329
+ and 1 (maximum penalty, decrease repetition). 0 means no penalty.
330
+ */
331
+ frequencyPenalty?: number;
332
+ /**
333
+ Stop sequences.
334
+ If set, the model will stop generating text when one of the stop sequences is generated.
335
+ Providers may have limits on the number of stop sequences.
336
+ */
337
+ stopSequences?: string[];
338
+ /**
339
+ The seed (integer) to use for random sampling. If set and supported
340
+ by the model, calls will generate deterministic results.
341
+ */
342
+ seed?: number;
343
+ /**
344
+ Maximum number of retries. Set to 0 to disable retries.
345
+
346
+ @default 2
347
+ */
348
+ maxRetries?: number;
349
+ /**
350
+ Abort signal.
351
+ */
352
+ abortSignal?: AbortSignal;
353
+ /**
354
+ Additional HTTP headers to be sent with the request.
355
+ Only applicable for HTTP-based providers.
356
+ */
357
+ headers?: Record<string, string | undefined>;
358
+ };
359
+
360
+ /**
361
+ * Validates call settings and sets default values.
362
+ */
363
+ declare function prepareCallSettings({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, }: Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>): Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries' | 'temperature'> & {
364
+ temperature?: number;
365
+ };
366
+
367
+ /**
368
+ Tool choice for the generation. It supports the following settings:
369
+
370
+ - `auto` (default): the model can choose whether and which tools to call.
371
+ - `required`: the model must call a tool. It can choose which tool to call.
372
+ - `none`: the model must not call tools
373
+ - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
374
+ */
375
+ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
376
+ type: 'tool';
377
+ toolName: Extract<keyof TOOLS, string>;
378
+ };
379
+
380
+ type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
381
+ interface ToolExecutionOptions {
382
+ /**
383
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
384
+ */
385
+ toolCallId: string;
386
+ /**
387
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
388
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
389
+ */
390
+ messages: ModelMessage[];
391
+ /**
392
+ * An optional abort signal that indicates that the overall operation should be aborted.
393
+ */
394
+ abortSignal?: AbortSignal;
395
+ }
396
+ type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
397
+ /**
398
+ A tool contains the description and the schema of the input that the tool expects.
399
+ This enables the language model to generate the input.
400
+
401
+ The tool can also contain an optional execute function for the actual execution function of the tool.
402
+ */
403
+ type Tool<PARAMETERS extends JSONValue | unknown | never = any, RESULT = any> = {
404
+ /**
405
+ An optional description of what the tool does.
406
+ Will be used by the language model to decide whether to use the tool.
407
+ Not used for provider-defined tools.
408
+ */
409
+ description?: string;
410
+ } & NeverOptional<PARAMETERS, {
411
+ /**
412
+ The schema of the input that the tool expects. The language model will use this to generate the input.
413
+ It is also used to validate the output of the language model.
414
+ Use descriptions to make the input understandable for the language model.
415
+ */
416
+ parameters: ToolParameters<PARAMETERS>;
417
+ }> & NeverOptional<RESULT, {
418
+ /**
419
+ An async function that is called with the arguments from the tool call and produces a result.
420
+ If not provided, the tool will not be executed automatically.
421
+
422
+ @args is the input of the tool call.
423
+ @options.abortSignal is a signal that can be used to abort the tool call.
424
+ */
425
+ execute: (args: [PARAMETERS] extends [never] ? undefined : PARAMETERS, options: ToolExecutionOptions) => PromiseLike<RESULT>;
426
+ /**
427
+ Optional conversion function that maps the tool result to multi-part tool content for LLMs.
428
+ */
429
+ experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
430
+ }> & ({
431
+ /**
432
+ Function tool.
433
+ */
434
+ type?: undefined | 'function';
435
+ } | {
436
+ /**
437
+ Provider-defined tool.
438
+ */
439
+ type: 'provider-defined';
440
+ /**
441
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
442
+ */
443
+ id: `${string}.${string}`;
444
+ /**
445
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
446
+ */
447
+ args: Record<string, unknown>;
448
+ });
449
+
450
+ type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute'>>;
451
+
452
+ declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
453
+ tools: TOOLS | undefined;
454
+ toolChoice: ToolChoice<TOOLS> | undefined;
455
+ activeTools: Array<keyof TOOLS> | undefined;
456
+ }): {
457
+ tools: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool> | undefined;
458
+ toolChoice: LanguageModelV2ToolChoice | undefined;
459
+ };
460
+
461
+ type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
462
+
463
+ /**
464
+ * Validate and prepare retries.
465
+ */
466
+ declare function prepareRetries({ maxRetries, }: {
467
+ maxRetries: number | undefined;
468
+ }): {
469
+ maxRetries: number;
470
+ retry: RetryFunction;
471
+ };
472
+
473
+ export { convertToLanguageModelPrompt, prepareCallSettings, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };