ai 5.0.0-canary.13 → 5.0.0-canary.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { ToolCall, ToolResult, FetchFunction, Validator, IDGenerator } from '@ai-sdk/provider-utils';
2
- export { IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
3
- import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, TranscriptionModelV1, TranscriptionModelV1CallWarning, SpeechModelV1, SpeechModelV1CallWarning, JSONValue as JSONValue$1, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7 as JSONSchema7$1, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
4
- export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
1
+ import { ToolCall, ToolResult, FetchFunction, Schema, IDGenerator } from '@ai-sdk/provider-utils';
2
+ export { IDGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
3
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
4
+ import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
5
+ export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
5
6
  import { ServerResponse } from 'node:http';
6
7
  import { AttributeValue, Tracer } from '@opentelemetry/api';
7
8
  import { z } from 'zod';
8
- import { JSONSchema7 } from 'json-schema';
9
9
  import { ServerResponse as ServerResponse$1 } from 'http';
10
10
 
11
11
  /**
@@ -42,6 +42,8 @@ type ImageModelResponseMetadata = {
42
42
  headers?: Record<string, string>;
43
43
  };
44
44
 
45
+ type JSONValue = JSONValue$1;
46
+
45
47
  /**
46
48
  Language model that is used by the AI SDK Core functions.
47
49
  */
@@ -159,36 +161,63 @@ provider-specific functionality that can be fully encapsulated in the provider.
159
161
  type ProviderOptions = SharedV2ProviderOptions;
160
162
 
161
163
  /**
162
- Represents the number of tokens used in a prompt and completion.
163
- */
164
- type LanguageModelUsage$1 = {
164
+ Speech model that is used by the AI SDK Core functions.
165
+ */
166
+ type SpeechModel = SpeechModelV1;
167
+ /**
168
+ Warning from the model provider for this call. The call will proceed, but e.g.
169
+ some settings might not be supported, which can lead to suboptimal results.
170
+ */
171
+ type SpeechWarning = SpeechModelV1CallWarning;
172
+
173
+ type SpeechModelResponseMetadata = {
165
174
  /**
166
- The number of tokens used in the prompt.
175
+ Timestamp for the start of the generated response.
167
176
  */
168
- promptTokens: number;
177
+ timestamp: Date;
169
178
  /**
170
- The number of tokens used in the completion.
171
- */
172
- completionTokens: number;
179
+ The ID of the response model that was used to generate the response.
180
+ */
181
+ modelId: string;
173
182
  /**
174
- The total number of tokens used (promptTokens + completionTokens).
183
+ Response headers.
175
184
  */
176
- totalTokens: number;
185
+ headers?: Record<string, string>;
186
+ /**
187
+ Response body.
188
+ */
189
+ body?: unknown;
177
190
  };
191
+
178
192
  /**
179
- Represents the number of tokens used in an embedding.
180
- */
181
- type EmbeddingModelUsage = {
193
+ Transcription model that is used by the AI SDK Core functions.
194
+ */
195
+ type TranscriptionModel = TranscriptionModelV1;
196
+ /**
197
+ Warning from the model provider for this call. The call will proceed, but e.g.
198
+ some settings might not be supported, which can lead to suboptimal results.
199
+ */
200
+ type TranscriptionWarning = TranscriptionModelV1CallWarning;
201
+
202
+ type TranscriptionModelResponseMetadata = {
182
203
  /**
183
- The number of tokens used in the embedding.
204
+ Timestamp for the start of the generated response.
184
205
  */
185
- tokens: number;
206
+ timestamp: Date;
207
+ /**
208
+ The ID of the response model that was used to generate the response.
209
+ */
210
+ modelId: string;
211
+ /**
212
+ Response headers.
213
+ */
214
+ headers?: Record<string, string>;
186
215
  };
187
216
 
188
217
  /**
189
218
  Represents the number of tokens used in a prompt and completion.
190
219
  */
191
- type LanguageModelUsage = {
220
+ type LanguageModelUsage$1 = {
192
221
  /**
193
222
  The number of tokens used in the prompt.
194
223
  */
@@ -258,12 +287,6 @@ interface Message {
258
287
  */
259
288
  content: string;
260
289
  /**
261
- Reasoning for the message.
262
-
263
- @deprecated Use `parts` instead.
264
- */
265
- reasoning?: string;
266
- /**
267
290
  * Additional attachments to be sent along with the message.
268
291
  */
269
292
  experimental_attachments?: Attachment[];
@@ -272,15 +295,9 @@ interface Message {
272
295
  */
273
296
  role: 'system' | 'user' | 'assistant' | 'data';
274
297
  /**
275
- For data messages.
276
-
277
- @deprecated Data messages will be removed.
278
- */
279
- data?: JSONValue;
280
- /**
281
298
  * Additional message-specific information added on the server via StreamData
282
299
  */
283
- annotations?: JSONValue[] | undefined;
300
+ annotations?: JSONValue$1[] | undefined;
284
301
  /**
285
302
  Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
286
303
  that the assistant made as part of this message.
@@ -390,7 +407,7 @@ type ChatRequest = {
390
407
  /**
391
408
  Additional data to be sent to the server.
392
409
  */
393
- data?: JSONValue;
410
+ data?: JSONValue$1;
394
411
  };
395
412
  type RequestOptions = {
396
413
  /**
@@ -414,7 +431,7 @@ type ChatRequestOptions = {
414
431
  /**
415
432
  Additional data to be sent to the API endpoint.
416
433
  */
417
- data?: JSONValue;
434
+ data?: JSONValue$1;
418
435
  /**
419
436
  * Additional files to be sent to the server.
420
437
  */
@@ -472,7 +489,7 @@ type UseChatOptions = {
472
489
  * @param options.finishReason The finish reason of the message.
473
490
  */
474
491
  onFinish?: (message: Message, options: {
475
- usage: LanguageModelUsage;
492
+ usage: LanguageModelUsage$1;
476
493
  finishReason: LanguageModelV2FinishReason;
477
494
  }) => void;
478
495
  /**
@@ -588,66 +605,32 @@ type UseCompletionOptions = {
588
605
  */
589
606
  fetch?: FetchFunction;
590
607
  };
591
- /**
592
- A JSON value can be a string, number, boolean, object, array, or null.
593
- JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
594
- */
595
- type JSONValue = null | string | number | boolean | {
596
- [value: string]: JSONValue;
597
- } | Array<JSONValue>;
598
608
 
599
609
  /**
600
- Transcription model that is used by the AI SDK Core functions.
601
- */
602
- type TranscriptionModel = TranscriptionModelV1;
603
- /**
604
- Warning from the model provider for this call. The call will proceed, but e.g.
605
- some settings might not be supported, which can lead to suboptimal results.
606
- */
607
- type TranscriptionWarning = TranscriptionModelV1CallWarning;
608
-
609
- type TranscriptionModelResponseMetadata = {
610
+ Represents the number of tokens used in a prompt and completion.
611
+ */
612
+ type LanguageModelUsage = {
610
613
  /**
611
- Timestamp for the start of the generated response.
614
+ The number of tokens used in the prompt.
612
615
  */
613
- timestamp: Date;
616
+ promptTokens: number;
614
617
  /**
615
- The ID of the response model that was used to generate the response.
616
- */
617
- modelId: string;
618
+ The number of tokens used in the completion.
619
+ */
620
+ completionTokens: number;
618
621
  /**
619
- Response headers.
622
+ The total number of tokens used (promptTokens + completionTokens).
620
623
  */
621
- headers?: Record<string, string>;
624
+ totalTokens: number;
622
625
  };
623
-
624
- /**
625
- Speech model that is used by the AI SDK Core functions.
626
- */
627
- type SpeechModel = SpeechModelV1;
628
626
  /**
629
- Warning from the model provider for this call. The call will proceed, but e.g.
630
- some settings might not be supported, which can lead to suboptimal results.
631
- */
632
- type SpeechWarning = SpeechModelV1CallWarning;
633
-
634
- type SpeechModelResponseMetadata = {
635
- /**
636
- Timestamp for the start of the generated response.
637
- */
638
- timestamp: Date;
639
- /**
640
- The ID of the response model that was used to generate the response.
641
- */
642
- modelId: string;
643
- /**
644
- Response headers.
645
- */
646
- headers?: Record<string, string>;
627
+ Represents the number of tokens used in an embedding.
628
+ */
629
+ type EmbeddingModelUsage = {
647
630
  /**
648
- Response body.
631
+ The number of tokens used in the embedding.
649
632
  */
650
- body?: unknown;
633
+ tokens: number;
651
634
  };
652
635
 
653
636
  declare const getOriginalFetch$1: () => typeof fetch;
@@ -662,7 +645,7 @@ declare function callChatApi({ api, body, streamProtocol, credentials, headers,
662
645
  onResponse: ((response: Response) => void | Promise<void>) | undefined;
663
646
  onUpdate: (options: {
664
647
  message: UIMessage;
665
- data: JSONValue[] | undefined;
648
+ data: JSONValue$1[] | undefined;
666
649
  replaceLastMessage: boolean;
667
650
  }) => void;
668
651
  onFinish: UseChatOptions['onFinish'];
@@ -700,7 +683,7 @@ interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
700
683
  value: TYPE;
701
684
  };
702
685
  }
703
- declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "args" | "toolName">>, DataStreamPart<"b", "tool_call_streaming_start", {
686
+ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "args" | "toolName">>, DataStreamPart<"b", "tool_call_streaming_start", {
704
687
  toolCallId: string;
705
688
  toolName: string;
706
689
  }>, DataStreamPart<"c", "tool_call_delta", {
@@ -874,39 +857,19 @@ declare function processTextStream({ stream, onTextPart, }: {
874
857
  }): Promise<void>;
875
858
 
876
859
  /**
877
- * Used to mark schemas so we can support both Zod and custom schemas.
878
- */
879
- declare const schemaSymbol: unique symbol;
880
- type Schema<OBJECT = unknown> = Validator<OBJECT> & {
881
- /**
882
- * Used to mark schemas so we can support both Zod and custom schemas.
883
- */
884
- [schemaSymbol]: true;
885
- /**
886
- * Schema type for inference.
887
- */
888
- _type: OBJECT;
889
- /**
890
- * The JSON Schema for the schema. It is passed to the providers.
891
- */
892
- readonly jsonSchema: JSONSchema7;
893
- };
894
- /**
895
- * Create a schema using a JSON Schema.
860
+ * Updates the result of a specific tool invocation in the last message of the given messages array.
896
861
  *
897
- * @param jsonSchema The JSON Schema for the schema.
898
- * @param options.validate Optional. A validation function for the schema.
862
+ * @param {object} params - The parameters object.
863
+ * @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
864
+ * @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
865
+ * @param {unknown} params.toolResult - The result object to attach to the tool invocation.
866
+ * @returns {void} This function does not return anything.
899
867
  */
900
- declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
901
- validate?: (value: unknown) => {
902
- success: true;
903
- value: OBJECT;
904
- } | {
905
- success: false;
906
- error: Error;
907
- };
908
- }): Schema<OBJECT>;
909
- declare function asSchema<OBJECT>(schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT> | undefined): Schema<OBJECT>;
868
+ declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
869
+ messages: UIMessage[];
870
+ toolCallId: string;
871
+ toolResult: unknown;
872
+ }): void;
910
873
 
911
874
  declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
912
875
  originalMaxToolInvocationStep: number | undefined;
@@ -923,31 +886,6 @@ declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): m
923
886
  role: 'assistant';
924
887
  };
925
888
 
926
- /**
927
- * Updates the result of a specific tool invocation in the last message of the given messages array.
928
- *
929
- * @param {object} params - The parameters object.
930
- * @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
931
- * @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
932
- * @param {unknown} params.toolResult - The result object to attach to the tool invocation.
933
- * @returns {void} This function does not return anything.
934
- */
935
- declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
936
- messages: UIMessage[];
937
- toolCallId: string;
938
- toolResult: unknown;
939
- }): void;
940
-
941
- declare function zodSchema<OBJECT>(zodSchema: z.Schema<OBJECT, z.ZodTypeDef, any>, options?: {
942
- /**
943
- * Enables support for references in the schema.
944
- * This is required for recursive schemas, e.g. with `z.lazy`.
945
- * However, not all language models and providers support such references.
946
- * Defaults to `false`.
947
- */
948
- useReferences?: boolean;
949
- }): Schema<OBJECT>;
950
-
951
889
  interface DataStreamWriter {
952
890
  /**
953
891
  * Appends a data part to the stream.
@@ -2792,7 +2730,7 @@ type StepResult<TOOLS extends ToolSet> = {
2792
2730
  /**
2793
2731
  The token usage of the generated text.
2794
2732
  */
2795
- readonly usage: LanguageModelUsage$1;
2733
+ readonly usage: LanguageModelUsage;
2796
2734
  /**
2797
2735
  Warnings from the model provider (e.g. unsupported settings).
2798
2736
  */
@@ -2880,7 +2818,7 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2880
2818
  /**
2881
2819
  The token usage of the generated text.
2882
2820
  */
2883
- readonly usage: LanguageModelUsage$1;
2821
+ readonly usage: LanguageModelUsage;
2884
2822
  /**
2885
2823
  Warnings from the model provider (e.g. unsupported settings)
2886
2824
  */
@@ -2933,7 +2871,7 @@ interface Output$1<OUTPUT, PARTIAL> {
2933
2871
  text: string;
2934
2872
  }, context: {
2935
2873
  response: LanguageModelResponseMetadata;
2936
- usage: LanguageModelUsage$1;
2874
+ usage: LanguageModelUsage;
2937
2875
  finishReason: FinishReason;
2938
2876
  }): Promise<OUTPUT>;
2939
2877
  }
@@ -3035,7 +2973,7 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
3035
2973
  tools: TOOLS;
3036
2974
  parameterSchema: (options: {
3037
2975
  toolName: string;
3038
- }) => JSONSchema7$1;
2976
+ }) => JSONSchema7;
3039
2977
  error: NoSuchToolError | InvalidToolArgumentsError;
3040
2978
  }) => Promise<LanguageModelV2ToolCall | null>;
