ai 4.1.62 → 4.1.64
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 +20 -0
- package/dist/index.d.mts +1828 -1807
- package/dist/index.d.ts +1828 -1807
- package/dist/index.js +261 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/rsc/dist/index.d.ts +3 -2
- package/rsc/dist/rsc-server.d.mts +3 -2
- package/rsc/dist/rsc-server.mjs +129 -20
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.d.mts
CHANGED
@@ -2,7 +2,7 @@ import { IDGenerator } from '@ai-sdk/provider-utils';
|
|
2
2
|
export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
3
|
import { DataStreamString, Message, Schema, DeepPartial, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
|
4
4
|
export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UIMessage, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream, zodSchema } from '@ai-sdk/ui-utils';
|
5
|
-
import { LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV1ProviderMetadata,
|
5
|
+
import { LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1CallOptions, AISDKError, LanguageModelV1FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, ProviderV1, NoSuchModelError } from '@ai-sdk/provider';
|
6
6
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1Prompt, LanguageModelV1StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
7
7
|
import { ServerResponse } from 'node:http';
|
8
8
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
@@ -411,119 +411,6 @@ declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, ab
|
|
411
411
|
experimental_telemetry?: TelemetrySettings;
|
412
412
|
}): Promise<EmbedManyResult<VALUE>>;
|
413
413
|
|
414
|
-
/**
|
415
|
-
The result of a `generateImage` call.
|
416
|
-
It contains the images and additional information.
|
417
|
-
*/
|
418
|
-
interface GenerateImageResult {
|
419
|
-
/**
|
420
|
-
The first image that was generated.
|
421
|
-
*/
|
422
|
-
readonly image: GeneratedImage;
|
423
|
-
/**
|
424
|
-
The images that were generated.
|
425
|
-
*/
|
426
|
-
readonly images: Array<GeneratedImage>;
|
427
|
-
/**
|
428
|
-
Warnings for the call, e.g. unsupported settings.
|
429
|
-
*/
|
430
|
-
readonly warnings: Array<ImageGenerationWarning>;
|
431
|
-
/**
|
432
|
-
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
433
|
-
*/
|
434
|
-
readonly responses: Array<ImageModelResponseMetadata>;
|
435
|
-
}
|
436
|
-
interface GeneratedImage {
|
437
|
-
/**
|
438
|
-
Image as a base64 encoded string.
|
439
|
-
*/
|
440
|
-
readonly base64: string;
|
441
|
-
/**
|
442
|
-
Image as a Uint8Array.
|
443
|
-
*/
|
444
|
-
readonly uint8Array: Uint8Array;
|
445
|
-
}
|
446
|
-
|
447
|
-
/**
|
448
|
-
Generates images using an image model.
|
449
|
-
|
450
|
-
@param model - The image model to use.
|
451
|
-
@param prompt - The prompt that should be used to generate the image.
|
452
|
-
@param n - Number of images to generate. Default: 1.
|
453
|
-
@param size - Size of the images to generate. Must have the format `{width}x{height}`.
|
454
|
-
@param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
|
455
|
-
@param seed - Seed for the image generation.
|
456
|
-
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
457
|
-
as body parameters.
|
458
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
459
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
460
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
461
|
-
|
462
|
-
@returns A result object that contains the generated images.
|
463
|
-
*/
|
464
|
-
declare function generateImage({ model, prompt, n, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, _internal, }: {
|
465
|
-
/**
|
466
|
-
The image model to use.
|
467
|
-
*/
|
468
|
-
model: ImageModelV1;
|
469
|
-
/**
|
470
|
-
The prompt that should be used to generate the image.
|
471
|
-
*/
|
472
|
-
prompt: string;
|
473
|
-
/**
|
474
|
-
Number of images to generate.
|
475
|
-
*/
|
476
|
-
n?: number;
|
477
|
-
/**
|
478
|
-
Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
|
479
|
-
*/
|
480
|
-
size?: `${number}x${number}`;
|
481
|
-
/**
|
482
|
-
Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
|
483
|
-
*/
|
484
|
-
aspectRatio?: `${number}:${number}`;
|
485
|
-
/**
|
486
|
-
Seed for the image generation. If not provided, the default seed will be used.
|
487
|
-
*/
|
488
|
-
seed?: number;
|
489
|
-
/**
|
490
|
-
Additional provider-specific options that are passed through to the provider
|
491
|
-
as body parameters.
|
492
|
-
|
493
|
-
The outer record is keyed by the provider name, and the inner
|
494
|
-
record is keyed by the provider-specific metadata key.
|
495
|
-
```ts
|
496
|
-
{
|
497
|
-
"openai": {
|
498
|
-
"style": "vivid"
|
499
|
-
}
|
500
|
-
}
|
501
|
-
```
|
502
|
-
*/
|
503
|
-
providerOptions?: Record<string, Record<string, JSONValue>>;
|
504
|
-
/**
|
505
|
-
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
506
|
-
|
507
|
-
@default 2
|
508
|
-
*/
|
509
|
-
maxRetries?: number;
|
510
|
-
/**
|
511
|
-
Abort signal.
|
512
|
-
*/
|
513
|
-
abortSignal?: AbortSignal;
|
514
|
-
/**
|
515
|
-
Additional headers to include in the request.
|
516
|
-
Only applicable for HTTP-based providers.
|
517
|
-
*/
|
518
|
-
headers?: Record<string, string>;
|
519
|
-
/**
|
520
|
-
* Internal. For test use only. May change without notice.
|
521
|
-
*/
|
522
|
-
_internal?: {
|
523
|
-
currentDate?: () => Date;
|
524
|
-
};
|
525
|
-
}): Promise<GenerateImageResult>;
|
526
|
-
|
527
414
|
type CallSettings = {
|
528
415
|
/**
|
529
416
|
Maximum number of tokens to generate.
|
@@ -862,9 +749,10 @@ type CoreAssistantMessage = {
|
|
862
749
|
};
|
863
750
|
declare const coreAssistantMessageSchema: z.ZodType<CoreAssistantMessage>;
|
864
751
|
/**
|
865
|
-
Content of an assistant message.
|
752
|
+
Content of an assistant message.
|
753
|
+
It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
866
754
|
*/
|
867
|
-
type AssistantContent = string | Array<TextPart | ReasoningPart | RedactedReasoningPart | ToolCallPart>;
|
755
|
+
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | RedactedReasoningPart | ToolCallPart>;
|
868
756
|
/**
|
869
757
|
A tool message. It contains the result of one or more tool calls.
|
870
758
|
*/
|
@@ -914,959 +802,318 @@ type Prompt = {
|
|
914
802
|
};
|
915
803
|
|
916
804
|
/**
|
917
|
-
|
805
|
+
* A generated file.
|
918
806
|
*/
|
919
|
-
interface
|
920
|
-
/**
|
921
|
-
The generated object (typed according to the schema).
|
922
|
-
*/
|
923
|
-
readonly object: OBJECT;
|
924
|
-
/**
|
925
|
-
The reason why the generation finished.
|
926
|
-
*/
|
927
|
-
readonly finishReason: FinishReason;
|
807
|
+
interface GeneratedFile {
|
928
808
|
/**
|
929
|
-
|
809
|
+
File as a base64 encoded string.
|
930
810
|
*/
|
931
|
-
readonly
|
811
|
+
readonly base64: string;
|
932
812
|
/**
|
933
|
-
|
813
|
+
File as a Uint8Array.
|
934
814
|
*/
|
935
|
-
readonly
|
815
|
+
readonly uint8Array: Uint8Array;
|
936
816
|
/**
|
937
|
-
|
817
|
+
MIME type of the file
|
938
818
|
*/
|
939
|
-
readonly
|
819
|
+
readonly mimeType: string;
|
820
|
+
}
|
821
|
+
|
822
|
+
type ReasoningDetail = {
|
823
|
+
type: 'text';
|
824
|
+
text: string;
|
825
|
+
signature?: string;
|
826
|
+
} | {
|
827
|
+
type: 'redacted';
|
828
|
+
data: string;
|
829
|
+
};
|
830
|
+
|
831
|
+
type ToolParameters = z.ZodTypeAny | Schema<any>;
|
832
|
+
type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
833
|
+
interface ToolExecutionOptions {
|
940
834
|
/**
|
941
|
-
|
835
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
942
836
|
*/
|
943
|
-
|
944
|
-
/**
|
945
|
-
Response body (available only for providers that use HTTP requests).
|
946
|
-
*/
|
947
|
-
body?: unknown;
|
948
|
-
};
|
949
|
-
/**
|
950
|
-
Logprobs for the completion.
|
951
|
-
`undefined` if the mode does not support logprobs or if was not enabled.
|
952
|
-
|
953
|
-
@deprecated Will become a provider extension in the future.
|
954
|
-
*/
|
955
|
-
readonly logprobs: LogProbs | undefined;
|
837
|
+
toolCallId: string;
|
956
838
|
/**
|
957
|
-
|
958
|
-
|
959
|
-
results that can be fully encapsulated in the provider.
|
839
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
840
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
960
841
|
*/
|
961
|
-
|
842
|
+
messages: CoreMessage[];
|
962
843
|
/**
|
963
|
-
|
844
|
+
* An optional abort signal that indicates that the overall operation should be aborted.
|
964
845
|
*/
|
965
|
-
|
966
|
-
/**
|
967
|
-
Converts the object to a JSON response.
|
968
|
-
The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
|
969
|
-
*/
|
970
|
-
toJsonResponse(init?: ResponseInit): Response;
|
846
|
+
abortSignal?: AbortSignal;
|
971
847
|
}
|
972
|
-
|
973
|
-
/**
|
974
|
-
A function that attempts to repair the raw output of the mode
|
975
|
-
to enable JSON parsing.
|
976
|
-
|
977
|
-
Should return the repaired text or null if the text cannot be repaired.
|
978
|
-
*/
|
979
|
-
type RepairTextFunction = (options: {
|
980
|
-
text: string;
|
981
|
-
error: JSONParseError | TypeValidationError;
|
982
|
-
}) => Promise<string | null>;
|
983
848
|
/**
|
984
|
-
|
985
|
-
|
986
|
-
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
849
|
+
A tool contains the description and the schema of the input that the tool expects.
|
850
|
+
This enables the language model to generate the input.
|
987
851
|
|
988
|
-
|
989
|
-
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
852
|
+
The tool can also contain an optional execute function for the actual execution function of the tool.
|
990
853
|
*/
|
991
|
-
|
992
|
-
output?: 'object' | undefined;
|
993
|
-
/**
|
994
|
-
The language model to use.
|
995
|
-
*/
|
996
|
-
model: LanguageModel;
|
854
|
+
type Tool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
|
997
855
|
/**
|
998
|
-
The schema of the
|
999
|
-
|
1000
|
-
|
856
|
+
The schema of the input that the tool expects. The language model will use this to generate the input.
|
857
|
+
It is also used to validate the output of the language model.
|
858
|
+
Use descriptions to make the input understandable for the language model.
|
859
|
+
*/
|
860
|
+
parameters: PARAMETERS;
|
1001
861
|
/**
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
862
|
+
An optional description of what the tool does.
|
863
|
+
Will be used by the language model to decide whether to use the tool.
|
864
|
+
Not used for provider-defined tools.
|
865
|
+
*/
|
866
|
+
description?: string;
|
1007
867
|
/**
|
1008
|
-
Optional
|
1009
|
-
|
1010
|
-
|
1011
|
-
*/
|
1012
|
-
schemaDescription?: string;
|
868
|
+
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
869
|
+
*/
|
870
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
1013
871
|
/**
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
Please note that most providers do not support all modes.
|
1023
|
-
|
1024
|
-
Default and recommended: 'auto' (best mode for the model).
|
1025
|
-
*/
|
1026
|
-
mode?: 'auto' | 'json' | 'tool';
|
872
|
+
An async function that is called with the arguments from the tool call and produces a result.
|
873
|
+
If not provided, the tool will not be executed automatically.
|
874
|
+
|
875
|
+
@args is the input of the tool call.
|
876
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
877
|
+
*/
|
878
|
+
execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
879
|
+
} & ({
|
1027
880
|
/**
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
881
|
+
Function tool.
|
882
|
+
*/
|
883
|
+
type?: undefined | 'function';
|
884
|
+
} | {
|
1032
885
|
/**
|
1033
|
-
|
886
|
+
Provider-defined tool.
|
1034
887
|
*/
|
1035
|
-
|
888
|
+
type: 'provider-defined';
|
1036
889
|
/**
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
*/
|
1041
|
-
providerOptions?: ProviderOptions;
|
1042
|
-
/**
|
1043
|
-
@deprecated Use `providerOptions` instead.
|
1044
|
-
*/
|
1045
|
-
experimental_providerMetadata?: ProviderMetadata;
|
890
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
891
|
+
*/
|
892
|
+
id: `${string}.${string}`;
|
1046
893
|
/**
|
1047
|
-
|
894
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1048
895
|
*/
|
1049
|
-
|
1050
|
-
|
1051
|
-
currentDate?: () => Date;
|
1052
|
-
};
|
1053
|
-
}): Promise<GenerateObjectResult<OBJECT>>;
|
896
|
+
args: Record<string, unknown>;
|
897
|
+
});
|
1054
898
|
/**
|
1055
|
-
|
1056
|
-
|
1057
|
-
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
1058
|
-
|
1059
|
-
@return
|
1060
|
-
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
899
|
+
* @deprecated Use `Tool` instead.
|
1061
900
|
*/
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
*/
|
1077
|
-
schemaName?: string;
|
1078
|
-
/**
|
1079
|
-
Optional description of the array that should be generated.
|
1080
|
-
Used by some providers for additional LLM guidance, e.g.
|
1081
|
-
via tool or schema description.
|
1082
|
-
*/
|
1083
|
-
schemaDescription?: string;
|
1084
|
-
/**
|
1085
|
-
The mode to use for object generation.
|
1086
|
-
|
1087
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
1088
|
-
|
1089
|
-
- 'auto': The provider will choose the best mode for the model.
|
1090
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
1091
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
1092
|
-
|
1093
|
-
Please note that most providers do not support all modes.
|
901
|
+
type CoreTool<PARAMETERS extends ToolParameters = any, RESULT = any> = Tool<PARAMETERS, RESULT>;
|
902
|
+
/**
|
903
|
+
Helper function for inferring the execute args of a tool.
|
904
|
+
*/
|
905
|
+
declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
906
|
+
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
907
|
+
}): Tool<PARAMETERS, RESULT> & {
|
908
|
+
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
909
|
+
};
|
910
|
+
declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
911
|
+
execute?: undefined;
|
912
|
+
}): Tool<PARAMETERS, RESULT> & {
|
913
|
+
execute: undefined;
|
914
|
+
};
|
1094
915
|
|
1095
|
-
Default and recommended: 'auto' (best mode for the model).
|
1096
|
-
*/
|
1097
|
-
mode?: 'auto' | 'json' | 'tool';
|
1098
|
-
/**
|
1099
|
-
A function that attempts to repair the raw output of the mode
|
1100
|
-
to enable JSON parsing.
|
1101
|
-
*/
|
1102
|
-
experimental_repairText?: RepairTextFunction;
|
1103
|
-
/**
|
1104
|
-
Optional telemetry configuration (experimental).
|
1105
|
-
*/
|
1106
|
-
experimental_telemetry?: TelemetrySettings;
|
1107
|
-
/**
|
1108
|
-
Additional provider-specific options. They are passed through
|
1109
|
-
to the provider from the AI SDK and enable provider-specific
|
1110
|
-
functionality that can be fully encapsulated in the provider.
|
1111
|
-
*/
|
1112
|
-
providerOptions?: ProviderOptions;
|
1113
|
-
/**
|
1114
|
-
@deprecated Use `providerOptions` instead.
|
1115
|
-
*/
|
1116
|
-
experimental_providerMetadata?: ProviderMetadata;
|
1117
|
-
/**
|
1118
|
-
* Internal. For test use only. May change without notice.
|
1119
|
-
*/
|
1120
|
-
_internal?: {
|
1121
|
-
generateId?: () => string;
|
1122
|
-
currentDate?: () => Date;
|
1123
|
-
};
|
1124
|
-
}): Promise<GenerateObjectResult<Array<ELEMENT>>>;
|
1125
916
|
/**
|
1126
|
-
|
917
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
1127
918
|
|
1128
|
-
|
919
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
1129
920
|
|
1130
|
-
@
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
model: LanguageModel;
|
1139
|
-
/**
|
1140
|
-
The enum values that the model should use.
|
1141
|
-
*/
|
1142
|
-
enum: Array<ENUM>;
|
1143
|
-
/**
|
1144
|
-
The mode to use for object generation.
|
921
|
+
@example
|
922
|
+
```
|
923
|
+
// data.json
|
924
|
+
{
|
925
|
+
'foo': 1,
|
926
|
+
'bar': 2,
|
927
|
+
'biz': 3
|
928
|
+
}
|
1145
929
|
|
1146
|
-
|
930
|
+
// main.ts
|
931
|
+
import type {ValueOf} from 'type-fest';
|
932
|
+
import data = require('./data.json');
|
1147
933
|
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
934
|
+
export function getData(name: string): ValueOf<typeof data> {
|
935
|
+
return data[name];
|
936
|
+
}
|
1151
937
|
|
1152
|
-
|
938
|
+
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
939
|
+
return data[name];
|
940
|
+
}
|
1153
941
|
|
1154
|
-
|
1155
|
-
|
1156
|
-
mode?: 'auto' | 'json' | 'tool';
|
1157
|
-
/**
|
1158
|
-
A function that attempts to repair the raw output of the mode
|
1159
|
-
to enable JSON parsing.
|
1160
|
-
*/
|
1161
|
-
experimental_repairText?: RepairTextFunction;
|
1162
|
-
/**
|
1163
|
-
Optional telemetry configuration (experimental).
|
1164
|
-
*/
|
1165
|
-
experimental_telemetry?: TelemetrySettings;
|
1166
|
-
/**
|
1167
|
-
Additional provider-specific options. They are passed through
|
1168
|
-
to the provider from the AI SDK and enable provider-specific
|
1169
|
-
functionality that can be fully encapsulated in the provider.
|
1170
|
-
*/
|
1171
|
-
providerOptions?: ProviderOptions;
|
1172
|
-
/**
|
1173
|
-
@deprecated Use `providerOptions` instead.
|
1174
|
-
*/
|
1175
|
-
experimental_providerMetadata?: ProviderMetadata;
|
1176
|
-
/**
|
1177
|
-
* Internal. For test use only. May change without notice.
|
1178
|
-
*/
|
1179
|
-
_internal?: {
|
1180
|
-
generateId?: () => string;
|
1181
|
-
currentDate?: () => Date;
|
1182
|
-
};
|
1183
|
-
}): Promise<GenerateObjectResult<ENUM>>;
|
1184
|
-
/**
|
1185
|
-
Generate JSON with any schema for a given prompt using a language model.
|
942
|
+
// file.ts
|
943
|
+
import {getData, onlyBar} from './main';
|
1186
944
|
|
1187
|
-
|
945
|
+
getData('foo');
|
946
|
+
//=> 1
|
1188
947
|
|
1189
|
-
|
1190
|
-
|
1191
|
-
*/
|
1192
|
-
declare function generateObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
1193
|
-
output: 'no-schema';
|
1194
|
-
/**
|
1195
|
-
The language model to use.
|
1196
|
-
*/
|
1197
|
-
model: LanguageModel;
|
1198
|
-
/**
|
1199
|
-
The mode to use for object generation. Must be "json" for no-schema output.
|
1200
|
-
*/
|
1201
|
-
mode?: 'json';
|
1202
|
-
/**
|
1203
|
-
A function that attempts to repair the raw output of the mode
|
1204
|
-
to enable JSON parsing.
|
1205
|
-
*/
|
1206
|
-
experimental_repairText?: RepairTextFunction;
|
1207
|
-
/**
|
1208
|
-
Optional telemetry configuration (experimental).
|
1209
|
-
*/
|
1210
|
-
experimental_telemetry?: TelemetrySettings;
|
1211
|
-
/**
|
1212
|
-
Additional provider-specific options. They are passed through
|
1213
|
-
to the provider from the AI SDK and enable provider-specific
|
1214
|
-
functionality that can be fully encapsulated in the provider.
|
1215
|
-
*/
|
1216
|
-
providerOptions?: ProviderOptions;
|
1217
|
-
/**
|
1218
|
-
@deprecated Use `providerOptions` instead.
|
1219
|
-
*/
|
1220
|
-
experimental_providerMetadata?: ProviderMetadata;
|
1221
|
-
/**
|
1222
|
-
* Internal. For test use only. May change without notice.
|
1223
|
-
*/
|
1224
|
-
_internal?: {
|
1225
|
-
generateId?: () => string;
|
1226
|
-
currentDate?: () => Date;
|
1227
|
-
};
|
1228
|
-
}): Promise<GenerateObjectResult<JSONValue>>;
|
948
|
+
onlyBar('foo');
|
949
|
+
//=> TypeError ...
|
1229
950
|
|
1230
|
-
|
951
|
+
onlyBar('bar');
|
952
|
+
//=> 2
|
953
|
+
```
|
954
|
+
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
955
|
+
*/
|
956
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
1231
957
|
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
}
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
958
|
+
declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
959
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
960
|
+
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
961
|
+
}, {
|
962
|
+
method: z.ZodString;
|
963
|
+
params: z.ZodOptional<z.ZodObject<{
|
964
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
965
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
966
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
967
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
968
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
969
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
970
|
+
}>, "strict", z.ZodTypeAny, {
|
971
|
+
id: string | number;
|
972
|
+
method: string;
|
973
|
+
jsonrpc: "2.0";
|
974
|
+
params?: z.objectOutputType<{
|
975
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
976
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
977
|
+
}, {
|
978
|
+
id: string | number;
|
979
|
+
method: string;
|
980
|
+
jsonrpc: "2.0";
|
981
|
+
params?: z.objectInputType<{
|
982
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
983
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
984
|
+
}>, z.ZodObject<z.objectUtil.extendShape<{
|
985
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
986
|
+
}, {
|
987
|
+
method: z.ZodString;
|
988
|
+
params: z.ZodOptional<z.ZodObject<{
|
989
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
990
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
991
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
992
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
993
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
994
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
995
|
+
}>, "strict", z.ZodTypeAny, {
|
996
|
+
method: string;
|
997
|
+
jsonrpc: "2.0";
|
998
|
+
params?: z.objectOutputType<{
|
999
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1000
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
1001
|
+
}, {
|
1002
|
+
method: string;
|
1003
|
+
jsonrpc: "2.0";
|
1004
|
+
params?: z.objectInputType<{
|
1005
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1006
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
1007
|
+
}>, z.ZodObject<{
|
1008
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
1009
|
+
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
1010
|
+
result: z.ZodObject<{
|
1011
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1012
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
1013
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1014
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
1015
|
+
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1016
|
+
}, z.ZodTypeAny, "passthrough">>;
|
1017
|
+
}, "strict", z.ZodTypeAny, {
|
1018
|
+
result: {
|
1019
|
+
_meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
1020
|
+
} & {
|
1021
|
+
[k: string]: unknown;
|
1022
|
+
};
|
1023
|
+
id: string | number;
|
1024
|
+
jsonrpc: "2.0";
|
1025
|
+
}, {
|
1026
|
+
result: {
|
1027
|
+
_meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
1028
|
+
} & {
|
1029
|
+
[k: string]: unknown;
|
1030
|
+
};
|
1031
|
+
id: string | number;
|
1032
|
+
jsonrpc: "2.0";
|
1033
|
+
}>, z.ZodObject<{
|
1034
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
1035
|
+
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
1036
|
+
error: z.ZodObject<{
|
1037
|
+
code: z.ZodNumber;
|
1038
|
+
message: z.ZodString;
|
1039
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
1040
|
+
}, "strip", z.ZodTypeAny, {
|
1041
|
+
code: number;
|
1042
|
+
message: string;
|
1043
|
+
data?: unknown;
|
1044
|
+
}, {
|
1045
|
+
code: number;
|
1046
|
+
message: string;
|
1047
|
+
data?: unknown;
|
1048
|
+
}>;
|
1049
|
+
}, "strict", z.ZodTypeAny, {
|
1050
|
+
error: {
|
1051
|
+
code: number;
|
1052
|
+
message: string;
|
1053
|
+
data?: unknown;
|
1054
|
+
};
|
1055
|
+
id: string | number;
|
1056
|
+
jsonrpc: "2.0";
|
1057
|
+
}, {
|
1058
|
+
error: {
|
1059
|
+
code: number;
|
1060
|
+
message: string;
|
1061
|
+
data?: unknown;
|
1062
|
+
};
|
1063
|
+
id: string | number;
|
1064
|
+
jsonrpc: "2.0";
|
1065
|
+
}>]>;
|
1066
|
+
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
1326
1067
|
|
1327
|
-
@param event - The event that is passed to the callback.
|
1328
|
-
*/
|
1329
|
-
type StreamObjectOnErrorCallback = (event: {
|
1330
|
-
error: unknown;
|
1331
|
-
}) => Promise<void> | void;
|
1332
1068
|
/**
|
1333
|
-
|
1334
|
-
|
1335
|
-
@param event - The event that is passed to the callback.
|
1069
|
+
* Transport interface for MCP (Model Context Protocol) communication.
|
1070
|
+
* Maps to the `Transport` interface in the MCP spec.
|
1336
1071
|
*/
|
1337
|
-
|
1338
|
-
/**
|
1339
|
-
The token usage of the generated response.
|
1340
|
-
*/
|
1341
|
-
usage: LanguageModelUsage;
|
1072
|
+
interface MCPTransport {
|
1342
1073
|
/**
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1074
|
+
* Initialize and start the transport
|
1075
|
+
*/
|
1076
|
+
start(): Promise<void>;
|
1346
1077
|
/**
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1078
|
+
* Send a JSON-RPC message through the transport
|
1079
|
+
* @param message The JSON-RPC message to send
|
1080
|
+
*/
|
1081
|
+
send(message: JSONRPCMessage): Promise<void>;
|
1350
1082
|
/**
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1083
|
+
* Clean up and close the transport
|
1084
|
+
*/
|
1085
|
+
close(): Promise<void>;
|
1354
1086
|
/**
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1087
|
+
* Event handler for transport closure
|
1088
|
+
*/
|
1089
|
+
onclose?: () => void;
|
1358
1090
|
/**
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
*/
|
1363
|
-
providerMetadata: ProviderMetadata | undefined;
|
1091
|
+
* Event handler for transport errors
|
1092
|
+
*/
|
1093
|
+
onerror?: (error: Error) => void;
|
1364
1094
|
/**
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
}
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1095
|
+
* Event handler for received messages
|
1096
|
+
*/
|
1097
|
+
onmessage?: (message: JSONRPCMessage) => void;
|
1098
|
+
}
|
1099
|
+
interface SSEConfig {
|
1100
|
+
type: 'sse';
|
1101
|
+
url: string;
|
1102
|
+
}
|
1103
|
+
type MCPTransportConfig = SSEConfig;
|
1373
1104
|
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
model: LanguageModel;
|
1383
|
-
/**
|
1384
|
-
The schema of the object that the model should generate.
|
1385
|
-
*/
|
1386
|
-
schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
|
1387
|
-
/**
|
1388
|
-
Optional name of the output that should be generated.
|
1389
|
-
Used by some providers for additional LLM guidance, e.g.
|
1390
|
-
via tool or schema name.
|
1391
|
-
*/
|
1392
|
-
schemaName?: string;
|
1393
|
-
/**
|
1394
|
-
Optional description of the output that should be generated.
|
1395
|
-
Used by some providers for additional LLM guidance, e.g.
|
1396
|
-
via tool or schema description.
|
1397
|
-
*/
|
1398
|
-
schemaDescription?: string;
|
1399
|
-
/**
|
1400
|
-
The mode to use for object generation.
|
1401
|
-
|
1402
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
1403
|
-
|
1404
|
-
- 'auto': The provider will choose the best mode for the model.
|
1405
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
1406
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
1407
|
-
|
1408
|
-
Please note that most providers do not support all modes.
|
1409
|
-
|
1410
|
-
Default and recommended: 'auto' (best mode for the model).
|
1411
|
-
*/
|
1412
|
-
mode?: 'auto' | 'json' | 'tool';
|
1413
|
-
/**
|
1414
|
-
Optional telemetry configuration (experimental).
|
1415
|
-
*/
|
1416
|
-
experimental_telemetry?: TelemetrySettings;
|
1417
|
-
/**
|
1418
|
-
Additional provider-specific options. They are passed through
|
1419
|
-
to the provider from the AI SDK and enable provider-specific
|
1420
|
-
functionality that can be fully encapsulated in the provider.
|
1421
|
-
*/
|
1422
|
-
providerOptions?: ProviderOptions;
|
1423
|
-
/**
|
1424
|
-
@deprecated Use `providerOptions` instead.
|
1425
|
-
*/
|
1426
|
-
experimental_providerMetadata?: ProviderMetadata;
|
1427
|
-
/**
|
1428
|
-
Callback that is invoked when an error occurs during streaming.
|
1429
|
-
You can use it to log errors.
|
1430
|
-
The stream processing will pause until the callback promise is resolved.
|
1431
|
-
*/
|
1432
|
-
onError?: StreamObjectOnErrorCallback;
|
1433
|
-
/**
|
1434
|
-
Callback that is called when the LLM response and the final object validation are finished.
|
1435
|
-
*/
|
1436
|
-
onFinish?: StreamObjectOnFinishCallback<OBJECT>;
|
1437
|
-
/**
|
1438
|
-
* Internal. For test use only. May change without notice.
|
1439
|
-
*/
|
1440
|
-
_internal?: {
|
1441
|
-
generateId?: () => string;
|
1442
|
-
currentDate?: () => Date;
|
1443
|
-
now?: () => number;
|
1444
|
-
};
|
1445
|
-
}): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
|
1446
|
-
/**
|
1447
|
-
Generate an array with structured, typed elements for a given prompt and element schema using a language model.
|
1448
|
-
|
1449
|
-
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
1450
|
-
|
1451
|
-
@return
|
1452
|
-
A result object for accessing the partial object stream and additional information.
|
1453
|
-
*/
|
1454
|
-
declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
1455
|
-
output: 'array';
|
1456
|
-
/**
|
1457
|
-
The language model to use.
|
1458
|
-
*/
|
1459
|
-
model: LanguageModel;
|
1460
|
-
/**
|
1461
|
-
The element schema of the array that the model should generate.
|
1462
|
-
*/
|
1463
|
-
schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
|
1464
|
-
/**
|
1465
|
-
Optional name of the array that should be generated.
|
1466
|
-
Used by some providers for additional LLM guidance, e.g.
|
1467
|
-
via tool or schema name.
|
1468
|
-
*/
|
1469
|
-
schemaName?: string;
|
1470
|
-
/**
|
1471
|
-
Optional description of the array that should be generated.
|
1472
|
-
Used by some providers for additional LLM guidance, e.g.
|
1473
|
-
via tool or schema description.
|
1474
|
-
*/
|
1475
|
-
schemaDescription?: string;
|
1476
|
-
/**
|
1477
|
-
The mode to use for object generation.
|
1478
|
-
|
1479
|
-
The schema is converted into a JSON schema and used in one of the following ways
|
1480
|
-
|
1481
|
-
- 'auto': The provider will choose the best mode for the model.
|
1482
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
1483
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
1484
|
-
|
1485
|
-
Please note that most providers do not support all modes.
|
1486
|
-
|
1487
|
-
Default and recommended: 'auto' (best mode for the model).
|
1488
|
-
*/
|
1489
|
-
mode?: 'auto' | 'json' | 'tool';
|
1490
|
-
/**
|
1491
|
-
Optional telemetry configuration (experimental).
|
1492
|
-
*/
|
1493
|
-
experimental_telemetry?: TelemetrySettings;
|
1494
|
-
/**
|
1495
|
-
Additional provider-specific options. They are passed through
|
1496
|
-
to the provider from the AI SDK and enable provider-specific
|
1497
|
-
functionality that can be fully encapsulated in the provider.
|
1498
|
-
*/
|
1499
|
-
providerOptions?: ProviderOptions;
|
1500
|
-
/**
|
1501
|
-
@deprecated Use `providerOptions` instead.
|
1502
|
-
*/
|
1503
|
-
experimental_providerMetadata?: ProviderMetadata;
|
1504
|
-
/**
|
1505
|
-
Callback that is invoked when an error occurs during streaming.
|
1506
|
-
You can use it to log errors.
|
1507
|
-
The stream processing will pause until the callback promise is resolved.
|
1508
|
-
*/
|
1509
|
-
onError?: StreamObjectOnErrorCallback;
|
1510
|
-
/**
|
1511
|
-
Callback that is called when the LLM response and the final object validation are finished.
|
1512
|
-
*/
|
1513
|
-
onFinish?: StreamObjectOnFinishCallback<Array<ELEMENT>>;
|
1514
|
-
/**
|
1515
|
-
* Internal. For test use only. May change without notice.
|
1516
|
-
*/
|
1517
|
-
_internal?: {
|
1518
|
-
generateId?: () => string;
|
1519
|
-
currentDate?: () => Date;
|
1520
|
-
now?: () => number;
|
1105
|
+
type ToolSchemas = Record<string, {
|
1106
|
+
parameters: ToolParameters;
|
1107
|
+
}> | 'automatic' | undefined;
|
1108
|
+
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
1109
|
+
parameters: ToolParameters;
|
1110
|
+
}> ? {
|
1111
|
+
[K in keyof TOOL_SCHEMAS]: Tool<TOOL_SCHEMAS[K]['parameters'], CallToolResult> & {
|
1112
|
+
execute: (args: inferParameters<TOOL_SCHEMAS[K]['parameters']>, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
|
1521
1113
|
};
|
1522
|
-
}
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
1527
|
-
|
1528
|
-
@return
|
1529
|
-
A result object for accessing the partial object stream and additional information.
|
1530
|
-
*/
|
1531
|
-
declare function streamObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
1532
|
-
output: 'no-schema';
|
1533
|
-
/**
|
1534
|
-
The language model to use.
|
1535
|
-
*/
|
1536
|
-
model: LanguageModel;
|
1537
|
-
/**
|
1538
|
-
The mode to use for object generation. Must be "json" for no-schema output.
|
1539
|
-
*/
|
1540
|
-
mode?: 'json';
|
1541
|
-
/**
|
1542
|
-
Optional telemetry configuration (experimental).
|
1543
|
-
*/
|
1544
|
-
experimental_telemetry?: TelemetrySettings;
|
1545
|
-
/**
|
1546
|
-
Additional provider-specific options. They are passed through
|
1547
|
-
to the provider from the AI SDK and enable provider-specific
|
1548
|
-
functionality that can be fully encapsulated in the provider.
|
1549
|
-
*/
|
1550
|
-
providerOptions?: ProviderOptions;
|
1551
|
-
/**
|
1552
|
-
@deprecated Use `providerOptions` instead.
|
1553
|
-
*/
|
1554
|
-
experimental_providerMetadata?: ProviderMetadata;
|
1555
|
-
/**
|
1556
|
-
Callback that is invoked when an error occurs during streaming.
|
1557
|
-
You can use it to log errors.
|
1558
|
-
The stream processing will pause until the callback promise is resolved.
|
1559
|
-
*/
|
1560
|
-
onError?: StreamObjectOnErrorCallback;
|
1561
|
-
/**
|
1562
|
-
Callback that is called when the LLM response and the final object validation are finished.
|
1563
|
-
*/
|
1564
|
-
onFinish?: StreamObjectOnFinishCallback<JSONValue>;
|
1565
|
-
/**
|
1566
|
-
* Internal. For test use only. May change without notice.
|
1567
|
-
*/
|
1568
|
-
_internal?: {
|
1569
|
-
generateId?: () => string;
|
1570
|
-
currentDate?: () => Date;
|
1571
|
-
now?: () => number;
|
1572
|
-
};
|
1573
|
-
}): StreamObjectResult<JSONValue, JSONValue, never>;
|
1574
|
-
|
1575
|
-
type ReasoningDetail = {
|
1576
|
-
type: 'text';
|
1577
|
-
text: string;
|
1578
|
-
signature?: string;
|
1579
|
-
} | {
|
1580
|
-
type: 'redacted';
|
1581
|
-
data: string;
|
1582
|
-
};
|
1583
|
-
|
1584
|
-
type ToolParameters = z.ZodTypeAny | Schema<any>;
|
1585
|
-
type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
1586
|
-
interface ToolExecutionOptions {
|
1587
|
-
/**
|
1588
|
-
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
1589
|
-
*/
|
1590
|
-
toolCallId: string;
|
1591
|
-
/**
|
1592
|
-
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
1593
|
-
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
1594
|
-
*/
|
1595
|
-
messages: CoreMessage[];
|
1596
|
-
/**
|
1597
|
-
* An optional abort signal that indicates that the overall operation should be aborted.
|
1598
|
-
*/
|
1599
|
-
abortSignal?: AbortSignal;
|
1600
|
-
}
|
1601
|
-
/**
|
1602
|
-
A tool contains the description and the schema of the input that the tool expects.
|
1603
|
-
This enables the language model to generate the input.
|
1604
|
-
|
1605
|
-
The tool can also contain an optional execute function for the actual execution function of the tool.
|
1606
|
-
*/
|
1607
|
-
type Tool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
|
1608
|
-
/**
|
1609
|
-
The schema of the input that the tool expects. The language model will use this to generate the input.
|
1610
|
-
It is also used to validate the output of the language model.
|
1611
|
-
Use descriptions to make the input understandable for the language model.
|
1612
|
-
*/
|
1613
|
-
parameters: PARAMETERS;
|
1614
|
-
/**
|
1615
|
-
An optional description of what the tool does.
|
1616
|
-
Will be used by the language model to decide whether to use the tool.
|
1617
|
-
Not used for provider-defined tools.
|
1618
|
-
*/
|
1619
|
-
description?: string;
|
1620
|
-
/**
|
1621
|
-
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
1622
|
-
*/
|
1623
|
-
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
1624
|
-
/**
|
1625
|
-
An async function that is called with the arguments from the tool call and produces a result.
|
1626
|
-
If not provided, the tool will not be executed automatically.
|
1627
|
-
|
1628
|
-
@args is the input of the tool call.
|
1629
|
-
@options.abortSignal is a signal that can be used to abort the tool call.
|
1630
|
-
*/
|
1631
|
-
execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1632
|
-
} & ({
|
1633
|
-
/**
|
1634
|
-
Function tool.
|
1635
|
-
*/
|
1636
|
-
type?: undefined | 'function';
|
1637
|
-
} | {
|
1638
|
-
/**
|
1639
|
-
Provider-defined tool.
|
1640
|
-
*/
|
1641
|
-
type: 'provider-defined';
|
1642
|
-
/**
|
1643
|
-
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
1644
|
-
*/
|
1645
|
-
id: `${string}.${string}`;
|
1646
|
-
/**
|
1647
|
-
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1648
|
-
*/
|
1649
|
-
args: Record<string, unknown>;
|
1650
|
-
});
|
1651
|
-
/**
|
1652
|
-
* @deprecated Use `Tool` instead.
|
1653
|
-
*/
|
1654
|
-
type CoreTool<PARAMETERS extends ToolParameters = any, RESULT = any> = Tool<PARAMETERS, RESULT>;
|
1655
|
-
/**
|
1656
|
-
Helper function for inferring the execute args of a tool.
|
1657
|
-
*/
|
1658
|
-
declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
1659
|
-
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1660
|
-
}): Tool<PARAMETERS, RESULT> & {
|
1661
|
-
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1662
|
-
};
|
1663
|
-
declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
1664
|
-
execute?: undefined;
|
1665
|
-
}): Tool<PARAMETERS, RESULT> & {
|
1666
|
-
execute: undefined;
|
1667
|
-
};
|
1668
|
-
|
1669
|
-
/**
|
1670
|
-
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
1671
|
-
|
1672
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
1673
|
-
|
1674
|
-
@example
|
1675
|
-
```
|
1676
|
-
// data.json
|
1677
|
-
{
|
1678
|
-
'foo': 1,
|
1679
|
-
'bar': 2,
|
1680
|
-
'biz': 3
|
1681
|
-
}
|
1682
|
-
|
1683
|
-
// main.ts
|
1684
|
-
import type {ValueOf} from 'type-fest';
|
1685
|
-
import data = require('./data.json');
|
1686
|
-
|
1687
|
-
export function getData(name: string): ValueOf<typeof data> {
|
1688
|
-
return data[name];
|
1689
|
-
}
|
1690
|
-
|
1691
|
-
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
1692
|
-
return data[name];
|
1693
|
-
}
|
1694
|
-
|
1695
|
-
// file.ts
|
1696
|
-
import {getData, onlyBar} from './main';
|
1697
|
-
|
1698
|
-
getData('foo');
|
1699
|
-
//=> 1
|
1700
|
-
|
1701
|
-
onlyBar('foo');
|
1702
|
-
//=> TypeError ...
|
1703
|
-
|
1704
|
-
onlyBar('bar');
|
1705
|
-
//=> 2
|
1706
|
-
```
|
1707
|
-
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
1708
|
-
*/
|
1709
|
-
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
1710
|
-
|
1711
|
-
declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
1712
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
1713
|
-
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
1714
|
-
}, {
|
1715
|
-
method: z.ZodString;
|
1716
|
-
params: z.ZodOptional<z.ZodObject<{
|
1717
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1718
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
1719
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1720
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
1721
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1722
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
1723
|
-
}>, "strict", z.ZodTypeAny, {
|
1724
|
-
id: string | number;
|
1725
|
-
method: string;
|
1726
|
-
jsonrpc: "2.0";
|
1727
|
-
params?: z.objectOutputType<{
|
1728
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1729
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
1730
|
-
}, {
|
1731
|
-
id: string | number;
|
1732
|
-
method: string;
|
1733
|
-
jsonrpc: "2.0";
|
1734
|
-
params?: z.objectInputType<{
|
1735
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1736
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
1737
|
-
}>, z.ZodObject<z.objectUtil.extendShape<{
|
1738
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
1739
|
-
}, {
|
1740
|
-
method: z.ZodString;
|
1741
|
-
params: z.ZodOptional<z.ZodObject<{
|
1742
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1743
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
1744
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1745
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
1746
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1747
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
1748
|
-
}>, "strict", z.ZodTypeAny, {
|
1749
|
-
method: string;
|
1750
|
-
jsonrpc: "2.0";
|
1751
|
-
params?: z.objectOutputType<{
|
1752
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1753
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
1754
|
-
}, {
|
1755
|
-
method: string;
|
1756
|
-
jsonrpc: "2.0";
|
1757
|
-
params?: z.objectInputType<{
|
1758
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1759
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
1760
|
-
}>, z.ZodObject<{
|
1761
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
1762
|
-
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
1763
|
-
result: z.ZodObject<{
|
1764
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1765
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
1766
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1767
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
1768
|
-
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
1769
|
-
}, z.ZodTypeAny, "passthrough">>;
|
1770
|
-
}, "strict", z.ZodTypeAny, {
|
1771
|
-
result: {
|
1772
|
-
_meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
1773
|
-
} & {
|
1774
|
-
[k: string]: unknown;
|
1775
|
-
};
|
1776
|
-
id: string | number;
|
1777
|
-
jsonrpc: "2.0";
|
1778
|
-
}, {
|
1779
|
-
result: {
|
1780
|
-
_meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
1781
|
-
} & {
|
1782
|
-
[k: string]: unknown;
|
1783
|
-
};
|
1784
|
-
id: string | number;
|
1785
|
-
jsonrpc: "2.0";
|
1786
|
-
}>, z.ZodObject<{
|
1787
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
1788
|
-
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
1789
|
-
error: z.ZodObject<{
|
1790
|
-
code: z.ZodNumber;
|
1791
|
-
message: z.ZodString;
|
1792
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
1793
|
-
}, "strip", z.ZodTypeAny, {
|
1794
|
-
code: number;
|
1795
|
-
message: string;
|
1796
|
-
data?: unknown;
|
1797
|
-
}, {
|
1798
|
-
code: number;
|
1799
|
-
message: string;
|
1800
|
-
data?: unknown;
|
1801
|
-
}>;
|
1802
|
-
}, "strict", z.ZodTypeAny, {
|
1803
|
-
error: {
|
1804
|
-
code: number;
|
1805
|
-
message: string;
|
1806
|
-
data?: unknown;
|
1807
|
-
};
|
1808
|
-
id: string | number;
|
1809
|
-
jsonrpc: "2.0";
|
1810
|
-
}, {
|
1811
|
-
error: {
|
1812
|
-
code: number;
|
1813
|
-
message: string;
|
1814
|
-
data?: unknown;
|
1815
|
-
};
|
1816
|
-
id: string | number;
|
1817
|
-
jsonrpc: "2.0";
|
1818
|
-
}>]>;
|
1819
|
-
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
1820
|
-
|
1821
|
-
/**
|
1822
|
-
* Transport interface for MCP (Model Context Protocol) communication.
|
1823
|
-
* Maps to the `Transport` interface in the MCP spec.
|
1824
|
-
*/
|
1825
|
-
interface MCPTransport {
|
1826
|
-
/**
|
1827
|
-
* Initialize and start the transport
|
1828
|
-
*/
|
1829
|
-
start(): Promise<void>;
|
1830
|
-
/**
|
1831
|
-
* Send a JSON-RPC message through the transport
|
1832
|
-
* @param message The JSON-RPC message to send
|
1833
|
-
*/
|
1834
|
-
send(message: JSONRPCMessage): Promise<void>;
|
1835
|
-
/**
|
1836
|
-
* Clean up and close the transport
|
1837
|
-
*/
|
1838
|
-
close(): Promise<void>;
|
1839
|
-
/**
|
1840
|
-
* Event handler for transport closure
|
1841
|
-
*/
|
1842
|
-
onclose?: () => void;
|
1843
|
-
/**
|
1844
|
-
* Event handler for transport errors
|
1845
|
-
*/
|
1846
|
-
onerror?: (error: Error) => void;
|
1847
|
-
/**
|
1848
|
-
* Event handler for received messages
|
1849
|
-
*/
|
1850
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
1851
|
-
}
|
1852
|
-
interface SSEConfig {
|
1853
|
-
type: 'sse';
|
1854
|
-
url: string;
|
1855
|
-
}
|
1856
|
-
type MCPTransportConfig = SSEConfig;
|
1857
|
-
|
1858
|
-
type ToolSchemas = Record<string, {
|
1859
|
-
parameters: ToolParameters;
|
1860
|
-
}> | 'automatic' | undefined;
|
1861
|
-
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
1862
|
-
parameters: ToolParameters;
|
1863
|
-
}> ? {
|
1864
|
-
[K in keyof TOOL_SCHEMAS]: Tool<TOOL_SCHEMAS[K]['parameters'], CallToolResult> & {
|
1865
|
-
execute: (args: inferParameters<TOOL_SCHEMAS[K]['parameters']>, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
|
1866
|
-
};
|
1867
|
-
} : {
|
1868
|
-
[k: string]: Tool<z.ZodUnknown, CallToolResult> & {
|
1869
|
-
execute: (args: unknown, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
|
1114
|
+
} : {
|
1115
|
+
[k: string]: Tool<z.ZodUnknown, CallToolResult> & {
|
1116
|
+
execute: (args: unknown, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
|
1870
1117
|
};
|
1871
1118
|
};
|
1872
1119
|
declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
@@ -2621,698 +1868,1507 @@ declare class MCPClient {
|
|
2621
1868
|
private callTool;
|
2622
1869
|
private notification;
|
2623
1870
|
/**
|
2624
|
-
* Returns a set of AI SDK tools from the MCP server
|
2625
|
-
* @returns A record of tool names to their implementations
|
1871
|
+
* Returns a set of AI SDK tools from the MCP server
|
1872
|
+
* @returns A record of tool names to their implementations
|
1873
|
+
*/
|
1874
|
+
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>({ schemas, }?: {
|
1875
|
+
schemas?: TOOL_SCHEMAS;
|
1876
|
+
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
1877
|
+
private onClose;
|
1878
|
+
private onError;
|
1879
|
+
private onResponse;
|
1880
|
+
}
|
1881
|
+
|
1882
|
+
type ToolSet = Record<string, Tool>;
|
1883
|
+
|
1884
|
+
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
1885
|
+
[NAME in keyof TOOLS]: {
|
1886
|
+
type: 'tool-call';
|
1887
|
+
toolCallId: string;
|
1888
|
+
toolName: NAME & string;
|
1889
|
+
args: inferParameters<TOOLS[NAME]['parameters']>;
|
1890
|
+
};
|
1891
|
+
}>;
|
1892
|
+
/**
|
1893
|
+
* @deprecated Use `ToolCallUnion` instead.
|
1894
|
+
*/
|
1895
|
+
type CoreToolCallUnion<TOOLS extends ToolSet> = ToolCallUnion<ToolSet>;
|
1896
|
+
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
1897
|
+
|
1898
|
+
type ToToolsWithExecute<TOOLS extends ToolSet> = {
|
1899
|
+
[K in keyof TOOLS as TOOLS[K] extends {
|
1900
|
+
execute: any;
|
1901
|
+
} ? K : never]: TOOLS[K];
|
1902
|
+
};
|
1903
|
+
type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
|
1904
|
+
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
1905
|
+
};
|
1906
|
+
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
1907
|
+
[NAME in keyof TOOLS]: {
|
1908
|
+
type: 'tool-result';
|
1909
|
+
toolCallId: string;
|
1910
|
+
toolName: NAME & string;
|
1911
|
+
args: inferParameters<TOOLS[NAME]['parameters']>;
|
1912
|
+
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
1913
|
+
};
|
1914
|
+
}>;
|
1915
|
+
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
|
1916
|
+
/**
|
1917
|
+
* @deprecated Use `ToolResultUnion` instead.
|
1918
|
+
*/
|
1919
|
+
type CoreToolResultUnion<TOOLS extends ToolSet> = ToolResultUnion<TOOLS>;
|
1920
|
+
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
1921
|
+
|
1922
|
+
/**
|
1923
|
+
A message that was generated during the generation process.
|
1924
|
+
It can be either an assistant message or a tool message.
|
1925
|
+
*/
|
1926
|
+
type ResponseMessage = (CoreAssistantMessage | CoreToolMessage) & {
|
1927
|
+
/**
|
1928
|
+
Message ID generated by the AI SDK.
|
1929
|
+
*/
|
1930
|
+
id: string;
|
1931
|
+
};
|
1932
|
+
/**
|
1933
|
+
* The result of a single step in the generation process.
|
1934
|
+
*/
|
1935
|
+
type StepResult<TOOLS extends ToolSet> = {
|
1936
|
+
/**
|
1937
|
+
The generated text.
|
1938
|
+
*/
|
1939
|
+
readonly text: string;
|
1940
|
+
/**
|
1941
|
+
The reasoning that was generated during the generation.
|
1942
|
+
*/
|
1943
|
+
readonly reasoning: string | undefined;
|
1944
|
+
readonly reasoningDetails: Array<ReasoningDetail>;
|
1945
|
+
/**
|
1946
|
+
The files that were generated during the generation.
|
1947
|
+
*/
|
1948
|
+
readonly files: GeneratedFile[];
|
1949
|
+
/**
|
1950
|
+
The sources that were used to generate the text.
|
1951
|
+
*/
|
1952
|
+
readonly sources: Source[];
|
1953
|
+
/**
|
1954
|
+
The tool calls that were made during the generation.
|
1955
|
+
*/
|
1956
|
+
readonly toolCalls: ToolCallArray<TOOLS>;
|
1957
|
+
/**
|
1958
|
+
The results of the tool calls.
|
1959
|
+
*/
|
1960
|
+
readonly toolResults: ToolResultArray<TOOLS>;
|
1961
|
+
/**
|
1962
|
+
The reason why the generation finished.
|
1963
|
+
*/
|
1964
|
+
readonly finishReason: FinishReason;
|
1965
|
+
/**
|
1966
|
+
The token usage of the generated text.
|
1967
|
+
*/
|
1968
|
+
readonly usage: LanguageModelUsage;
|
1969
|
+
/**
|
1970
|
+
Warnings from the model provider (e.g. unsupported settings).
|
1971
|
+
*/
|
1972
|
+
readonly warnings: CallWarning[] | undefined;
|
1973
|
+
/**
|
1974
|
+
Logprobs for the completion.
|
1975
|
+
`undefined` if the mode does not support logprobs or if was not enabled.
|
1976
|
+
*/
|
1977
|
+
readonly logprobs: LogProbs | undefined;
|
1978
|
+
/**
|
1979
|
+
Additional request information.
|
1980
|
+
*/
|
1981
|
+
readonly request: LanguageModelRequestMetadata;
|
1982
|
+
/**
|
1983
|
+
Additional response information.
|
1984
|
+
*/
|
1985
|
+
readonly response: LanguageModelResponseMetadata & {
|
1986
|
+
/**
|
1987
|
+
The response messages that were generated during the call.
|
1988
|
+
Response messages can be either assistant messages or tool messages.
|
1989
|
+
They contain a generated id.
|
1990
|
+
*/
|
1991
|
+
readonly messages: Array<ResponseMessage>;
|
1992
|
+
/**
|
1993
|
+
Response body (available only for providers that use HTTP requests).
|
1994
|
+
*/
|
1995
|
+
body?: unknown;
|
1996
|
+
};
|
1997
|
+
/**
|
1998
|
+
Additional provider-specific metadata. They are passed through
|
1999
|
+
from the provider to the AI SDK and enable provider-specific
|
2000
|
+
results that can be fully encapsulated in the provider.
|
2001
|
+
*/
|
2002
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
2003
|
+
/**
|
2004
|
+
@deprecated Use `providerMetadata` instead.
|
2005
|
+
*/
|
2006
|
+
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
2007
|
+
/**
|
2008
|
+
The type of step that this result is for. The first step is always
|
2009
|
+
an "initial" step, and subsequent steps are either "continue" steps
|
2010
|
+
or "tool-result" steps.
|
2011
|
+
*/
|
2012
|
+
readonly stepType: 'initial' | 'continue' | 'tool-result';
|
2013
|
+
/**
|
2014
|
+
True when there will be a continuation step with a continuation text.
|
2015
|
+
*/
|
2016
|
+
readonly isContinued: boolean;
|
2017
|
+
};
|
2018
|
+
|
2019
|
+
/**
|
2020
|
+
The result of a `generateText` call.
|
2021
|
+
It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
2022
|
+
*/
|
2023
|
+
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
2024
|
+
/**
|
2025
|
+
The generated text.
|
2026
|
+
*/
|
2027
|
+
readonly text: string;
|
2028
|
+
/**
|
2029
|
+
The reasoning text that the model has generated. Can be undefined if the model
|
2030
|
+
has only generated text.
|
2031
|
+
*/
|
2032
|
+
readonly reasoning: string | undefined;
|
2033
|
+
/**
|
2034
|
+
The files that were generated. Empty array if no files were generated.
|
2035
|
+
*/
|
2036
|
+
readonly files: Array<GeneratedFile>;
|
2037
|
+
/**
|
2038
|
+
The full reasoning that the model has generated.
|
2039
|
+
*/
|
2040
|
+
readonly reasoningDetails: Array<ReasoningDetail>;
|
2041
|
+
/**
|
2042
|
+
Sources that have been used as input to generate the response.
|
2043
|
+
For multi-step generation, the sources are accumulated from all steps.
|
2044
|
+
*/
|
2045
|
+
readonly sources: Source[];
|
2046
|
+
/**
|
2047
|
+
The generated structured output. It uses the `experimental_output` specification.
|
2048
|
+
*/
|
2049
|
+
readonly experimental_output: OUTPUT;
|
2050
|
+
/**
|
2051
|
+
The tool calls that were made during the generation.
|
2052
|
+
*/
|
2053
|
+
readonly toolCalls: ToolCallArray<TOOLS>;
|
2054
|
+
/**
|
2055
|
+
The results of the tool calls.
|
2056
|
+
*/
|
2057
|
+
readonly toolResults: ToolResultArray<TOOLS>;
|
2058
|
+
/**
|
2059
|
+
The reason why the generation finished.
|
2060
|
+
*/
|
2061
|
+
readonly finishReason: FinishReason;
|
2062
|
+
/**
|
2063
|
+
The token usage of the generated text.
|
2064
|
+
*/
|
2065
|
+
readonly usage: LanguageModelUsage;
|
2066
|
+
/**
|
2067
|
+
Warnings from the model provider (e.g. unsupported settings)
|
2068
|
+
*/
|
2069
|
+
readonly warnings: CallWarning[] | undefined;
|
2070
|
+
/**
|
2071
|
+
Details for all steps.
|
2072
|
+
You can use this to get information about intermediate steps,
|
2073
|
+
such as the tool calls or the response headers.
|
2074
|
+
*/
|
2075
|
+
readonly steps: Array<StepResult<TOOLS>>;
|
2076
|
+
/**
|
2077
|
+
Additional request information.
|
2078
|
+
*/
|
2079
|
+
readonly request: LanguageModelRequestMetadata;
|
2080
|
+
/**
|
2081
|
+
Additional response information.
|
2082
|
+
*/
|
2083
|
+
readonly response: LanguageModelResponseMetadata & {
|
2084
|
+
/**
|
2085
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
2086
|
+
potentially containing tool calls.
|
2087
|
+
|
2088
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
2089
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
2090
|
+
need to be added separately.
|
2091
|
+
*/
|
2092
|
+
messages: Array<ResponseMessage>;
|
2093
|
+
/**
|
2094
|
+
Response body (available only for providers that use HTTP requests).
|
2095
|
+
*/
|
2096
|
+
body?: unknown;
|
2097
|
+
};
|
2098
|
+
/**
|
2099
|
+
Logprobs for the completion.
|
2100
|
+
`undefined` if the mode does not support logprobs or if it was not enabled.
|
2101
|
+
|
2102
|
+
@deprecated Will become a provider extension in the future.
|
2103
|
+
*/
|
2104
|
+
readonly logprobs: LogProbs | undefined;
|
2105
|
+
/**
|
2106
|
+
Additional provider-specific metadata. They are passed through
|
2107
|
+
from the provider to the AI SDK and enable provider-specific
|
2108
|
+
results that can be fully encapsulated in the provider.
|
2109
|
+
*/
|
2110
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
2111
|
+
/**
|
2112
|
+
@deprecated Use `providerMetadata` instead.
|
2113
|
+
*/
|
2114
|
+
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
2115
|
+
}
|
2116
|
+
|
2117
|
+
interface Output<OUTPUT, PARTIAL> {
|
2118
|
+
readonly type: 'object' | 'text';
|
2119
|
+
injectIntoSystemPrompt(options: {
|
2120
|
+
system: string | undefined;
|
2121
|
+
model: LanguageModel;
|
2122
|
+
}): string | undefined;
|
2123
|
+
responseFormat: (options: {
|
2124
|
+
model: LanguageModel;
|
2125
|
+
}) => LanguageModelV1CallOptions['responseFormat'];
|
2126
|
+
parsePartial(options: {
|
2127
|
+
text: string;
|
2128
|
+
}): {
|
2129
|
+
partial: PARTIAL;
|
2130
|
+
} | undefined;
|
2131
|
+
parseOutput(options: {
|
2132
|
+
text: string;
|
2133
|
+
}, context: {
|
2134
|
+
response: LanguageModelResponseMetadata;
|
2135
|
+
usage: LanguageModelUsage;
|
2136
|
+
}): OUTPUT;
|
2137
|
+
}
|
2138
|
+
declare const text: () => Output<string, string>;
|
2139
|
+
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
2140
|
+
schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
|
2141
|
+
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
2142
|
+
|
2143
|
+
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
2144
|
+
declare const output_object: typeof object;
|
2145
|
+
declare const output_text: typeof text;
|
2146
|
+
declare namespace output {
|
2147
|
+
export {
|
2148
|
+
output_Output as Output,
|
2149
|
+
output_object as object,
|
2150
|
+
output_text as text,
|
2151
|
+
};
|
2152
|
+
}
|
2153
|
+
|
2154
|
+
declare const symbol$f: unique symbol;
|
2155
|
+
declare class InvalidToolArgumentsError extends AISDKError {
|
2156
|
+
private readonly [symbol$f];
|
2157
|
+
readonly toolName: string;
|
2158
|
+
readonly toolArgs: string;
|
2159
|
+
constructor({ toolArgs, toolName, cause, message, }: {
|
2160
|
+
message?: string;
|
2161
|
+
toolArgs: string;
|
2162
|
+
toolName: string;
|
2163
|
+
cause: unknown;
|
2164
|
+
});
|
2165
|
+
static isInstance(error: unknown): error is InvalidToolArgumentsError;
|
2166
|
+
}
|
2167
|
+
|
2168
|
+
declare const symbol$e: unique symbol;
|
2169
|
+
declare class NoSuchToolError extends AISDKError {
|
2170
|
+
private readonly [symbol$e];
|
2171
|
+
readonly toolName: string;
|
2172
|
+
readonly availableTools: string[] | undefined;
|
2173
|
+
constructor({ toolName, availableTools, message, }: {
|
2174
|
+
toolName: string;
|
2175
|
+
availableTools?: string[] | undefined;
|
2176
|
+
message?: string;
|
2177
|
+
});
|
2178
|
+
static isInstance(error: unknown): error is NoSuchToolError;
|
2179
|
+
}
|
2180
|
+
|
2181
|
+
/**
|
2182
|
+
* Appends a client message to the messages array.
|
2183
|
+
* If the last message in the array has the same id as the new message, it will be replaced.
|
2184
|
+
* Otherwise, the new message will be appended.
|
2185
|
+
*/
|
2186
|
+
declare function appendClientMessage({ messages, message, }: {
|
2187
|
+
messages: Message[];
|
2188
|
+
message: Message;
|
2189
|
+
}): Message[];
|
2190
|
+
|
2191
|
+
/**
|
2192
|
+
* Appends the ResponseMessage[] from the response to a Message[] (for useChat).
|
2193
|
+
* The messages are converted to Messages before being appended.
|
2194
|
+
* Timestamps are generated for the new messages.
|
2195
|
+
*
|
2196
|
+
* @returns A new Message[] with the response messages appended.
|
2197
|
+
*/
|
2198
|
+
declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
|
2199
|
+
messages: Message[];
|
2200
|
+
responseMessages: ResponseMessage[];
|
2201
|
+
/**
|
2202
|
+
Internal. For test use only. May change without notice.
|
2203
|
+
*/
|
2204
|
+
_internal?: {
|
2205
|
+
currentDate?: () => Date;
|
2206
|
+
};
|
2207
|
+
}): Message[];
|
2208
|
+
|
2209
|
+
/**
|
2210
|
+
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
2211
|
+
with the AI core functions (e.g. `streamText`).
|
2212
|
+
*/
|
2213
|
+
declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
|
2214
|
+
tools?: TOOLS;
|
2215
|
+
}): CoreMessage[];
|
2216
|
+
|
2217
|
+
/**
|
2218
|
+
* A function that attempts to repair a tool call that failed to parse.
|
2219
|
+
*
|
2220
|
+
* It receives the error and the context as arguments and returns the repair
|
2221
|
+
* tool call JSON as text.
|
2222
|
+
*
|
2223
|
+
* @param options.system - The system prompt.
|
2224
|
+
* @param options.messages - The messages in the current generation step.
|
2225
|
+
* @param options.toolCall - The tool call that failed to parse.
|
2226
|
+
* @param options.tools - The tools that are available.
|
2227
|
+
* @param options.parameterSchema - A function that returns the JSON Schema for a tool.
|
2228
|
+
* @param options.error - The error that occurred while parsing the tool call.
|
2229
|
+
*/
|
2230
|
+
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
2231
|
+
system: string | undefined;
|
2232
|
+
messages: CoreMessage[];
|
2233
|
+
toolCall: LanguageModelV1FunctionToolCall;
|
2234
|
+
tools: TOOLS;
|
2235
|
+
parameterSchema: (options: {
|
2236
|
+
toolName: string;
|
2237
|
+
}) => JSONSchema7;
|
2238
|
+
error: NoSuchToolError | InvalidToolArgumentsError;
|
2239
|
+
}) => Promise<LanguageModelV1FunctionToolCall | null>;
|
2240
|
+
|
2241
|
+
/**
|
2242
|
+
Callback that is set using the `onStepFinish` option.
|
2243
|
+
|
2244
|
+
@param stepResult - The result of the step.
|
2245
|
+
*/
|
2246
|
+
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
2247
|
+
/**
|
2248
|
+
Generate a text and call tools for a given prompt using a language model.
|
2249
|
+
|
2250
|
+
This function does not stream the output. If you want to stream the output, use `streamText` instead.
|
2251
|
+
|
2252
|
+
@param model - The language model to use.
|
2253
|
+
|
2254
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2255
|
+
@param toolChoice - The tool choice strategy. Default: 'auto'.
|
2256
|
+
|
2257
|
+
@param system - A system message that will be part of the prompt.
|
2258
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
2259
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
2260
|
+
|
2261
|
+
@param maxTokens - Maximum number of tokens to generate.
|
2262
|
+
@param temperature - Temperature setting.
|
2263
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2264
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2265
|
+
@param topP - Nucleus sampling.
|
2266
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2267
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2268
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
2269
|
+
Used to remove "long tail" low probability responses.
|
2270
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
2271
|
+
@param presencePenalty - Presence penalty setting.
|
2272
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
2273
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2274
|
+
@param frequencyPenalty - Frequency penalty setting.
|
2275
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
2276
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2277
|
+
@param stopSequences - Stop sequences.
|
2278
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
2279
|
+
@param seed - The seed (integer) to use for random sampling.
|
2280
|
+
If set and supported by the model, calls will generate deterministic results.
|
2281
|
+
|
2282
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2283
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2284
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2285
|
+
|
2286
|
+
@param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
2287
|
+
@param experimental_generateMessageId - Generate a unique ID for each message.
|
2288
|
+
|
2289
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2290
|
+
|
2291
|
+
@returns
|
2292
|
+
A result object that contains the generated text, the results of the tool calls, and additional information.
|
2293
|
+
*/
|
2294
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata, providerOptions, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
2295
|
+
/**
|
2296
|
+
The language model to use.
|
2297
|
+
*/
|
2298
|
+
model: LanguageModel;
|
2299
|
+
/**
|
2300
|
+
The tools that the model can call. The model needs to support calling tools.
|
2301
|
+
*/
|
2302
|
+
tools?: TOOLS;
|
2303
|
+
/**
|
2304
|
+
The tool choice strategy. Default: 'auto'.
|
2305
|
+
*/
|
2306
|
+
toolChoice?: ToolChoice<TOOLS>;
|
2307
|
+
/**
|
2308
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
2309
|
+
|
2310
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
2311
|
+
|
2312
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
2313
|
+
*/
|
2314
|
+
maxSteps?: number;
|
2315
|
+
/**
|
2316
|
+
Generate a unique ID for each message.
|
2317
|
+
*/
|
2318
|
+
experimental_generateMessageId?: IDGenerator;
|
2319
|
+
/**
|
2320
|
+
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
2321
|
+
|
2322
|
+
By default, it's set to false.
|
2323
|
+
*/
|
2324
|
+
experimental_continueSteps?: boolean;
|
2325
|
+
/**
|
2326
|
+
Optional telemetry configuration (experimental).
|
2327
|
+
*/
|
2328
|
+
experimental_telemetry?: TelemetrySettings;
|
2329
|
+
/**
|
2330
|
+
Additional provider-specific options. They are passed through
|
2331
|
+
to the provider from the AI SDK and enable provider-specific
|
2332
|
+
functionality that can be fully encapsulated in the provider.
|
2333
|
+
*/
|
2334
|
+
providerOptions?: ProviderOptions;
|
2335
|
+
/**
|
2336
|
+
@deprecated Use `providerOptions` instead.
|
2337
|
+
*/
|
2338
|
+
experimental_providerMetadata?: ProviderMetadata;
|
2339
|
+
/**
|
2340
|
+
Limits the tools that are available for the model to call without
|
2341
|
+
changing the tool call and result types in the result.
|
2342
|
+
*/
|
2343
|
+
experimental_activeTools?: Array<keyof TOOLS>;
|
2344
|
+
/**
|
2345
|
+
Optional specification for parsing structured outputs from the LLM response.
|
2346
|
+
*/
|
2347
|
+
experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
|
2348
|
+
/**
|
2349
|
+
A function that attempts to repair a tool call that failed to parse.
|
2350
|
+
*/
|
2351
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
2352
|
+
/**
|
2353
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2354
|
+
*/
|
2355
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
|
2356
|
+
/**
|
2357
|
+
* Internal. For test use only. May change without notice.
|
2358
|
+
*/
|
2359
|
+
_internal?: {
|
2360
|
+
generateId?: IDGenerator;
|
2361
|
+
currentDate?: () => Date;
|
2362
|
+
};
|
2363
|
+
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
2364
|
+
|
2365
|
+
/**
|
2366
|
+
* A stream wrapper to send custom JSON-encoded data back to the client.
|
2367
|
+
*
|
2368
|
+
* @deprecated Please use `createDataStream`, `createDataStreamResponse`, and `pipeDataStreamToResponse` instead.
|
2369
|
+
*/
|
2370
|
+
declare class StreamData {
|
2371
|
+
private encoder;
|
2372
|
+
private controller;
|
2373
|
+
stream: ReadableStream<Uint8Array>;
|
2374
|
+
private isClosed;
|
2375
|
+
private warningTimeout;
|
2376
|
+
constructor();
|
2377
|
+
close(): Promise<void>;
|
2378
|
+
append(value: JSONValue$1): void;
|
2379
|
+
appendMessageAnnotation(value: JSONValue$1): void;
|
2380
|
+
}
|
2381
|
+
|
2382
|
+
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
2383
|
+
|
2384
|
+
type DataStreamOptions = {
|
2385
|
+
/**
|
2386
|
+
* Send usage parts to the client.
|
2387
|
+
* Default to true.
|
2388
|
+
*/
|
2389
|
+
sendUsage?: boolean;
|
2390
|
+
/**
|
2391
|
+
* Send reasoning parts to the client.
|
2392
|
+
* Default to false.
|
2393
|
+
*/
|
2394
|
+
sendReasoning?: boolean;
|
2395
|
+
/**
|
2396
|
+
* Send source parts to the client.
|
2397
|
+
* Default to false.
|
2398
|
+
*/
|
2399
|
+
sendSources?: boolean;
|
2400
|
+
/**
|
2401
|
+
* Send the finish event to the client.
|
2402
|
+
* Set to false if you are using additional streamText calls
|
2403
|
+
* that send additional data.
|
2404
|
+
* Default to true.
|
2405
|
+
*/
|
2406
|
+
experimental_sendFinish?: boolean;
|
2407
|
+
/**
|
2408
|
+
* Send the message start event to the client.
|
2409
|
+
* Set to false if you are using additional streamText calls
|
2410
|
+
* and the message start event has already been sent.
|
2411
|
+
* Default to true.
|
2412
|
+
*
|
2413
|
+
* Note: this setting is currently not used, but you should
|
2414
|
+
* already set it to false if you are using additional
|
2415
|
+
* streamText calls that send additional data to prevent
|
2416
|
+
* the message start event from being sent multiple times.
|
2417
|
+
*/
|
2418
|
+
experimental_sendStart?: boolean;
|
2419
|
+
};
|
2420
|
+
/**
|
2421
|
+
A result object for accessing different stream types and additional information.
|
2422
|
+
*/
|
2423
|
+
interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
2424
|
+
/**
|
2425
|
+
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
2426
|
+
*/
|
2427
|
+
readonly warnings: Promise<CallWarning[] | undefined>;
|
2428
|
+
/**
|
2429
|
+
The total token usage of the generated response.
|
2430
|
+
When there are multiple steps, the usage is the sum of all step usages.
|
2431
|
+
|
2432
|
+
Resolved when the response is finished.
|
2433
|
+
*/
|
2434
|
+
readonly usage: Promise<LanguageModelUsage>;
|
2435
|
+
/**
|
2436
|
+
Sources that have been used as input to generate the response.
|
2437
|
+
For multi-step generation, the sources are accumulated from all steps.
|
2438
|
+
|
2439
|
+
Resolved when the response is finished.
|
2440
|
+
*/
|
2441
|
+
readonly sources: Promise<Source[]>;
|
2442
|
+
/**
|
2443
|
+
Files that have been generated by the model in the last step.
|
2444
|
+
|
2445
|
+
Resolved when the response is finished.
|
2446
|
+
*/
|
2447
|
+
readonly files: Promise<GeneratedFile[]>;
|
2448
|
+
/**
|
2449
|
+
The reason why the generation finished. Taken from the last step.
|
2450
|
+
|
2451
|
+
Resolved when the response is finished.
|
2452
|
+
*/
|
2453
|
+
readonly finishReason: Promise<FinishReason>;
|
2454
|
+
/**
|
2455
|
+
Additional provider-specific metadata from the last step.
|
2456
|
+
Metadata is passed through from the provider to the AI SDK and
|
2457
|
+
enables provider-specific results that can be fully encapsulated in the provider.
|
2458
|
+
*/
|
2459
|
+
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
2460
|
+
/**
|
2461
|
+
@deprecated Use `providerMetadata` instead.
|
2462
|
+
*/
|
2463
|
+
readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
|
2464
|
+
/**
|
2465
|
+
The full text that has been generated by the last step.
|
2466
|
+
|
2467
|
+
Resolved when the response is finished.
|
2468
|
+
*/
|
2469
|
+
readonly text: Promise<string>;
|
2470
|
+
/**
|
2471
|
+
The reasoning that has been generated by the last step.
|
2472
|
+
|
2473
|
+
Resolved when the response is finished.
|
2474
|
+
*/
|
2475
|
+
readonly reasoning: Promise<string | undefined>;
|
2476
|
+
/**
|
2477
|
+
The full reasoning that the model has generated.
|
2478
|
+
|
2479
|
+
Resolved when the response is finished.
|
2480
|
+
*/
|
2481
|
+
readonly reasoningDetails: Promise<Array<ReasoningDetail>>;
|
2482
|
+
/**
|
2483
|
+
The tool calls that have been executed in the last step.
|
2484
|
+
|
2485
|
+
Resolved when the response is finished.
|
2486
|
+
*/
|
2487
|
+
readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
|
2488
|
+
/**
|
2489
|
+
The tool results that have been generated in the last step.
|
2490
|
+
|
2491
|
+
Resolved when the all tool executions are finished.
|
2492
|
+
*/
|
2493
|
+
readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
|
2494
|
+
/**
|
2495
|
+
Details for all steps.
|
2496
|
+
You can use this to get information about intermediate steps,
|
2497
|
+
such as the tool calls or the response headers.
|
2498
|
+
*/
|
2499
|
+
readonly steps: Promise<Array<StepResult<TOOLS>>>;
|
2500
|
+
/**
|
2501
|
+
Additional request information from the last step.
|
2502
|
+
*/
|
2503
|
+
readonly request: Promise<LanguageModelRequestMetadata>;
|
2504
|
+
/**
|
2505
|
+
Additional response information from the last step.
|
2506
|
+
*/
|
2507
|
+
readonly response: Promise<LanguageModelResponseMetadata & {
|
2508
|
+
/**
|
2509
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
2510
|
+
potentially containing tool calls.
|
2511
|
+
|
2512
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
2513
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
2514
|
+
need to be added separately.
|
2515
|
+
*/
|
2516
|
+
messages: Array<ResponseMessage>;
|
2517
|
+
}>;
|
2518
|
+
/**
|
2519
|
+
A text stream that returns only the generated text deltas. You can use it
|
2520
|
+
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
2521
|
+
stream will throw the error.
|
2522
|
+
*/
|
2523
|
+
readonly textStream: AsyncIterableStream<string>;
|
2524
|
+
/**
|
2525
|
+
A stream with all events, including text deltas, tool calls, tool results, and
|
2526
|
+
errors.
|
2527
|
+
You can use it as either an AsyncIterable or a ReadableStream.
|
2528
|
+
Only errors that stop the stream, such as network errors, are thrown.
|
2529
|
+
*/
|
2530
|
+
readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
|
2531
|
+
/**
|
2532
|
+
A stream of partial outputs. It uses the `experimental_output` specification.
|
2533
|
+
*/
|
2534
|
+
readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
|
2535
|
+
/**
|
2536
|
+
Consumes the stream without processing the parts.
|
2537
|
+
This is useful to force the stream to finish.
|
2538
|
+
It effectively removes the backpressure and allows the stream to finish,
|
2539
|
+
triggering the `onFinish` callback and the promise resolution.
|
2540
|
+
*/
|
2541
|
+
consumeStream(): Promise<void>;
|
2542
|
+
/**
|
2543
|
+
Converts the result to a data stream.
|
2544
|
+
|
2545
|
+
@param data an optional StreamData object that will be merged into the stream.
|
2546
|
+
@param getErrorMessage an optional function that converts an error to an error message.
|
2547
|
+
@param sendUsage whether to send the usage information to the client. Defaults to true.
|
2548
|
+
@param sendReasoning whether to send the reasoning information to the client. Defaults to false.
|
2549
|
+
@return A data stream.
|
2550
|
+
*/
|
2551
|
+
toDataStream(options?: {
|
2552
|
+
data?: StreamData;
|
2553
|
+
getErrorMessage?: (error: unknown) => string;
|
2554
|
+
} & DataStreamOptions): ReadableStream<Uint8Array>;
|
2555
|
+
/**
|
2556
|
+
* Merges the result as a data stream into another data stream.
|
2557
|
+
*
|
2558
|
+
* @param dataStream A data stream writer.
|
2559
|
+
* @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
2560
|
+
* @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
2561
|
+
*/
|
2562
|
+
mergeIntoDataStream(dataStream: DataStreamWriter, options?: DataStreamOptions): void;
|
2563
|
+
/**
|
2564
|
+
Writes data stream output to a Node.js response-like object.
|
2565
|
+
|
2566
|
+
@param response A Node.js response-like object (ServerResponse).
|
2567
|
+
@param options.status The status code.
|
2568
|
+
@param options.statusText The status text.
|
2569
|
+
@param options.headers The headers.
|
2570
|
+
@param options.data The stream data.
|
2571
|
+
@param options.getErrorMessage An optional function that converts an error to an error message.
|
2572
|
+
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
2573
|
+
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
2574
|
+
*/
|
2575
|
+
pipeDataStreamToResponse(response: ServerResponse, options?: ResponseInit & {
|
2576
|
+
data?: StreamData;
|
2577
|
+
getErrorMessage?: (error: unknown) => string;
|
2578
|
+
} & DataStreamOptions): void;
|
2579
|
+
/**
|
2580
|
+
Writes text delta output to a Node.js response-like object.
|
2581
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
2582
|
+
writes each text delta as a separate chunk.
|
2583
|
+
|
2584
|
+
@param response A Node.js response-like object (ServerResponse).
|
2585
|
+
@param init Optional headers, status code, and status text.
|
2586
|
+
*/
|
2587
|
+
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
2588
|
+
/**
|
2589
|
+
Converts the result to a streamed response object with a stream data part stream.
|
2590
|
+
It can be used with the `useChat` and `useCompletion` hooks.
|
2591
|
+
|
2592
|
+
@param options.status The status code.
|
2593
|
+
@param options.statusText The status text.
|
2594
|
+
@param options.headers The headers.
|
2595
|
+
@param options.data The stream data.
|
2596
|
+
@param options.getErrorMessage An optional function that converts an error to an error message.
|
2597
|
+
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
2598
|
+
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
2599
|
+
|
2600
|
+
@return A response object.
|
2601
|
+
*/
|
2602
|
+
toDataStreamResponse(options?: ResponseInit & {
|
2603
|
+
data?: StreamData;
|
2604
|
+
getErrorMessage?: (error: unknown) => string;
|
2605
|
+
} & DataStreamOptions): Response;
|
2606
|
+
/**
|
2607
|
+
Creates a simple text stream response.
|
2608
|
+
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
2609
|
+
Non-text-delta events are ignored.
|
2610
|
+
|
2611
|
+
@param init Optional headers, status code, and status text.
|
2612
|
+
*/
|
2613
|
+
toTextStreamResponse(init?: ResponseInit): Response;
|
2614
|
+
}
|
2615
|
+
type TextStreamPart<TOOLS extends ToolSet> = {
|
2616
|
+
type: 'text-delta';
|
2617
|
+
textDelta: string;
|
2618
|
+
} | {
|
2619
|
+
type: 'reasoning';
|
2620
|
+
textDelta: string;
|
2621
|
+
} | {
|
2622
|
+
type: 'reasoning-signature';
|
2623
|
+
signature: string;
|
2624
|
+
} | {
|
2625
|
+
type: 'redacted-reasoning';
|
2626
|
+
data: string;
|
2627
|
+
} | {
|
2628
|
+
type: 'source';
|
2629
|
+
source: Source;
|
2630
|
+
} | ({
|
2631
|
+
type: 'file';
|
2632
|
+
} & GeneratedFile) | ({
|
2633
|
+
type: 'tool-call';
|
2634
|
+
} & ToolCallUnion<TOOLS>) | {
|
2635
|
+
type: 'tool-call-streaming-start';
|
2636
|
+
toolCallId: string;
|
2637
|
+
toolName: string;
|
2638
|
+
} | {
|
2639
|
+
type: 'tool-call-delta';
|
2640
|
+
toolCallId: string;
|
2641
|
+
toolName: string;
|
2642
|
+
argsTextDelta: string;
|
2643
|
+
} | ({
|
2644
|
+
type: 'tool-result';
|
2645
|
+
} & ToolResultUnion<TOOLS>) | {
|
2646
|
+
type: 'step-start';
|
2647
|
+
messageId: string;
|
2648
|
+
request: LanguageModelRequestMetadata;
|
2649
|
+
warnings: CallWarning[];
|
2650
|
+
} | {
|
2651
|
+
type: 'step-finish';
|
2652
|
+
messageId: string;
|
2653
|
+
logprobs?: LogProbs;
|
2654
|
+
request: LanguageModelRequestMetadata;
|
2655
|
+
warnings: CallWarning[] | undefined;
|
2656
|
+
response: LanguageModelResponseMetadata;
|
2657
|
+
usage: LanguageModelUsage;
|
2658
|
+
finishReason: FinishReason;
|
2659
|
+
providerMetadata: ProviderMetadata | undefined;
|
2660
|
+
/**
|
2661
|
+
* @deprecated Use `providerMetadata` instead.
|
2662
|
+
*/
|
2663
|
+
experimental_providerMetadata?: ProviderMetadata;
|
2664
|
+
isContinued: boolean;
|
2665
|
+
} | {
|
2666
|
+
type: 'finish';
|
2667
|
+
finishReason: FinishReason;
|
2668
|
+
usage: LanguageModelUsage;
|
2669
|
+
providerMetadata: ProviderMetadata | undefined;
|
2670
|
+
/**
|
2671
|
+
* @deprecated Use `providerMetadata` instead.
|
2672
|
+
*/
|
2673
|
+
experimental_providerMetadata?: ProviderMetadata;
|
2674
|
+
/**
|
2675
|
+
* @deprecated will be moved into provider metadata
|
2676
|
+
*/
|
2677
|
+
logprobs?: LogProbs;
|
2678
|
+
/**
|
2679
|
+
* @deprecated use response on step-finish instead
|
2680
|
+
*/
|
2681
|
+
response: LanguageModelResponseMetadata;
|
2682
|
+
} | {
|
2683
|
+
type: 'error';
|
2684
|
+
error: unknown;
|
2685
|
+
};
|
2686
|
+
|
2687
|
+
/**
|
2688
|
+
* Smooths text streaming output.
|
2689
|
+
*
|
2690
|
+
* @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
|
2691
|
+
* @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
|
2692
|
+
*
|
2693
|
+
* @returns A transform stream that smooths text streaming output.
|
2694
|
+
*/
|
2695
|
+
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
2696
|
+
delayInMs?: number | null;
|
2697
|
+
chunking?: 'word' | 'line' | RegExp;
|
2698
|
+
/**
|
2699
|
+
* Internal. For test use only. May change without notice.
|
2626
2700
|
*/
|
2627
|
-
|
2628
|
-
|
2629
|
-
}
|
2630
|
-
|
2631
|
-
|
2632
|
-
|
2633
|
-
}
|
2701
|
+
_internal?: {
|
2702
|
+
delay?: (delayInMs: number | null) => Promise<void>;
|
2703
|
+
};
|
2704
|
+
}): (options: {
|
2705
|
+
tools: TOOLS;
|
2706
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
2634
2707
|
|
2635
|
-
|
2708
|
+
/**
|
2709
|
+
A transformation that is applied to the stream.
|
2636
2710
|
|
2637
|
-
|
2638
|
-
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2642
|
-
|
2643
|
-
|
2644
|
-
}>;
|
2711
|
+
@param stopStream - A function that stops the source stream.
|
2712
|
+
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2713
|
+
*/
|
2714
|
+
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
2715
|
+
tools: TOOLS;
|
2716
|
+
stopStream: () => void;
|
2717
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
2645
2718
|
/**
|
2646
|
-
|
2719
|
+
Callback that is set using the `onError` option.
|
2720
|
+
|
2721
|
+
@param event - The event that is passed to the callback.
|
2647
2722
|
*/
|
2648
|
-
type
|
2649
|
-
|
2723
|
+
type StreamTextOnErrorCallback = (event: {
|
2724
|
+
error: unknown;
|
2725
|
+
}) => Promise<void> | void;
|
2726
|
+
/**
|
2727
|
+
Callback that is set using the `onStepFinish` option.
|
2650
2728
|
|
2651
|
-
|
2652
|
-
|
2653
|
-
|
2654
|
-
} ? K : never]: TOOLS[K];
|
2655
|
-
};
|
2656
|
-
type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
|
2657
|
-
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
2658
|
-
};
|
2659
|
-
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
2660
|
-
[NAME in keyof TOOLS]: {
|
2661
|
-
type: 'tool-result';
|
2662
|
-
toolCallId: string;
|
2663
|
-
toolName: NAME & string;
|
2664
|
-
args: inferParameters<TOOLS[NAME]['parameters']>;
|
2665
|
-
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
2666
|
-
};
|
2667
|
-
}>;
|
2668
|
-
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
|
2729
|
+
@param stepResult - The result of the step.
|
2730
|
+
*/
|
2731
|
+
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
2669
2732
|
/**
|
2670
|
-
|
2733
|
+
Callback that is set using the `onChunk` option.
|
2734
|
+
|
2735
|
+
@param event - The event that is passed to the callback.
|
2671
2736
|
*/
|
2672
|
-
type
|
2673
|
-
|
2737
|
+
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
2738
|
+
chunk: Extract<TextStreamPart<TOOLS>, {
|
2739
|
+
type: 'text-delta' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
|
2740
|
+
}>;
|
2741
|
+
}) => Promise<void> | void;
|
2742
|
+
/**
|
2743
|
+
Callback that is set using the `onFinish` option.
|
2674
2744
|
|
2745
|
+
@param event - The event that is passed to the callback.
|
2746
|
+
*/
|
2747
|
+
type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: Omit<StepResult<TOOLS>, 'stepType' | 'isContinued'> & {
|
2748
|
+
/**
|
2749
|
+
Details for all steps.
|
2750
|
+
*/
|
2751
|
+
readonly steps: StepResult<TOOLS>[];
|
2752
|
+
}) => Promise<void> | void;
|
2675
2753
|
/**
|
2676
|
-
|
2677
|
-
|
2754
|
+
Generate a text and call tools for a given prompt using a language model.
|
2755
|
+
|
2756
|
+
This function streams the output. If you do not want to stream the output, use `generateText` instead.
|
2757
|
+
|
2758
|
+
@param model - The language model to use.
|
2759
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2760
|
+
|
2761
|
+
@param system - A system message that will be part of the prompt.
|
2762
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
2763
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
2764
|
+
|
2765
|
+
@param maxTokens - Maximum number of tokens to generate.
|
2766
|
+
@param temperature - Temperature setting.
|
2767
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2768
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2769
|
+
@param topP - Nucleus sampling.
|
2770
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2771
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2772
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
2773
|
+
Used to remove "long tail" low probability responses.
|
2774
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
2775
|
+
@param presencePenalty - Presence penalty setting.
|
2776
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
2777
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2778
|
+
@param frequencyPenalty - Frequency penalty setting.
|
2779
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
2780
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2781
|
+
@param stopSequences - Stop sequences.
|
2782
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
2783
|
+
@param seed - The seed (integer) to use for random sampling.
|
2784
|
+
If set and supported by the model, calls will generate deterministic results.
|
2785
|
+
|
2786
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2787
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2788
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2789
|
+
|
2790
|
+
@param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
2791
|
+
@param experimental_generateMessageId - Generate a unique ID for each message.
|
2792
|
+
|
2793
|
+
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
2794
|
+
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
2795
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2796
|
+
@param onFinish - Callback that is called when the LLM response and all request tool executions
|
2797
|
+
(for tools that have an `execute` function) are finished.
|
2798
|
+
|
2799
|
+
@return
|
2800
|
+
A result object for accessing different stream types and additional information.
|
2678
2801
|
*/
|
2679
|
-
|
2802
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
2680
2803
|
/**
|
2681
|
-
|
2804
|
+
The language model to use.
|
2682
2805
|
*/
|
2683
|
-
|
2684
|
-
|
2685
|
-
|
2686
|
-
|
2806
|
+
model: LanguageModel;
|
2807
|
+
/**
|
2808
|
+
The tools that the model can call. The model needs to support calling tools.
|
2809
|
+
*/
|
2810
|
+
tools?: TOOLS;
|
2811
|
+
/**
|
2812
|
+
The tool choice strategy. Default: 'auto'.
|
2813
|
+
*/
|
2814
|
+
toolChoice?: ToolChoice<TOOLS>;
|
2815
|
+
/**
|
2816
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
2817
|
+
|
2818
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
2819
|
+
|
2820
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
2687
2821
|
*/
|
2688
|
-
|
2822
|
+
maxSteps?: number;
|
2689
2823
|
/**
|
2690
|
-
|
2691
|
-
|
2692
|
-
|
2824
|
+
Generate a unique ID for each message.
|
2825
|
+
*/
|
2826
|
+
experimental_generateMessageId?: IDGenerator;
|
2693
2827
|
/**
|
2694
|
-
|
2695
|
-
|
2696
|
-
|
2697
|
-
|
2828
|
+
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
2829
|
+
|
2830
|
+
By default, it's set to false.
|
2831
|
+
*/
|
2832
|
+
experimental_continueSteps?: boolean;
|
2698
2833
|
/**
|
2699
|
-
|
2700
|
-
|
2701
|
-
|
2834
|
+
Optional telemetry configuration (experimental).
|
2835
|
+
*/
|
2836
|
+
experimental_telemetry?: TelemetrySettings;
|
2702
2837
|
/**
|
2703
|
-
|
2704
|
-
|
2705
|
-
|
2838
|
+
Additional provider-specific options. They are passed through
|
2839
|
+
to the provider from the AI SDK and enable provider-specific
|
2840
|
+
functionality that can be fully encapsulated in the provider.
|
2841
|
+
*/
|
2842
|
+
providerOptions?: ProviderOptions;
|
2706
2843
|
/**
|
2707
|
-
|
2708
|
-
|
2709
|
-
|
2844
|
+
@deprecated Use `providerOptions` instead.
|
2845
|
+
*/
|
2846
|
+
experimental_providerMetadata?: ProviderMetadata;
|
2710
2847
|
/**
|
2711
|
-
|
2712
|
-
|
2713
|
-
|
2848
|
+
Limits the tools that are available for the model to call without
|
2849
|
+
changing the tool call and result types in the result.
|
2850
|
+
*/
|
2851
|
+
experimental_activeTools?: Array<keyof TOOLS>;
|
2714
2852
|
/**
|
2715
|
-
|
2716
|
-
|
2717
|
-
|
2853
|
+
Optional specification for parsing structured outputs from the LLM response.
|
2854
|
+
*/
|
2855
|
+
experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
|
2718
2856
|
/**
|
2719
|
-
|
2720
|
-
|
2721
|
-
|
2857
|
+
A function that attempts to repair a tool call that failed to parse.
|
2858
|
+
*/
|
2859
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
2722
2860
|
/**
|
2723
|
-
|
2724
|
-
|
2725
|
-
|
2726
|
-
|
2861
|
+
Enable streaming of tool call deltas as they are generated. Disabled by default.
|
2862
|
+
*/
|
2863
|
+
toolCallStreaming?: boolean;
|
2864
|
+
/**
|
2865
|
+
@deprecated Use `toolCallStreaming` instead.
|
2866
|
+
*/
|
2867
|
+
experimental_toolCallStreaming?: boolean;
|
2868
|
+
/**
|
2869
|
+
Optional stream transformations.
|
2870
|
+
They are applied in the order they are provided.
|
2871
|
+
The stream transformations must maintain the stream structure for streamText to work correctly.
|
2872
|
+
*/
|
2873
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
2874
|
+
/**
|
2875
|
+
Callback that is called for each chunk of the stream.
|
2876
|
+
The stream processing will pause until the callback promise is resolved.
|
2877
|
+
*/
|
2878
|
+
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
2879
|
+
/**
|
2880
|
+
Callback that is invoked when an error occurs during streaming.
|
2881
|
+
You can use it to log errors.
|
2882
|
+
The stream processing will pause until the callback promise is resolved.
|
2883
|
+
*/
|
2884
|
+
onError?: StreamTextOnErrorCallback;
|
2727
2885
|
/**
|
2728
|
-
|
2886
|
+
Callback that is called when the LLM response and all request tool executions
|
2887
|
+
(for tools that have an `execute` function) are finished.
|
2888
|
+
|
2889
|
+
The usage is the combined usage of all steps.
|
2729
2890
|
*/
|
2730
|
-
|
2891
|
+
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
2731
2892
|
/**
|
2732
|
-
|
2733
|
-
*/
|
2734
|
-
readonly response: LanguageModelResponseMetadata & {
|
2735
|
-
/**
|
2736
|
-
The response messages that were generated during the call.
|
2737
|
-
Response messages can be either assistant messages or tool messages.
|
2738
|
-
They contain a generated id.
|
2893
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2739
2894
|
*/
|
2740
|
-
|
2741
|
-
/**
|
2742
|
-
Response body (available only for providers that use HTTP requests).
|
2743
|
-
*/
|
2744
|
-
body?: unknown;
|
2745
|
-
};
|
2895
|
+
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
2746
2896
|
/**
|
2747
|
-
|
2748
|
-
from the provider to the AI SDK and enable provider-specific
|
2749
|
-
results that can be fully encapsulated in the provider.
|
2897
|
+
Internal. For test use only. May change without notice.
|
2750
2898
|
*/
|
2751
|
-
|
2899
|
+
_internal?: {
|
2900
|
+
now?: () => number;
|
2901
|
+
generateId?: IDGenerator;
|
2902
|
+
currentDate?: () => Date;
|
2903
|
+
};
|
2904
|
+
}): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
|
2905
|
+
|
2906
|
+
/**
|
2907
|
+
The result of a `generateImage` call.
|
2908
|
+
It contains the images and additional information.
|
2909
|
+
*/
|
2910
|
+
interface GenerateImageResult {
|
2752
2911
|
/**
|
2753
|
-
|
2912
|
+
The first image that was generated.
|
2754
2913
|
*/
|
2755
|
-
readonly
|
2914
|
+
readonly image: GeneratedFile;
|
2756
2915
|
/**
|
2757
|
-
The
|
2758
|
-
|
2759
|
-
|
2760
|
-
*/
|
2761
|
-
readonly stepType: 'initial' | 'continue' | 'tool-result';
|
2916
|
+
The images that were generated.
|
2917
|
+
*/
|
2918
|
+
readonly images: Array<GeneratedFile>;
|
2762
2919
|
/**
|
2763
|
-
|
2920
|
+
Warnings for the call, e.g. unsupported settings.
|
2921
|
+
*/
|
2922
|
+
readonly warnings: Array<ImageGenerationWarning>;
|
2923
|
+
/**
|
2924
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
2764
2925
|
*/
|
2765
|
-
readonly
|
2766
|
-
}
|
2926
|
+
readonly responses: Array<ImageModelResponseMetadata>;
|
2927
|
+
}
|
2767
2928
|
|
2768
2929
|
/**
|
2769
|
-
|
2770
|
-
|
2930
|
+
Generates images using an image model.
|
2931
|
+
|
2932
|
+
@param model - The image model to use.
|
2933
|
+
@param prompt - The prompt that should be used to generate the image.
|
2934
|
+
@param n - Number of images to generate. Default: 1.
|
2935
|
+
@param size - Size of the images to generate. Must have the format `{width}x{height}`.
|
2936
|
+
@param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
|
2937
|
+
@param seed - Seed for the image generation.
|
2938
|
+
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
2939
|
+
as body parameters.
|
2940
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2941
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2942
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2943
|
+
|
2944
|
+
@returns A result object that contains the generated images.
|
2771
2945
|
*/
|
2772
|
-
|
2946
|
+
declare function generateImage({ model, prompt, n, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
2773
2947
|
/**
|
2774
|
-
The
|
2948
|
+
The image model to use.
|
2775
2949
|
*/
|
2776
|
-
|
2950
|
+
model: ImageModelV1;
|
2777
2951
|
/**
|
2778
|
-
The
|
2779
|
-
has only generated text.
|
2952
|
+
The prompt that should be used to generate the image.
|
2780
2953
|
*/
|
2781
|
-
|
2954
|
+
prompt: string;
|
2782
2955
|
/**
|
2783
|
-
|
2956
|
+
Number of images to generate.
|
2784
2957
|
*/
|
2785
|
-
|
2958
|
+
n?: number;
|
2786
2959
|
/**
|
2787
|
-
|
2788
|
-
For multi-step generation, the sources are accumulated from all steps.
|
2960
|
+
Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
|
2789
2961
|
*/
|
2790
|
-
|
2962
|
+
size?: `${number}x${number}`;
|
2791
2963
|
/**
|
2792
|
-
|
2964
|
+
Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
|
2793
2965
|
*/
|
2794
|
-
|
2966
|
+
aspectRatio?: `${number}:${number}`;
|
2795
2967
|
/**
|
2796
|
-
|
2968
|
+
Seed for the image generation. If not provided, the default seed will be used.
|
2797
2969
|
*/
|
2798
|
-
|
2970
|
+
seed?: number;
|
2799
2971
|
/**
|
2800
|
-
|
2972
|
+
Additional provider-specific options that are passed through to the provider
|
2973
|
+
as body parameters.
|
2974
|
+
|
2975
|
+
The outer record is keyed by the provider name, and the inner
|
2976
|
+
record is keyed by the provider-specific metadata key.
|
2977
|
+
```ts
|
2978
|
+
{
|
2979
|
+
"openai": {
|
2980
|
+
"style": "vivid"
|
2981
|
+
}
|
2982
|
+
}
|
2983
|
+
```
|
2984
|
+
*/
|
2985
|
+
providerOptions?: Record<string, Record<string, JSONValue>>;
|
2986
|
+
/**
|
2987
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
2988
|
+
|
2989
|
+
@default 2
|
2801
2990
|
*/
|
2802
|
-
|
2991
|
+
maxRetries?: number;
|
2992
|
+
/**
|
2993
|
+
Abort signal.
|
2994
|
+
*/
|
2995
|
+
abortSignal?: AbortSignal;
|
2996
|
+
/**
|
2997
|
+
Additional headers to include in the request.
|
2998
|
+
Only applicable for HTTP-based providers.
|
2999
|
+
*/
|
3000
|
+
headers?: Record<string, string>;
|
3001
|
+
}): Promise<GenerateImageResult>;
|
3002
|
+
|
3003
|
+
/**
|
3004
|
+
The result of a `generateObject` call.
|
3005
|
+
*/
|
3006
|
+
interface GenerateObjectResult<OBJECT> {
|
3007
|
+
/**
|
3008
|
+
The generated object (typed according to the schema).
|
3009
|
+
*/
|
3010
|
+
readonly object: OBJECT;
|
2803
3011
|
/**
|
2804
3012
|
The reason why the generation finished.
|
2805
|
-
|
3013
|
+
*/
|
2806
3014
|
readonly finishReason: FinishReason;
|
2807
3015
|
/**
|
2808
3016
|
The token usage of the generated text.
|
2809
|
-
|
3017
|
+
*/
|
2810
3018
|
readonly usage: LanguageModelUsage;
|
2811
3019
|
/**
|
2812
|
-
Warnings from the model provider (e.g. unsupported settings)
|
2813
|
-
|
3020
|
+
Warnings from the model provider (e.g. unsupported settings).
|
3021
|
+
*/
|
2814
3022
|
readonly warnings: CallWarning[] | undefined;
|
2815
3023
|
/**
|
2816
|
-
Details for all steps.
|
2817
|
-
You can use this to get information about intermediate steps,
|
2818
|
-
such as the tool calls or the response headers.
|
2819
|
-
*/
|
2820
|
-
readonly steps: Array<StepResult<TOOLS>>;
|
2821
|
-
/**
|
2822
3024
|
Additional request information.
|
2823
3025
|
*/
|
2824
3026
|
readonly request: LanguageModelRequestMetadata;
|
2825
3027
|
/**
|
2826
3028
|
Additional response information.
|
2827
3029
|
*/
|
2828
|
-
readonly response: LanguageModelResponseMetadata & {
|
2829
|
-
/**
|
2830
|
-
|
2831
|
-
|
2832
|
-
|
2833
|
-
|
2834
|
-
|
2835
|
-
|
2836
|
-
|
2837
|
-
|
2838
|
-
|
2839
|
-
|
2840
|
-
|
2841
|
-
|
2842
|
-
|
2843
|
-
|
2844
|
-
|
2845
|
-
|
2846
|
-
|
2847
|
-
|
2848
|
-
|
2849
|
-
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2854
|
-
|
2855
|
-
|
2856
|
-
/**
|
2857
|
-
@deprecated Use `providerMetadata` instead.
|
2858
|
-
*/
|
2859
|
-
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
2860
|
-
}
|
2861
|
-
|
2862
|
-
interface Output<OUTPUT, PARTIAL> {
|
2863
|
-
readonly type: 'object' | 'text';
|
2864
|
-
injectIntoSystemPrompt(options: {
|
2865
|
-
system: string | undefined;
|
2866
|
-
model: LanguageModel;
|
2867
|
-
}): string | undefined;
|
2868
|
-
responseFormat: (options: {
|
2869
|
-
model: LanguageModel;
|
2870
|
-
}) => LanguageModelV1CallOptions['responseFormat'];
|
2871
|
-
parsePartial(options: {
|
2872
|
-
text: string;
|
2873
|
-
}): {
|
2874
|
-
partial: PARTIAL;
|
2875
|
-
} | undefined;
|
2876
|
-
parseOutput(options: {
|
2877
|
-
text: string;
|
2878
|
-
}, context: {
|
2879
|
-
response: LanguageModelResponseMetadata;
|
2880
|
-
usage: LanguageModelUsage;
|
2881
|
-
}): OUTPUT;
|
2882
|
-
}
|
2883
|
-
declare const text: () => Output<string, string>;
|
2884
|
-
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
2885
|
-
schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
|
2886
|
-
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
2887
|
-
|
2888
|
-
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
2889
|
-
declare const output_object: typeof object;
|
2890
|
-
declare const output_text: typeof text;
|
2891
|
-
declare namespace output {
|
2892
|
-
export {
|
2893
|
-
output_Output as Output,
|
2894
|
-
output_object as object,
|
2895
|
-
output_text as text,
|
2896
|
-
};
|
2897
|
-
}
|
2898
|
-
|
2899
|
-
declare const symbol$f: unique symbol;
|
2900
|
-
declare class InvalidToolArgumentsError extends AISDKError {
|
2901
|
-
private readonly [symbol$f];
|
2902
|
-
readonly toolName: string;
|
2903
|
-
readonly toolArgs: string;
|
2904
|
-
constructor({ toolArgs, toolName, cause, message, }: {
|
2905
|
-
message?: string;
|
2906
|
-
toolArgs: string;
|
2907
|
-
toolName: string;
|
2908
|
-
cause: unknown;
|
2909
|
-
});
|
2910
|
-
static isInstance(error: unknown): error is InvalidToolArgumentsError;
|
2911
|
-
}
|
2912
|
-
|
2913
|
-
declare const symbol$e: unique symbol;
|
2914
|
-
declare class NoSuchToolError extends AISDKError {
|
2915
|
-
private readonly [symbol$e];
|
2916
|
-
readonly toolName: string;
|
2917
|
-
readonly availableTools: string[] | undefined;
|
2918
|
-
constructor({ toolName, availableTools, message, }: {
|
2919
|
-
toolName: string;
|
2920
|
-
availableTools?: string[] | undefined;
|
2921
|
-
message?: string;
|
2922
|
-
});
|
2923
|
-
static isInstance(error: unknown): error is NoSuchToolError;
|
3030
|
+
readonly response: LanguageModelResponseMetadata & {
|
3031
|
+
/**
|
3032
|
+
Response body (available only for providers that use HTTP requests).
|
3033
|
+
*/
|
3034
|
+
body?: unknown;
|
3035
|
+
};
|
3036
|
+
/**
|
3037
|
+
Logprobs for the completion.
|
3038
|
+
`undefined` if the mode does not support logprobs or if was not enabled.
|
3039
|
+
|
3040
|
+
@deprecated Will become a provider extension in the future.
|
3041
|
+
*/
|
3042
|
+
readonly logprobs: LogProbs | undefined;
|
3043
|
+
/**
|
3044
|
+
Additional provider-specific metadata. They are passed through
|
3045
|
+
from the provider to the AI SDK and enable provider-specific
|
3046
|
+
results that can be fully encapsulated in the provider.
|
3047
|
+
*/
|
3048
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
3049
|
+
/**
|
3050
|
+
@deprecated Use `providerMetadata` instead.
|
3051
|
+
*/
|
3052
|
+
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
3053
|
+
/**
|
3054
|
+
Converts the object to a JSON response.
|
3055
|
+
The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
|
3056
|
+
*/
|
3057
|
+
toJsonResponse(init?: ResponseInit): Response;
|
2924
3058
|
}
|
2925
3059
|
|
2926
3060
|
/**
|
2927
|
-
|
2928
|
-
|
2929
|
-
* Otherwise, the new message will be appended.
|
2930
|
-
*/
|
2931
|
-
declare function appendClientMessage({ messages, message, }: {
|
2932
|
-
messages: Message[];
|
2933
|
-
message: Message;
|
2934
|
-
}): Message[];
|
3061
|
+
A function that attempts to repair the raw output of the mode
|
3062
|
+
to enable JSON parsing.
|
2935
3063
|
|
3064
|
+
Should return the repaired text or null if the text cannot be repaired.
|
3065
|
+
*/
|
3066
|
+
type RepairTextFunction = (options: {
|
3067
|
+
text: string;
|
3068
|
+
error: JSONParseError | TypeValidationError;
|
3069
|
+
}) => Promise<string | null>;
|
2936
3070
|
/**
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
3071
|
+
Generate a structured, typed object for a given prompt and schema using a language model.
|
3072
|
+
|
3073
|
+
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
3074
|
+
|
3075
|
+
@returns
|
3076
|
+
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
2942
3077
|
*/
|
2943
|
-
declare function
|
2944
|
-
|
2945
|
-
responseMessages: ResponseMessage[];
|
3078
|
+
declare function generateObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3079
|
+
output?: 'object' | undefined;
|
2946
3080
|
/**
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
3081
|
+
The language model to use.
|
3082
|
+
*/
|
3083
|
+
model: LanguageModel;
|
3084
|
+
/**
|
3085
|
+
The schema of the object that the model should generate.
|
3086
|
+
*/
|
3087
|
+
schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
|
3088
|
+
/**
|
3089
|
+
Optional name of the output that should be generated.
|
3090
|
+
Used by some providers for additional LLM guidance, e.g.
|
3091
|
+
via tool or schema name.
|
3092
|
+
*/
|
3093
|
+
schemaName?: string;
|
3094
|
+
/**
|
3095
|
+
Optional description of the output that should be generated.
|
3096
|
+
Used by some providers for additional LLM guidance, e.g.
|
3097
|
+
via tool or schema description.
|
3098
|
+
*/
|
3099
|
+
schemaDescription?: string;
|
3100
|
+
/**
|
3101
|
+
The mode to use for object generation.
|
2953
3102
|
|
2954
|
-
|
2955
|
-
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
2956
|
-
with the AI core functions (e.g. `streamText`).
|
2957
|
-
*/
|
2958
|
-
declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
|
2959
|
-
tools?: TOOLS;
|
2960
|
-
}): CoreMessage[];
|
3103
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
2961
3104
|
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
* It receives the error and the context as arguments and returns the repair
|
2966
|
-
* tool call JSON as text.
|
2967
|
-
*
|
2968
|
-
* @param options.system - The system prompt.
|
2969
|
-
* @param options.messages - The messages in the current generation step.
|
2970
|
-
* @param options.toolCall - The tool call that failed to parse.
|
2971
|
-
* @param options.tools - The tools that are available.
|
2972
|
-
* @param options.parameterSchema - A function that returns the JSON Schema for a tool.
|
2973
|
-
* @param options.error - The error that occurred while parsing the tool call.
|
2974
|
-
*/
|
2975
|
-
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
2976
|
-
system: string | undefined;
|
2977
|
-
messages: CoreMessage[];
|
2978
|
-
toolCall: LanguageModelV1FunctionToolCall;
|
2979
|
-
tools: TOOLS;
|
2980
|
-
parameterSchema: (options: {
|
2981
|
-
toolName: string;
|
2982
|
-
}) => JSONSchema7;
|
2983
|
-
error: NoSuchToolError | InvalidToolArgumentsError;
|
2984
|
-
}) => Promise<LanguageModelV1FunctionToolCall | null>;
|
3105
|
+
- 'auto': The provider will choose the best mode for the model.
|
3106
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3107
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
2985
3108
|
|
2986
|
-
|
2987
|
-
Callback that is set using the `onStepFinish` option.
|
3109
|
+
Please note that most providers do not support all modes.
|
2988
3110
|
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
3111
|
+
Default and recommended: 'auto' (best mode for the model).
|
3112
|
+
*/
|
3113
|
+
mode?: 'auto' | 'json' | 'tool';
|
3114
|
+
/**
|
3115
|
+
A function that attempts to repair the raw output of the mode
|
3116
|
+
to enable JSON parsing.
|
3117
|
+
*/
|
3118
|
+
experimental_repairText?: RepairTextFunction;
|
3119
|
+
/**
|
3120
|
+
Optional telemetry configuration (experimental).
|
3121
|
+
*/
|
3122
|
+
experimental_telemetry?: TelemetrySettings;
|
3123
|
+
/**
|
3124
|
+
Additional provider-specific options. They are passed through
|
3125
|
+
to the provider from the AI SDK and enable provider-specific
|
3126
|
+
functionality that can be fully encapsulated in the provider.
|
3127
|
+
*/
|
3128
|
+
providerOptions?: ProviderOptions;
|
3129
|
+
/**
|
3130
|
+
@deprecated Use `providerOptions` instead.
|
3131
|
+
*/
|
3132
|
+
experimental_providerMetadata?: ProviderMetadata;
|
3133
|
+
/**
|
3134
|
+
* Internal. For test use only. May change without notice.
|
3135
|
+
*/
|
3136
|
+
_internal?: {
|
3137
|
+
generateId?: () => string;
|
3138
|
+
currentDate?: () => Date;
|
3139
|
+
};
|
3140
|
+
}): Promise<GenerateObjectResult<OBJECT>>;
|
2992
3141
|
/**
|
2993
|
-
Generate
|
2994
|
-
|
2995
|
-
This function does not stream the output. If you want to stream the output, use `streamText` instead.
|
3142
|
+
Generate an array with structured, typed elements for a given prompt and element schema using a language model.
|
2996
3143
|
|
2997
|
-
|
3144
|
+
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
2998
3145
|
|
2999
|
-
@
|
3000
|
-
|
3146
|
+
@return
|
3147
|
+
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3148
|
+
*/
|
3149
|
+
declare function generateObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3150
|
+
output: 'array';
|
3151
|
+
/**
|
3152
|
+
The language model to use.
|
3153
|
+
*/
|
3154
|
+
model: LanguageModel;
|
3155
|
+
/**
|
3156
|
+
The element schema of the array that the model should generate.
|
3157
|
+
*/
|
3158
|
+
schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
|
3159
|
+
/**
|
3160
|
+
Optional name of the array that should be generated.
|
3161
|
+
Used by some providers for additional LLM guidance, e.g.
|
3162
|
+
via tool or schema name.
|
3163
|
+
*/
|
3164
|
+
schemaName?: string;
|
3165
|
+
/**
|
3166
|
+
Optional description of the array that should be generated.
|
3167
|
+
Used by some providers for additional LLM guidance, e.g.
|
3168
|
+
via tool or schema description.
|
3169
|
+
*/
|
3170
|
+
schemaDescription?: string;
|
3171
|
+
/**
|
3172
|
+
The mode to use for object generation.
|
3001
3173
|
|
3002
|
-
|
3003
|
-
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
3004
|
-
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
3174
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
3005
3175
|
|
3006
|
-
|
3007
|
-
|
3008
|
-
The
|
3009
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
3010
|
-
@param topP - Nucleus sampling.
|
3011
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3012
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
3013
|
-
@param topK - Only sample from the top K options for each subsequent token.
|
3014
|
-
Used to remove "long tail" low probability responses.
|
3015
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
3016
|
-
@param presencePenalty - Presence penalty setting.
|
3017
|
-
It affects the likelihood of the model to repeat information that is already in the prompt.
|
3018
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3019
|
-
@param frequencyPenalty - Frequency penalty setting.
|
3020
|
-
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
3021
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3022
|
-
@param stopSequences - Stop sequences.
|
3023
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
3024
|
-
@param seed - The seed (integer) to use for random sampling.
|
3025
|
-
If set and supported by the model, calls will generate deterministic results.
|
3176
|
+
- 'auto': The provider will choose the best mode for the model.
|
3177
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3178
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3026
3179
|
|
3027
|
-
|
3028
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3029
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3180
|
+
Please note that most providers do not support all modes.
|
3030
3181
|
|
3031
|
-
|
3032
|
-
|
3182
|
+
Default and recommended: 'auto' (best mode for the model).
|
3183
|
+
*/
|
3184
|
+
mode?: 'auto' | 'json' | 'tool';
|
3185
|
+
/**
|
3186
|
+
A function that attempts to repair the raw output of the mode
|
3187
|
+
to enable JSON parsing.
|
3188
|
+
*/
|
3189
|
+
experimental_repairText?: RepairTextFunction;
|
3190
|
+
/**
|
3191
|
+
Optional telemetry configuration (experimental).
|
3192
|
+
*/
|
3193
|
+
experimental_telemetry?: TelemetrySettings;
|
3194
|
+
/**
|
3195
|
+
Additional provider-specific options. They are passed through
|
3196
|
+
to the provider from the AI SDK and enable provider-specific
|
3197
|
+
functionality that can be fully encapsulated in the provider.
|
3198
|
+
*/
|
3199
|
+
providerOptions?: ProviderOptions;
|
3200
|
+
/**
|
3201
|
+
@deprecated Use `providerOptions` instead.
|
3202
|
+
*/
|
3203
|
+
experimental_providerMetadata?: ProviderMetadata;
|
3204
|
+
/**
|
3205
|
+
* Internal. For test use only. May change without notice.
|
3206
|
+
*/
|
3207
|
+
_internal?: {
|
3208
|
+
generateId?: () => string;
|
3209
|
+
currentDate?: () => Date;
|
3210
|
+
};
|
3211
|
+
}): Promise<GenerateObjectResult<Array<ELEMENT>>>;
|
3212
|
+
/**
|
3213
|
+
Generate a value from an enum (limited list of string values) using a language model.
|
3033
3214
|
|
3034
|
-
|
3215
|
+
This function does not stream the output.
|
3035
3216
|
|
3036
|
-
@
|
3037
|
-
A result object that contains the generated
|
3217
|
+
@return
|
3218
|
+
A result object that contains the generated value, the finish reason, the token usage, and additional information.
|
3038
3219
|
*/
|
3039
|
-
declare function
|
3220
|
+
declare function generateObject<ENUM extends string>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3221
|
+
output: 'enum';
|
3040
3222
|
/**
|
3041
3223
|
The language model to use.
|
3042
|
-
|
3224
|
+
*/
|
3043
3225
|
model: LanguageModel;
|
3044
3226
|
/**
|
3045
|
-
The
|
3046
|
-
*/
|
3047
|
-
|
3048
|
-
/**
|
3049
|
-
The tool choice strategy. Default: 'auto'.
|
3050
|
-
*/
|
3051
|
-
toolChoice?: ToolChoice<TOOLS>;
|
3227
|
+
The enum values that the model should use.
|
3228
|
+
*/
|
3229
|
+
enum: Array<ENUM>;
|
3052
3230
|
/**
|
3053
|
-
|
3231
|
+
The mode to use for object generation.
|
3054
3232
|
|
3055
|
-
|
3233
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
3056
3234
|
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
/**
|
3061
|
-
Generate a unique ID for each message.
|
3062
|
-
*/
|
3063
|
-
experimental_generateMessageId?: IDGenerator;
|
3064
|
-
/**
|
3065
|
-
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3235
|
+
- 'auto': The provider will choose the best mode for the model.
|
3236
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3237
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3066
3238
|
|
3067
|
-
|
3068
|
-
|
3069
|
-
|
3239
|
+
Please note that most providers do not support all modes.
|
3240
|
+
|
3241
|
+
Default and recommended: 'auto' (best mode for the model).
|
3242
|
+
*/
|
3243
|
+
mode?: 'auto' | 'json' | 'tool';
|
3244
|
+
/**
|
3245
|
+
A function that attempts to repair the raw output of the mode
|
3246
|
+
to enable JSON parsing.
|
3247
|
+
*/
|
3248
|
+
experimental_repairText?: RepairTextFunction;
|
3070
3249
|
/**
|
3071
3250
|
Optional telemetry configuration (experimental).
|
3072
|
-
|
3251
|
+
*/
|
3073
3252
|
experimental_telemetry?: TelemetrySettings;
|
3074
3253
|
/**
|
3075
3254
|
Additional provider-specific options. They are passed through
|
3076
3255
|
to the provider from the AI SDK and enable provider-specific
|
3077
3256
|
functionality that can be fully encapsulated in the provider.
|
3078
|
-
|
3257
|
+
*/
|
3079
3258
|
providerOptions?: ProviderOptions;
|
3080
3259
|
/**
|
3081
3260
|
@deprecated Use `providerOptions` instead.
|
3082
|
-
|
3261
|
+
*/
|
3083
3262
|
experimental_providerMetadata?: ProviderMetadata;
|
3084
3263
|
/**
|
3085
|
-
Limits the tools that are available for the model to call without
|
3086
|
-
changing the tool call and result types in the result.
|
3087
|
-
*/
|
3088
|
-
experimental_activeTools?: Array<keyof TOOLS>;
|
3089
|
-
/**
|
3090
|
-
Optional specification for parsing structured outputs from the LLM response.
|
3091
|
-
*/
|
3092
|
-
experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
|
3093
|
-
/**
|
3094
|
-
A function that attempts to repair a tool call that failed to parse.
|
3095
|
-
*/
|
3096
|
-
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
3097
|
-
/**
|
3098
|
-
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
3099
|
-
*/
|
3100
|
-
onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
|
3101
|
-
/**
|
3102
3264
|
* Internal. For test use only. May change without notice.
|
3103
3265
|
*/
|
3104
3266
|
_internal?: {
|
3105
|
-
generateId?:
|
3267
|
+
generateId?: () => string;
|
3106
3268
|
currentDate?: () => Date;
|
3107
3269
|
};
|
3108
|
-
}): Promise<
|
3109
|
-
|
3270
|
+
}): Promise<GenerateObjectResult<ENUM>>;
|
3110
3271
|
/**
|
3111
|
-
|
3112
|
-
*
|
3113
|
-
* @deprecated Please use `createDataStream`, `createDataStreamResponse`, and `pipeDataStreamToResponse` instead.
|
3114
|
-
*/
|
3115
|
-
declare class StreamData {
|
3116
|
-
private encoder;
|
3117
|
-
private controller;
|
3118
|
-
stream: ReadableStream<Uint8Array>;
|
3119
|
-
private isClosed;
|
3120
|
-
private warningTimeout;
|
3121
|
-
constructor();
|
3122
|
-
close(): Promise<void>;
|
3123
|
-
append(value: JSONValue$1): void;
|
3124
|
-
appendMessageAnnotation(value: JSONValue$1): void;
|
3125
|
-
}
|
3272
|
+
Generate JSON with any schema for a given prompt using a language model.
|
3126
3273
|
|
3127
|
-
|
3128
|
-
|
3129
|
-
|
3130
|
-
|
3131
|
-
*/
|
3132
|
-
sendUsage?: boolean;
|
3133
|
-
/**
|
3134
|
-
* Send reasoning parts to the client.
|
3135
|
-
* Default to false.
|
3136
|
-
*/
|
3137
|
-
sendReasoning?: boolean;
|
3138
|
-
/**
|
3139
|
-
* Send source parts to the client.
|
3140
|
-
* Default to false.
|
3141
|
-
*/
|
3142
|
-
sendSources?: boolean;
|
3143
|
-
/**
|
3144
|
-
* Send the finish event to the client.
|
3145
|
-
* Set to false if you are using additional streamText calls
|
3146
|
-
* that send additional data.
|
3147
|
-
* Default to true.
|
3148
|
-
*/
|
3149
|
-
experimental_sendFinish?: boolean;
|
3150
|
-
/**
|
3151
|
-
* Send the message start event to the client.
|
3152
|
-
* Set to false if you are using additional streamText calls
|
3153
|
-
* and the message start event has already been sent.
|
3154
|
-
* Default to true.
|
3155
|
-
*
|
3156
|
-
* Note: this setting is currently not used, but you should
|
3157
|
-
* already set it to false if you are using additional
|
3158
|
-
* streamText calls that send additional data to prevent
|
3159
|
-
* the message start event from being sent multiple times.
|
3160
|
-
*/
|
3161
|
-
experimental_sendStart?: boolean;
|
3162
|
-
};
|
3163
|
-
/**
|
3164
|
-
A result object for accessing different stream types and additional information.
|
3274
|
+
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
3275
|
+
|
3276
|
+
@returns
|
3277
|
+
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3165
3278
|
*/
|
3166
|
-
|
3167
|
-
|
3168
|
-
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
3169
|
-
*/
|
3170
|
-
readonly warnings: Promise<CallWarning[] | undefined>;
|
3171
|
-
/**
|
3172
|
-
The total token usage of the generated response.
|
3173
|
-
When there are multiple steps, the usage is the sum of all step usages.
|
3174
|
-
|
3175
|
-
Resolved when the response is finished.
|
3176
|
-
*/
|
3177
|
-
readonly usage: Promise<LanguageModelUsage>;
|
3178
|
-
/**
|
3179
|
-
Sources that have been used as input to generate the response.
|
3180
|
-
For multi-step generation, the sources are accumulated from all steps.
|
3181
|
-
|
3182
|
-
Resolved when the response is finished.
|
3183
|
-
*/
|
3184
|
-
readonly sources: Promise<Source[]>;
|
3185
|
-
/**
|
3186
|
-
The reason why the generation finished. Taken from the last step.
|
3187
|
-
|
3188
|
-
Resolved when the response is finished.
|
3189
|
-
*/
|
3190
|
-
readonly finishReason: Promise<FinishReason>;
|
3191
|
-
/**
|
3192
|
-
Additional provider-specific metadata from the last step.
|
3193
|
-
Metadata is passed through from the provider to the AI SDK and
|
3194
|
-
enables provider-specific results that can be fully encapsulated in the provider.
|
3195
|
-
*/
|
3196
|
-
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
3279
|
+
declare function generateObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3280
|
+
output: 'no-schema';
|
3197
3281
|
/**
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3282
|
+
The language model to use.
|
3283
|
+
*/
|
3284
|
+
model: LanguageModel;
|
3201
3285
|
/**
|
3202
|
-
|
3203
|
-
|
3204
|
-
|
3205
|
-
*/
|
3206
|
-
readonly text: Promise<string>;
|
3286
|
+
The mode to use for object generation. Must be "json" for no-schema output.
|
3287
|
+
*/
|
3288
|
+
mode?: 'json';
|
3207
3289
|
/**
|
3208
|
-
|
3209
|
-
|
3210
|
-
|
3211
|
-
|
3212
|
-
readonly reasoning: Promise<string | undefined>;
|
3290
|
+
A function that attempts to repair the raw output of the mode
|
3291
|
+
to enable JSON parsing.
|
3292
|
+
*/
|
3293
|
+
experimental_repairText?: RepairTextFunction;
|
3213
3294
|
/**
|
3214
|
-
|
3215
|
-
|
3216
|
-
Resolved when the response is finished.
|
3295
|
+
Optional telemetry configuration (experimental).
|
3217
3296
|
*/
|
3218
|
-
|
3297
|
+
experimental_telemetry?: TelemetrySettings;
|
3219
3298
|
/**
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3223
|
-
|
3224
|
-
|
3299
|
+
Additional provider-specific options. They are passed through
|
3300
|
+
to the provider from the AI SDK and enable provider-specific
|
3301
|
+
functionality that can be fully encapsulated in the provider.
|
3302
|
+
*/
|
3303
|
+
providerOptions?: ProviderOptions;
|
3225
3304
|
/**
|
3226
|
-
|
3227
|
-
|
3228
|
-
|
3229
|
-
*/
|
3230
|
-
readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
|
3305
|
+
@deprecated Use `providerOptions` instead.
|
3306
|
+
*/
|
3307
|
+
experimental_providerMetadata?: ProviderMetadata;
|
3231
3308
|
/**
|
3232
|
-
|
3233
|
-
You can use this to get information about intermediate steps,
|
3234
|
-
such as the tool calls or the response headers.
|
3309
|
+
* Internal. For test use only. May change without notice.
|
3235
3310
|
*/
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3245
|
-
|
3246
|
-
The response messages that were generated during the call. It consists of an assistant message,
|
3247
|
-
potentially containing tool calls.
|
3248
|
-
|
3249
|
-
When there are tool results, there is an additional tool message with the tool results that are available.
|
3250
|
-
If there are tools that do not have execute functions, they are not included in the tool results and
|
3251
|
-
need to be added separately.
|
3252
|
-
*/
|
3253
|
-
messages: Array<ResponseMessage>;
|
3254
|
-
}>;
|
3311
|
+
_internal?: {
|
3312
|
+
generateId?: () => string;
|
3313
|
+
currentDate?: () => Date;
|
3314
|
+
};
|
3315
|
+
}): Promise<GenerateObjectResult<JSONValue>>;
|
3316
|
+
|
3317
|
+
/**
|
3318
|
+
The result of a `streamObject` call that contains the partial object stream and additional information.
|
3319
|
+
*/
|
3320
|
+
interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
3255
3321
|
/**
|
3256
|
-
|
3257
|
-
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
3258
|
-
stream will throw the error.
|
3322
|
+
Warnings from the model provider (e.g. unsupported settings)
|
3259
3323
|
*/
|
3260
|
-
readonly
|
3324
|
+
readonly warnings: Promise<CallWarning[] | undefined>;
|
3261
3325
|
/**
|
3262
|
-
|
3263
|
-
errors.
|
3264
|
-
You can use it as either an AsyncIterable or a ReadableStream.
|
3265
|
-
Only errors that stop the stream, such as network errors, are thrown.
|
3326
|
+
The token usage of the generated response. Resolved when the response is finished.
|
3266
3327
|
*/
|
3267
|
-
readonly
|
3328
|
+
readonly usage: Promise<LanguageModelUsage>;
|
3268
3329
|
/**
|
3269
|
-
|
3330
|
+
Additional provider-specific metadata. They are passed through
|
3331
|
+
from the provider to the AI SDK and enable provider-specific
|
3332
|
+
results that can be fully encapsulated in the provider.
|
3270
3333
|
*/
|
3271
|
-
readonly
|
3334
|
+
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
3272
3335
|
/**
|
3273
|
-
|
3274
|
-
|
3275
|
-
|
3276
|
-
triggering the `onFinish` callback and the promise resolution.
|
3277
|
-
*/
|
3278
|
-
consumeStream(): Promise<void>;
|
3336
|
+
@deprecated Use `providerMetadata` instead.
|
3337
|
+
*/
|
3338
|
+
readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
|
3279
3339
|
/**
|
3280
|
-
|
3340
|
+
Additional request information from the last step.
|
3341
|
+
*/
|
3342
|
+
readonly request: Promise<LanguageModelRequestMetadata>;
|
3343
|
+
/**
|
3344
|
+
Additional response information.
|
3345
|
+
*/
|
3346
|
+
readonly response: Promise<LanguageModelResponseMetadata>;
|
3347
|
+
/**
|
3348
|
+
The generated object (typed according to the schema). Resolved when the response is finished.
|
3349
|
+
*/
|
3350
|
+
readonly object: Promise<RESULT>;
|
3351
|
+
/**
|
3352
|
+
Stream of partial objects. It gets more complete as the stream progresses.
|
3281
3353
|
|
3282
|
-
|
3283
|
-
|
3284
|
-
@param sendUsage whether to send the usage information to the client. Defaults to true.
|
3285
|
-
@param sendReasoning whether to send the reasoning information to the client. Defaults to false.
|
3286
|
-
@return A data stream.
|
3354
|
+
Note that the partial object is not validated.
|
3355
|
+
If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
|
3287
3356
|
*/
|
3288
|
-
|
3289
|
-
data?: StreamData;
|
3290
|
-
getErrorMessage?: (error: unknown) => string;
|
3291
|
-
} & DataStreamOptions): ReadableStream<Uint8Array>;
|
3357
|
+
readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
|
3292
3358
|
/**
|
3293
|
-
*
|
3294
|
-
*
|
3295
|
-
* @param dataStream A data stream writer.
|
3296
|
-
* @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3297
|
-
* @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3359
|
+
* Stream over complete array elements. Only available if the output strategy is set to `array`.
|
3298
3360
|
*/
|
3299
|
-
|
3361
|
+
readonly elementStream: ELEMENT_STREAM;
|
3300
3362
|
/**
|
3301
|
-
|
3302
|
-
|
3303
|
-
@param response A Node.js response-like object (ServerResponse).
|
3304
|
-
@param options.status The status code.
|
3305
|
-
@param options.statusText The status text.
|
3306
|
-
@param options.headers The headers.
|
3307
|
-
@param options.data The stream data.
|
3308
|
-
@param options.getErrorMessage An optional function that converts an error to an error message.
|
3309
|
-
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3310
|
-
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3363
|
+
Text stream of the JSON representation of the generated object. It contains text chunks.
|
3364
|
+
When the stream is finished, the object is valid JSON that can be parsed.
|
3311
3365
|
*/
|
3312
|
-
|
3313
|
-
|
3314
|
-
|
3315
|
-
|
3366
|
+
readonly textStream: AsyncIterableStream<string>;
|
3367
|
+
/**
|
3368
|
+
Stream of different types of events, including partial objects, errors, and finish events.
|
3369
|
+
Only errors that stop the stream, such as network errors, are thrown.
|
3370
|
+
*/
|
3371
|
+
readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
|
3316
3372
|
/**
|
3317
3373
|
Writes text delta output to a Node.js response-like object.
|
3318
3374
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
@@ -3321,27 +3377,10 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3321
3377
|
@param response A Node.js response-like object (ServerResponse).
|
3322
3378
|
@param init Optional headers, status code, and status text.
|
3323
3379
|
*/
|
3324
|
-
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
3325
|
-
/**
|
3326
|
-
Converts the result to a streamed response object with a stream data part stream.
|
3327
|
-
It can be used with the `useChat` and `useCompletion` hooks.
|
3328
|
-
|
3329
|
-
@param options.status The status code.
|
3330
|
-
@param options.statusText The status text.
|
3331
|
-
@param options.headers The headers.
|
3332
|
-
@param options.data The stream data.
|
3333
|
-
@param options.getErrorMessage An optional function that converts an error to an error message.
|
3334
|
-
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3335
|
-
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3336
|
-
|
3337
|
-
@return A response object.
|
3338
|
-
*/
|
3339
|
-
toDataStreamResponse(options?: ResponseInit & {
|
3340
|
-
data?: StreamData;
|
3341
|
-
getErrorMessage?: (error: unknown) => string;
|
3342
|
-
} & DataStreamOptions): Response;
|
3380
|
+
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
|
3343
3381
|
/**
|
3344
3382
|
Creates a simple text stream response.
|
3383
|
+
The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
|
3345
3384
|
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
3346
3385
|
Non-text-delta events are ignored.
|
3347
3386
|
|
@@ -3349,294 +3388,274 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3349
3388
|
*/
|
3350
3389
|
toTextStreamResponse(init?: ResponseInit): Response;
|
3351
3390
|
}
|
3352
|
-
type
|
3353
|
-
type: '
|
3354
|
-
|
3391
|
+
type ObjectStreamPart<PARTIAL> = {
|
3392
|
+
type: 'object';
|
3393
|
+
object: PARTIAL;
|
3355
3394
|
} | {
|
3356
|
-
type: '
|
3395
|
+
type: 'text-delta';
|
3357
3396
|
textDelta: string;
|
3358
3397
|
} | {
|
3359
|
-
type: '
|
3360
|
-
|
3361
|
-
} | {
|
3362
|
-
type: 'redacted-reasoning';
|
3363
|
-
data: string;
|
3364
|
-
} | {
|
3365
|
-
type: 'source';
|
3366
|
-
source: Source;
|
3367
|
-
} | ({
|
3368
|
-
type: 'tool-call';
|
3369
|
-
} & ToolCallUnion<TOOLS>) | {
|
3370
|
-
type: 'tool-call-streaming-start';
|
3371
|
-
toolCallId: string;
|
3372
|
-
toolName: string;
|
3373
|
-
} | {
|
3374
|
-
type: 'tool-call-delta';
|
3375
|
-
toolCallId: string;
|
3376
|
-
toolName: string;
|
3377
|
-
argsTextDelta: string;
|
3378
|
-
} | ({
|
3379
|
-
type: 'tool-result';
|
3380
|
-
} & ToolResultUnion<TOOLS>) | {
|
3381
|
-
type: 'step-start';
|
3382
|
-
messageId: string;
|
3383
|
-
request: LanguageModelRequestMetadata;
|
3384
|
-
warnings: CallWarning[];
|
3385
|
-
} | {
|
3386
|
-
type: 'step-finish';
|
3387
|
-
messageId: string;
|
3388
|
-
logprobs?: LogProbs;
|
3389
|
-
request: LanguageModelRequestMetadata;
|
3390
|
-
warnings: CallWarning[] | undefined;
|
3391
|
-
response: LanguageModelResponseMetadata;
|
3392
|
-
usage: LanguageModelUsage;
|
3393
|
-
finishReason: FinishReason;
|
3394
|
-
providerMetadata: ProviderMetadata | undefined;
|
3395
|
-
/**
|
3396
|
-
* @deprecated Use `providerMetadata` instead.
|
3397
|
-
*/
|
3398
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3399
|
-
isContinued: boolean;
|
3398
|
+
type: 'error';
|
3399
|
+
error: unknown;
|
3400
3400
|
} | {
|
3401
3401
|
type: 'finish';
|
3402
3402
|
finishReason: FinishReason;
|
3403
|
-
usage: LanguageModelUsage;
|
3404
|
-
providerMetadata: ProviderMetadata | undefined;
|
3405
|
-
/**
|
3406
|
-
* @deprecated Use `providerMetadata` instead.
|
3407
|
-
*/
|
3408
|
-
experimental_providerMetadata?: ProviderMetadata;
|
3409
|
-
/**
|
3410
|
-
* @deprecated will be moved into provider metadata
|
3411
|
-
*/
|
3412
3403
|
logprobs?: LogProbs;
|
3413
|
-
|
3414
|
-
* @deprecated use response on step-finish instead
|
3415
|
-
*/
|
3404
|
+
usage: LanguageModelUsage;
|
3416
3405
|
response: LanguageModelResponseMetadata;
|
3417
|
-
|
3418
|
-
type: 'error';
|
3419
|
-
error: unknown;
|
3406
|
+
providerMetadata?: ProviderMetadata;
|
3420
3407
|
};
|
3421
3408
|
|
3422
|
-
/**
|
3423
|
-
* Smooths text streaming output.
|
3424
|
-
*
|
3425
|
-
* @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
|
3426
|
-
* @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
|
3427
|
-
*
|
3428
|
-
* @returns A transform stream that smooths text streaming output.
|
3429
|
-
*/
|
3430
|
-
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
3431
|
-
delayInMs?: number | null;
|
3432
|
-
chunking?: 'word' | 'line' | RegExp;
|
3433
|
-
/**
|
3434
|
-
* Internal. For test use only. May change without notice.
|
3435
|
-
*/
|
3436
|
-
_internal?: {
|
3437
|
-
delay?: (delayInMs: number | null) => Promise<void>;
|
3438
|
-
};
|
3439
|
-
}): (options: {
|
3440
|
-
tools: TOOLS;
|
3441
|
-
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
3442
|
-
|
3443
|
-
/**
|
3444
|
-
A transformation that is applied to the stream.
|
3445
|
-
|
3446
|
-
@param stopStream - A function that stops the source stream.
|
3447
|
-
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
3448
|
-
*/
|
3449
|
-
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
3450
|
-
tools: TOOLS;
|
3451
|
-
stopStream: () => void;
|
3452
|
-
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
3453
3409
|
/**
|
3454
3410
|
Callback that is set using the `onError` option.
|
3455
3411
|
|
3456
3412
|
@param event - The event that is passed to the callback.
|
3457
3413
|
*/
|
3458
|
-
type
|
3414
|
+
type StreamObjectOnErrorCallback = (event: {
|
3459
3415
|
error: unknown;
|
3460
3416
|
}) => Promise<void> | void;
|
3461
3417
|
/**
|
3462
|
-
Callback that is set using the `
|
3463
|
-
|
3464
|
-
@param stepResult - The result of the step.
|
3465
|
-
*/
|
3466
|
-
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
3467
|
-
/**
|
3468
|
-
Callback that is set using the `onChunk` option.
|
3418
|
+
Callback that is set using the `onFinish` option.
|
3469
3419
|
|
3470
3420
|
@param event - The event that is passed to the callback.
|
3471
3421
|
*/
|
3472
|
-
type
|
3473
|
-
|
3474
|
-
|
3475
|
-
|
3422
|
+
type StreamObjectOnFinishCallback<RESULT> = (event: {
|
3423
|
+
/**
|
3424
|
+
The token usage of the generated response.
|
3425
|
+
*/
|
3426
|
+
usage: LanguageModelUsage;
|
3427
|
+
/**
|
3428
|
+
The generated object. Can be undefined if the final object does not match the schema.
|
3429
|
+
*/
|
3430
|
+
object: RESULT | undefined;
|
3431
|
+
/**
|
3432
|
+
Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
|
3433
|
+
*/
|
3434
|
+
error: unknown | undefined;
|
3435
|
+
/**
|
3436
|
+
Response metadata.
|
3437
|
+
*/
|
3438
|
+
response: LanguageModelResponseMetadata;
|
3439
|
+
/**
|
3440
|
+
Warnings from the model provider (e.g. unsupported settings).
|
3441
|
+
*/
|
3442
|
+
warnings?: CallWarning[];
|
3443
|
+
/**
|
3444
|
+
Additional provider-specific metadata. They are passed through
|
3445
|
+
to the provider from the AI SDK and enable provider-specific
|
3446
|
+
functionality that can be fully encapsulated in the provider.
|
3447
|
+
*/
|
3448
|
+
providerMetadata: ProviderMetadata | undefined;
|
3449
|
+
/**
|
3450
|
+
@deprecated Use `providerMetadata` instead.
|
3451
|
+
*/
|
3452
|
+
experimental_providerMetadata?: ProviderMetadata;
|
3476
3453
|
}) => Promise<void> | void;
|
3477
3454
|
/**
|
3478
|
-
|
3455
|
+
Generate a structured, typed object for a given prompt and schema using a language model.
|
3479
3456
|
|
3480
|
-
|
3457
|
+
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
3458
|
+
|
3459
|
+
@return
|
3460
|
+
A result object for accessing the partial object stream and additional information.
|
3481
3461
|
*/
|
3482
|
-
|
3462
|
+
declare function streamObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3463
|
+
output?: 'object' | undefined;
|
3464
|
+
/**
|
3465
|
+
The language model to use.
|
3466
|
+
*/
|
3467
|
+
model: LanguageModel;
|
3483
3468
|
/**
|
3484
|
-
|
3469
|
+
The schema of the object that the model should generate.
|
3470
|
+
*/
|
3471
|
+
schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
|
3472
|
+
/**
|
3473
|
+
Optional name of the output that should be generated.
|
3474
|
+
Used by some providers for additional LLM guidance, e.g.
|
3475
|
+
via tool or schema name.
|
3485
3476
|
*/
|
3486
|
-
|
3487
|
-
|
3488
|
-
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3477
|
+
schemaName?: string;
|
3478
|
+
/**
|
3479
|
+
Optional description of the output that should be generated.
|
3480
|
+
Used by some providers for additional LLM guidance, e.g.
|
3481
|
+
via tool or schema description.
|
3482
|
+
*/
|
3483
|
+
schemaDescription?: string;
|
3484
|
+
/**
|
3485
|
+
The mode to use for object generation.
|
3495
3486
|
|
3496
|
-
|
3497
|
-
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
3498
|
-
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
3487
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
3499
3488
|
|
3500
|
-
|
3501
|
-
|
3502
|
-
The
|
3503
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
3504
|
-
@param topP - Nucleus sampling.
|
3505
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3506
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
3507
|
-
@param topK - Only sample from the top K options for each subsequent token.
|
3508
|
-
Used to remove "long tail" low probability responses.
|
3509
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
3510
|
-
@param presencePenalty - Presence penalty setting.
|
3511
|
-
It affects the likelihood of the model to repeat information that is already in the prompt.
|
3512
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3513
|
-
@param frequencyPenalty - Frequency penalty setting.
|
3514
|
-
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
3515
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3516
|
-
@param stopSequences - Stop sequences.
|
3517
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
3518
|
-
@param seed - The seed (integer) to use for random sampling.
|
3519
|
-
If set and supported by the model, calls will generate deterministic results.
|
3489
|
+
- 'auto': The provider will choose the best mode for the model.
|
3490
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3491
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3520
3492
|
|
3521
|
-
|
3522
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3523
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3493
|
+
Please note that most providers do not support all modes.
|
3524
3494
|
|
3525
|
-
|
3526
|
-
|
3495
|
+
Default and recommended: 'auto' (best mode for the model).
|
3496
|
+
*/
|
3497
|
+
mode?: 'auto' | 'json' | 'tool';
|
3498
|
+
/**
|
3499
|
+
Optional telemetry configuration (experimental).
|
3500
|
+
*/
|
3501
|
+
experimental_telemetry?: TelemetrySettings;
|
3502
|
+
/**
|
3503
|
+
Additional provider-specific options. They are passed through
|
3504
|
+
to the provider from the AI SDK and enable provider-specific
|
3505
|
+
functionality that can be fully encapsulated in the provider.
|
3506
|
+
*/
|
3507
|
+
providerOptions?: ProviderOptions;
|
3508
|
+
/**
|
3509
|
+
@deprecated Use `providerOptions` instead.
|
3510
|
+
*/
|
3511
|
+
experimental_providerMetadata?: ProviderMetadata;
|
3512
|
+
/**
|
3513
|
+
Callback that is invoked when an error occurs during streaming.
|
3514
|
+
You can use it to log errors.
|
3515
|
+
The stream processing will pause until the callback promise is resolved.
|
3516
|
+
*/
|
3517
|
+
onError?: StreamObjectOnErrorCallback;
|
3518
|
+
/**
|
3519
|
+
Callback that is called when the LLM response and the final object validation are finished.
|
3520
|
+
*/
|
3521
|
+
onFinish?: StreamObjectOnFinishCallback<OBJECT>;
|
3522
|
+
/**
|
3523
|
+
* Internal. For test use only. May change without notice.
|
3524
|
+
*/
|
3525
|
+
_internal?: {
|
3526
|
+
generateId?: () => string;
|
3527
|
+
currentDate?: () => Date;
|
3528
|
+
now?: () => number;
|
3529
|
+
};
|
3530
|
+
}): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
|
3531
|
+
/**
|
3532
|
+
Generate an array with structured, typed elements for a given prompt and element schema using a language model.
|
3527
3533
|
|
3528
|
-
|
3529
|
-
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
3530
|
-
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
3531
|
-
@param onFinish - Callback that is called when the LLM response and all request tool executions
|
3532
|
-
(for tools that have an `execute` function) are finished.
|
3534
|
+
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
3533
3535
|
|
3534
3536
|
@return
|
3535
|
-
A result object for accessing
|
3537
|
+
A result object for accessing the partial object stream and additional information.
|
3536
3538
|
*/
|
3537
|
-
declare function
|
3539
|
+
declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3540
|
+
output: 'array';
|
3538
3541
|
/**
|
3539
3542
|
The language model to use.
|
3540
|
-
|
3543
|
+
*/
|
3541
3544
|
model: LanguageModel;
|
3542
3545
|
/**
|
3543
|
-
The
|
3544
|
-
|
3545
|
-
|
3546
|
+
The element schema of the array that the model should generate.
|
3547
|
+
*/
|
3548
|
+
schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
|
3546
3549
|
/**
|
3547
|
-
|
3548
|
-
|
3549
|
-
|
3550
|
+
Optional name of the array that should be generated.
|
3551
|
+
Used by some providers for additional LLM guidance, e.g.
|
3552
|
+
via tool or schema name.
|
3553
|
+
*/
|
3554
|
+
schemaName?: string;
|
3550
3555
|
/**
|
3551
|
-
|
3556
|
+
Optional description of the array that should be generated.
|
3557
|
+
Used by some providers for additional LLM guidance, e.g.
|
3558
|
+
via tool or schema description.
|
3559
|
+
*/
|
3560
|
+
schemaDescription?: string;
|
3561
|
+
/**
|
3562
|
+
The mode to use for object generation.
|
3552
3563
|
|
3553
|
-
|
3564
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
3554
3565
|
|
3555
|
-
|
3556
|
-
|
3557
|
-
|
3558
|
-
/**
|
3559
|
-
Generate a unique ID for each message.
|
3560
|
-
*/
|
3561
|
-
experimental_generateMessageId?: IDGenerator;
|
3562
|
-
/**
|
3563
|
-
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3566
|
+
- 'auto': The provider will choose the best mode for the model.
|
3567
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3568
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3564
3569
|
|
3565
|
-
|
3566
|
-
|
3567
|
-
|
3570
|
+
Please note that most providers do not support all modes.
|
3571
|
+
|
3572
|
+
Default and recommended: 'auto' (best mode for the model).
|
3573
|
+
*/
|
3574
|
+
mode?: 'auto' | 'json' | 'tool';
|
3568
3575
|
/**
|
3569
3576
|
Optional telemetry configuration (experimental).
|
3570
|
-
|
3577
|
+
*/
|
3571
3578
|
experimental_telemetry?: TelemetrySettings;
|
3572
3579
|
/**
|
3573
3580
|
Additional provider-specific options. They are passed through
|
3574
3581
|
to the provider from the AI SDK and enable provider-specific
|
3575
3582
|
functionality that can be fully encapsulated in the provider.
|
3576
|
-
|
3583
|
+
*/
|
3577
3584
|
providerOptions?: ProviderOptions;
|
3578
3585
|
/**
|
3579
3586
|
@deprecated Use `providerOptions` instead.
|
3580
|
-
|
3587
|
+
*/
|
3581
3588
|
experimental_providerMetadata?: ProviderMetadata;
|
3582
3589
|
/**
|
3583
|
-
|
3584
|
-
|
3585
|
-
|
3586
|
-
|
3590
|
+
Callback that is invoked when an error occurs during streaming.
|
3591
|
+
You can use it to log errors.
|
3592
|
+
The stream processing will pause until the callback promise is resolved.
|
3593
|
+
*/
|
3594
|
+
onError?: StreamObjectOnErrorCallback;
|
3587
3595
|
/**
|
3588
|
-
|
3589
|
-
|
3590
|
-
|
3596
|
+
Callback that is called when the LLM response and the final object validation are finished.
|
3597
|
+
*/
|
3598
|
+
onFinish?: StreamObjectOnFinishCallback<Array<ELEMENT>>;
|
3591
3599
|
/**
|
3592
|
-
|
3600
|
+
* Internal. For test use only. May change without notice.
|
3593
3601
|
*/
|
3594
|
-
|
3602
|
+
_internal?: {
|
3603
|
+
generateId?: () => string;
|
3604
|
+
currentDate?: () => Date;
|
3605
|
+
now?: () => number;
|
3606
|
+
};
|
3607
|
+
}): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
|
3608
|
+
/**
|
3609
|
+
Generate JSON with any schema for a given prompt using a language model.
|
3610
|
+
|
3611
|
+
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
3612
|
+
|
3613
|
+
@return
|
3614
|
+
A result object for accessing the partial object stream and additional information.
|
3615
|
+
*/
|
3616
|
+
declare function streamObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
3617
|
+
output: 'no-schema';
|
3595
3618
|
/**
|
3596
|
-
|
3597
|
-
|
3598
|
-
|
3619
|
+
The language model to use.
|
3620
|
+
*/
|
3621
|
+
model: LanguageModel;
|
3599
3622
|
/**
|
3600
|
-
|
3601
|
-
|
3602
|
-
|
3623
|
+
The mode to use for object generation. Must be "json" for no-schema output.
|
3624
|
+
*/
|
3625
|
+
mode?: 'json';
|
3603
3626
|
/**
|
3604
|
-
Optional
|
3605
|
-
|
3606
|
-
|
3607
|
-
*/
|
3608
|
-
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
3627
|
+
Optional telemetry configuration (experimental).
|
3628
|
+
*/
|
3629
|
+
experimental_telemetry?: TelemetrySettings;
|
3609
3630
|
/**
|
3610
|
-
|
3611
|
-
|
3612
|
-
|
3613
|
-
|
3631
|
+
Additional provider-specific options. They are passed through
|
3632
|
+
to the provider from the AI SDK and enable provider-specific
|
3633
|
+
functionality that can be fully encapsulated in the provider.
|
3634
|
+
*/
|
3635
|
+
providerOptions?: ProviderOptions;
|
3636
|
+
/**
|
3637
|
+
@deprecated Use `providerOptions` instead.
|
3638
|
+
*/
|
3639
|
+
experimental_providerMetadata?: ProviderMetadata;
|
3614
3640
|
/**
|
3615
3641
|
Callback that is invoked when an error occurs during streaming.
|
3616
3642
|
You can use it to log errors.
|
3617
3643
|
The stream processing will pause until the callback promise is resolved.
|
3618
|
-
|
3619
|
-
onError?:
|
3620
|
-
/**
|
3621
|
-
Callback that is called when the LLM response and all request tool executions
|
3622
|
-
(for tools that have an `execute` function) are finished.
|
3623
|
-
|
3624
|
-
The usage is the combined usage of all steps.
|
3625
|
-
*/
|
3626
|
-
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
3644
|
+
*/
|
3645
|
+
onError?: StreamObjectOnErrorCallback;
|
3627
3646
|
/**
|
3628
|
-
Callback that is called when
|
3629
|
-
|
3630
|
-
|
3647
|
+
Callback that is called when the LLM response and the final object validation are finished.
|
3648
|
+
*/
|
3649
|
+
onFinish?: StreamObjectOnFinishCallback<JSONValue>;
|
3631
3650
|
/**
|
3632
|
-
Internal. For test use only. May change without notice.
|
3651
|
+
* Internal. For test use only. May change without notice.
|
3633
3652
|
*/
|
3634
3653
|
_internal?: {
|
3635
|
-
|
3636
|
-
generateId?: IDGenerator;
|
3654
|
+
generateId?: () => string;
|
3637
3655
|
currentDate?: () => Date;
|
3656
|
+
now?: () => number;
|
3638
3657
|
};
|
3639
|
-
}):
|
3658
|
+
}): StreamObjectResult<JSONValue, JSONValue, never>;
|
3640
3659
|
|
3641
3660
|
/**
|
3642
3661
|
* Experimental middleware for LanguageModelV1.
|
@@ -3863,7 +3882,9 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
|
3863
3882
|
} | {
|
3864
3883
|
type: 'redacted-reasoning';
|
3865
3884
|
data: string;
|
3866
|
-
} | {
|
3885
|
+
} | ({
|
3886
|
+
type: 'file';
|
3887
|
+
} & GeneratedFile) | {
|
3867
3888
|
type: 'source';
|
3868
3889
|
source: Source;
|
3869
3890
|
} | ({
|
@@ -4215,4 +4236,4 @@ declare namespace llamaindexAdapter {
|
|
4215
4236
|
};
|
4216
4237
|
}
|
4217
4238
|
|
4218
|
-
export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolCallUnion, CoreToolChoice, CoreToolMessage, CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamOptions, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult,
|
4239
|
+
export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolCallUnion, CoreToolChoice, CoreToolMessage, CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamOptions, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LanguageModelV1Middleware, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Provider, ProviderMetadata, RepairTextFunction, RetryError, StepResult, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolResultPart, ToolResultUnion, ToolSet, UserContent, appendClientMessage, appendResponseMessages, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, experimental_wrapLanguageModel, extractReasoningMiddleware, generateObject, generateText, pipeDataStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, tool, wrapLanguageModel };
|