ai 3.4.18 → 3.4.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.
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import { ServerResponse } from 'http';
8
8
  import { ServerResponse as ServerResponse$1 } from 'node:http';
9
9
  import { AssistantStream } from 'openai/lib/AssistantStream';
10
10
  import { Run } from 'openai/resources/beta/threads/runs/runs';
11
+ export { ToolCall as CoreToolCall, ToolResult as CoreToolResult } from '@ai-sdk/provider-utils';
11
12
 
12
13
  /**
13
14
  * Telemetry configuration.
@@ -120,23 +121,36 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
120
121
  type: 'tool';
121
122
  toolName: keyof TOOLS;
122
123
  };
124
+
125
+ type LanguageModelRequestMetadata = {
126
+ /**
127
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
128
+ */
129
+ body?: string;
130
+ };
131
+
123
132
  type LanguageModelResponseMetadata = {
124
133
  /**
125
- ID for the generated response.
134
+ ID for the generated response.
126
135
  */
127
136
  id: string;
128
137
  /**
129
- Timestamp for the start of the generated response.
130
- */
138
+ Timestamp for the start of the generated response.
139
+ */
131
140
  timestamp: Date;
132
141
  /**
133
- The ID of the response model that was used to generate the response.
134
- */
142
+ The ID of the response model that was used to generate the response.
143
+ */
135
144
  modelId: string;
136
- };
137
- type LanguageModelResponseMetadataWithHeaders = LanguageModelResponseMetadata & {
145
+ /**
146
+ Response headers.
147
+ */
138
148
  headers?: Record<string, string>;
139
149
  };
150
+ /**
151
+ @deprecated Use `LanguageModelResponseMetadata` instead.
152
+ */
153
+ type LanguageModelResponseMetadataWithHeaders = LanguageModelResponseMetadata;
140
154
 
141
155
  /**
142
156
  * Provider for language and text embedding models.
@@ -402,6 +416,15 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
402
416
  */
403
417
  type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
404
418
 
419
+ type ToolResultContent = Array<{
420
+ type: 'text';
421
+ text: string;
422
+ } | {
423
+ type: 'image';
424
+ data: string;
425
+ mimeType?: string;
426
+ }>;
427
+
405
428
  /**
406
429
  Text content part of a prompt. It contains a string of text.
407
430
  */