3041
2979
 
@@ -3092,7 +3030,7 @@ If set and supported by the model, calls will generate deterministic results.
3092
3030
  @returns
3093
3031
  A result object that contains the generated text, the results of the tool calls, and additional information.
3094
3032
  */
3095
- 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, providerOptions, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
3033
+ 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, providerOptions, experimental_activeTools: activeTools, experimental_prepareStep: prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
3096
3034
  /**
3097
3035
  The language model to use.
3098
3036
  */
@@ -3143,6 +3081,28 @@ Optional specification for parsing structured outputs from the LLM response.
3143
3081
  */
3144
3082
  experimental_output?: Output$1<OUTPUT, OUTPUT_PARTIAL>;
3145
3083
  /**
3084
+ Optional function that you can use to provide different settings for a step.
3085
+
3086
+ @param options - The options for the step.
3087
+ @param options.steps - The steps that have been executed so far.
3088
+ @param options.stepNumber - The number of the step that is being executed.
3089
+ @param options.maxSteps - The maximum number of steps.
3090
+ @param options.model - The model that is being used.
3091
+
3092
+ @returns An object that contains the settings for the step.
3093
+ If you return undefined (or for undefined settings), the settings from the outer level will be used.
3094
+ */
3095
+ experimental_prepareStep?: (options: {
3096
+ steps: Array<StepResult<TOOLS>>;
3097
+ stepNumber: number;
3098
+ maxSteps: number;
3099
+ model: LanguageModel;
3100
+ }) => PromiseLike<{
3101
+ model?: LanguageModel;
3102
+ toolChoice?: ToolChoice<TOOLS>;
3103
+ experimental_activeTools?: Array<keyof TOOLS>;
3104
+ } | undefined>;
3105
+ /**
3146
3106
  A function that attempts to repair a tool call that failed to parse.
3147
3107
  */
