ai 3.4.17 → 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/CHANGELOG.md +43 -0
- package/dist/index.d.mts +110 -76
- package/dist/index.d.ts +110 -76
- package/dist/index.js +388 -447
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +374 -436
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -12
- package/rsc/dist/index.d.ts +16 -2
- package/rsc/dist/rsc-server.d.mts +16 -2
- package/rsc/dist/rsc-server.mjs +192 -269
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +3 -1
- package/test/dist/index.d.ts +3 -1
- package/test/dist/index.js +2 -0
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +2 -0
- package/test/dist/index.mjs.map +1 -1
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
|
-
|
134
|
+
ID for the generated response.
|
126
135
|
*/
|
127
136
|
id: string;
|
128
137
|
/**
|
129
|
-
|
130
|
-
|
138
|
+
Timestamp for the start of the generated response.
|
139
|
+
*/
|
131
140
|
timestamp: Date;
|
132
141
|
/**
|
133
|
-
|
134
|
-
|
142
|
+
The ID of the response model that was used to generate the response.
|
143
|
+
*/
|
135
144
|
modelId: string;
|
136
|
-
|
137
|
-
|
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;
|
@@ -608,7 +635,8 @@ It can be a user message, an assistant message, or a tool message.
|
|
608
635
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
609
636
|
|
610
637
|
/**
|
611
|
-
Prompt part of the AI function options.
|
638
|
+
Prompt part of the AI function options.
|
639
|
+
It contains a system message, a simple text prompt, or a list of messages.
|
612
640
|
*/
|
613
641
|
type Prompt = {
|
614
642
|
/**
|
@@ -620,7 +648,7 @@ type Prompt = {
|
|
620
648
|
*/
|
621
649
|
prompt?: string;
|
622
650
|
/**
|
623
|
-
A list of
|
651
|
+
A list of messages. You can either use `prompt` or `messages` but not both.
|
624
652
|
*/
|
625
653
|
messages?: Array<CoreMessage>;
|
626
654
|
};
|
@@ -657,9 +685,13 @@ interface GenerateObjectResult<T> {
|
|
657
685
|
headers?: Record<string, string>;
|
658
686
|
};
|
659
687
|
/**
|
688
|
+
Additional request information.
|
689
|
+
*/
|
690
|
+
readonly request: LanguageModelRequestMetadata;
|
691
|
+
/**
|
660
692
|
Additional response information.
|
661
693
|
*/
|
662
|
-
readonly response:
|
694
|
+
readonly response: LanguageModelResponseMetadata;
|
663
695
|
/**
|
664
696
|
Logprobs for the completion.
|
665
697
|
`undefined` if the mode does not support logprobs or if was not enabled.
|
@@ -927,9 +959,13 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
|
927
959
|
headers?: Record<string, string>;
|
928
960
|
};
|
929
961
|
/**
|
962
|
+
Additional request information from the last step.
|
963
|
+
*/
|
964
|
+
readonly request: Promise<LanguageModelRequestMetadata>;
|
965
|
+
/**
|
930
966
|
Additional response information.
|
931
967
|
*/
|
932
|
-
readonly response: Promise<
|
968
|
+
readonly response: Promise<LanguageModelResponseMetadata>;
|
933
969
|
/**
|
934
970
|
The generated object (typed according to the schema). Resolved when the response is finished.
|
935
971
|
*/
|
@@ -1019,7 +1055,7 @@ type OnFinishCallback<RESULT> = (event: {
|
|
1019
1055
|
/**
|
1020
1056
|
Response metadata.
|
1021
1057
|
*/
|
1022
|
-
response:
|
1058
|
+
response: LanguageModelResponseMetadata;
|
1023
1059
|
/**
|
1024
1060
|
Warnings from the model provider (e.g. unsupported settings).
|
1025
1061
|
*/
|
@@ -1219,11 +1255,7 @@ This enables the language model to generate the input.
|
|
1219
1255
|
|
1220
1256
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
1221
1257
|
*/
|
1222
|
-
|
1223
|
-
/**
|
1224
|
-
An optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
|
1225
|
-
*/
|
1226
|
-
description?: string;
|
1258
|
+
type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = {
|
1227
1259
|
/**
|
1228
1260
|
The schema of the input that the tool expects. The language model will use this to generate the input.
|
1229
1261
|
It is also used to validate the output of the language model.
|
@@ -1231,6 +1263,10 @@ interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
|
|
1231
1263
|
*/
|
1232
1264
|
parameters: PARAMETERS;
|
1233
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
|
+
/**
|
1234
1270
|
An async function that is called with the arguments from the tool call and produces a result.
|
1235
1271
|
If not provided, the tool will not be executed automatically.
|
1236
1272
|
|
@@ -1240,7 +1276,29 @@ interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
|
|
1240
1276
|
execute?: (args: inferParameters<PARAMETERS>, options: {
|
1241
1277
|
abortSignal?: AbortSignal;
|
1242
1278
|
}) => PromiseLike<RESULT>;
|
1243
|
-
}
|
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
|
+
});
|
1244
1302
|
/**
|
1245
1303
|
Helper function for inferring the execute args of a tool.
|
1246
1304
|
*/
|
@@ -1317,24 +1375,6 @@ onlyBar('bar');
|
|
1317
1375
|
*/
|
1318
1376
|
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
1319
1377
|
|
1320
|
-
/**
|
1321
|
-
Typed tool call that is returned by `generateText` and `streamText`.
|
1322
|
-
It contains the tool call ID, the tool name, and the tool arguments.
|
1323
|
-
*/
|
1324
|
-
interface ToolCall<NAME extends string, ARGS> {
|
1325
|
-
/**
|
1326
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
1327
|
-
*/
|
1328
|
-
toolCallId: string;
|
1329
|
-
/**
|
1330
|
-
Name of the tool that is being called.
|
1331
|
-
*/
|
1332
|
-
toolName: NAME;
|
1333
|
-
/**
|
1334
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
1335
|
-
*/
|
1336
|
-
args: ARGS;
|
1337
|
-
}
|
1338
1378
|
type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
|
1339
1379
|
[NAME in keyof TOOLS]: {
|
1340
1380
|
type: 'tool-call';
|
@@ -1345,28 +1385,6 @@ type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
|
|
1345
1385
|
}>;
|
1346
1386
|
type ToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToolCallUnion<TOOLS>>;
|
1347
1387
|
|
1348
|
-
/**
|
1349
|
-
Typed tool result that is returned by `generateText` and `streamText`.
|
1350
|
-
It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
1351
|
-
*/
|
1352
|
-
interface ToolResult<NAME extends string, ARGS, RESULT> {
|
1353
|
-
/**
|
1354
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
1355
|
-
*/
|
1356
|
-
toolCallId: string;
|
1357
|
-
/**
|
1358
|
-
Name of the tool that was called.
|
1359
|
-
*/
|
1360
|
-
toolName: NAME;
|
1361
|
-
/**
|
1362
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
1363
|
-
*/
|
1364
|
-
args: ARGS;
|
1365
|
-
/**
|
1366
|
-
Result of the tool call. This is the result of the tool's execution.
|
1367
|
-
*/
|
1368
|
-
result: RESULT;
|
1369
|
-
}
|
1370
1388
|
type ToToolsWithExecute<TOOLS extends Record<string, CoreTool>> = {
|
1371
1389
|
[K in keyof TOOLS as TOOLS[K] extends {
|
1372
1390
|
execute: any;
|
@@ -1432,9 +1450,19 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
|
|
1432
1450
|
readonly headers?: Record<string, string>;
|
1433
1451
|
};
|
1434
1452
|
/**
|
1453
|
+
Additional request information.
|
1454
|
+
*/
|
1455
|
+
readonly request: LanguageModelRequestMetadata;
|
1456
|
+
/**
|
1435
1457
|
Additional response information.
|
1436
1458
|
*/
|
1437
|
-
readonly response:
|
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
|
+
};
|
1438
1466
|
/**
|
1439
1467
|
Additional provider-specific metadata. They are passed through
|
1440
1468
|
from the provider to the AI SDK and enable provider-specific
|
@@ -1483,12 +1511,7 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1483
1511
|
*/
|
1484
1512
|
readonly warnings: CallWarning[] | undefined;
|
1485
1513
|
/**
|
1486
|
-
|
1487
|
-
potentially containing tool calls.
|
1488
|
-
|
1489
|
-
When there are tool results, there is an additional tool message with the tool results that are available.
|
1490
|
-
If there are tools that do not have execute functions, they are not included in the tool results and
|
1491
|
-
need to be added separately.
|
1514
|
+
@deprecated use `response.messages` instead.
|
1492
1515
|
*/
|
1493
1516
|
readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
|
1494
1517
|
/**
|
@@ -1516,9 +1539,23 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1516
1539
|
readonly headers?: Record<string, string>;
|
1517
1540
|
};
|
1518
1541
|
/**
|
1542
|
+
Additional request information.
|
1543
|
+
*/
|
1544
|
+
readonly request: LanguageModelRequestMetadata;
|
1545
|
+
/**
|
1519
1546
|
Additional response information.
|
1520
1547
|
*/
|
1521
|
-
readonly response:
|
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
|
+
};
|
1522
1559
|
/**
|
1523
1560
|
Logprobs for the completion.
|
1524
1561
|
`undefined` if the mode does not support logprobs or if it was not enabled.
|
@@ -1719,14 +1756,7 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1719
1756
|
headers?: Record<string, string>;
|
1720
1757
|
};
|
1721
1758
|
/**
|
1722
|
-
|
1723
|
-
potentially containing tool calls.
|
1724
|
-
|
1725
|
-
When there are tool results, there is an additional tool message with the tool results that are available.
|
1726
|
-
If there are tools that do not have execute functions, they are not included in the tool results and
|
1727
|
-
need to be added separately.
|
1728
|
-
|
1729
|
-
Resolved when the response is finished.
|
1759
|
+
@deprecated use `response.messages` instead.
|
1730
1760
|
*/
|
1731
1761
|
readonly responseMessages: Promise<Array<CoreAssistantMessage | CoreToolMessage>>;
|
1732
1762
|
/**
|
@@ -1736,7 +1766,11 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1736
1766
|
*/
|
1737
1767
|
readonly steps: Promise<Array<StepResult<TOOLS>>>;
|
1738
1768
|
/**
|
1739
|
-
Additional
|
1769
|
+
Additional request information from the last step.
|
1770
|
+
*/
|
1771
|
+
readonly request: Promise<LanguageModelRequestMetadata>;
|
1772
|
+
/**
|
1773
|
+
Additional response information from the last step.
|
1740
1774
|
*/
|
1741
1775
|
readonly response: Promise<LanguageModelResponseMetadataWithHeaders>;
|
1742
1776
|
/**
|
@@ -3241,4 +3275,4 @@ declare const generateId: (size?: number) => string;
|
|
3241
3275
|
*/
|
3242
3276
|
declare const nanoid: (size?: number) => string;
|
3243
3277
|
|
3244
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool,
|
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 };
|