@@ -506,6 +529,10 @@ interface ToolResultPart {
506
529
  */
507
530
  result: unknown;
508
531
  /**
532
+ Multi-part content of the tool result. Only for tools that support multipart results.
533
+ */
534
+ experimental_content?: ToolResultContent;
535
+ /**
509
536
  Optional flag if the result is an error or an error message.
510
537
  */
511
538
  isError?: boolean;
@@ -658,9 +685,13 @@ interface GenerateObjectResult<T> {
658
685
  headers?: Record<string, string>;
659
686
  };
660
687
  /**
688
+ Additional request information.
689
+ */
690
+ readonly request: LanguageModelRequestMetadata;
691
+ /**
661
692
  Additional response information.
662
693
  */
663
- readonly response: LanguageModelResponseMetadataWithHeaders;
694
+ readonly response: LanguageModelResponseMetadata;
664
695
  /**
665
696
  Logprobs for the completion.
666
697
  `undefined` if the mode does not support logprobs or if was not enabled.
@@ -928,9 +959,13 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
928
959
  headers?: Record<string, string>;
929
960
  };
930
961
  /**
962
+ Additional request information from the last step.
963
+ */
964
+ readonly request: Promise<LanguageModelRequestMetadata>;
965
+ /**
931
966
  Additional response information.
932
967
  */
933
- readonly response: Promise<LanguageModelResponseMetadataWithHeaders>;
968
+ readonly response: Promise<LanguageModelResponseMetadata>;
934
969
  /**
935
970
  The generated object (typed according to the schema). Resolved when the response is finished.
936
971
  */
@@ -1020,7 +1055,7 @@ type OnFinishCallback<RESULT> = (event: {
1020
1055
  /**
1021
1056
  Response metadata.
1022
1057
  */
1023
- response: LanguageModelResponseMetadataWithHeaders;
1058
+ response: LanguageModelResponseMetadata;
1024
1059
  /**
1025
1060
  Warnings from the model provider (e.g. unsupported settings).
1026
1061
  */
@@ -1220,11 +1255,7 @@ This enables the language model to generate the input.
1220
1255
 
1221
1256
  The tool can also contain an optional execute function for the actual execution function of the tool.
1222
1257
  */
1223
- interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
1224
- /**
1225
- An optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
1226
- */
1227
- description?: string;
1258
+ type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = {
1228
1259
  /**
1229
1260
  The schema of the input that the tool expects. The language model will use this to generate the input.
1230
1261
  It is also used to validate the output of the language model.
@@ -1232,6 +1263,10 @@ interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
1232
1263
  */
1233
1264
  parameters: PARAMETERS;
1234
1265
  /**
1266
+ Optional conversion function that maps the tool result to multi-part tool content for LLMs.
1267
+ */
1268
+ experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
1269
+ /**
1235
1270
  An async function that is called with the arguments from the tool call and produces a result.
1236
1271
  If not provided, the tool will not be executed automatically.
1237
1272
 
@@ -1241,7 +1276,29 @@ interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
1241
1276
  execute?: (args: inferParameters<PARAMETERS>, options: {
1242
1277
  abortSignal?: AbortSignal;
1243
1278
  }) => PromiseLike<RESULT>;
1244
- }
1279
+ } & ({
1280
+ /**
1281
+ Function tool.
1282
+ */
1283
+ type?: undefined | 'function';
1284
+ /**
1285
+ An optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
1286
+ */
1287
+ description?: string;
1288
+ } | {
1289
+ /**
1290
+ Provider-defined tool.
1291
+ */
1292
+ type: 'provider-defined';
1293
+ /**
1294
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
1295
+ */
1296
+ id: `${string}.${string}`;
1297
+ /**
1298
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
1299
+ */
1300
+ args: Record<string, unknown>;
1301
+ });
1245
1302
  /**
1246
1303
  Helper function for inferring the execute args of a tool.
1247
1304
  */
@@ -1273,8 +1330,6 @@ type ConvertibleMessage = {
1273
1330
  /**
1274
1331
  Converts an array of messages from useChat into an array of CoreMessages that can be used
1275
1332
  with the AI core functions (e.g. `streamText`).
1276
-
1277
- Only full tool calls are included in assistant messages. Partial tool calls are removed.
1278
1333
  */
1279
1334
  declare function convertToCoreMessages(messages: Array<ConvertibleMessage>): CoreMessage[];
1280
1335
 
@@ -1320,24 +1375,6 @@ onlyBar('bar');
1320
1375
  */
1321
1376
  type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
1322
1377
 
1323
- /**
1324
- Typed tool call that is returned by `generateText` and `streamText`.
1325
- It contains the tool call ID, the tool name, and the tool arguments.
1326
- */
1327
- interface ToolCall<NAME extends string, ARGS> {
1328
- /**
1329
- ID of the tool call. This ID is used to match the tool call with the tool result.
1330
- */
1331
- toolCallId: string;
1332
- /**
1333
- Name of the tool that is being called.
1334
- */
1335
- toolName: NAME;
1336
- /**
1337
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
1338
- */
1339
- args: ARGS;
1340
- }
1341
1378
  type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
1342
1379
  [NAME in keyof TOOLS]: {
1343
1380
  type: 'tool-call';
@@ -1348,28 +1385,6 @@ type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
1348
1385
  }>;
1349
1386
  type ToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToolCallUnion<TOOLS>>;
1350
1387
 
1351
- /**
1352
- Typed tool result that is returned by `generateText` and `streamText`.
1353
- It contains the tool call ID, the tool name, the tool arguments, and the tool result.
1354
- */
1355
- interface ToolResult<NAME extends string, ARGS, RESULT> {
1356
- /**
1357
- ID of the tool call. This ID is used to match the tool call with the tool result.
1358
- */
1359
- toolCallId: string;
1360
- /**
1361
- Name of the tool that was called.
1362
- */
1363
- toolName: NAME;
1364
- /**
1365
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
1366
- */
1367
- args: ARGS;
1368
- /**
1369
- Result of the tool call. This is the result of the tool's execution.
1370
- */
1371
- result: RESULT;
1372
- }
1373
1388
  type ToToolsWithExecute<TOOLS extends Record<string, CoreTool>> = {
1374
1389
  [K in keyof TOOLS as TOOLS[K] extends {
1375
1390
  execute: any;
@@ -1435,9 +1450,19 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
1435
1450
  readonly headers?: Record<string, string>;
1436
1451
  };
1437
1452
  /**
1453
+ Additional request information.
1454
+ */
1455
+ readonly request: LanguageModelRequestMetadata;
1456
+ /**
1438
1457
  Additional response information.
1439
1458
  */
1440
- readonly response: LanguageModelResponseMetadataWithHeaders;
1459
+ readonly response: LanguageModelResponseMetadata & {
1460
+ /**
1461
+ The response messages that were generated during the call. It consists of an assistant message,
1462
+ potentially containing tool calls.
1463
+ */
1464
+ readonly messages: Array<CoreAssistantMessage | CoreToolMessage>;
1465
+ };
1441
1466
  /**
1442
1467
  Additional provider-specific metadata. They are passed through
1443
1468
  from the provider to the AI SDK and enable provider-specific
@@ -1486,12 +1511,7 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
1486
1511
  */
1487
1512
  readonly warnings: CallWarning[] | undefined;
1488
1513
  /**
1489
- The response messages that were generated during the call. It consists of an assistant message,
1490
- potentially containing tool calls.
1491
-
1492
- When there are tool results, there is an additional tool message with the tool results that are available.
1493
- If there are tools that do not have execute functions, they are not included in the tool results and
1494
- need to be added separately.
1514
+ @deprecated use `response.messages` instead.
1495
1515
  */
1496
1516
  readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
1497
1517
  /**
@@ -1519,9 +1539,23 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
1519
1539
  readonly headers?: Record<string, string>;
1520
1540
  };
1521
1541
  /**
1542
+ Additional request information.
1543
+ */
1544
+ readonly request: LanguageModelRequestMetadata;
1545
+ /**
1522
1546
  Additional response information.
1523
1547
  */
1524
- readonly response: LanguageModelResponseMetadataWithHeaders;
1548
+ readonly response: LanguageModelResponseMetadata & {
1549
+ /**
1550
+ The response messages that were generated during the call. It consists of an assistant message,
1551
+ potentially containing tool calls.
1552
+
1553
+ When there are tool results, there is an additional tool message with the tool results that are available.
1554
+ If there are tools that do not have execute functions, they are not included in the tool results and
1555
+ need to be added separately.
1556
+ */
1557
+ messages: Array<CoreAssistantMessage | CoreToolMessage>;
1558
+ };
1525
1559
  /**
1526
1560
  Logprobs for the completion.
1527
1561
  `undefined` if the mode does not support logprobs or if it was not enabled.
@@ -1722,14 +1756,7 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1722
1756
  headers?: Record<string, string>;
1723
1757
  };
1724
1758
  /**
1725
- The response messages that were generated during the call. It consists of an assistant message,
1726
- potentially containing tool calls.
1727
-
1728
- When there are tool results, there is an additional tool message with the tool results that are available.
1729
- If there are tools that do not have execute functions, they are not included in the tool results and
1730
- need to be added separately.
1731
-
1732
- Resolved when the response is finished.
1759
+ @deprecated use `response.messages` instead.
1733
1760
  */
1734
1761
  readonly responseMessages: Promise<Array<CoreAssistantMessage | CoreToolMessage>>;
1735
1762
  /**
@@ -1739,7 +1766,11 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1739
1766
  */
1740
1767
  readonly steps: Promise<Array<StepResult<TOOLS>>>;
1741
1768
  /**
1742
- Additional response information.
1769
+ Additional request information from the last step.
1770
+ */
1771
+ readonly request: Promise<LanguageModelRequestMetadata>;
1772
+ /**
1773
+ Additional response information from the last step.
1743
1774
  */
1744
1775
  readonly response: Promise<LanguageModelResponseMetadataWithHeaders>;
1745
1776
  /**
@@ -3244,4 +3275,4 @@ declare const generateId: (size?: number) => string;
3244
3275
  */
3245
3276
  declare const nanoid: (size?: number) => string;
3246
3277
 
3247
- export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, ToolCall as CoreToolCall, ToolCallUnion as CoreToolCallUnion, CoreToolChoice, CoreToolMessage, ToolResult as CoreToolResult, ToolResultUnion as CoreToolResultUnion, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LanguageModelResponseMetadata, LanguageModelResponseMetadataWithHeaders, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, MistralStream, NoObjectGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, Provider, ProviderMetadata, ReplicateStream, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createCallbacksTransformer, createEventStreamTransformer, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_customProvider, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, experimental_wrapLanguageModel, generateId, generateObject, generateText, nanoid, readableFromAsyncIterable, streamObject, streamText, streamToResponse, tool, trimStartOfStreamHelper };
3278
+ export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, ToolCallUnion as CoreToolCallUnion, CoreToolChoice, CoreToolMessage, ToolResultUnion as CoreToolResultUnion, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelResponseMetadataWithHeaders, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, MistralStream, NoObjectGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, Provider, ProviderMetadata, ReplicateStream, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createCallbacksTransformer, createEventStreamTransformer, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_customProvider, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, experimental_wrapLanguageModel, generateId, generateObject, generateText, nanoid, readableFromAsyncIterable, streamObject, streamText, streamToResponse, tool, trimStartOfStreamHelper };