3148
3108
  experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
@@ -3231,7 +3191,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3231
3191
 
3232
3192
  Resolved when the response is finished.
3233
3193
  */
3234
- readonly usage: Promise<LanguageModelUsage$1>;
3194
+ readonly usage: Promise<LanguageModelUsage>;
3235
3195
  /**
3236
3196
  Sources that have been used as input to generate the response.
3237
3197
  For multi-step generation, the sources are accumulated from all steps.
@@ -3448,14 +3408,14 @@ type TextStreamPart<TOOLS extends ToolSet> = {
3448
3408
  request: LanguageModelRequestMetadata;
3449
3409
  warnings: CallWarning[] | undefined;
3450
3410
  response: LanguageModelResponseMetadata;
3451
- usage: LanguageModelUsage$1;
3411
+ usage: LanguageModelUsage;
3452
3412
  finishReason: FinishReason;
3453
3413
  providerMetadata: ProviderMetadata | undefined;
3454
3414
  isContinued: boolean;
3455
3415
  } | {
3456
3416
  type: 'finish';
3457
3417
  finishReason: FinishReason;
3458
- usage: LanguageModelUsage$1;
3418
+ usage: LanguageModelUsage;
3459
3419
  providerMetadata: ProviderMetadata | undefined;
3460
3420
  /**
3461
3421
  * @deprecated use response on step-finish instead
@@ -3768,7 +3728,7 @@ declare function generateImage({ model, prompt, n, size, aspectRatio, seed, prov
3768
3728
  }
3769
3729
  ```
3770
3730
  */
3771
- providerOptions?: Record<string, Record<string, JSONValue$1>>;
3731
+ providerOptions?: ProviderOptions;
3772
3732
  /**
3773
3733
  Maximum number of retries per embedding model call. Set to 0 to disable retries.
3774
3734
 
@@ -3801,7 +3761,7 @@ interface GenerateObjectResult<OBJECT> {
3801
3761
  /**
3802
3762
  The token usage of the generated text.
3803
3763
  */
3804
- readonly usage: LanguageModelUsage$1;
3764
+ readonly usage: LanguageModelUsage;
3805
3765
  /**
3806
3766
  Warnings from the model provider (e.g. unsupported settings).
3807
3767
  */
@@ -3850,11 +3810,11 @@ This function does not stream the output. If you want to stream the output, use
3850
3810
  @returns
3851
3811
  A result object that contains the generated object, the finish reason, the token usage, and additional information.
3852
3812
  */
3853
- declare function generateObject<TYPE extends SCHEMA extends z.Schema ? Output extends 'array' ? Array<z.infer<SCHEMA>> : z.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? Output extends 'array' ? Array<T> : T : never, SCHEMA extends z.Schema | Schema = z.Schema<JSONValue$1>, Output extends 'object' | 'array' | 'enum' | 'no-schema' = TYPE extends string ? 'enum' : 'object'>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (Output extends 'enum' ? {
3813
+ declare function generateObject<RESULT extends SCHEMA extends z.Schema ? Output extends 'array' ? Array<z.infer<SCHEMA>> : z.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? Output extends 'array' ? Array<T> : T : never, SCHEMA extends z.Schema | Schema = z.Schema<JSONValue$1>, Output extends 'object' | 'array' | 'enum' | 'no-schema' = RESULT extends string ? 'enum' : 'object'>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (Output extends 'enum' ? {
3854
3814
  /**
3855
3815
  The enum values that the model should use.
3856
3816
  */
3857
- enum: Array<TYPE>;
3817
+ enum: Array<RESULT>;
3858
3818
  mode?: 'json';
3859
3819
  output: 'enum';
3860
3820
  } : Output extends 'no-schema' ? {} : {
@@ -3916,7 +3876,7 @@ functionality that can be fully encapsulated in the provider.
3916
3876
  generateId?: () => string;
3917
3877
  currentDate?: () => Date;
3918
3878
  };
3919
- }): Promise<GenerateObjectResult<TYPE>>;
3879
+ }): Promise<GenerateObjectResult<RESULT>>;
3920
3880
 
3921
3881
  /**
3922
3882
  The result of a `streamObject` call that contains the partial object stream and additional information.
@@ -3929,7 +3889,7 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
3929
3889
  /**
3930
3890
  The token usage of the generated response. Resolved when the response is finished.
3931
3891
  */
3932
- readonly usage: Promise<LanguageModelUsage$1>;
3892
+ readonly usage: Promise<LanguageModelUsage>;
3933
3893
  /**
3934
3894
  Additional provider-specific metadata. They are passed through
3935
3895
  from the provider to the AI SDK and enable provider-specific
@@ -4000,7 +3960,7 @@ type ObjectStreamPart<PARTIAL> = {
4000
3960
  } | {
4001
3961
  type: 'finish';
4002
3962
  finishReason: FinishReason;
4003
- usage: LanguageModelUsage$1;
3963
+ usage: LanguageModelUsage;
4004
3964
  response: LanguageModelResponseMetadata;
4005
3965
  providerMetadata?: ProviderMetadata;
4006
3966
  };
@@ -4022,7 +3982,7 @@ type StreamObjectOnFinishCallback<RESULT> = (event: {
4022
3982
  /**
4023
3983
  The token usage of the generated response.
4024
3984
  */
4025
- usage: LanguageModelUsage$1;
3985
+ usage: LanguageModelUsage;
4026
3986
  /**
4027
3987
  The generated object. Can be undefined if the final object does not match the schema.
4028
3988
  */
@@ -4048,27 +4008,20 @@ type StreamObjectOnFinishCallback<RESULT> = (event: {
4048
4008
  }) => Promise<void> | void;
4049
4009
  /**
4050
4010
  Generate a structured, typed object for a given prompt and schema using a language model.
4051
-
4052
4011
  This function streams the output. If you do not want to stream the output, use `generateObject` instead.
4053
-
4054
4012
  @return
4055
4013
  A result object for accessing the partial object stream and additional information.
4056
4014
  */
4057
- declare function streamObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
4058
- output?: 'object' | undefined;
4059
- /**
4060
- The language model to use.
4061
- */
4062
- model: LanguageModel;
4015
+ declare function streamObject<RESULT extends SCHEMA extends z.Schema ? Output extends 'array' ? Array<z.infer<SCHEMA>> : z.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? Output extends 'array' ? Array<T> : T : never, SCHEMA extends z.Schema | Schema = z.Schema<JSONValue$1>, Output extends 'object' | 'array' | 'no-schema' = 'object'>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (Output extends 'no-schema' ? {} : {
4063
4016
  /**
4064
4017
  The schema of the object that the model should generate.
4065
4018
  */
4066
- schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
4019
+ schema: SCHEMA;
4067
4020
  /**
4068
4021
  Optional name of the output that should be generated.
4069
4022
  Used by some providers for additional LLM guidance, e.g.
4070
4023
  via tool or schema name.
4071
- */
4024
+ */
4072
4025
  schemaName?: string;
4073
4026
  /**
4074
4027
  Optional description of the output that should be generated.
@@ -4088,131 +4041,17 @@ The schema is converted into a JSON schema and used in one of the following ways
4088
4041
  Please note that most providers do not support all modes.
4089
4042
 
4090
4043
  Default and recommended: 'auto' (best mode for the model).
4091
- */
4092
- mode?: 'auto' | 'json' | 'tool';
4093
- /**
4094
- Optional telemetry configuration (experimental).
4095
- */
4096
- experimental_telemetry?: TelemetrySettings;
4097
- /**
4098
- Additional provider-specific options. They are passed through
4099
- to the provider from the AI SDK and enable provider-specific
4100
- functionality that can be fully encapsulated in the provider.
4101
- */
4102
- providerOptions?: ProviderOptions;
4103
- /**
4104
- Callback that is invoked when an error occurs during streaming.
4105
- You can use it to log errors.
4106
- The stream processing will pause until the callback promise is resolved.
4107
- */
4108
- onError?: StreamObjectOnErrorCallback;
4109
- /**
4110
- Callback that is called when the LLM response and the final object validation are finished.
4111
- */
4112
- onFinish?: StreamObjectOnFinishCallback<OBJECT>;
4113
- /**
4114
- * Internal. For test use only. May change without notice.
4115
- */
4116
- _internal?: {
4117
- generateId?: () => string;
4118
- currentDate?: () => Date;
4119
- now?: () => number;
4120
- };
4121
- }): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
4122
- /**
4123
- Generate an array with structured, typed elements for a given prompt and element schema using a language model.
4124
-
4125
- This function streams the output. If you do not want to stream the output, use `generateObject` instead.
4126
-
4127
- @return
4128
- A result object for accessing the partial object stream and additional information.
4129
- */
4130
- declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
4131
- output: 'array';
4132
- /**
4133
- The language model to use.
4134
- */
4135
- model: LanguageModel;
4136
- /**
4137
- The element schema of the array that the model should generate.
4138
4044
  */
4139
- schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
4140
- /**
4141
- Optional name of the array that should be generated.
4142
- Used by some providers for additional LLM guidance, e.g.
4143
- via tool or schema name.
4144
- */
4145
- schemaName?: string;
4146
- /**
4147
- Optional description of the array that should be generated.
4148
- Used by some providers for additional LLM guidance, e.g.
4149
- via tool or schema description.
4150
- */
4151
- schemaDescription?: string;
4152
- /**
4153
- The mode to use for object generation.
4154
-
4155
- The schema is converted into a JSON schema and used in one of the following ways
4156
-
4157
- - 'auto': The provider will choose the best mode for the model.
4158
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
4159
- - '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.
4160
-
4161
- Please note that most providers do not support all modes.
4162
-
4163
- Default and recommended: 'auto' (best mode for the model).
4164
- */
4165
4045
  mode?: 'auto' | 'json' | 'tool';
4166
- /**
4167
- Optional telemetry configuration (experimental).
4168
- */
4169
- experimental_telemetry?: TelemetrySettings;
4170
- /**
4171
- Additional provider-specific options. They are passed through
4172
- to the provider from the AI SDK and enable provider-specific
4173
- functionality that can be fully encapsulated in the provider.
4174
- */
4175
- providerOptions?: ProviderOptions;
4176
- /**
4177
- Callback that is invoked when an error occurs during streaming.
4178
- You can use it to log errors.
4179
- The stream processing will pause until the callback promise is resolved.
4180
- */
4181
- onError?: StreamObjectOnErrorCallback;
4182
- /**
4183
- Callback that is called when the LLM response and the final object validation are finished.
4184
- */
4185
- onFinish?: StreamObjectOnFinishCallback<Array<ELEMENT>>;
4186
- /**
4187
- * Internal. For test use only. May change without notice.
4188
- */
4189
- _internal?: {
4190
- generateId?: () => string;
4191
- currentDate?: () => Date;
4192
- now?: () => number;
4193
- };
4194
- }): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
4195
- /**
4196
- Generate JSON with any schema for a given prompt using a language model.
4197
-
4198
- This function streams the output. If you do not want to stream the output, use `generateObject` instead.
4199
-
4200
- @return
4201
- A result object for accessing the partial object stream and additional information.
4202
- */
4203
- declare function streamObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
4204
- output: 'no-schema';
4046
+ }) & {
4047
+ output?: Output;
4205
4048
  /**
4206
4049
  The language model to use.
4207
4050
  */
4208
4051
  model: LanguageModel;
4209
4052
  /**
4210
- The mode to use for object generation. Must be "json" for no-schema output.
4211
- */
4212
- mode?: 'json';
4213
- /**
4214
4053
  Optional telemetry configuration (experimental).
4215
- */
4054
+ */
4216
4055
  experimental_telemetry?: TelemetrySettings;
4217
4056
  /**
4218
4057
  Additional provider-specific options. They are passed through
@@ -4228,8 +4067,8 @@ The stream processing will pause until the callback promise is resolved.
4228
4067
  onError?: StreamObjectOnErrorCallback;
4229
4068
  /**
4230
4069
  Callback that is called when the LLM response and the final object validation are finished.
4231
- */
4232
- onFinish?: StreamObjectOnFinishCallback<JSONValue$1>;
4070
+ */
4071
+ onFinish?: StreamObjectOnFinishCallback<RESULT>;
4233
4072
  /**
4234
4073
  * Internal. For test use only. May change without notice.
4235
4074
  */
@@ -4238,7 +4077,7 @@ Callback that is called when the LLM response and the final object validation ar
4238
4077
  currentDate?: () => Date;
4239
4078
  now?: () => number;
4240
4079
  };
4241
- }): StreamObjectResult<JSONValue$1, JSONValue$1, never>;
4080
+ }): StreamObjectResult<Output extends 'array' ? RESULT : DeepPartial<RESULT>, Output extends 'array' ? RESULT : RESULT, Output extends 'array' ? RESULT extends Array<infer U> ? AsyncIterableStream<U> : never : never>;
4242
4081
 
4243
4082
  /**
4244
4083
  * A generated audio file.
@@ -4655,7 +4494,7 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
4655
4494
  } | {
4656
4495
  type: 'finish';
4657
4496
  finishReason: FinishReason;
4658
- usage: LanguageModelUsage$1;
4497
+ usage: LanguageModelUsage;
4659
4498
  providerMetadata?: ProviderMetadata;
4660
4499
  } | {
4661
4500
  type: 'error';
@@ -4719,7 +4558,7 @@ declare class NoObjectGeneratedError extends AISDKError {
4719
4558
  /**
4720
4559
  The usage of the model.
4721
4560
  */
4722
- readonly usage: LanguageModelUsage$1 | undefined;
4561
+ readonly usage: LanguageModelUsage | undefined;
4723
4562
  /**
4724
4563
  Reason why the model finished generating a response.
4725
4564
  */
@@ -4729,7 +4568,7 @@ declare class NoObjectGeneratedError extends AISDKError {
4729
4568
  cause?: Error;
4730
4569
  text?: string;
4731
4570
  response: LanguageModelResponseMetadata;
4732
- usage: LanguageModelUsage$1;
4571
+ usage: LanguageModelUsage;
4733
4572
  finishReason: FinishReason;
4734
4573
  });
4735
4574
  static isInstance(error: unknown): error is NoObjectGeneratedError;
@@ -4854,4 +4693,4 @@ declare class RetryError extends AISDKError {
4854
4693
  static isInstance(error: unknown): error is RetryError;
4855
4694
  }
4856
4695
 
4857
- export { AssistantContent, Attachment, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, IdGenerator, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage$1 as LanguageModelUsage, MCPClientError, MCPTransport, Message, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RequestOptions, RetryError, Schema, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UseChatOptions, UseCompletionOptions, UserContent, appendClientMessage, appendResponseMessages, asSchema, callChatApi, callCompletionApi, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, fillMessageParts, formatDataStreamPart, generateObject, generateText, getMessageParts, getTextFromDataUrl, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, jsonSchema, parseDataStreamPart, parsePartialJson, pipeDataStreamToResponse, prepareAttachmentsForRequest, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, tool, updateToolCallResult, wrapLanguageModel, zodSchema };
4696
+ export { AssistantContent, Attachment, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamString, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, IdGenerator, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, Message, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RequestOptions, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UseChatOptions, UseCompletionOptions, UserContent, appendClientMessage, appendResponseMessages, callChatApi, callCompletionApi, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, fillMessageParts, formatDataStreamPart, generateObject, generateText, getMessageParts, getTextFromDataUrl, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, parseDataStreamPart, parsePartialJson, pipeDataStreamToResponse, prepareAttachmentsForRequest, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, tool, updateToolCallResult, wrapLanguageModel };