ai 7.0.0-beta.113 → 7.0.0-beta.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/index.d.ts +1506 -1468
  3. package/dist/index.js +889 -979
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +273 -273
  6. package/dist/internal/index.js +367 -405
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/test/index.d.ts +18 -18
  9. package/dist/test/index.js +22 -22
  10. package/dist/test/index.js.map +1 -1
  11. package/docs/02-foundations/03-prompts.mdx +13 -11
  12. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +2 -1
  13. package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
  14. package/docs/03-ai-sdk-core/45-provider-management.mdx +1 -1
  15. package/docs/03-ai-sdk-core/60-telemetry.mdx +87 -13
  16. package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +2 -2
  17. package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +7 -0
  18. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +7 -0
  19. package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +9 -1
  20. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +104 -0
  21. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +56 -10
  22. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +1 -1
  23. package/docs/08-migration-guides/23-migration-guide-7-0.mdx +42 -0
  24. package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
  25. package/package.json +5 -5
  26. package/src/agent/agent.ts +13 -9
  27. package/src/agent/create-agent-ui-stream-response.ts +8 -8
  28. package/src/agent/create-agent-ui-stream.ts +9 -9
  29. package/src/agent/infer-agent-tools.ts +1 -1
  30. package/src/agent/infer-agent-ui-message.ts +2 -2
  31. package/src/agent/pipe-agent-ui-stream-to-response.ts +9 -9
  32. package/src/agent/tool-loop-agent-settings.ts +17 -19
  33. package/src/agent/tool-loop-agent.ts +16 -8
  34. package/src/embed/embed-many-result.ts +3 -4
  35. package/src/embed/embed-many.ts +5 -5
  36. package/src/embed/embed-result.ts +3 -4
  37. package/src/embed/embed.ts +4 -4
  38. package/src/error/invalid-stream-part-error.ts +1 -1
  39. package/src/error/no-image-generated-error.ts +1 -1
  40. package/src/error/no-object-generated-error.ts +3 -3
  41. package/src/error/no-speech-generated-error.ts +1 -1
  42. package/src/error/no-transcript-generated-error.ts +1 -1
  43. package/src/error/no-video-generated-error.ts +1 -1
  44. package/src/error/tool-call-repair-error.ts +2 -2
  45. package/src/error/verify-no-object-generated-error.ts +1 -1
  46. package/src/generate-image/generate-image-result.ts +5 -5
  47. package/src/generate-image/generate-image.ts +12 -15
  48. package/src/generate-image/index.ts +3 -2
  49. package/src/generate-object/generate-object-result.ts +2 -2
  50. package/src/generate-object/generate-object.ts +14 -14
  51. package/src/generate-object/inject-json-instruction.ts +1 -1
  52. package/src/generate-object/output-strategy.ts +10 -10
  53. package/src/generate-object/parse-and-validate-object-result.ts +1 -1
  54. package/src/generate-object/repair-text.ts +1 -1
  55. package/src/generate-object/stream-object-result.ts +4 -4
  56. package/src/generate-object/stream-object.ts +22 -19
  57. package/src/generate-object/validate-object-generation-input.ts +1 -1
  58. package/src/generate-speech/generate-speech-result.ts +4 -4
  59. package/src/generate-speech/generate-speech.ts +12 -13
  60. package/src/generate-speech/generated-audio-file.ts +1 -2
  61. package/src/generate-text/collect-tool-approvals.ts +4 -4
  62. package/src/generate-text/content-part.ts +9 -9
  63. package/src/generate-text/create-execute-tools-transformation.ts +9 -7
  64. package/src/generate-text/execute-tool-call.ts +11 -13
  65. package/src/generate-text/extract-reasoning-content.ts +1 -1
  66. package/src/generate-text/extract-text-content.ts +4 -1
  67. package/src/generate-text/generate-text-events.ts +2 -2
  68. package/src/generate-text/generate-text-result.ts +18 -14
  69. package/src/generate-text/generate-text.ts +42 -38
  70. package/src/generate-text/invoke-tool-callbacks-from-stream.ts +2 -3
  71. package/src/generate-text/output-utils.ts +1 -1
  72. package/src/generate-text/output.ts +8 -8
  73. package/src/generate-text/parse-tool-call.ts +36 -9
  74. package/src/generate-text/prepare-step.ts +3 -5
  75. package/src/generate-text/prune-messages.ts +1 -1
  76. package/src/generate-text/reasoning-output.ts +26 -9
  77. package/src/generate-text/reasoning.ts +1 -1
  78. package/src/generate-text/resolve-tool-approval.ts +3 -3
  79. package/src/generate-text/response-message.ts +1 -1
  80. package/src/generate-text/restricted-telemetry-dispatcher.ts +1 -1
  81. package/src/generate-text/smooth-stream.ts +6 -5
  82. package/src/generate-text/step-result.ts +16 -11
  83. package/src/generate-text/stop-condition.ts +1 -1
  84. package/src/generate-text/stream-language-model-call.ts +26 -21
  85. package/src/generate-text/stream-text-result.ts +29 -26
  86. package/src/generate-text/stream-text.ts +48 -46
  87. package/src/generate-text/to-response-messages.ts +2 -2
  88. package/src/generate-text/tool-approval-configuration.ts +2 -2
  89. package/src/generate-text/tool-approval-request-output.ts +1 -1
  90. package/src/generate-text/tool-approval-response-output.ts +1 -1
  91. package/src/generate-text/tool-call-repair-function.ts +4 -4
  92. package/src/generate-text/tool-call.ts +3 -4
  93. package/src/generate-text/tool-error.ts +3 -4
  94. package/src/generate-text/tool-execution-events.ts +2 -2
  95. package/src/generate-text/tool-output-denied.ts +1 -1
  96. package/src/generate-text/tool-output.ts +2 -2
  97. package/src/generate-text/tool-result.ts +7 -4
  98. package/src/generate-text/tools-context-parameter.ts +1 -1
  99. package/src/generate-text/validate-tool-context.ts +1 -2
  100. package/src/generate-video/generate-video-result.ts +4 -4
  101. package/src/generate-video/generate-video.ts +6 -10
  102. package/src/global.ts +2 -2
  103. package/src/index.ts +3 -3
  104. package/src/logger/log-warnings.ts +1 -1
  105. package/src/middleware/add-tool-input-examples-middleware.ts +2 -2
  106. package/src/middleware/default-embedding-settings-middleware.ts +2 -2
  107. package/src/middleware/default-settings-middleware.ts +2 -2
  108. package/src/middleware/extract-json-middleware.ts +1 -1
  109. package/src/middleware/extract-reasoning-middleware.ts +1 -1
  110. package/src/middleware/simulate-streaming-middleware.ts +1 -1
  111. package/src/middleware/wrap-embedding-model.ts +2 -2
  112. package/src/middleware/wrap-image-model.ts +2 -2
  113. package/src/middleware/wrap-language-model.ts +2 -2
  114. package/src/middleware/wrap-provider.ts +2 -2
  115. package/src/model/as-embedding-model-v3.ts +1 -1
  116. package/src/model/as-embedding-model-v4.ts +1 -1
  117. package/src/model/as-image-model-v3.ts +1 -1
  118. package/src/model/as-image-model-v4.ts +5 -1
  119. package/src/model/as-language-model-v3.ts +1 -1
  120. package/src/model/as-language-model-v4.ts +1 -1
  121. package/src/model/as-provider-v3.ts +1 -1
  122. package/src/model/as-provider-v4.ts +1 -1
  123. package/src/model/as-reranking-model-v4.ts +1 -1
  124. package/src/model/as-speech-model-v3.ts +1 -1
  125. package/src/model/as-speech-model-v4.ts +5 -1
  126. package/src/model/as-transcription-model-v3.ts +4 -1
  127. package/src/model/as-transcription-model-v4.ts +1 -1
  128. package/src/model/as-video-model-v4.ts +1 -1
  129. package/src/model/resolve-model.ts +8 -8
  130. package/src/prompt/content-part.ts +45 -15
  131. package/src/prompt/convert-to-language-model-prompt.ts +108 -122
  132. package/src/prompt/create-tool-model-output.ts +2 -2
  133. package/src/prompt/data-content.ts +1 -78
  134. package/src/prompt/file-part-data.ts +125 -0
  135. package/src/prompt/index.ts +3 -2
  136. package/src/prompt/language-model-call-options.ts +1 -1
  137. package/src/prompt/message-conversion-error.ts +1 -1
  138. package/src/prompt/message.ts +1 -1
  139. package/src/prompt/prepare-language-model-call-options.ts +1 -1
  140. package/src/prompt/prepare-tool-choice.ts +2 -2
  141. package/src/prompt/prepare-tools.ts +2 -2
  142. package/src/prompt/prompt.ts +1 -1
  143. package/src/prompt/standardize-prompt.ts +3 -3
  144. package/src/registry/custom-provider.ts +127 -92
  145. package/src/registry/index.ts +1 -1
  146. package/src/registry/provider-registry.ts +91 -87
  147. package/src/rerank/rerank-result.ts +1 -1
  148. package/src/rerank/rerank.ts +8 -5
  149. package/src/telemetry/create-telemetry-dispatcher.ts +11 -1
  150. package/src/telemetry/diagnostic-channel-publisher.ts +50 -0
  151. package/src/telemetry/diagnostic-channel.ts +24 -0
  152. package/src/telemetry/index.ts +5 -0
  153. package/src/telemetry/telemetry.ts +1 -1
  154. package/src/test/mock-embedding-model-v2.ts +1 -1
  155. package/src/test/mock-embedding-model-v3.ts +1 -1
  156. package/src/test/mock-embedding-model-v4.ts +1 -1
  157. package/src/test/mock-image-model-v2.ts +1 -1
  158. package/src/test/mock-image-model-v3.ts +1 -1
  159. package/src/test/mock-image-model-v4.ts +1 -1
  160. package/src/test/mock-language-model-v2.ts +1 -1
  161. package/src/test/mock-language-model-v3.ts +1 -1
  162. package/src/test/mock-language-model-v4.ts +1 -1
  163. package/src/test/mock-provider-v2.ts +6 -7
  164. package/src/test/mock-provider-v3.ts +7 -8
  165. package/src/test/mock-provider-v4.ts +7 -8
  166. package/src/test/mock-reranking-model-v3.ts +1 -1
  167. package/src/test/mock-reranking-model-v4.ts +1 -1
  168. package/src/test/mock-server-response.ts +1 -1
  169. package/src/test/mock-speech-model-v2.ts +1 -1
  170. package/src/test/mock-speech-model-v3.ts +1 -1
  171. package/src/test/mock-speech-model-v4.ts +1 -1
  172. package/src/test/mock-transcription-model-v2.ts +1 -1
  173. package/src/test/mock-transcription-model-v3.ts +1 -1
  174. package/src/test/mock-transcription-model-v4.ts +1 -1
  175. package/src/test/mock-video-model-v3.ts +1 -1
  176. package/src/test/mock-video-model-v4.ts +1 -1
  177. package/src/text-stream/pipe-text-stream-to-response.ts +1 -1
  178. package/src/transcribe/transcribe-result.ts +3 -3
  179. package/src/transcribe/transcribe.ts +12 -12
  180. package/src/types/embedding-model-middleware.ts +1 -1
  181. package/src/types/embedding-model.ts +1 -1
  182. package/src/types/image-model-middleware.ts +1 -1
  183. package/src/types/image-model.ts +1 -1
  184. package/src/types/json-value.ts +1 -1
  185. package/src/types/language-model-middleware.ts +1 -1
  186. package/src/types/language-model.ts +2 -2
  187. package/src/types/provider-metadata.ts +1 -1
  188. package/src/types/provider-reference.ts +1 -1
  189. package/src/types/provider.ts +4 -4
  190. package/src/types/reranking-model.ts +1 -1
  191. package/src/types/speech-model.ts +5 -1
  192. package/src/types/transcription-model.ts +1 -1
  193. package/src/types/usage.ts +1 -1
  194. package/src/types/video-model.ts +1 -1
  195. package/src/types/warning.ts +1 -1
  196. package/src/ui/call-completion-api.ts +2 -2
  197. package/src/ui/chat-transport.ts +3 -3
  198. package/src/ui/chat.ts +10 -11
  199. package/src/ui/convert-file-list-to-file-ui-parts.ts +1 -1
  200. package/src/ui/convert-to-model-messages.ts +34 -23
  201. package/src/ui/default-chat-transport.ts +4 -4
  202. package/src/ui/direct-chat-transport.ts +6 -6
  203. package/src/ui/http-chat-transport.ts +5 -5
  204. package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +0 -1
  205. package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +0 -1
  206. package/src/ui/process-ui-message-stream.ts +20 -21
  207. package/src/ui/text-stream-chat-transport.ts +3 -3
  208. package/src/ui/transform-text-to-ui-message-stream.ts +1 -1
  209. package/src/ui/ui-messages.ts +13 -6
  210. package/src/ui/use-completion.ts +1 -1
  211. package/src/ui/validate-ui-messages.ts +3 -3
  212. package/src/ui-message-stream/create-ui-message-stream-response.ts +2 -2
  213. package/src/ui-message-stream/create-ui-message-stream.ts +6 -6
  214. package/src/ui-message-stream/get-response-ui-message-id.ts +2 -2
  215. package/src/ui-message-stream/handle-ui-message-stream-finish.ts +6 -6
  216. package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -3
  217. package/src/ui-message-stream/read-ui-message-stream.ts +4 -4
  218. package/src/ui-message-stream/ui-message-chunks.ts +4 -4
  219. package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +2 -2
  220. package/src/ui-message-stream/ui-message-stream-on-step-finish-callback.ts +1 -1
  221. package/src/ui-message-stream/ui-message-stream-writer.ts +3 -3
  222. package/src/upload-file/upload-file-result.ts +3 -3
  223. package/src/upload-file/upload-file.ts +34 -56
  224. package/src/upload-skill/upload-skill-result.ts +3 -3
  225. package/src/upload-skill/upload-skill.ts +27 -8
  226. package/src/util/create-resolvable-promise.ts +1 -1
  227. package/src/util/deep-partial.ts +1 -1
  228. package/src/util/download/download.ts +0 -2
  229. package/src/util/extract-literal-union.ts +18 -0
  230. package/src/util/is-node-runtime.ts +3 -0
  231. package/src/util/notify.ts +1 -1
  232. package/src/util/parse-partial-json.ts +1 -1
  233. package/src/util/prepare-retries.ts +1 -2
  234. package/src/util/serial-job-executor.ts +1 -1
  235. package/src/util/write-to-server-response.ts +1 -1
  236. package/src/util/detect-media-type.ts +0 -235
package/dist/index.d.ts CHANGED
@@ -1,205 +1,72 @@
1
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
2
+ import { EmbeddingModelV4, EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV4Embedding, EmbeddingModelV4Middleware, ImageModelV4, ImageModelV3, ImageModelV2, ImageModelV4ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV4Middleware, JSONValue as JSONValue$1, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4Warning, LanguageModelV4Source, LanguageModelV4Middleware, RerankingModelV4, RerankingModelV3, SharedV4ProviderMetadata, SharedV4ProviderReference, SpeechModelV4, SpeechModelV3, SpeechModelV2, TranscriptionModelV4, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV4Usage, LanguageModelV4Prompt, LanguageModelV4CallOptions, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, EmbeddingModelV4CallOptions, FilesV4, SkillsV4, NoSuchModelError, FilesV4UploadFileCallOptions, SkillsV4UploadSkillResult, SkillsV4UploadSkillCallOptions, SkillsV4File } from '@ai-sdk/provider';
3
+ export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
1
4
  import { GatewayModelId } from '@ai-sdk/gateway';
2
5
  export { GatewayModelId, createGateway, gateway } from '@ai-sdk/gateway';
3
6
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
- import { ToolSet, SystemModelMessage, ModelMessage, FlexibleSchema, InferSchema, ProviderOptions, InferToolInput, InferToolOutput, UserModelMessage, AssistantModelMessage, ToolModelMessage, DataContent, InferToolContext, Arrayable, Context, InferToolSetContext, ReasoningPart, ReasoningFilePart, Tool, ToolCall, IdGenerator, ToolExecutionOptions, MaybePromiseLike, HasRequiredKey, SensitiveContext, TextPart, FilePart, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
7
+ import { ProviderOptions, SystemModelMessage, ModelMessage, ToolSet, FlexibleSchema, InferSchema, Arrayable, InferToolInput, InferToolOutput, UserModelMessage, AssistantModelMessage, ToolModelMessage, DataContent, Context, InferToolSetContext, ReasoningPart, ReasoningFilePart, Tool, ToolCall, IdGenerator, ToolExecutionOptions, MaybePromiseLike, InferToolContext, HasRequiredKey, SensitiveContext, TextPart, FilePart, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
5
8
  export { AssistantContent, AssistantModelMessage, DataContent, DownloadError, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SensitiveContext, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallPart, ToolContent, ToolExecuteFunction, ToolExecutionOptions, ToolModelMessage, ToolResultPart, ToolSet, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
6
- import * as _ai_sdk_provider from '@ai-sdk/provider';
7
- import { LanguageModelV4CallOptions, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4Warning, LanguageModelV4Source, JSONObject, ImageModelV4Usage, EmbeddingModelV4, EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV4Embedding, EmbeddingModelV4Middleware, ImageModelV4, ImageModelV3, ImageModelV2, ImageModelV4ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV4Middleware, JSONValue as JSONValue$1, LanguageModelV4Middleware, RerankingModelV4, RerankingModelV3, SharedV4ProviderMetadata, SharedV4ProviderReference, SpeechModelV4, SpeechModelV3, SpeechModelV2, TranscriptionModelV4, TranscriptionModelV3, TranscriptionModelV2, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, EmbeddingModelV4CallOptions, ProviderV4, ProviderV3, ProviderV2, FilesV4, SkillsV4, NoSuchModelError, SkillsV4UploadSkillResult, SkillsV4File } from '@ai-sdk/provider';
8
- export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
9
9
  import { ServerResponse } from 'node:http';
10
10
  import { ServerResponse as ServerResponse$1 } from 'http';
11
11
  import { z } from 'zod/v4';
12
12
 
13
13
  /**
14
- * Model-facing generation controls. These settings influence how the model
15
- * generates its response (token limits, sampling, penalties, stop sequences,
16
- * seed, reasoning).
14
+ * Embedding model that is used by the AI SDK.
17
15
  */
18
- type LanguageModelCallOptions = {
19
- /**
20
- * Maximum number of tokens to generate.
21
- */
22
- maxOutputTokens?: number;
23
- /**
24
- * Temperature setting. The range depends on the provider and model.
25
- *
26
- * It is recommended to set either `temperature` or `topP`, but not both.
27
- */
28
- temperature?: number;
29
- /**
30
- * Nucleus sampling. This is a number between 0 and 1.
31
- *
32
- * E.g. 0.1 would mean that only tokens with the top 10% probability mass
33
- * are considered.
34
- *
35
- * It is recommended to set either `temperature` or `topP`, but not both.
36
- */
37
- topP?: number;
38
- /**
39
- * Only sample from the top K options for each subsequent token.
40
- *
41
- * Used to remove "long tail" low probability responses.
42
- * Recommended for advanced use cases only. You usually only need to use temperature.
43
- */
44
- topK?: number;
45
- /**
46
- * Presence penalty setting. It affects the likelihood of the model to
47
- * repeat information that is already in the prompt.
48
- *
49
- * The presence penalty is a number between -1 (increase repetition)
50
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
51
- */
52
- presencePenalty?: number;
53
- /**
54
- * Frequency penalty setting. It affects the likelihood of the model
55
- * to repeatedly use the same words or phrases.
56
- *
57
- * The frequency penalty is a number between -1 (increase repetition)
58
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
59
- */
60
- frequencyPenalty?: number;
61
- /**
62
- * Stop sequences.
63
- * If set, the model will stop generating text when one of the stop sequences is generated.
64
- * Providers may have limits on the number of stop sequences.
65
- */
66
- stopSequences?: string[];
67
- /**
68
- * The seed (integer) to use for random sampling. If set and supported
69
- * by the model, calls will generate deterministic results.
70
- */
71
- seed?: number;
72
- /**
73
- * Reasoning effort level for the model. Controls how much reasoning
74
- * the model performs before generating a response.
75
- *
76
- * Use `'provider-default'` to use the provider's default reasoning level.
77
- * Use `'none'` to disable reasoning (if supported by the provider).
78
- */
79
- reasoning?: LanguageModelV4CallOptions['reasoning'];
80
- };
81
-
16
+ type EmbeddingModel = string | EmbeddingModelV4 | EmbeddingModelV3 | EmbeddingModelV2<string>;
82
17
  /**
83
- * Timeout configuration for API calls. Can be specified as:
84
- * - A number representing milliseconds
85
- * - An object with `totalMs` property for the total timeout in milliseconds
86
- * - An object with `stepMs` property for the timeout of each step in milliseconds
87
- * - An object with `chunkMs` property for the timeout between stream chunks (streaming only)
88
- * - An object with `toolMs` property for the default timeout for all tool executions
89
- * - An object with `tools` property for per-tool timeout overrides using `{toolName}Ms` keys
18
+ * Embedding.
90
19
  */
91
- type TimeoutConfiguration<TOOLS extends ToolSet> = number | {
92
- totalMs?: number;
93
- stepMs?: number;
94
- chunkMs?: number;
95
- toolMs?: number;
96
- tools?: Partial<Record<`${keyof TOOLS & string}Ms`, number>>;
97
- };
20
+ type Embedding = EmbeddingModelV4Embedding;
21
+
98
22
  /**
99
- * Extracts the total timeout value in milliseconds from a TimeoutConfiguration.
23
+ * Middleware for embedding models.
24
+ * Accepts both V3 and V4 middleware types for backward compatibility.
100
25
  *
101
- * @param timeout - The timeout configuration.
102
- * @returns The total timeout in milliseconds, or undefined if no timeout is configured.
26
+ * Uses EmbeddingModelV4Middleware as the base but relaxes specificationVersion
27
+ * to accept any string (including 'v3') and makes it optional.
103
28
  */
104
- declare function getTotalTimeoutMs(timeout: TimeoutConfiguration<any> | undefined): number | undefined;
29
+ type EmbeddingModelMiddleware = Omit<EmbeddingModelV4Middleware, 'specificationVersion'> & {
30
+ readonly specificationVersion?: string;
31
+ };
32
+
105
33
  /**
106
- * Extracts the step timeout value in milliseconds from a TimeoutConfiguration.
107
- *
108
- * @param timeout - The timeout configuration.
109
- * @returns The step timeout in milliseconds, or undefined if no step timeout is configured.
34
+ * Image model that is used by the AI SDK.
110
35
  */
111
- declare function getStepTimeoutMs(timeout: TimeoutConfiguration<any> | undefined): number | undefined;
36
+ type ImageModel = string | ImageModelV4 | ImageModelV3 | ImageModelV2;
112
37
  /**
113
- * Extracts the chunk timeout value in milliseconds from a TimeoutConfiguration.
114
- * This timeout is for streaming only - it aborts if no new chunk is received within the specified duration.
115
- *
116
- * @param timeout - The timeout configuration.
117
- * @returns The chunk timeout in milliseconds, or undefined if no chunk timeout is configured.
38
+ * Metadata from the model provider for this call.
118
39
  */
119
- declare function getChunkTimeoutMs(timeout: TimeoutConfiguration<any> | undefined): number | undefined;
120
- declare function getToolTimeoutMs<TOOLS extends ToolSet>(timeout: TimeoutConfiguration<TOOLS> | undefined, toolName: keyof TOOLS & string): number | undefined;
40
+ type ImageModelProviderMetadata = ImageModelV4ProviderMetadata | ImageModelV2ProviderMetadata;
41
+
121
42
  /**
122
- * Request-facing controls. These settings affect transport, retries,
123
- * cancellation, headers, and timeout not model generation behavior.
43
+ * Middleware for image models.
44
+ * Accepts both V3 and V4 middleware types for backward compatibility.
45
+ *
46
+ * Uses ImageModelV4Middleware as the base but relaxes specificationVersion
47
+ * to accept any string (including 'v3') and makes it optional.
124
48
  */
125
- type RequestOptions<TOOLS extends ToolSet = ToolSet> = {
126
- /**
127
- * Maximum number of retries. Set to 0 to disable retries.
128
- *
129
- * @default 2
130
- */
131
- maxRetries?: number;
132
- /**
133
- * Abort signal.
134
- */
135
- abortSignal?: AbortSignal;
136
- /**
137
- * Additional HTTP headers to be sent with the request.
138
- * Only applicable for HTTP-based providers.
139
- */
140
- headers?: Record<string, string | undefined>;
141
- /**
142
- * Timeout configuration for the request.
143
- */
144
- timeout?: TimeoutConfiguration<TOOLS>;
49
+ type ImageModelMiddleware = Omit<ImageModelV4Middleware, 'specificationVersion'> & {
50
+ readonly specificationVersion?: string;
145
51
  };
146
52
 
147
- /**
148
- * Prompt part of the AI function options.
149
- * It contains a system message, a simple text prompt, or a list of messages.
150
- */
151
- type Prompt = {
152
- /**
153
- * System message to include in the prompt. Can be used with `prompt` or `messages`.
154
- */
155
- system?: string | SystemModelMessage | Array<SystemModelMessage>;
156
- /**
157
- * Whether system messages are allowed in the `prompt` or `messages` fields.
158
- *
159
- * When disabled, system messages must be provided through the `system` option.
160
- *
161
- * @default false
162
- */
163
- allowSystemInMessages?: boolean;
164
- } & ({
165
- /**
166
- * A prompt. It can be either a text prompt or a list of messages.
167
- *
168
- * You can either use `prompt` or `messages` but not both.
169
- */
170
- prompt: string | Array<ModelMessage>;
171
- /**
172
- * A list of messages.
173
- *
174
- * You can either use `prompt` or `messages` but not both.
175
- */
176
- messages?: never;
177
- } | {
178
- /**
179
- * A list of messages.
180
- *
181
- * You can either use `prompt` or `messages` but not both.
182
- */
183
- messages: Array<ModelMessage>;
53
+ type ImageModelResponseMetadata = {
184
54
  /**
185
- * A prompt. It can be either a text prompt or a list of messages.
186
- *
187
- * You can either use `prompt` or `messages` but not both.
55
+ * Timestamp for the start of the generated response.
188
56
  */
189
- prompt?: never;
190
- });
191
-
192
- type StandardizedPrompt = {
57
+ timestamp: Date;
193
58
  /**
194
- * System message.
59
+ * The ID of the response model that was used to generate the response.
195
60
  */
196
- system?: string | SystemModelMessage | Array<SystemModelMessage>;
61
+ modelId: string;
197
62
  /**
198
- * Messages.
63
+ * Response headers.
199
64
  */
200
- messages: ModelMessage[];
65
+ headers?: Record<string, string>;
201
66
  };
202
67
 
68
+ type JSONValue = JSONValue$1;
69
+
203
70
  declare global {
204
71
  /**
205
72
  * Global interface that can be augmented by third-party packages to register custom model IDs.
@@ -279,106 +146,34 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
279
146
  };
280
147
 
281
148
  /**
282
- * Represents the number of tokens used in a prompt and completion.
149
+ * Middleware for language models.
150
+ * Accepts both V3 and V4 middleware types for backward compatibility.
151
+ *
152
+ * Uses LanguageModelV4Middleware as the base but relaxes specificationVersion
153
+ * to accept any string (including 'v3') and makes it optional.
283
154
  */
284
- type LanguageModelUsage = {
155
+ type LanguageModelMiddleware = Omit<LanguageModelV4Middleware, 'specificationVersion'> & {
156
+ readonly specificationVersion?: string;
157
+ };
158
+
159
+ type LanguageModelRequestMetadata = {
285
160
  /**
286
- * The total number of input (prompt) tokens used.
161
+ * Request HTTP body that was sent to the provider API.
287
162
  */
288
- inputTokens: number | undefined;
163
+ body?: unknown;
164
+ };
165
+
166
+ type LanguageModelResponseMetadata = {
289
167
  /**
290
- * Detailed information about the input tokens.
168
+ * ID for the generated response.
291
169
  */
292
- inputTokenDetails: {
293
- /**
294
- * The number of non-cached input (prompt) tokens used.
295
- */
296
- noCacheTokens: number | undefined;
297
- /**
298
- * The number of cached input (prompt) tokens read.
299
- */
300
- cacheReadTokens: number | undefined;
301
- /**
302
- * The number of cached input (prompt) tokens written.
303
- */
304
- cacheWriteTokens: number | undefined;
305
- };
170
+ id: string;
306
171
  /**
307
- * The number of total output (completion) tokens used.
172
+ * Timestamp for the start of the generated response.
308
173
  */
309
- outputTokens: number | undefined;
174
+ timestamp: Date;
310
175
  /**
311
- * Detailed information about the output tokens.
312
- */
313
- outputTokenDetails: {
314
- /**
315
- * The number of text tokens used.
316
- */
317
- textTokens: number | undefined;
318
- /**
319
- * The number of reasoning tokens used.
320
- */
321
- reasoningTokens: number | undefined;
322
- };
323
- /**
324
- * The total number of tokens used.
325
- */
326
- totalTokens: number | undefined;
327
- /**
328
- * @deprecated Use outputTokenDetails.reasoningTokens instead.
329
- */
330
- reasoningTokens?: number | undefined;
331
- /**
332
- * @deprecated Use inputTokenDetails.cacheReadTokens instead.
333
- */
334
- cachedInputTokens?: number | undefined;
335
- /**
336
- * Raw usage information from the provider.
337
- *
338
- * This is the usage information in the shape that the provider returns.
339
- * It can include additional information that is not part of the standard usage information.
340
- */
341
- raw?: JSONObject;
342
- };
343
- /**
344
- * Represents the number of tokens used in an embedding.
345
- */
346
- type EmbeddingModelUsage = {
347
- /**
348
- * The number of tokens used in the embedding.
349
- */
350
- tokens: number;
351
- };
352
- /**
353
- * Usage information for an image model call.
354
- */
355
- type ImageModelUsage = ImageModelV4Usage;
356
-
357
- /**
358
- * A callback function that can be used with `notify`.
359
- */
360
- type Callback<EVENT> = (event: EVENT) => PromiseLike<void> | void;
361
-
362
- /**
363
- * Tool names that are enabled for a generation step.
364
- *
365
- * `undefined` means no tool restriction is applied. Tool names are object keys
366
- * at runtime, so the type is restricted to the string keys of the configured
367
- * tool set.
368
- */
369
- type ActiveTools<TOOLS extends ToolSet> = ReadonlyArray<keyof TOOLS & string> | undefined;
370
-
371
- type LanguageModelResponseMetadata = {
372
- /**
373
- * ID for the generated response.
374
- */
375
- id: string;
376
- /**
377
- * Timestamp for the start of the generated response.
378
- */
379
- timestamp: Date;
380
- /**
381
- * The ID of the response model that was used to generate the response.
176
+ * The ID of the response model that was used to generate the response.
382
177
  */
383
178
  modelId: string;
384
179
  /**
@@ -387,98 +182,6 @@ type LanguageModelResponseMetadata = {
387
182
  headers?: Record<string, string>;
388
183
  };
389
184
 
390
- /**
391
- * Create a type from an object with all keys and nested keys set to optional.
392
- * The helper supports normal objects and schemas (which are resolved automatically).
393
- * It always recurses into arrays.
394
- *
395
- * Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
396
- */
397
- type DeepPartial<T> = T extends FlexibleSchema ? DeepPartialInternal<InferSchema<T>> : DeepPartialInternal<T>;
398
- type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
399
- type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
400
- type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
401
- type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
402
- type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
403
- type PartialObject<ObjectType extends object> = {
404
- [KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
405
- };
406
-
407
- /**
408
- * Embedding model that is used by the AI SDK.
409
- */
410
- type EmbeddingModel = string | EmbeddingModelV4 | EmbeddingModelV3 | EmbeddingModelV2<string>;
411
- /**
412
- * Embedding.
413
- */
414
- type Embedding = EmbeddingModelV4Embedding;
415
-
416
- /**
417
- * Middleware for embedding models.
418
- * Accepts both V3 and V4 middleware types for backward compatibility.
419
- *
420
- * Uses EmbeddingModelV4Middleware as the base but relaxes specificationVersion
421
- * to accept any string (including 'v3') and makes it optional.
422
- */
423
- type EmbeddingModelMiddleware = Omit<EmbeddingModelV4Middleware, 'specificationVersion'> & {
424
- readonly specificationVersion?: string;
425
- };
426
-
427
- /**
428
- * Image model that is used by the AI SDK.
429
- */
430
- type ImageModel = string | ImageModelV4 | ImageModelV3 | ImageModelV2;
431
- /**
432
- * Metadata from the model provider for this call.
433
- */
434
- type ImageModelProviderMetadata = ImageModelV4ProviderMetadata | ImageModelV2ProviderMetadata;
435
-
436
- /**
437
- * Middleware for image models.
438
- * Accepts both V3 and V4 middleware types for backward compatibility.
439
- *
440
- * Uses ImageModelV4Middleware as the base but relaxes specificationVersion
441
- * to accept any string (including 'v3') and makes it optional.
442
- */
443
- type ImageModelMiddleware = Omit<ImageModelV4Middleware, 'specificationVersion'> & {
444
- readonly specificationVersion?: string;
445
- };
446
-
447
- type ImageModelResponseMetadata = {
448
- /**
449
- * Timestamp for the start of the generated response.
450
- */
451
- timestamp: Date;
452
- /**
453
- * The ID of the response model that was used to generate the response.
454
- */
455
- modelId: string;
456
- /**
457
- * Response headers.
458
- */
459
- headers?: Record<string, string>;
460
- };
461
-
462
- type JSONValue = JSONValue$1;
463
-
464
- /**
465
- * Middleware for language models.
466
- * Accepts both V3 and V4 middleware types for backward compatibility.
467
- *
468
- * Uses LanguageModelV4Middleware as the base but relaxes specificationVersion
469
- * to accept any string (including 'v3') and makes it optional.
470
- */
471
- type LanguageModelMiddleware = Omit<LanguageModelV4Middleware, 'specificationVersion'> & {
472
- readonly specificationVersion?: string;
473
- };
474
-
475
- type LanguageModelRequestMetadata = {
476
- /**
477
- * Request HTTP body that was sent to the provider API.
478
- */
479
- body?: unknown;
480
- };
481
-
482
185
  /**
483
186
  * Reranking model that is used by the AI SDK.
484
187
  */
@@ -586,12 +289,115 @@ type TranscriptionModelResponseMetadata = {
586
289
  headers?: Record<string, string>;
587
290
  };
588
291
 
292
+ /**
293
+ * Represents the number of tokens used in a prompt and completion.
294
+ */
295
+ type LanguageModelUsage = {
296
+ /**
297
+ * The total number of input (prompt) tokens used.
298
+ */
299
+ inputTokens: number | undefined;
300
+ /**
301
+ * Detailed information about the input tokens.
302
+ */
303
+ inputTokenDetails: {
304
+ /**
305
+ * The number of non-cached input (prompt) tokens used.
306
+ */
307
+ noCacheTokens: number | undefined;
308
+ /**
309
+ * The number of cached input (prompt) tokens read.
310
+ */
311
+ cacheReadTokens: number | undefined;
312
+ /**
313
+ * The number of cached input (prompt) tokens written.
314
+ */
315
+ cacheWriteTokens: number | undefined;
316
+ };
317
+ /**
318
+ * The number of total output (completion) tokens used.
319
+ */
320
+ outputTokens: number | undefined;
321
+ /**
322
+ * Detailed information about the output tokens.
323
+ */
324
+ outputTokenDetails: {
325
+ /**
326
+ * The number of text tokens used.
327
+ */
328
+ textTokens: number | undefined;
329
+ /**
330
+ * The number of reasoning tokens used.
331
+ */
332
+ reasoningTokens: number | undefined;
333
+ };
334
+ /**
335
+ * The total number of tokens used.
336
+ */
337
+ totalTokens: number | undefined;
338
+ /**
339
+ * @deprecated Use outputTokenDetails.reasoningTokens instead.
340
+ */
341
+ reasoningTokens?: number | undefined;
342
+ /**
343
+ * @deprecated Use inputTokenDetails.cacheReadTokens instead.
344
+ */
345
+ cachedInputTokens?: number | undefined;
346
+ /**
347
+ * Raw usage information from the provider.
348
+ *
349
+ * This is the usage information in the shape that the provider returns.
350
+ * It can include additional information that is not part of the standard usage information.
351
+ */
352
+ raw?: JSONObject;
353
+ };
354
+ /**
355
+ * Represents the number of tokens used in an embedding.
356
+ */
357
+ type EmbeddingModelUsage = {
358
+ /**
359
+ * The number of tokens used in the embedding.
360
+ */
361
+ tokens: number;
362
+ };
363
+ /**
364
+ * Usage information for an image model call.
365
+ */
366
+ type ImageModelUsage = ImageModelV4Usage;
367
+
589
368
  /**
590
369
  * Warning from the model provider for this call. The call will proceed, but e.g.
591
370
  * some settings might not be supported, which can lead to suboptimal results.
592
371
  */
593
372
  type Warning = SharedV4Warning;
594
373
 
374
+ /**
375
+ * A function for logging warnings.
376
+ *
377
+ * You can assign it to the `AI_SDK_LOG_WARNINGS` global variable to use it as the default warning logger.
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * globalThis.AI_SDK_LOG_WARNINGS = (options) => {
382
+ * console.log('WARNINGS:', options.warnings, options.provider, options.model);
383
+ * };
384
+ * ```
385
+ */
386
+ type LogWarningsFunction = (options: {
387
+ /**
388
+ * The warnings returned by the model provider.
389
+ */
390
+ warnings: Warning[];
391
+ /**
392
+ * The provider id used for the call, if scoped to a specific provider.
393
+ */
394
+ provider?: string;
395
+ /**
396
+ * The model id used for the call, if scoped to a specific provider.
397
+ */
398
+ model?: string;
399
+ }) => void;
400
+
595
401
  /**
596
402
  * Event passed to the `onStart` callback for embed and embedMany operations.
597
403
  *
@@ -851,799 +657,647 @@ interface GenerateObjectEndEvent<RESULT> {
851
657
  }
852
658
 
853
659
  /**
854
- * A generated file.
660
+ * Model-facing generation controls. These settings influence how the model
661
+ * generates its response (token limits, sampling, penalties, stop sequences,
662
+ * seed, reasoning).
855
663
  */
856
- interface GeneratedFile {
664
+ type LanguageModelCallOptions = {
857
665
  /**
858
- * File as a base64 encoded string.
666
+ * Maximum number of tokens to generate.
859
667
  */
860
- readonly base64: string;
668
+ maxOutputTokens?: number;
861
669
  /**
862
- * File as a Uint8Array.
670
+ * Temperature setting. The range depends on the provider and model.
671
+ *
672
+ * It is recommended to set either `temperature` or `topP`, but not both.
863
673
  */
864
- readonly uint8Array: Uint8Array;
674
+ temperature?: number;
865
675
  /**
866
- * The IANA media type of the file.
676
+ * Nucleus sampling. This is a number between 0 and 1.
867
677
  *
868
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
678
+ * E.g. 0.1 would mean that only tokens with the top 10% probability mass
679
+ * are considered.
680
+ *
681
+ * It is recommended to set either `temperature` or `topP`, but not both.
869
682
  */
870
- readonly mediaType: string;
871
- }
872
- declare class DefaultGeneratedFile implements GeneratedFile {
873
- private base64Data;
874
- private uint8ArrayData;
875
- readonly mediaType: string;
876
- constructor({ data, mediaType, }: {
877
- data: string | Uint8Array;
878
- mediaType: string;
879
- });
880
- get base64(): string;
881
- get uint8Array(): Uint8Array<ArrayBufferLike>;
882
- }
883
-
884
- /**
885
- * Reasoning output of a text generation. It contains a reasoning.
886
- */
887
- interface ReasoningOutput {
888
- type: 'reasoning';
683
+ topP?: number;
889
684
  /**
890
- * The reasoning text.
685
+ * Only sample from the top K options for each subsequent token.
686
+ *
687
+ * Used to remove "long tail" low probability responses.
688
+ * Recommended for advanced use cases only. You usually only need to use temperature.
891
689
  */
892
- text: string;
690
+ topK?: number;
893
691
  /**
894
- * Additional provider-specific metadata. They are passed through
895
- * to the provider from the AI SDK and enable provider-specific
896
- * functionality that can be fully encapsulated in the provider.
692
+ * Presence penalty setting. It affects the likelihood of the model to
693
+ * repeat information that is already in the prompt.
694
+ *
695
+ * The presence penalty is a number between -1 (increase repetition)
696
+ * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
897
697
  */
898
- providerMetadata?: ProviderMetadata;
899
- }
900
- /**
901
- * Reasoning file output of a text generation.
902
- * It contains a file generated as part of reasoning.
903
- */
904
- interface ReasoningFileOutput {
905
- type: 'reasoning-file';
698
+ presencePenalty?: number;
906
699
  /**
907
- * The generated file.
700
+ * Frequency penalty setting. It affects the likelihood of the model
701
+ * to repeatedly use the same words or phrases.
702
+ *
703
+ * The frequency penalty is a number between -1 (increase repetition)
704
+ * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
908
705
  */
909
- file: GeneratedFile;
706
+ frequencyPenalty?: number;
910
707
  /**
911
- * Additional provider-specific metadata. They are passed through
912
- * to the provider from the AI SDK and enable provider-specific
913
- * functionality that can be fully encapsulated in the provider.
708
+ * Stop sequences.
709
+ * If set, the model will stop generating text when one of the stop sequences is generated.
710
+ * Providers may have limits on the number of stop sequences.
914
711
  */
915
- providerMetadata?: ProviderMetadata;
916
- }
712
+ stopSequences?: string[];
713
+ /**
714
+ * The seed (integer) to use for random sampling. If set and supported
715
+ * by the model, calls will generate deterministic results.
716
+ */
717
+ seed?: number;
718
+ /**
719
+ * Reasoning effort level for the model. Controls how much reasoning
720
+ * the model performs before generating a response.
721
+ *
722
+ * Use `'provider-default'` to use the provider's default reasoning level.
723
+ * Use `'none'` to disable reasoning (if supported by the provider).
724
+ */
725
+ reasoning?: LanguageModelV4CallOptions['reasoning'];
726
+ };
917
727
 
918
728
  /**
919
- * Create a union of the given object's values, and optionally specify which keys to get the values from.
920
- *
921
- * Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
922
- *
923
- * @example
924
- * ```
925
- * // data.json
926
- * {
927
- * 'foo': 1,
928
- * 'bar': 2,
929
- * 'biz': 3
930
- * }
931
- *
932
- * // main.ts
933
- * import type {ValueOf} from 'type-fest';
934
- * import data = require('./data.json');
935
- *
936
- * export function getData(name: string): ValueOf<typeof data> {
937
- * return data[name];
938
- * }
939
- *
940
- * export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
941
- * return data[name];
942
- * }
943
- *
944
- * // file.ts
945
- * import {getData, onlyBar} from './main';
946
- *
947
- * getData('foo');
948
- * //=> 1
949
- *
950
- * onlyBar('foo');
951
- * //=> TypeError ...
952
- *
953
- * onlyBar('bar');
954
- * //=> 2
955
- * ```
956
- * @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
729
+ * Timeout configuration for API calls. Can be specified as:
730
+ * - A number representing milliseconds
731
+ * - An object with `totalMs` property for the total timeout in milliseconds
732
+ * - An object with `stepMs` property for the timeout of each step in milliseconds
733
+ * - An object with `chunkMs` property for the timeout between stream chunks (streaming only)
734
+ * - An object with `toolMs` property for the default timeout for all tool executions
735
+ * - An object with `tools` property for per-tool timeout overrides using `{toolName}Ms` keys
957
736
  */
958
- type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
959
-
960
- type BaseToolCall = {
961
- type: 'tool-call';
962
- toolCallId: string;
963
- providerExecuted?: boolean;
964
- providerMetadata?: ProviderMetadata;
737
+ type TimeoutConfiguration<TOOLS extends ToolSet> = number | {
738
+ totalMs?: number;
739
+ stepMs?: number;
740
+ chunkMs?: number;
741
+ toolMs?: number;
742
+ tools?: Partial<Record<`${keyof TOOLS & string}Ms`, number>>;
965
743
  };
966
744
  /**
967
- * A tool call whose `toolName` maps to a tool in the declared tool set,
968
- * with an `input` type inferred from that tool's input schema.
745
+ * Extracts the total timeout value in milliseconds from a TimeoutConfiguration.
746
+ *
747
+ * @param timeout - The timeout configuration.
748
+ * @returns The total timeout in milliseconds, or undefined if no timeout is configured.
969
749
  */
970
- type StaticToolCall<TOOLS extends ToolSet> = ValueOf<{
971
- [NAME in keyof TOOLS]: BaseToolCall & {
972
- toolName: NAME & string;
973
- input: InferToolInput<TOOLS[NAME]>;
974
- dynamic?: false | undefined;
975
- invalid?: false | undefined;
976
- error?: never;
977
- title?: string;
978
- };
979
- }>;
750
+ declare function getTotalTimeoutMs(timeout: TimeoutConfiguration<any> | undefined): number | undefined;
980
751
  /**
981
- * A tool call whose `toolName` is only known at runtime, such as an invalid
982
- * or otherwise untyped call that cannot be matched to the declared tool set.
752
+ * Extracts the step timeout value in milliseconds from a TimeoutConfiguration.
753
+ *
754
+ * @param timeout - The timeout configuration.
755
+ * @returns The step timeout in milliseconds, or undefined if no step timeout is configured.
983
756
  */
984
- type DynamicToolCall = BaseToolCall & {
985
- toolName: string;
986
- input: unknown;
987
- dynamic: true;
988
- title?: string;
989
- /**
990
- * True if this is caused by an unparsable tool call or
991
- * a tool that does not exist.
992
- */
993
- invalid?: boolean;
994
- /**
995
- * The error that caused the tool call to be invalid.
996
- */
997
- error?: unknown;
998
- };
757
+ declare function getStepTimeoutMs(timeout: TimeoutConfiguration<any> | undefined): number | undefined;
999
758
  /**
1000
- * A tool call returned by text generation, either statically typed from the
1001
- * declared tool set or dynamically typed when the tool cannot be inferred.
759
+ * Extracts the chunk timeout value in milliseconds from a TimeoutConfiguration.
760
+ * This timeout is for streaming only - it aborts if no new chunk is received within the specified duration.
761
+ *
762
+ * @param timeout - The timeout configuration.
763
+ * @returns The chunk timeout in milliseconds, or undefined if no chunk timeout is configured.
1002
764
  */
1003
- type TypedToolCall<TOOLS extends ToolSet> = StaticToolCall<TOOLS> | DynamicToolCall;
1004
-
765
+ declare function getChunkTimeoutMs(timeout: TimeoutConfiguration<any> | undefined): number | undefined;
766
+ declare function getToolTimeoutMs<TOOLS extends ToolSet>(timeout: TimeoutConfiguration<TOOLS> | undefined, toolName: keyof TOOLS & string): number | undefined;
1005
767
  /**
1006
- * Output part that indicates that a tool approval request has been made.
1007
- *
1008
- * The tool approval request can be approved or denied in the next tool message.
768
+ * Request-facing controls. These settings affect transport, retries,
769
+ * cancellation, headers, and timeout – not model generation behavior.
1009
770
  */
1010
- type ToolApprovalRequestOutput<TOOLS extends ToolSet> = {
1011
- type: 'tool-approval-request';
771
+ type RequestOptions<TOOLS extends ToolSet = ToolSet> = {
1012
772
  /**
1013
- * ID of the tool approval request.
773
+ * Maximum number of retries. Set to 0 to disable retries.
774
+ *
775
+ * @default 2
1014
776
  */
1015
- approvalId: string;
777
+ maxRetries?: number;
1016
778
  /**
1017
- * Tool call that the approval request is for.
779
+ * Abort signal.
1018
780
  */
1019
- toolCall: TypedToolCall<TOOLS>;
781
+ abortSignal?: AbortSignal;
1020
782
  /**
1021
- * Flag indicating whether the tool was automatically approved or denied.
1022
- *
1023
- * @default false
783
+ * Additional HTTP headers to be sent with the request.
784
+ * Only applicable for HTTP-based providers.
1024
785
  */
1025
- isAutomatic?: boolean;
786
+ headers?: Record<string, string | undefined>;
787
+ /**
788
+ * Timeout configuration for the request.
789
+ */
790
+ timeout?: TimeoutConfiguration<TOOLS>;
1026
791
  };
1027
792
 
1028
793
  /**
1029
- * Output part that indicates that a tool approval response is available.
794
+ * Prompt part of the AI function options.
795
+ * It contains a system message, a simple text prompt, or a list of messages.
1030
796
  */
1031
- type ToolApprovalResponseOutput<TOOLS extends ToolSet> = {
1032
- type: 'tool-approval-response';
797
+ type Prompt = {
1033
798
  /**
1034
- * ID of the tool approval.
799
+ * System message to include in the prompt. Can be used with `prompt` or `messages`.
1035
800
  */
1036
- approvalId: string;
801
+ system?: string | SystemModelMessage | Array<SystemModelMessage>;
1037
802
  /**
1038
- * Tool call that the approval response is for.
803
+ * Whether system messages are allowed in the `prompt` or `messages` fields.
804
+ *
805
+ * When disabled, system messages must be provided through the `system` option.
806
+ *
807
+ * @default false
1039
808
  */
1040
- toolCall: TypedToolCall<TOOLS>;
809
+ allowSystemInMessages?: boolean;
810
+ } & ({
1041
811
  /**
1042
- * Flag indicating whether the approval was granted or denied.
1043
- */
1044
- approved: boolean;
812
+ * A prompt. It can be either a text prompt or a list of messages.
813
+ *
814
+ * You can either use `prompt` or `messages` but not both.
815
+ */
816
+ prompt: string | Array<ModelMessage>;
1045
817
  /**
1046
- * Optional reason for the approval or denial.
818
+ * A list of messages.
819
+ *
820
+ * You can either use `prompt` or `messages` but not both.
1047
821
  */
1048
- reason?: string;
822
+ messages?: never;
823
+ } | {
1049
824
  /**
1050
- * Flag indicating whether the tool call is provider-executed.
1051
- * Only provider-executed tool approval responses should be sent to the model.
825
+ * A list of messages.
826
+ *
827
+ * You can either use `prompt` or `messages` but not both.
1052
828
  */
1053
- providerExecuted?: boolean;
1054
- };
1055
-
1056
- type StaticToolError<TOOLS extends ToolSet> = ValueOf<{
1057
- [NAME in keyof TOOLS]: {
1058
- type: 'tool-error';
1059
- toolCallId: string;
1060
- toolName: NAME & string;
1061
- input: InferToolInput<TOOLS[NAME]>;
1062
- error: unknown;
1063
- providerExecuted?: boolean;
1064
- providerMetadata?: ProviderMetadata;
1065
- dynamic?: false | undefined;
1066
- title?: string;
1067
- };
1068
- }>;
1069
- type DynamicToolError = {
1070
- type: 'tool-error';
1071
- toolCallId: string;
1072
- toolName: string;
1073
- input: unknown;
1074
- error: unknown;
1075
- providerExecuted?: boolean;
1076
- providerMetadata?: ProviderMetadata;
1077
- dynamic: true;
1078
- title?: string;
1079
- };
1080
- type TypedToolError<TOOLS extends ToolSet> = StaticToolError<TOOLS> | DynamicToolError;
829
+ messages: Array<ModelMessage>;
830
+ /**
831
+ * A prompt. It can be either a text prompt or a list of messages.
832
+ *
833
+ * You can either use `prompt` or `messages` but not both.
834
+ */
835
+ prompt?: never;
836
+ });
1081
837
 
1082
- type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{
1083
- [NAME in keyof TOOLS]: {
1084
- type: 'tool-result';
1085
- toolCallId: string;
1086
- toolName: NAME & string;
1087
- input: InferToolInput<TOOLS[NAME]>;
1088
- output: InferToolOutput<TOOLS[NAME]>;
1089
- providerExecuted?: boolean;
1090
- providerMetadata?: ProviderMetadata;
1091
- dynamic?: false | undefined;
1092
- preliminary?: boolean;
1093
- title?: string;
1094
- };
1095
- }>;
1096
- type DynamicToolResult = {
1097
- type: 'tool-result';
1098
- toolCallId: string;
1099
- toolName: string;
1100
- input: unknown;
1101
- output: unknown;
1102
- providerExecuted?: boolean;
1103
- providerMetadata?: ProviderMetadata;
1104
- dynamic: true;
1105
- preliminary?: boolean;
1106
- title?: string;
838
+ type StandardizedPrompt = {
839
+ /**
840
+ * System message.
841
+ */
842
+ system?: string | SystemModelMessage | Array<SystemModelMessage>;
843
+ /**
844
+ * Messages.
845
+ */
846
+ messages: ModelMessage[];
1107
847
  };
1108
- type TypedToolResult<TOOLS extends ToolSet> = StaticToolResult<TOOLS> | DynamicToolResult;
1109
-
1110
- type ContentPart<TOOLS extends ToolSet> = {
1111
- type: 'text';
1112
- text: string;
1113
- providerMetadata?: ProviderMetadata;
1114
- } | {
1115
- type: 'custom';
1116
- kind: `${string}.${string}`;
1117
- providerMetadata?: ProviderMetadata;
1118
- } | ReasoningOutput | ReasoningFileOutput | ({
1119
- type: 'source';
1120
- } & Source) | {
1121
- type: 'file';
1122
- file: GeneratedFile;
1123
- providerMetadata?: ProviderMetadata;
1124
- } | ({
1125
- type: 'tool-call';
1126
- } & TypedToolCall<TOOLS> & {
1127
- providerMetadata?: ProviderMetadata;
1128
- }) | ({
1129
- type: 'tool-result';
1130
- } & TypedToolResult<TOOLS> & {
1131
- providerMetadata?: ProviderMetadata;
1132
- }) | ({
1133
- type: 'tool-error';
1134
- } & TypedToolError<TOOLS> & {
1135
- providerMetadata?: ProviderMetadata;
1136
- }) | ToolApprovalRequestOutput<TOOLS> | ToolApprovalResponseOutput<TOOLS>;
1137
-
1138
- declare const systemModelMessageSchema: z.ZodType<SystemModelMessage>;
1139
- declare const userModelMessageSchema: z.ZodType<UserModelMessage>;
1140
- declare const assistantModelMessageSchema: z.ZodType<AssistantModelMessage>;
1141
- declare const toolModelMessageSchema: z.ZodType<ToolModelMessage>;
1142
- declare const modelMessageSchema: z.ZodType<ModelMessage>;
1143
848
 
1144
849
  /**
1145
- * Converts data content to a base64-encoded string.
1146
- *
1147
- * @param content - Data content to convert.
1148
- * @returns Base64-encoded string.
850
+ * A callback function that can be used with `notify`.
1149
851
  */
1150
- declare function convertDataContentToBase64String(content: DataContent): string;
1151
-
1152
- /** @deprecated Use `LanguageModelCallOptions` combined with `RequestOptions` instead. */
1153
- type CallSettings = LanguageModelCallOptions & Omit<RequestOptions, 'timeout'>;
852
+ type Callback<EVENT> = (event: EVENT) => PromiseLike<void> | void;
1154
853
 
1155
854
  /**
1156
- * Common model information used across callback events.
855
+ * Tool names that are enabled for a generation step.
856
+ *
857
+ * `undefined` means no tool restriction is applied. Tool names are object keys
858
+ * at runtime, so the type is restricted to the string keys of the configured
859
+ * tool set.
1157
860
  */
1158
- type ModelInfo = {
1159
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
1160
- readonly provider: string;
1161
- /** The specific model identifier (e.g., 'gpt-4o'). */
1162
- readonly modelId: string;
1163
- };
861
+ type ActiveTools<TOOLS extends ToolSet> = ReadonlyArray<keyof TOOLS & string> | undefined;
862
+
1164
863
  /**
1165
- * Event passed to the `onLanguageModelCallStart` callback.
864
+ * Create a type from an object with all keys and nested keys set to optional.
865
+ * The helper supports normal objects and schemas (which are resolved automatically).
866
+ * It always recurses into arrays.
1166
867
  *
1167
- * Called immediately before the provider model call begins.
1168
- * Unlike `onStepStart`, this only represents model invocation work.
868
+ * Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
1169
869
  */
1170
- type LanguageModelCallStartEvent = ModelInfo & {
1171
- /** Unique identifier for this generation call, used to correlate events. */
1172
- readonly callId: string;
1173
- /** Prepared tool definitions for the model call, if any. */
1174
- readonly tools: ReadonlyArray<Record<string, unknown>> | undefined;
1175
- } & StandardizedPrompt & LanguageModelCallOptions;
870
+ type DeepPartial<T> = T extends FlexibleSchema ? DeepPartialInternal<InferSchema<T>> : DeepPartialInternal<T>;
871
+ type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
872
+ type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
873
+ type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
874
+ type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
875
+ type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
876
+ type PartialObject<ObjectType extends object> = {
877
+ [KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
878
+ };
879
+
1176
880
  /**
1177
- * Event passed to the `onLanguageModelCallEnd` callback.
1178
- *
1179
- * Called after the model response has been normalized and parsed, but before
1180
- * any client-side tool execution begins.
881
+ * Telemetry configuration.
1181
882
  */
1182
- type LanguageModelCallEndEvent<TOOLS extends ToolSet = ToolSet> = ModelInfo & {
1183
- /** Unique identifier for this generation call, used to correlate events. */
1184
- readonly callId: string;
1185
- /** The unified reason why the model call finished. */
1186
- readonly finishReason: FinishReason;
1187
- /** The token usage reported by the model call. */
1188
- readonly usage: LanguageModelUsage;
1189
- /** The content parts produced by the model call. */
1190
- readonly content: ReadonlyArray<ContentPart<TOOLS>>;
1191
- /** The provider-returned response id for this model call. */
1192
- readonly responseId: string;
883
+ type TelemetryOptions = {
884
+ /**
885
+ * Enable or disable telemetry. Enabled by default when a telemetry
886
+ * integration is registered. Set to `false` to opt out.
887
+ */
888
+ isEnabled?: boolean;
889
+ /**
890
+ * Enable or disable input recording. Enabled by default.
891
+ *
892
+ * You might want to disable input recording to avoid recording sensitive
893
+ * information, to reduce data transfers, or to increase performance.
894
+ */
895
+ recordInputs?: boolean;
896
+ /**
897
+ * Enable or disable output recording. Enabled by default.
898
+ *
899
+ * You might want to disable output recording to avoid recording sensitive
900
+ * information, to reduce data transfers, or to increase performance.
901
+ */
902
+ recordOutputs?: boolean;
903
+ /**
904
+ * Identifier for this function. Used to group telemetry data by function.
905
+ */
906
+ functionId?: string;
907
+ /**
908
+ * Per-call telemetry integrations that receive lifecycle events during generation.
909
+ *
910
+ * When provided, these integrations will take precedence over the globally registered
911
+ * integrations for this call.
912
+ */
913
+ integrations?: Arrayable<Telemetry>;
1193
914
  };
915
+
1194
916
  /**
1195
- * Callback that is set using the `experimental_onLanguageModelCallStart` option.
917
+ * Experimental. Can change in patch versions without warning.
1196
918
  *
1197
- * Called immediately before the provider model call begins.
1198
- * Unlike step-start callbacks, this is scoped to model work only and
1199
- * excludes any later client-side tool execution.
919
+ * Download function. Called with the array of URLs and a boolean indicating
920
+ * whether the URL is supported by the model.
1200
921
  *
1201
- * @param event - The event object containing model-call-specific inputs.
1202
- */
1203
- type OnLanguageModelCallStartCallback = Callback<LanguageModelCallStartEvent>;
1204
- /**
1205
- * Callback that is set using the `experimental_onLanguageModelCallEnd` option.
922
+ * The download function can decide for each URL:
923
+ * - to return null (which means that the URL should be passed to the model)
924
+ * - to download the asset and return the data (incl. retries, authentication, etc.)
1206
925
  *
1207
- * Called after the model response has been normalized and parsed, but before
1208
- * any client-side tool execution begins.
926
+ * Should throw DownloadError if the download fails.
1209
927
  *
1210
- * @param event - The event object containing model-call-specific outputs.
928
+ * Should return an array of objects sorted by the order of the requested downloads.
929
+ * For each object, the data should be a Uint8Array if the URL was downloaded.
930
+ * For each object, the mediaType should be the media type of the downloaded asset.
931
+ * For each object, the data should be null if the URL should be passed through as is.
1211
932
  */
1212
- type OnLanguageModelCallEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<LanguageModelCallEndEvent<TOOLS>>;
1213
-
1214
- type ToolOutput<TOOLS extends ToolSet> = TypedToolResult<TOOLS> | TypedToolError<TOOLS>;
933
+ type DownloadFunction = (options: Array<{
934
+ url: URL;
935
+ isUrlSupportedByModel: boolean;
936
+ }>) => PromiseLike<Array<{
937
+ data: Uint8Array;
938
+ mediaType: string | undefined;
939
+ } | null>>;
1215
940
 
1216
941
  /**
1217
- * Resolves a single tool's context type, falling back to `undefined` when the
1218
- * tool does not declare a `contextSchema`.
942
+ * A generated file.
1219
943
  */
1220
- type ToolContextFor<TOOL extends ToolSet[keyof ToolSet]> = [
1221
- InferToolContext<TOOL>
1222
- ] extends [never] ? undefined : InferToolContext<TOOL>;
1223
- type BaseToolExecutionStartFields = {
1224
- /** Unique identifier for this generation call, used to correlate events. */
1225
- readonly callId: string;
944
+ interface GeneratedFile {
1226
945
  /**
1227
- * Messages that were sent to the language model to initiate the response that contained the tool call.
1228
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
946
+ * File as a base64 encoded string.
1229
947
  */
1230
- readonly messages: ModelMessage[];
1231
- };
948
+ readonly base64: string;
949
+ /**
950
+ * File as a Uint8Array.
951
+ */
952
+ readonly uint8Array: Uint8Array;
953
+ /**
954
+ * The IANA media type of the file.
955
+ *
956
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
957
+ */
958
+ readonly mediaType: string;
959
+ }
960
+ declare class DefaultGeneratedFile implements GeneratedFile {
961
+ private base64Data;
962
+ private uint8ArrayData;
963
+ readonly mediaType: string;
964
+ constructor({ data, mediaType, }: {
965
+ data: string | Uint8Array;
966
+ mediaType: string;
967
+ });
968
+ get base64(): string;
969
+ get uint8Array(): Uint8Array<ArrayBufferLike>;
970
+ }
971
+
1232
972
  /**
1233
- * Precise start event union for statically known tools.
1234
- *
1235
- * Each union member ties a specific `toolCall.toolName` to that tool's
1236
- * validated `toolContext` type.
973
+ * Reasoning output of a text generation. It contains a reasoning.
1237
974
  */
1238
- type StaticToolExecutionStartEvent<TOOLS extends ToolSet> = ValueOf<{
1239
- [NAME in keyof TOOLS]: BaseToolExecutionStartFields & {
1240
- readonly toolCall: Extract<StaticToolCall<TOOLS>, {
1241
- toolName: NAME;
1242
- }>;
1243
- readonly toolContext: ToolContextFor<TOOLS[NAME]>;
1244
- };
1245
- }>;
975
+ interface ReasoningOutput {
976
+ type: 'reasoning';
977
+ /**
978
+ * The reasoning text.
979
+ */
980
+ text: string;
981
+ /**
982
+ * Additional provider-specific metadata. They are passed through
983
+ * to the provider from the AI SDK and enable provider-specific
984
+ * functionality that can be fully encapsulated in the provider.
985
+ */
986
+ providerMetadata?: ProviderMetadata;
987
+ }
1246
988
  /**
1247
- * Start event shape for dynamic or untyped tool calls.
989
+ * Reasoning file output of a text generation.
990
+ * It contains a file generated as part of reasoning.
1248
991
  */
1249
- type DynamicToolExecutionStartEvent = BaseToolExecutionStartFields & {
1250
- readonly toolCall: DynamicToolCall;
1251
- readonly toolContext: unknown;
1252
- };
992
+ interface ReasoningFileOutput {
993
+ type: 'reasoning-file';
994
+ /**
995
+ * The generated file.
996
+ */
997
+ file: GeneratedFile;
998
+ /**
999
+ * Additional provider-specific metadata. They are passed through
1000
+ * to the provider from the AI SDK and enable provider-specific
1001
+ * functionality that can be fully encapsulated in the provider.
1002
+ */
1003
+ providerMetadata?: ProviderMetadata;
1004
+ }
1005
+
1253
1006
  /**
1254
- * Broad start event shape used for the default `ToolSet` specialization.
1007
+ * Create a union of the given object's values, and optionally specify which keys to get the values from.
1255
1008
  *
1256
- * This keeps generic collectors ergonomic when the caller is not working with
1257
- * a concrete tool set and therefore cannot benefit from per-tool narrowing.
1258
- */
1259
- type WidenedToolExecutionStartEvent = BaseToolExecutionStartFields & {
1260
- readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
1261
- readonly toolContext: unknown;
1262
- };
1263
- /**
1264
- * Event passed to the `onToolExecutionStart` callback.
1009
+ * Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
1265
1010
  *
1266
- * Called when a tool execution begins, before the tool's `execute` function is invoked.
1011
+ * @example
1012
+ * ```
1013
+ * // data.json
1014
+ * {
1015
+ * 'foo': 1,
1016
+ * 'bar': 2,
1017
+ * 'biz': 3
1018
+ * }
1019
+ *
1020
+ * // main.ts
1021
+ * import type {ValueOf} from 'type-fest';
1022
+ * import data = require('./data.json');
1023
+ *
1024
+ * export function getData(name: string): ValueOf<typeof data> {
1025
+ * return data[name];
1026
+ * }
1027
+ *
1028
+ * export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
1029
+ * return data[name];
1030
+ * }
1031
+ *
1032
+ * // file.ts
1033
+ * import {getData, onlyBar} from './main';
1034
+ *
1035
+ * getData('foo');
1036
+ * //=> 1
1037
+ *
1038
+ * onlyBar('foo');
1039
+ * //=> TypeError ...
1040
+ *
1041
+ * onlyBar('bar');
1042
+ * //=> 2
1043
+ * ```
1044
+ * @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
1267
1045
  */
1268
- type ToolExecutionStartEvent<TOOLS extends ToolSet = ToolSet> = [
1269
- ToolSet
1270
- ] extends [TOOLS] ? WidenedToolExecutionStartEvent : StaticToolExecutionStartEvent<TOOLS> | DynamicToolExecutionStartEvent;
1271
- type BaseToolExecutionEndFields = {
1272
- /** Unique identifier for this generation call, used to correlate events. */
1273
- readonly callId: string;
1274
- /** Execution time of the tool call in milliseconds. */
1275
- readonly durationMs: number;
1276
- /**
1277
- * Messages that were sent to the language model to initiate the response that contained the tool call.
1278
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
1279
- */
1280
- readonly messages: ModelMessage[];
1046
+ type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
1047
+
1048
+ type BaseToolCall = {
1049
+ type: 'tool-call';
1050
+ toolCallId: string;
1051
+ providerExecuted?: boolean;
1052
+ providerMetadata?: ProviderMetadata;
1281
1053
  };
1282
1054
  /**
1283
- * Precise end event union for statically known tools.
1284
- *
1285
- * Each union member preserves the link between `toolCall.toolName`, the
1286
- * corresponding validated `toolContext`, and the tool execution result.
1055
+ * A tool call whose `toolName` maps to a tool in the declared tool set,
1056
+ * with an `input` type inferred from that tool's input schema.
1287
1057
  */
1288
- type StaticToolExecutionEndEvent<TOOLS extends ToolSet> = ValueOf<{
1289
- [NAME in keyof TOOLS]: BaseToolExecutionEndFields & {
1290
- readonly toolCall: Extract<StaticToolCall<TOOLS>, {
1291
- toolName: NAME;
1292
- }>;
1293
- readonly toolContext: ToolContextFor<TOOLS[NAME]>;
1294
- readonly toolOutput: ToolOutput<TOOLS>;
1058
+ type StaticToolCall<TOOLS extends ToolSet> = ValueOf<{
1059
+ [NAME in keyof TOOLS]: BaseToolCall & {
1060
+ toolName: NAME & string;
1061
+ input: InferToolInput<TOOLS[NAME]>;
1062
+ dynamic?: false | undefined;
1063
+ invalid?: false | undefined;
1064
+ error?: never;
1065
+ title?: string;
1295
1066
  };
1296
1067
  }>;
1297
1068
  /**
1298
- * End event shape for dynamic or untyped tool calls.
1299
- */
1300
- type DynamicToolExecutionEndEvent<TOOLS extends ToolSet> = BaseToolExecutionEndFields & {
1301
- readonly toolCall: DynamicToolCall;
1302
- readonly toolContext: unknown;
1303
- readonly toolOutput: ToolOutput<TOOLS>;
1304
- };
1305
- /**
1306
- * Broad end event shape used for the default `ToolSet` specialization.
1307
- *
1308
- * This provides an assignable catch-all event type for generic consumers while
1309
- * the concrete-tool specialization retains full per-tool narrowing.
1069
+ * A tool call whose `toolName` is only known at runtime, such as an invalid
1070
+ * or otherwise untyped call that cannot be matched to the declared tool set.
1310
1071
  */
1311
- type WidenedToolExecutionEndEvent = BaseToolExecutionEndFields & {
1312
- readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
1313
- readonly toolContext: unknown;
1314
- readonly toolOutput: ToolOutput<ToolSet>;
1072
+ type DynamicToolCall = BaseToolCall & {
1073
+ toolName: string;
1074
+ input: unknown;
1075
+ dynamic: true;
1076
+ title?: string;
1077
+ /**
1078
+ * True if this is caused by an unparsable tool call or
1079
+ * a tool that does not exist.
1080
+ */
1081
+ invalid?: boolean;
1082
+ /**
1083
+ * The error that caused the tool call to be invalid.
1084
+ */
1085
+ error?: unknown;
1315
1086
  };
1316
1087
  /**
1317
- * Event passed to the `onToolExecutionEnd` callback.
1318
- *
1319
- * Called when a tool execution completes, either successfully or with an error.
1320
- * Uses the `toolOutput.type` discriminator to distinguish success and error.
1321
- */
1322
- type ToolExecutionEndEvent<TOOLS extends ToolSet = ToolSet> = [
1323
- ToolSet
1324
- ] extends [TOOLS] ? WidenedToolExecutionEndEvent : StaticToolExecutionEndEvent<TOOLS> | DynamicToolExecutionEndEvent<TOOLS>;
1325
- /**
1326
- * Callback that is set using the `experimental_onToolExecutionStart` option.
1327
- *
1328
- * Called when a tool execution begins, before the tool's `execute` function is invoked.
1329
- * Use this for logging tool invocations, tracking tool usage, or pre-execution validation.
1330
- *
1331
- * @param event - The event object containing tool call information.
1088
+ * A tool call returned by text generation, either statically typed from the
1089
+ * declared tool set or dynamically typed when the tool cannot be inferred.
1332
1090
  */
1333
- type OnToolExecutionStartCallback<TOOLS extends ToolSet = ToolSet> = Callback<ToolExecutionStartEvent<TOOLS>>;
1091
+ type TypedToolCall<TOOLS extends ToolSet> = StaticToolCall<TOOLS> | DynamicToolCall;
1092
+
1334
1093
  /**
1335
- * Callback that is set using the `experimental_onToolExecutionEnd` option.
1336
- *
1337
- * Called when a tool execution completes, either successfully or with an error.
1338
- * Use this for logging tool results, tracking execution time, or error handling.
1339
- *
1340
- * The event uses a discriminated union on `toolOutput.type`:
1341
- * - When `toolOutput.type === 'tool-result'`: `toolOutput.output` contains the tool result.
1342
- * - When `toolOutput.type === 'tool-error'`: `toolOutput.error` contains the error.
1094
+ * Output part that indicates that a tool approval request has been made.
1343
1095
  *
1344
- * @param event - The event object containing tool call result information.
1096
+ * The tool approval request can be approved or denied in the next tool message.
1345
1097
  */
1346
- type OnToolExecutionEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<ToolExecutionEndEvent<TOOLS>>;
1347
- /** @deprecated Use `ToolExecutionStartEvent` instead. */
1348
- type OnToolCallStartEvent<TOOLS extends ToolSet = ToolSet> = ToolExecutionStartEvent<TOOLS>;
1349
- /** @deprecated Use `ToolExecutionEndEvent` instead. */
1350
- type OnToolCallFinishEvent<TOOLS extends ToolSet = ToolSet> = ToolExecutionEndEvent<TOOLS>;
1098
+ type ToolApprovalRequestOutput<TOOLS extends ToolSet> = {
1099
+ type: 'tool-approval-request';
1100
+ /**
1101
+ * ID of the tool approval request.
1102
+ */
1103
+ approvalId: string;
1104
+ /**
1105
+ * Tool call that the approval request is for.
1106
+ */
1107
+ toolCall: TypedToolCall<TOOLS>;
1108
+ /**
1109
+ * Flag indicating whether the tool was automatically approved or denied.
1110
+ *
1111
+ * @default false
1112
+ */
1113
+ isAutomatic?: boolean;
1114
+ };
1351
1115
 
1352
1116
  /**
1353
- * Event passed to the `onStart` callback for rerank operations.
1354
- *
1355
- * Called when the operation begins, before the reranking model is called.
1117
+ * Output part that indicates that a tool approval response is available.
1356
1118
  */
1357
- type RerankStartEvent = {
1358
- /** Unique identifier for this rerank call, used to correlate events. */
1359
- readonly callId: string;
1360
- /** Identifies the operation type ('ai.rerank'). */
1361
- readonly operationId: string;
1362
- readonly provider: string;
1363
- /** The specific model identifier (e.g., 'gpt-4o'). */
1364
- readonly modelId: string;
1365
- /** The documents being reranked. */
1366
- readonly documents: Array<JSONObject | string>;
1367
- /** The query to rerank the documents against. */
1368
- readonly query: string;
1369
- /** Number of top documents to return. */
1370
- readonly topN: number | undefined;
1371
- /** Maximum number of retries for failed requests. */
1372
- readonly maxRetries: number;
1373
- /** Additional HTTP headers sent with the request. */
1374
- readonly headers: Record<string, string | undefined> | undefined;
1375
- /** Additional provider-specific options. */
1376
- readonly providerOptions: ProviderOptions | undefined;
1119
+ type ToolApprovalResponseOutput<TOOLS extends ToolSet> = {
1120
+ type: 'tool-approval-response';
1121
+ /**
1122
+ * ID of the tool approval.
1123
+ */
1124
+ approvalId: string;
1125
+ /**
1126
+ * Tool call that the approval response is for.
1127
+ */
1128
+ toolCall: TypedToolCall<TOOLS>;
1129
+ /**
1130
+ * Flag indicating whether the approval was granted or denied.
1131
+ */
1132
+ approved: boolean;
1133
+ /**
1134
+ * Optional reason for the approval or denial.
1135
+ */
1136
+ reason?: string;
1137
+ /**
1138
+ * Flag indicating whether the tool call is provider-executed.
1139
+ * Only provider-executed tool approval responses should be sent to the model.
1140
+ */
1141
+ providerExecuted?: boolean;
1142
+ };
1143
+
1144
+ type StaticToolError<TOOLS extends ToolSet> = ValueOf<{
1145
+ [NAME in keyof TOOLS]: {
1146
+ type: 'tool-error';
1147
+ toolCallId: string;
1148
+ toolName: NAME & string;
1149
+ input: InferToolInput<TOOLS[NAME]>;
1150
+ error: unknown;
1151
+ providerExecuted?: boolean;
1152
+ providerMetadata?: ProviderMetadata;
1153
+ dynamic?: false | undefined;
1154
+ title?: string;
1155
+ };
1156
+ }>;
1157
+ type DynamicToolError = {
1158
+ type: 'tool-error';
1159
+ toolCallId: string;
1160
+ toolName: string;
1161
+ input: unknown;
1162
+ error: unknown;
1163
+ providerExecuted?: boolean;
1164
+ providerMetadata?: ProviderMetadata;
1165
+ dynamic: true;
1166
+ title?: string;
1167
+ };
1168
+ type TypedToolError<TOOLS extends ToolSet> = StaticToolError<TOOLS> | DynamicToolError;
1169
+
1170
+ type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{
1171
+ [NAME in keyof TOOLS]: {
1172
+ type: 'tool-result';
1173
+ toolCallId: string;
1174
+ toolName: NAME & string;
1175
+ input: InferToolInput<TOOLS[NAME]>;
1176
+ output: InferToolOutput<TOOLS[NAME]>;
1177
+ providerExecuted?: boolean;
1178
+ providerMetadata?: ProviderMetadata;
1179
+ dynamic?: false | undefined;
1180
+ preliminary?: boolean;
1181
+ title?: string;
1182
+ };
1183
+ }>;
1184
+ type DynamicToolResult = {
1185
+ type: 'tool-result';
1186
+ toolCallId: string;
1187
+ toolName: string;
1188
+ input: unknown;
1189
+ output: unknown;
1190
+ providerExecuted?: boolean;
1191
+ providerMetadata?: ProviderMetadata;
1192
+ dynamic: true;
1193
+ preliminary?: boolean;
1194
+ title?: string;
1377
1195
  };
1196
+ type TypedToolResult<TOOLS extends ToolSet> = StaticToolResult<TOOLS> | DynamicToolResult;
1197
+
1198
+ type ContentPart<TOOLS extends ToolSet> = {
1199
+ type: 'text';
1200
+ text: string;
1201
+ providerMetadata?: ProviderMetadata;
1202
+ } | {
1203
+ type: 'custom';
1204
+ kind: `${string}.${string}`;
1205
+ providerMetadata?: ProviderMetadata;
1206
+ } | ReasoningOutput | ReasoningFileOutput | ({
1207
+ type: 'source';
1208
+ } & Source) | {
1209
+ type: 'file';
1210
+ file: GeneratedFile;
1211
+ providerMetadata?: ProviderMetadata;
1212
+ } | ({
1213
+ type: 'tool-call';
1214
+ } & TypedToolCall<TOOLS> & {
1215
+ providerMetadata?: ProviderMetadata;
1216
+ }) | ({
1217
+ type: 'tool-result';
1218
+ } & TypedToolResult<TOOLS> & {
1219
+ providerMetadata?: ProviderMetadata;
1220
+ }) | ({
1221
+ type: 'tool-error';
1222
+ } & TypedToolError<TOOLS> & {
1223
+ providerMetadata?: ProviderMetadata;
1224
+ }) | ToolApprovalRequestOutput<TOOLS> | ToolApprovalResponseOutput<TOOLS>;
1225
+
1226
+ declare const systemModelMessageSchema: z.ZodType<SystemModelMessage>;
1227
+ declare const userModelMessageSchema: z.ZodType<UserModelMessage>;
1228
+ declare const assistantModelMessageSchema: z.ZodType<AssistantModelMessage>;
1229
+ declare const toolModelMessageSchema: z.ZodType<ToolModelMessage>;
1230
+ declare const modelMessageSchema: z.ZodType<ModelMessage>;
1231
+
1378
1232
  /**
1379
- * Event passed to the `onFinish` callback for rerank operations.
1233
+ * Converts data content to a base64-encoded string.
1380
1234
  *
1381
- * Called when the operation completes, after the reranking model returns.
1235
+ * @param content - Data content to convert.
1236
+ * @returns Base64-encoded string.
1382
1237
  */
1383
- type RerankEndEvent = {
1384
- /** Unique identifier for this rerank call, used to correlate events. */
1385
- readonly callId: string;
1386
- /** Identifies the operation type ('ai.rerank'). */
1387
- readonly operationId: string;
1238
+ declare function convertDataContentToBase64String(content: DataContent): string;
1239
+
1240
+ /** @deprecated Use `LanguageModelCallOptions` combined with `RequestOptions` instead. */
1241
+ type CallSettings = LanguageModelCallOptions & Omit<RequestOptions, 'timeout'>;
1242
+
1243
+ /**
1244
+ * Common model information used across callback events.
1245
+ */
1246
+ type ModelInfo = {
1247
+ /** The provider identifier (e.g., 'openai', 'anthropic'). */
1388
1248
  readonly provider: string;
1389
1249
  /** The specific model identifier (e.g., 'gpt-4o'). */
1390
1250
  readonly modelId: string;
1391
- /** The documents that were reranked. */
1392
- readonly documents: Array<JSONObject | string>;
1393
- /** The query that documents were reranked against. */
1394
- readonly query: string;
1395
- /** The reranked results sorted by relevance score in descending order. */
1396
- readonly ranking: Array<{
1397
- originalIndex: number;
1398
- score: number;
1399
- document: JSONObject | string;
1400
- }>;
1401
- /** Warnings from the reranking model. */
1402
- readonly warnings: Array<Warning>;
1403
- /** Optional provider-specific metadata. */
1404
- readonly providerMetadata: ProviderMetadata | undefined;
1405
- /** Response data including headers and body. */
1406
- readonly response: {
1407
- id?: string;
1408
- timestamp: Date;
1409
- modelId: string;
1410
- headers?: Record<string, string>;
1411
- body?: unknown;
1412
- };
1413
1251
  };
1414
1252
  /**
1415
- * Event fired when an individual reranking model call (inner doRerank) begins.
1253
+ * Event passed to the `onLanguageModelCallStart` callback.
1254
+ *
1255
+ * Called immediately before the provider model call begins.
1256
+ * Unlike `onStepStart`, this only represents model invocation work.
1416
1257
  */
1417
- type RerankingModelCallStartEvent = {
1418
- /** Unique identifier for this rerank call, used to correlate events. */
1258
+ type LanguageModelCallStartEvent = ModelInfo & {
1259
+ /** Unique identifier for this generation call, used to correlate events. */
1419
1260
  readonly callId: string;
1420
- /** Identifies the inner operation ('ai.rerank.doRerank'). */
1421
- readonly operationId: string;
1422
- /** The provider identifier. */
1423
- readonly provider: string;
1424
- /** The specific model identifier. */
1425
- readonly modelId: string;
1426
- /** The documents being reranked. */
1427
- readonly documents: Array<JSONObject | string>;
1428
- /** The type of documents ('text' or 'object'). */
1429
- readonly documentsType: string;
1430
- /** The query to rerank against. */
1431
- readonly query: string;
1432
- /** Number of top documents to return. */
1433
- readonly topN: number | undefined;
1434
- };
1261
+ /** Prepared tool definitions for the model call, if any. */
1262
+ readonly tools: ReadonlyArray<Record<string, unknown>> | undefined;
1263
+ } & StandardizedPrompt & LanguageModelCallOptions;
1435
1264
  /**
1436
- * Event fired when an individual reranking model call (doRerank) completes.
1265
+ * Event passed to the `onLanguageModelCallEnd` callback.
1437
1266
  *
1438
- * Contains the ranking results from the model response.
1267
+ * Called after the model response has been normalized and parsed, but before
1268
+ * any client-side tool execution begins.
1439
1269
  */
1440
- type RerankingModelCallEndEvent = {
1441
- /** Unique identifier for this rerank call, used to correlate events. */
1270
+ type LanguageModelCallEndEvent<TOOLS extends ToolSet = ToolSet> = ModelInfo & {
1271
+ /** Unique identifier for this generation call, used to correlate events. */
1442
1272
  readonly callId: string;
1443
- /** Identifies the inner operation ('ai.rerank.doRerank'). */
1444
- readonly operationId: string;
1445
- /** The provider identifier. */
1446
- readonly provider: string;
1447
- /** The specific model identifier. */
1448
- readonly modelId: string;
1449
- /** The type of documents ('text' or 'object'). */
1450
- readonly documentsType: string;
1451
- /** The ranking results from the model. */
1452
- readonly ranking: Array<{
1453
- index: number;
1454
- relevanceScore: number;
1455
- }>;
1273
+ /** The unified reason why the model call finished. */
1274
+ readonly finishReason: FinishReason;
1275
+ /** The token usage reported by the model call. */
1276
+ readonly usage: LanguageModelUsage;
1277
+ /** The content parts produced by the model call. */
1278
+ readonly content: ReadonlyArray<ContentPart<TOOLS>>;
1279
+ /** The provider-returned response id for this model call. */
1280
+ readonly responseId: string;
1456
1281
  };
1457
-
1458
- type InferTelemetryEvent<EVENT> = EVENT & Omit<TelemetryOptions, 'integrations' | 'isEnabled'>;
1459
- type OperationStartEvent = GenerateTextStartEvent | GenerateObjectStartEvent | EmbedStartEvent | RerankStartEvent;
1460
- type OperationFinishEvent = GenerateTextEndEvent<ToolSet> | GenerateObjectEndEvent<unknown> | EmbedEndEvent | RerankEndEvent;
1461
1282
  /**
1462
- * Implement this interface to create custom telemetry integrations.
1463
- * Methods can be sync or return a PromiseLike.
1283
+ * Callback that is set using the `experimental_onLanguageModelCallStart` option.
1284
+ *
1285
+ * Called immediately before the provider model call begins.
1286
+ * Unlike step-start callbacks, this is scoped to model work only and
1287
+ * excludes any later client-side tool execution.
1288
+ *
1289
+ * @param event - The event object containing model-call-specific inputs.
1464
1290
  */
1465
- interface Telemetry {
1466
- /**
1467
- * Called when an operation begins. Fired for text generation
1468
- * (generateText/streamText), object generation (generateObject/streamObject),
1469
- * embedding (embed/embedMany), and reranking operations.
1470
- *
1471
- * Use the `operationId` field to distinguish between operation types.
1472
- */
1473
- onStart?: Callback<InferTelemetryEvent<OperationStartEvent>>;
1474
- /**
1475
- * Called when an individual step (single LLM invocation) begins.
1476
- * A generation may consist of multiple steps (e.g. when tool calls trigger
1477
- * follow-up LLM calls). Use this to create per-step spans or record
1478
- * step-level inputs.
1479
- *
1480
- * The event includes the step number, accumulated previous step results,
1481
- * and the messages that will be sent to the model.
1482
- */
1483
- onStepStart?: Callback<InferTelemetryEvent<GenerateTextStepStartEvent>>;
1484
- /**
1485
- * Called immediately before the provider model call begins.
1486
- * Unlike `onStepStart`, this callback is scoped to model work only and
1487
- * excludes any later client-side tool execution.
1488
- */
1489
- onLanguageModelCallStart?: Callback<InferTelemetryEvent<LanguageModelCallStartEvent>>;
1490
- /**
1491
- * Called after the model response has been normalized and parsed, but before
1492
- * any client-side tool execution begins.
1493
- */
1494
- onLanguageModelCallEnd?: Callback<InferTelemetryEvent<LanguageModelCallEndEvent>>;
1495
- /**
1496
- * Called when a tool execution begins, before the tool's `execute` function
1497
- * is invoked. Use this to create tool-level spans or log tool invocations.
1498
- */
1499
- onToolExecutionStart?: Callback<InferTelemetryEvent<ToolExecutionStartEvent>>;
1500
- /**
1501
- * Called when a tool execution completes, either successfully or with an error.
1502
- * The event uses a discriminated union on the `success` field — check
1503
- * `event.success` to determine whether `output` or `error` is available.
1504
- *
1505
- * The event includes execution duration (`durationMs`) for performance tracking.
1506
- */
1507
- onToolExecutionEnd?: Callback<InferTelemetryEvent<ToolExecutionEndEvent>>;
1508
- /**
1509
- * Called for each chunk received during streaming.
1510
- * Only relevant for `streamText` — not called during `generateText`.
1511
- */
1512
- onChunk?: Callback<StreamTextChunkEvent>;
1513
- /**
1514
- * Called when an individual step (single LLM invocation) completes.
1515
- * The event is a `StepResult` containing the model's response, tool calls
1516
- * and results, usage statistics, finish reason, and optional request/response
1517
- * bodies.
1518
- */
1519
- onStepFinish?: Callback<InferTelemetryEvent<GenerateTextStepEndEvent>>;
1520
- /**
1521
- * Called when an object generation step (single LLM invocation) begins.
1522
- * For generateObject/streamObject there is always exactly one step.
1523
- *
1524
- * @deprecated
1525
- */
1526
- onObjectStepStart?: Callback<InferTelemetryEvent<GenerateObjectStepStartEvent>>;
1527
- /**
1528
- * Called when an object generation step (single LLM invocation) completes,
1529
- * with the raw result before JSON parsing and schema validation.
1530
- *
1531
- * @deprecated
1532
- */
1533
- onObjectStepFinish?: Callback<InferTelemetryEvent<GenerateObjectStepEndEvent>>;
1534
- /**
1535
- * Called when an individual embedding model call (doEmbed) begins.
1536
- * For `embed`, there is one call. For `embedMany`, there may be multiple
1537
- * calls when values are chunked.
1538
- */
1539
- onEmbedStart?: Callback<InferTelemetryEvent<EmbeddingModelCallStartEvent>>;
1540
- /**
1541
- * Called when an individual embedding model call (doEmbed) completes.
1542
- * Contains the embeddings, usage, and any warnings from the model response.
1543
- */
1544
- onEmbedFinish?: Callback<InferTelemetryEvent<EmbeddingModelCallEndEvent>>;
1545
- /**
1546
- * Called when an individual reranking model call (doRerank) begins.
1547
- * There is one call per `rerank` invocation.
1548
- */
1549
- onRerankStart?: Callback<InferTelemetryEvent<RerankingModelCallStartEvent>>;
1550
- /**
1551
- * Called when an individual reranking model call (doRerank) completes.
1552
- * Contains the ranking results from the model response.
1553
- */
1554
- onRerankFinish?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>;
1555
- /**
1556
- * Called when an operation completes. Fired for text generation
1557
- * (generateText/streamText), object generation (generateObject/streamObject),
1558
- * embedding (embed/embedMany), and reranking operations.
1559
- *
1560
- * Use the event shape or `operationId` to distinguish between operation types.
1561
- */
1562
- onFinish?: Callback<InferTelemetryEvent<OperationFinishEvent>>;
1563
- /**
1564
- * Called when an unrecoverable error occurs during the generation lifecycle.
1565
- * The error value is untyped — it may be an `Error` instance, an `AISDKError`,
1566
- * or any thrown value.
1567
- *
1568
- * Use this to record error details on telemetry spans and set error status.
1569
- */
1570
- onError?: Callback<unknown>;
1571
- /**
1572
- * Optionally runs the tool execute function in a telemetry-integration-specific context. This enables
1573
- * nested traces — e.g. when a tool's `execute` function calls `generateText`,
1574
- * the inner call's spans become children of the tool span.
1575
- *
1576
- * @param options.callId - The call ID of the tool call.
1577
- * @param options.toolCallId - The tool call ID.
1578
- * @param options.execute - The function to execute.
1579
- */
1580
- executeTool?: <T>(options: {
1581
- callId: string;
1582
- toolCallId: string;
1583
- execute: () => PromiseLike<T>;
1584
- }) => PromiseLike<T>;
1585
- }
1586
-
1587
- /**
1588
- * Telemetry configuration.
1589
- */
1590
- type TelemetryOptions = {
1591
- /**
1592
- * Enable or disable telemetry. Enabled by default when a telemetry
1593
- * integration is registered. Set to `false` to opt out.
1594
- */
1595
- isEnabled?: boolean;
1596
- /**
1597
- * Enable or disable input recording. Enabled by default.
1598
- *
1599
- * You might want to disable input recording to avoid recording sensitive
1600
- * information, to reduce data transfers, or to increase performance.
1601
- */
1602
- recordInputs?: boolean;
1603
- /**
1604
- * Enable or disable output recording. Enabled by default.
1605
- *
1606
- * You might want to disable output recording to avoid recording sensitive
1607
- * information, to reduce data transfers, or to increase performance.
1608
- */
1609
- recordOutputs?: boolean;
1610
- /**
1611
- * Identifier for this function. Used to group telemetry data by function.
1612
- */
1613
- functionId?: string;
1614
- /**
1615
- * Per-call telemetry integrations that receive lifecycle events during generation.
1616
- *
1617
- * When provided, these integrations will take precedence over the globally registered
1618
- * integrations for this call.
1619
- */
1620
- integrations?: Arrayable<Telemetry>;
1621
- };
1622
-
1291
+ type OnLanguageModelCallStartCallback = Callback<LanguageModelCallStartEvent>;
1623
1292
  /**
1624
- * Experimental. Can change in patch versions without warning.
1625
- *
1626
- * Download function. Called with the array of URLs and a boolean indicating
1627
- * whether the URL is supported by the model.
1628
- *
1629
- * The download function can decide for each URL:
1630
- * - to return null (which means that the URL should be passed to the model)
1631
- * - to download the asset and return the data (incl. retries, authentication, etc.)
1293
+ * Callback that is set using the `experimental_onLanguageModelCallEnd` option.
1632
1294
  *
1633
- * Should throw DownloadError if the download fails.
1295
+ * Called after the model response has been normalized and parsed, but before
1296
+ * any client-side tool execution begins.
1634
1297
  *
1635
- * Should return an array of objects sorted by the order of the requested downloads.
1636
- * For each object, the data should be a Uint8Array if the URL was downloaded.
1637
- * For each object, the mediaType should be the media type of the downloaded asset.
1638
- * For each object, the data should be null if the URL should be passed through as is.
1298
+ * @param event - The event object containing model-call-specific outputs.
1639
1299
  */
1640
- type DownloadFunction = (options: Array<{
1641
- url: URL;
1642
- isUrlSupportedByModel: boolean;
1643
- }>) => PromiseLike<Array<{
1644
- data: Uint8Array;
1645
- mediaType: string | undefined;
1646
- } | null>>;
1300
+ type OnLanguageModelCallEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<LanguageModelCallEndEvent<TOOLS>>;
1647
1301
 
1648
1302
  /**
1649
1303
  * A message that was generated during the generation process.
@@ -2025,7 +1679,14 @@ type SourceDocumentUIPart = {
2025
1679
  type FileUIPart = {
2026
1680
  type: 'file';
2027
1681
  /**
2028
- * IANA media type of the file.
1682
+ * Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
1683
+ * the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
1684
+ *
1685
+ * `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
1686
+ * top-level segment alone (e.g. `image`). Providers can use the helpers in
1687
+ * `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
1688
+ * `detectMediaType`) to resolve the field according to their API
1689
+ * requirements.
2029
1690
  *
2030
1691
  * @see https://www.iana.org/assignments/media-types/media-types.xhtml
2031
1692
  */
@@ -3243,62 +2904,200 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
3243
2904
  error: NoSuchToolError | InvalidToolInputError;
3244
2905
  }) => Promise<LanguageModelV4ToolCall | null>;
3245
2906
 
3246
- /**
3247
- * Helper type to make the toolsContext parameter optional or required based on the tool set.
3248
- */
3249
- type ToolsContextParameter<TOOLS extends ToolSet> = {
3250
- tools?: TOOLS;
3251
- } & (HasRequiredKey<InferToolSetContext<TOOLS>> extends true ? {
3252
- toolsContext: InferToolSetContext<TOOLS>;
3253
- } : {
3254
- toolsContext?: never;
3255
- });
2907
+ type ToolOutput<TOOLS extends ToolSet> = TypedToolResult<TOOLS> | TypedToolError<TOOLS>;
3256
2908
 
3257
2909
  /**
3258
- * A transformation that is applied to the stream.
3259
- *
3260
- * @param stopStream - A function that stops the source stream.
3261
- * @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
2910
+ * Resolves a single tool's context type, falling back to `undefined` when the
2911
+ * tool does not declare a `contextSchema`.
3262
2912
  */
3263
- type StreamTextTransform<TOOLS extends ToolSet> = (options: {
3264
- tools: TOOLS;
3265
- stopStream: () => void;
3266
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
2913
+ type ToolContextFor<TOOL extends ToolSet[keyof ToolSet]> = [
2914
+ InferToolContext<TOOL>
2915
+ ] extends [never] ? undefined : InferToolContext<TOOL>;
2916
+ type BaseToolExecutionStartFields = {
2917
+ /** Unique identifier for this generation call, used to correlate events. */
2918
+ readonly callId: string;
2919
+ /**
2920
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
2921
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
2922
+ */
2923
+ readonly messages: ModelMessage[];
2924
+ };
3267
2925
  /**
3268
- * Callback that is set using the `onError` option.
2926
+ * Precise start event union for statically known tools.
3269
2927
  *
3270
- * @param event - The event that is passed to the callback.
2928
+ * Each union member ties a specific `toolCall.toolName` to that tool's
2929
+ * validated `toolContext` type.
3271
2930
  */
3272
- type StreamTextOnErrorCallback = Callback<{
3273
- error: unknown;
2931
+ type StaticToolExecutionStartEvent<TOOLS extends ToolSet> = ValueOf<{
2932
+ [NAME in keyof TOOLS]: BaseToolExecutionStartFields & {
2933
+ readonly toolCall: Extract<StaticToolCall<TOOLS>, {
2934
+ toolName: NAME;
2935
+ }>;
2936
+ readonly toolContext: ToolContextFor<TOOLS[NAME]>;
2937
+ };
3274
2938
  }>;
3275
2939
  /**
3276
- * Callback that is set using the `onChunk` option.
3277
- *
3278
- * @param event - The event that is passed to the callback.
2940
+ * Start event shape for dynamic or untyped tool calls.
3279
2941
  */
3280
- type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3281
- chunk: Extract<TextStreamPart<TOOLS>, {
3282
- type: 'text-delta' | 'reasoning-delta' | 'custom' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
3283
- }>;
3284
- }) => PromiseLike<void> | void;
2942
+ type DynamicToolExecutionStartEvent = BaseToolExecutionStartFields & {
2943
+ readonly toolCall: DynamicToolCall;
2944
+ readonly toolContext: unknown;
2945
+ };
3285
2946
  /**
3286
- * Callback that is set using the `onAbort` option.
2947
+ * Broad start event shape used for the default `ToolSet` specialization.
3287
2948
  *
3288
- * @param event - The event that is passed to the callback.
2949
+ * This keeps generic collectors ergonomic when the caller is not working with
2950
+ * a concrete tool set and therefore cannot benefit from per-tool narrowing.
3289
2951
  */
3290
- type StreamTextOnAbortCallback<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = Callback<{
3291
- /**
3292
- * Details for all previously finished steps.
3293
- */
3294
- readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
3295
- }>;
2952
+ type WidenedToolExecutionStartEvent = BaseToolExecutionStartFields & {
2953
+ readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
2954
+ readonly toolContext: unknown;
2955
+ };
3296
2956
  /**
3297
- * Generate a text and call tools for a given prompt using a language model.
3298
- *
3299
- * This function streams the output. If you do not want to stream the output, use `generateText` instead.
2957
+ * Event passed to the `onToolExecutionStart` callback.
3300
2958
  *
3301
- * @param model - The language model to use.
2959
+ * Called when a tool execution begins, before the tool's `execute` function is invoked.
2960
+ */
2961
+ type ToolExecutionStartEvent<TOOLS extends ToolSet = ToolSet> = [
2962
+ ToolSet
2963
+ ] extends [TOOLS] ? WidenedToolExecutionStartEvent : StaticToolExecutionStartEvent<TOOLS> | DynamicToolExecutionStartEvent;
2964
+ type BaseToolExecutionEndFields = {
2965
+ /** Unique identifier for this generation call, used to correlate events. */
2966
+ readonly callId: string;
2967
+ /** Execution time of the tool call in milliseconds. */
2968
+ readonly durationMs: number;
2969
+ /**
2970
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
2971
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
2972
+ */
2973
+ readonly messages: ModelMessage[];
2974
+ };
2975
+ /**
2976
+ * Precise end event union for statically known tools.
2977
+ *
2978
+ * Each union member preserves the link between `toolCall.toolName`, the
2979
+ * corresponding validated `toolContext`, and the tool execution result.
2980
+ */
2981
+ type StaticToolExecutionEndEvent<TOOLS extends ToolSet> = ValueOf<{
2982
+ [NAME in keyof TOOLS]: BaseToolExecutionEndFields & {
2983
+ readonly toolCall: Extract<StaticToolCall<TOOLS>, {
2984
+ toolName: NAME;
2985
+ }>;
2986
+ readonly toolContext: ToolContextFor<TOOLS[NAME]>;
2987
+ readonly toolOutput: ToolOutput<TOOLS>;
2988
+ };
2989
+ }>;
2990
+ /**
2991
+ * End event shape for dynamic or untyped tool calls.
2992
+ */
2993
+ type DynamicToolExecutionEndEvent<TOOLS extends ToolSet> = BaseToolExecutionEndFields & {
2994
+ readonly toolCall: DynamicToolCall;
2995
+ readonly toolContext: unknown;
2996
+ readonly toolOutput: ToolOutput<TOOLS>;
2997
+ };
2998
+ /**
2999
+ * Broad end event shape used for the default `ToolSet` specialization.
3000
+ *
3001
+ * This provides an assignable catch-all event type for generic consumers while
3002
+ * the concrete-tool specialization retains full per-tool narrowing.
3003
+ */
3004
+ type WidenedToolExecutionEndEvent = BaseToolExecutionEndFields & {
3005
+ readonly toolCall: StaticToolCall<ToolSet> | DynamicToolCall;
3006
+ readonly toolContext: unknown;
3007
+ readonly toolOutput: ToolOutput<ToolSet>;
3008
+ };
3009
+ /**
3010
+ * Event passed to the `onToolExecutionEnd` callback.
3011
+ *
3012
+ * Called when a tool execution completes, either successfully or with an error.
3013
+ * Uses the `toolOutput.type` discriminator to distinguish success and error.
3014
+ */
3015
+ type ToolExecutionEndEvent<TOOLS extends ToolSet = ToolSet> = [
3016
+ ToolSet
3017
+ ] extends [TOOLS] ? WidenedToolExecutionEndEvent : StaticToolExecutionEndEvent<TOOLS> | DynamicToolExecutionEndEvent<TOOLS>;
3018
+ /**
3019
+ * Callback that is set using the `experimental_onToolExecutionStart` option.
3020
+ *
3021
+ * Called when a tool execution begins, before the tool's `execute` function is invoked.
3022
+ * Use this for logging tool invocations, tracking tool usage, or pre-execution validation.
3023
+ *
3024
+ * @param event - The event object containing tool call information.
3025
+ */
3026
+ type OnToolExecutionStartCallback<TOOLS extends ToolSet = ToolSet> = Callback<ToolExecutionStartEvent<TOOLS>>;
3027
+ /**
3028
+ * Callback that is set using the `experimental_onToolExecutionEnd` option.
3029
+ *
3030
+ * Called when a tool execution completes, either successfully or with an error.
3031
+ * Use this for logging tool results, tracking execution time, or error handling.
3032
+ *
3033
+ * The event uses a discriminated union on `toolOutput.type`:
3034
+ * - When `toolOutput.type === 'tool-result'`: `toolOutput.output` contains the tool result.
3035
+ * - When `toolOutput.type === 'tool-error'`: `toolOutput.error` contains the error.
3036
+ *
3037
+ * @param event - The event object containing tool call result information.
3038
+ */
3039
+ type OnToolExecutionEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<ToolExecutionEndEvent<TOOLS>>;
3040
+ /** @deprecated Use `ToolExecutionStartEvent` instead. */
3041
+ type OnToolCallStartEvent<TOOLS extends ToolSet = ToolSet> = ToolExecutionStartEvent<TOOLS>;
3042
+ /** @deprecated Use `ToolExecutionEndEvent` instead. */
3043
+ type OnToolCallFinishEvent<TOOLS extends ToolSet = ToolSet> = ToolExecutionEndEvent<TOOLS>;
3044
+
3045
+ /**
3046
+ * Helper type to make the toolsContext parameter optional or required based on the tool set.
3047
+ */
3048
+ type ToolsContextParameter<TOOLS extends ToolSet> = {
3049
+ tools?: TOOLS;
3050
+ } & (HasRequiredKey<InferToolSetContext<TOOLS>> extends true ? {
3051
+ toolsContext: InferToolSetContext<TOOLS>;
3052
+ } : {
3053
+ toolsContext?: never;
3054
+ });
3055
+
3056
+ /**
3057
+ * A transformation that is applied to the stream.
3058
+ *
3059
+ * @param stopStream - A function that stops the source stream.
3060
+ * @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
3061
+ */
3062
+ type StreamTextTransform<TOOLS extends ToolSet> = (options: {
3063
+ tools: TOOLS;
3064
+ stopStream: () => void;
3065
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3066
+ /**
3067
+ * Callback that is set using the `onError` option.
3068
+ *
3069
+ * @param event - The event that is passed to the callback.
3070
+ */
3071
+ type StreamTextOnErrorCallback = Callback<{
3072
+ error: unknown;
3073
+ }>;
3074
+ /**
3075
+ * Callback that is set using the `onChunk` option.
3076
+ *
3077
+ * @param event - The event that is passed to the callback.
3078
+ */
3079
+ type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3080
+ chunk: Extract<TextStreamPart<TOOLS>, {
3081
+ type: 'text-delta' | 'reasoning-delta' | 'custom' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
3082
+ }>;
3083
+ }) => PromiseLike<void> | void;
3084
+ /**
3085
+ * Callback that is set using the `onAbort` option.
3086
+ *
3087
+ * @param event - The event that is passed to the callback.
3088
+ */
3089
+ type StreamTextOnAbortCallback<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = Callback<{
3090
+ /**
3091
+ * Details for all previously finished steps.
3092
+ */
3093
+ readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
3094
+ }>;
3095
+ /**
3096
+ * Generate a text and call tools for a given prompt using a language model.
3097
+ *
3098
+ * This function streams the output. If you do not want to stream the output, use `generateText` instead.
3099
+ *
3100
+ * @param model - The language model to use.
3302
3101
  * @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
3303
3102
  *
3304
3103
  * @param system - A system message that will be part of the prompt.
@@ -3486,342 +3285,607 @@ declare function streamText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Conte
3486
3285
  */
3487
3286
  experimental_onToolExecutionEnd?: OnToolExecutionEndCallback<NoInfer<TOOLS>>;
3488
3287
  /**
3489
- * Settings for controlling what data is included in step results.
3490
- * Disabling inclusion can help reduce memory usage when processing
3491
- * large payloads like images.
3288
+ * Settings for controlling what data is included in step results.
3289
+ * Disabling inclusion can help reduce memory usage when processing
3290
+ * large payloads like images.
3291
+ *
3292
+ * By default, all data is included for backwards compatibility.
3293
+ */
3294
+ experimental_include?: {
3295
+ /**
3296
+ * Whether to retain the request body in step results.
3297
+ * The request body can be large when sending images or files.
3298
+ * @default true
3299
+ */
3300
+ requestBody?: boolean;
3301
+ };
3302
+ /**
3303
+ * Internal. For test use only. May change without notice.
3304
+ */
3305
+ _internal?: {
3306
+ now?: () => number;
3307
+ generateId?: IdGenerator;
3308
+ generateCallId?: IdGenerator;
3309
+ };
3310
+ }): StreamTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
3311
+ type EnrichedStreamPart<TOOLS extends ToolSet, PARTIAL_OUTPUT> = {
3312
+ part: TextStreamPart<TOOLS>;
3313
+ partialOutput: PARTIAL_OUTPUT | undefined;
3314
+ };
3315
+
3316
+ interface Output<OUTPUT = any, PARTIAL = any, ELEMENT = any> {
3317
+ /**
3318
+ * The name of the output mode.
3319
+ */
3320
+ name: string;
3321
+ /**
3322
+ * The response format to use for the model.
3323
+ */
3324
+ responseFormat: PromiseLike<LanguageModelV4CallOptions['responseFormat']>;
3325
+ /**
3326
+ * Parses the complete output of the model.
3327
+ */
3328
+ parseCompleteOutput(options: {
3329
+ text: string;
3330
+ }, context: {
3331
+ response: LanguageModelResponseMetadata;
3332
+ usage: LanguageModelUsage;
3333
+ finishReason: FinishReason;
3334
+ }): Promise<OUTPUT>;
3335
+ /**
3336
+ * Parses the partial output of the model.
3337
+ */
3338
+ parsePartialOutput(options: {
3339
+ text: string;
3340
+ }): Promise<{
3341
+ partial: PARTIAL;
3342
+ } | undefined>;
3343
+ /**
3344
+ * Creates a stream transform that emits individual elements as they complete.
3345
+ */
3346
+ createElementStreamTransform(): TransformStream<EnrichedStreamPart<any, PARTIAL>, ELEMENT> | undefined;
3347
+ }
3348
+ /**
3349
+ * Output specification for text generation.
3350
+ * This is the default output mode that generates plain text.
3351
+ *
3352
+ * @returns An output specification for generating text.
3353
+ */
3354
+ declare const text: () => Output<string, string, never>;
3355
+ /**
3356
+ * Output specification for typed object generation using schemas.
3357
+ * When the model generates a text response, it will return an object that matches the schema.
3358
+ *
3359
+ * @param schema - The schema of the object to generate.
3360
+ * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3361
+ * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3362
+ *
3363
+ * @returns An output specification for generating objects with the specified schema.
3364
+ */
3365
+ declare const object: <OBJECT>({ schema: inputSchema, name, description, }: {
3366
+ schema: FlexibleSchema<OBJECT>;
3367
+ /**
3368
+ * Optional name of the output that should be generated.
3369
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3370
+ */
3371
+ name?: string;
3372
+ /**
3373
+ * Optional description of the output that should be generated.
3374
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3375
+ */
3376
+ description?: string;
3377
+ }) => Output<OBJECT, DeepPartial<OBJECT>, never>;
3378
+ /**
3379
+ * Output specification for array generation.
3380
+ * When the model generates a text response, it will return an array of elements.
3381
+ *
3382
+ * @param element - The schema of the array elements to generate.
3383
+ * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3384
+ * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3385
+ *
3386
+ * @returns An output specification for generating an array of elements.
3387
+ */
3388
+ declare const array: <ELEMENT>({ element: inputElementSchema, name, description, }: {
3389
+ element: FlexibleSchema<ELEMENT>;
3390
+ /**
3391
+ * Optional name of the output that should be generated.
3392
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3393
+ */
3394
+ name?: string;
3395
+ /**
3396
+ * Optional description of the output that should be generated.
3397
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3398
+ */
3399
+ description?: string;
3400
+ }) => Output<Array<ELEMENT>, Array<ELEMENT>, ELEMENT>;
3401
+ /**
3402
+ * Output specification for choice generation.
3403
+ * When the model generates a text response, it will return a one of the choice options.
3404
+ *
3405
+ * @param options - The available choices.
3406
+ * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3407
+ * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3408
+ *
3409
+ * @returns An output specification for generating a choice.
3410
+ */
3411
+ declare const choice: <CHOICE extends string>({ options: choiceOptions, name, description, }: {
3412
+ options: Array<CHOICE>;
3413
+ /**
3414
+ * Optional name of the output that should be generated.
3415
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3416
+ */
3417
+ name?: string;
3418
+ /**
3419
+ * Optional description of the output that should be generated.
3420
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3421
+ */
3422
+ description?: string;
3423
+ }) => Output<CHOICE, CHOICE, never>;
3424
+ /**
3425
+ * Output specification for unstructured JSON generation.
3426
+ * When the model generates a text response, it will return a JSON object.
3427
+ *
3428
+ * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3429
+ * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3430
+ *
3431
+ * @returns An output specification for generating JSON.
3432
+ */
3433
+ declare const json: ({ name, description, }?: {
3434
+ /**
3435
+ * Optional name of the output that should be generated.
3436
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3437
+ */
3438
+ name?: string;
3439
+ /**
3440
+ * Optional description of the output that should be generated.
3441
+ * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3442
+ */
3443
+ description?: string;
3444
+ }) => Output<JSONValue$1, JSONValue$1, never>;
3445
+
3446
+ type output_Output<OUTPUT = any, PARTIAL = any, ELEMENT = any> = Output<OUTPUT, PARTIAL, ELEMENT>;
3447
+ declare const output_array: typeof array;
3448
+ declare const output_choice: typeof choice;
3449
+ declare const output_json: typeof json;
3450
+ declare const output_object: typeof object;
3451
+ declare const output_text: typeof text;
3452
+ declare namespace output {
3453
+ export {
3454
+ output_Output as Output,
3455
+ output_array as array,
3456
+ output_choice as choice,
3457
+ output_json as json,
3458
+ output_object as object,
3459
+ output_text as text,
3460
+ };
3461
+ }
3462
+
3463
+ /**
3464
+ * Event passed to the `onStart` callback.
3465
+ *
3466
+ * Called when the generation operation begins, before any LLM calls.
3467
+ */
3468
+ type GenerateTextStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = {
3469
+ /** Unique identifier for this generation call, used to correlate events. */
3470
+ readonly callId: string;
3471
+ /** Identifies the operation type (e.g. 'ai.generateText' or 'ai.streamText'). */
3472
+ readonly operationId: string;
3473
+ /** The provider identifier (e.g., 'openai', 'anthropic'). */
3474
+ readonly provider: string;
3475
+ /** The specific model identifier (e.g., 'gpt-4o'). */
3476
+ readonly modelId: string;
3477
+ /** The tools available for this generation. */
3478
+ readonly tools: TOOLS | undefined;
3479
+ /** The tool choice strategy for this generation. */
3480
+ readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
3481
+ /** Limits which tools are available for the model to call. */
3482
+ readonly activeTools: ActiveTools<TOOLS>;
3483
+ /** Maximum number of retries for failed requests. */
3484
+ readonly maxRetries: number;
3485
+ /**
3486
+ * Timeout configuration for the generation.
3487
+ * Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs, toolMs, and per-tool overrides via tools.
3488
+ */
3489
+ readonly timeout: TimeoutConfiguration<TOOLS> | undefined;
3490
+ /** Additional HTTP headers sent with the request. */
3491
+ readonly headers: Record<string, string | undefined> | undefined;
3492
+ /** Additional provider-specific options. */
3493
+ readonly providerOptions: ProviderOptions | undefined;
3494
+ /** The output specification for structured outputs, if configured. */
3495
+ readonly output: OUTPUT | undefined;
3496
+ /**
3497
+ * Tool context.
3498
+ */
3499
+ readonly toolsContext: InferToolSetContext<TOOLS>;
3500
+ /**
3501
+ * User-defined runtime context.
3502
+ */
3503
+ readonly runtimeContext: RUNTIME_CONTEXT;
3504
+ } & LanguageModelCallOptions & StandardizedPrompt;
3505
+ /**
3506
+ * Event passed to the `onStepStart` callback.
3507
+ *
3508
+ * Called when a step (LLM call) begins, before the provider is called.
3509
+ * Each step represents a single LLM invocation.
3510
+ */
3511
+ type GenerateTextStepStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = {
3512
+ /** Unique identifier for this generation call, used to correlate events. */
3513
+ readonly callId: string;
3514
+ /** The provider identifier (e.g., 'openai', 'anthropic'). */
3515
+ readonly provider: string;
3516
+ /** The specific model identifier (e.g., 'gpt-4o'). */
3517
+ readonly modelId: string;
3518
+ /** Zero-based index of the current step. */
3519
+ readonly stepNumber: number;
3520
+ /** The tools available for this generation. */
3521
+ readonly tools: TOOLS | undefined;
3522
+ /** The tool choice configuration for this step. */
3523
+ readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
3524
+ /** Limits which tools are available for this step. */
3525
+ readonly activeTools: ActiveTools<TOOLS>;
3526
+ /** Array of results from previous steps (empty for first step). */
3527
+ readonly steps: ReadonlyArray<StepResult<TOOLS, RUNTIME_CONTEXT>>;
3528
+ /** Additional provider-specific options for this step. */
3529
+ readonly providerOptions: ProviderOptions | undefined;
3530
+ /** The output specification for structured outputs, if configured. */
3531
+ readonly output: OUTPUT | undefined;
3532
+ /**
3533
+ * Runtime context. May be updated from `prepareStep` between steps.
3534
+ */
3535
+ readonly runtimeContext: RUNTIME_CONTEXT;
3536
+ /**
3537
+ * Tool context. May be updated from `prepareStep` between steps.
3538
+ */
3539
+ readonly toolsContext: InferToolSetContext<TOOLS>;
3540
+ } & StandardizedPrompt;
3541
+ /**
3542
+ * Event passed to the `onChunk` callback.
3543
+ *
3544
+ * Called for each chunk received during streaming (`streamText` only).
3545
+ * The chunk is either a content part (text-delta, tool-call, etc.) or
3546
+ * a stream lifecycle marker (`ai.stream.firstChunk` / `ai.stream.finish`).
3547
+ */
3548
+ type StreamTextChunkEvent<TOOLS extends ToolSet = ToolSet> = {
3549
+ readonly chunk: TextStreamPart<TOOLS> | {
3550
+ readonly type: 'ai.stream.firstChunk' | 'ai.stream.finish';
3551
+ readonly callId: string;
3552
+ readonly stepNumber: number;
3553
+ readonly attributes?: Record<string, unknown>;
3554
+ };
3555
+ };
3556
+ /**
3557
+ * Event passed to the `onStepFinish` callback.
3558
+ *
3559
+ * Called when a step (LLM call) completes.
3560
+ * Includes the StepResult for that step along with the call identifier.
3561
+ */
3562
+ type GenerateTextStepEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = StepResult<TOOLS, RUNTIME_CONTEXT>;
3563
+ /**
3564
+ * Event passed to the `onFinish` callback.
3565
+ *
3566
+ * Called when the entire generation completes (all steps finished).
3567
+ * Includes the final step's result along with aggregated data from all steps.
3568
+ */
3569
+ type GenerateTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = StepResult<TOOLS, RUNTIME_CONTEXT> & {
3570
+ /** Array containing results from all steps in the generation. */
3571
+ readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
3572
+ /** Aggregated token usage across all steps. */
3573
+ readonly totalUsage: LanguageModelUsage;
3574
+ };
3575
+ /** @deprecated Use `GenerateTextStartEvent` instead. */
3576
+ type OnStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = GenerateTextStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
3577
+ /** @deprecated Use `GenerateTextStepStartEvent` instead. */
3578
+ type OnStepStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = GenerateTextStepStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
3579
+ /** @deprecated Use `StreamTextChunkEvent` instead. */
3580
+ type OnChunkEvent<TOOLS extends ToolSet = ToolSet> = StreamTextChunkEvent<TOOLS>;
3581
+ /** @deprecated Use `GenerateTextStepEndEvent` instead. */
3582
+ type OnStepFinishEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = GenerateTextStepEndEvent<TOOLS, RUNTIME_CONTEXT>;
3583
+ /** @deprecated Use `GenerateTextEndEvent` instead. */
3584
+ type OnFinishEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = GenerateTextEndEvent<TOOLS, RUNTIME_CONTEXT>;
3585
+ /**
3586
+ * Callback that is set using the `experimental_onStart` option.
3587
+ *
3588
+ * Called when the generateText operation begins, before any LLM calls.
3589
+ * Use this callback for logging, analytics, or initializing state at the
3590
+ * start of a generation.
3591
+ *
3592
+ * @param event - The event object containing generation configuration.
3593
+ */
3594
+ type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = Callback<GenerateTextStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>>;
3595
+ /**
3596
+ * Callback that is set using the `experimental_onStepStart` option.
3597
+ *
3598
+ * Called when a step (LLM call) begins, before the provider is called.
3599
+ * Each step represents a single LLM invocation. Multiple steps occur when
3600
+ * using tool calls (the model may be called multiple times in a loop).
3601
+ *
3602
+ * @param event - The event object containing step configuration.
3603
+ */
3604
+ type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = Callback<GenerateTextStepStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>>;
3605
+ /**
3606
+ * Callback that is set using the `onStepFinish` option.
3607
+ *
3608
+ * Called when a step (LLM call) completes. The event includes all step result
3609
+ * properties (text, tool calls, usage, etc.) along with additional metadata.
3610
+ *
3611
+ * @param stepResult - The result of the step.
3612
+ */
3613
+ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = Callback<GenerateTextStepEndEvent<TOOLS, RUNTIME_CONTEXT>>;
3614
+ /**
3615
+ * Callback that is set using the `onFinish` option.
3616
+ *
3617
+ * Called when the entire generation completes (all steps finished).
3618
+ * The event includes the final step's result properties along with
3619
+ * aggregated data from all steps.
3620
+ *
3621
+ * @param event - The final result along with aggregated step data.
3622
+ */
3623
+ type GenerateTextOnFinishCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = Callback<GenerateTextEndEvent<TOOLS, RUNTIME_CONTEXT>>;
3624
+
3625
+ /**
3626
+ * Event passed to the `onStart` callback for rerank operations.
3627
+ *
3628
+ * Called when the operation begins, before the reranking model is called.
3629
+ */
3630
+ type RerankStartEvent = {
3631
+ /** Unique identifier for this rerank call, used to correlate events. */
3632
+ readonly callId: string;
3633
+ /** Identifies the operation type ('ai.rerank'). */
3634
+ readonly operationId: string;
3635
+ readonly provider: string;
3636
+ /** The specific model identifier (e.g., 'gpt-4o'). */
3637
+ readonly modelId: string;
3638
+ /** The documents being reranked. */
3639
+ readonly documents: Array<JSONObject | string>;
3640
+ /** The query to rerank the documents against. */
3641
+ readonly query: string;
3642
+ /** Number of top documents to return. */
3643
+ readonly topN: number | undefined;
3644
+ /** Maximum number of retries for failed requests. */
3645
+ readonly maxRetries: number;
3646
+ /** Additional HTTP headers sent with the request. */
3647
+ readonly headers: Record<string, string | undefined> | undefined;
3648
+ /** Additional provider-specific options. */
3649
+ readonly providerOptions: ProviderOptions | undefined;
3650
+ };
3651
+ /**
3652
+ * Event passed to the `onFinish` callback for rerank operations.
3653
+ *
3654
+ * Called when the operation completes, after the reranking model returns.
3655
+ */
3656
+ type RerankEndEvent = {
3657
+ /** Unique identifier for this rerank call, used to correlate events. */
3658
+ readonly callId: string;
3659
+ /** Identifies the operation type ('ai.rerank'). */
3660
+ readonly operationId: string;
3661
+ readonly provider: string;
3662
+ /** The specific model identifier (e.g., 'gpt-4o'). */
3663
+ readonly modelId: string;
3664
+ /** The documents that were reranked. */
3665
+ readonly documents: Array<JSONObject | string>;
3666
+ /** The query that documents were reranked against. */
3667
+ readonly query: string;
3668
+ /** The reranked results sorted by relevance score in descending order. */
3669
+ readonly ranking: Array<{
3670
+ originalIndex: number;
3671
+ score: number;
3672
+ document: JSONObject | string;
3673
+ }>;
3674
+ /** Warnings from the reranking model. */
3675
+ readonly warnings: Array<Warning>;
3676
+ /** Optional provider-specific metadata. */
3677
+ readonly providerMetadata: ProviderMetadata | undefined;
3678
+ /** Response data including headers and body. */
3679
+ readonly response: {
3680
+ id?: string;
3681
+ timestamp: Date;
3682
+ modelId: string;
3683
+ headers?: Record<string, string>;
3684
+ body?: unknown;
3685
+ };
3686
+ };
3687
+ /**
3688
+ * Event fired when an individual reranking model call (inner doRerank) begins.
3689
+ */
3690
+ type RerankingModelCallStartEvent = {
3691
+ /** Unique identifier for this rerank call, used to correlate events. */
3692
+ readonly callId: string;
3693
+ /** Identifies the inner operation ('ai.rerank.doRerank'). */
3694
+ readonly operationId: string;
3695
+ /** The provider identifier. */
3696
+ readonly provider: string;
3697
+ /** The specific model identifier. */
3698
+ readonly modelId: string;
3699
+ /** The documents being reranked. */
3700
+ readonly documents: Array<JSONObject | string>;
3701
+ /** The type of documents ('text' or 'object'). */
3702
+ readonly documentsType: string;
3703
+ /** The query to rerank against. */
3704
+ readonly query: string;
3705
+ /** Number of top documents to return. */
3706
+ readonly topN: number | undefined;
3707
+ };
3708
+ /**
3709
+ * Event fired when an individual reranking model call (doRerank) completes.
3710
+ *
3711
+ * Contains the ranking results from the model response.
3712
+ */
3713
+ type RerankingModelCallEndEvent = {
3714
+ /** Unique identifier for this rerank call, used to correlate events. */
3715
+ readonly callId: string;
3716
+ /** Identifies the inner operation ('ai.rerank.doRerank'). */
3717
+ readonly operationId: string;
3718
+ /** The provider identifier. */
3719
+ readonly provider: string;
3720
+ /** The specific model identifier. */
3721
+ readonly modelId: string;
3722
+ /** The type of documents ('text' or 'object'). */
3723
+ readonly documentsType: string;
3724
+ /** The ranking results from the model. */
3725
+ readonly ranking: Array<{
3726
+ index: number;
3727
+ relevanceScore: number;
3728
+ }>;
3729
+ };
3730
+
3731
+ type InferTelemetryEvent<EVENT> = EVENT & Omit<TelemetryOptions, 'integrations' | 'isEnabled'>;
3732
+ type OperationStartEvent = GenerateTextStartEvent | GenerateObjectStartEvent | EmbedStartEvent | RerankStartEvent;
3733
+ type OperationFinishEvent = GenerateTextEndEvent<ToolSet> | GenerateObjectEndEvent<unknown> | EmbedEndEvent | RerankEndEvent;
3734
+ /**
3735
+ * Implement this interface to create custom telemetry integrations.
3736
+ * Methods can be sync or return a PromiseLike.
3737
+ */
3738
+ interface Telemetry {
3739
+ /**
3740
+ * Called when an operation begins. Fired for text generation
3741
+ * (generateText/streamText), object generation (generateObject/streamObject),
3742
+ * embedding (embed/embedMany), and reranking operations.
3492
3743
  *
3493
- * By default, all data is included for backwards compatibility.
3744
+ * Use the `operationId` field to distinguish between operation types.
3494
3745
  */
3495
- experimental_include?: {
3496
- /**
3497
- * Whether to retain the request body in step results.
3498
- * The request body can be large when sending images or files.
3499
- * @default true
3500
- */
3501
- requestBody?: boolean;
3502
- };
3746
+ onStart?: Callback<InferTelemetryEvent<OperationStartEvent>>;
3503
3747
  /**
3504
- * Internal. For test use only. May change without notice.
3748
+ * Called when an individual step (single LLM invocation) begins.
3749
+ * A generation may consist of multiple steps (e.g. when tool calls trigger
3750
+ * follow-up LLM calls). Use this to create per-step spans or record
3751
+ * step-level inputs.
3752
+ *
3753
+ * The event includes the step number, accumulated previous step results,
3754
+ * and the messages that will be sent to the model.
3505
3755
  */
3506
- _internal?: {
3507
- now?: () => number;
3508
- generateId?: IdGenerator;
3509
- generateCallId?: IdGenerator;
3510
- };
3511
- }): StreamTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
3512
- type EnrichedStreamPart<TOOLS extends ToolSet, PARTIAL_OUTPUT> = {
3513
- part: TextStreamPart<TOOLS>;
3514
- partialOutput: PARTIAL_OUTPUT | undefined;
3515
- };
3516
-
3517
- interface Output<OUTPUT = any, PARTIAL = any, ELEMENT = any> {
3756
+ onStepStart?: Callback<InferTelemetryEvent<GenerateTextStepStartEvent>>;
3518
3757
  /**
3519
- * The name of the output mode.
3758
+ * Called immediately before the provider model call begins.
3759
+ * Unlike `onStepStart`, this callback is scoped to model work only and
3760
+ * excludes any later client-side tool execution.
3520
3761
  */
3521
- name: string;
3762
+ onLanguageModelCallStart?: Callback<InferTelemetryEvent<LanguageModelCallStartEvent>>;
3522
3763
  /**
3523
- * The response format to use for the model.
3764
+ * Called after the model response has been normalized and parsed, but before
3765
+ * any client-side tool execution begins.
3524
3766
  */
3525
- responseFormat: PromiseLike<LanguageModelV4CallOptions['responseFormat']>;
3767
+ onLanguageModelCallEnd?: Callback<InferTelemetryEvent<LanguageModelCallEndEvent>>;
3526
3768
  /**
3527
- * Parses the complete output of the model.
3769
+ * Called when a tool execution begins, before the tool's `execute` function
3770
+ * is invoked. Use this to create tool-level spans or log tool invocations.
3528
3771
  */
3529
- parseCompleteOutput(options: {
3530
- text: string;
3531
- }, context: {
3532
- response: LanguageModelResponseMetadata;
3533
- usage: LanguageModelUsage;
3534
- finishReason: FinishReason;
3535
- }): Promise<OUTPUT>;
3772
+ onToolExecutionStart?: Callback<InferTelemetryEvent<ToolExecutionStartEvent>>;
3536
3773
  /**
3537
- * Parses the partial output of the model.
3774
+ * Called when a tool execution completes, either successfully or with an error.
3775
+ * The event uses a discriminated union on the `success` field — check
3776
+ * `event.success` to determine whether `output` or `error` is available.
3777
+ *
3778
+ * The event includes execution duration (`durationMs`) for performance tracking.
3538
3779
  */
3539
- parsePartialOutput(options: {
3540
- text: string;
3541
- }): Promise<{
3542
- partial: PARTIAL;
3543
- } | undefined>;
3780
+ onToolExecutionEnd?: Callback<InferTelemetryEvent<ToolExecutionEndEvent>>;
3544
3781
  /**
3545
- * Creates a stream transform that emits individual elements as they complete.
3782
+ * Called for each chunk received during streaming.
3783
+ * Only relevant for `streamText` — not called during `generateText`.
3546
3784
  */
3547
- createElementStreamTransform(): TransformStream<EnrichedStreamPart<any, PARTIAL>, ELEMENT> | undefined;
3548
- }
3549
- /**
3550
- * Output specification for text generation.
3551
- * This is the default output mode that generates plain text.
3552
- *
3553
- * @returns An output specification for generating text.
3554
- */
3555
- declare const text: () => Output<string, string, never>;
3556
- /**
3557
- * Output specification for typed object generation using schemas.
3558
- * When the model generates a text response, it will return an object that matches the schema.
3559
- *
3560
- * @param schema - The schema of the object to generate.
3561
- * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3562
- * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3563
- *
3564
- * @returns An output specification for generating objects with the specified schema.
3565
- */
3566
- declare const object: <OBJECT>({ schema: inputSchema, name, description, }: {
3567
- schema: FlexibleSchema<OBJECT>;
3785
+ onChunk?: Callback<StreamTextChunkEvent>;
3568
3786
  /**
3569
- * Optional name of the output that should be generated.
3570
- * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3787
+ * Called when an individual step (single LLM invocation) completes.
3788
+ * The event is a `StepResult` containing the model's response, tool calls
3789
+ * and results, usage statistics, finish reason, and optional request/response
3790
+ * bodies.
3571
3791
  */
3572
- name?: string;
3792
+ onStepFinish?: Callback<InferTelemetryEvent<GenerateTextStepEndEvent>>;
3573
3793
  /**
3574
- * Optional description of the output that should be generated.
3575
- * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3794
+ * Called when an object generation step (single LLM invocation) begins.
3795
+ * For generateObject/streamObject there is always exactly one step.
3796
+ *
3797
+ * @deprecated
3576
3798
  */
3577
- description?: string;
3578
- }) => Output<OBJECT, DeepPartial<OBJECT>, never>;
3579
- /**
3580
- * Output specification for array generation.
3581
- * When the model generates a text response, it will return an array of elements.
3582
- *
3583
- * @param element - The schema of the array elements to generate.
3584
- * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3585
- * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3586
- *
3587
- * @returns An output specification for generating an array of elements.
3588
- */
3589
- declare const array: <ELEMENT>({ element: inputElementSchema, name, description, }: {
3590
- element: FlexibleSchema<ELEMENT>;
3799
+ onObjectStepStart?: Callback<InferTelemetryEvent<GenerateObjectStepStartEvent>>;
3591
3800
  /**
3592
- * Optional name of the output that should be generated.
3593
- * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3801
+ * Called when an object generation step (single LLM invocation) completes,
3802
+ * with the raw result before JSON parsing and schema validation.
3803
+ *
3804
+ * @deprecated
3594
3805
  */
3595
- name?: string;
3806
+ onObjectStepFinish?: Callback<InferTelemetryEvent<GenerateObjectStepEndEvent>>;
3596
3807
  /**
3597
- * Optional description of the output that should be generated.
3598
- * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3808
+ * Called when an individual embedding model call (doEmbed) begins.
3809
+ * For `embed`, there is one call. For `embedMany`, there may be multiple
3810
+ * calls when values are chunked.
3599
3811
  */
3600
- description?: string;
3601
- }) => Output<Array<ELEMENT>, Array<ELEMENT>, ELEMENT>;
3602
- /**
3603
- * Output specification for choice generation.
3604
- * When the model generates a text response, it will return a one of the choice options.
3605
- *
3606
- * @param options - The available choices.
3607
- * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3608
- * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3609
- *
3610
- * @returns An output specification for generating a choice.
3611
- */
3612
- declare const choice: <CHOICE extends string>({ options: choiceOptions, name, description, }: {
3613
- options: Array<CHOICE>;
3812
+ onEmbedStart?: Callback<InferTelemetryEvent<EmbeddingModelCallStartEvent>>;
3614
3813
  /**
3615
- * Optional name of the output that should be generated.
3616
- * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3814
+ * Called when an individual embedding model call (doEmbed) completes.
3815
+ * Contains the embeddings, usage, and any warnings from the model response.
3617
3816
  */
3618
- name?: string;
3817
+ onEmbedFinish?: Callback<InferTelemetryEvent<EmbeddingModelCallEndEvent>>;
3619
3818
  /**
3620
- * Optional description of the output that should be generated.
3621
- * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3819
+ * Called when an individual reranking model call (doRerank) begins.
3820
+ * There is one call per `rerank` invocation.
3622
3821
  */
3623
- description?: string;
3624
- }) => Output<CHOICE, CHOICE, never>;
3625
- /**
3626
- * Output specification for unstructured JSON generation.
3627
- * When the model generates a text response, it will return a JSON object.
3628
- *
3629
- * @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3630
- * @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3631
- *
3632
- * @returns An output specification for generating JSON.
3633
- */
3634
- declare const json: ({ name, description, }?: {
3822
+ onRerankStart?: Callback<InferTelemetryEvent<RerankingModelCallStartEvent>>;
3635
3823
  /**
3636
- * Optional name of the output that should be generated.
3637
- * Used by some providers for additional LLM guidance, e.g. via tool or schema name.
3824
+ * Called when an individual reranking model call (doRerank) completes.
3825
+ * Contains the ranking results from the model response.
3638
3826
  */
3639
- name?: string;
3827
+ onRerankFinish?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>;
3640
3828
  /**
3641
- * Optional description of the output that should be generated.
3642
- * Used by some providers for additional LLM guidance, e.g. via tool or schema description.
3643
- */
3644
- description?: string;
3645
- }) => Output<JSONValue$1, JSONValue$1, never>;
3646
-
3647
- type output_Output<OUTPUT = any, PARTIAL = any, ELEMENT = any> = Output<OUTPUT, PARTIAL, ELEMENT>;
3648
- declare const output_array: typeof array;
3649
- declare const output_choice: typeof choice;
3650
- declare const output_json: typeof json;
3651
- declare const output_object: typeof object;
3652
- declare const output_text: typeof text;
3653
- declare namespace output {
3654
- export {
3655
- output_Output as Output,
3656
- output_array as array,
3657
- output_choice as choice,
3658
- output_json as json,
3659
- output_object as object,
3660
- output_text as text,
3661
- };
3662
- }
3663
-
3664
- /**
3665
- * Event passed to the `onStart` callback.
3666
- *
3667
- * Called when the generation operation begins, before any LLM calls.
3668
- */
3669
- type GenerateTextStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = {
3670
- /** Unique identifier for this generation call, used to correlate events. */
3671
- readonly callId: string;
3672
- /** Identifies the operation type (e.g. 'ai.generateText' or 'ai.streamText'). */
3673
- readonly operationId: string;
3674
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
3675
- readonly provider: string;
3676
- /** The specific model identifier (e.g., 'gpt-4o'). */
3677
- readonly modelId: string;
3678
- /** The tools available for this generation. */
3679
- readonly tools: TOOLS | undefined;
3680
- /** The tool choice strategy for this generation. */
3681
- readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
3682
- /** Limits which tools are available for the model to call. */
3683
- readonly activeTools: ActiveTools<TOOLS>;
3684
- /** Maximum number of retries for failed requests. */
3685
- readonly maxRetries: number;
3829
+ * Called when an operation completes. Fired for text generation
3830
+ * (generateText/streamText), object generation (generateObject/streamObject),
3831
+ * embedding (embed/embedMany), and reranking operations.
3832
+ *
3833
+ * Use the event shape or `operationId` to distinguish between operation types.
3834
+ */
3835
+ onFinish?: Callback<InferTelemetryEvent<OperationFinishEvent>>;
3686
3836
  /**
3687
- * Timeout configuration for the generation.
3688
- * Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs, toolMs, and per-tool overrides via tools.
3837
+ * Called when an unrecoverable error occurs during the generation lifecycle.
3838
+ * The error value is untyped it may be an `Error` instance, an `AISDKError`,
3839
+ * or any thrown value.
3840
+ *
3841
+ * Use this to record error details on telemetry spans and set error status.
3689
3842
  */
3690
- readonly timeout: TimeoutConfiguration<TOOLS> | undefined;
3691
- /** Additional HTTP headers sent with the request. */
3692
- readonly headers: Record<string, string | undefined> | undefined;
3693
- /** Additional provider-specific options. */
3694
- readonly providerOptions: ProviderOptions | undefined;
3695
- /** The output specification for structured outputs, if configured. */
3696
- readonly output: OUTPUT | undefined;
3843
+ onError?: Callback<unknown>;
3697
3844
  /**
3698
- * Tool context.
3845
+ * Optionally runs the tool execute function in a telemetry-integration-specific context. This enables
3846
+ * nested traces — e.g. when a tool's `execute` function calls `generateText`,
3847
+ * the inner call's spans become children of the tool span.
3848
+ *
3849
+ * @param options.callId - The call ID of the tool call.
3850
+ * @param options.toolCallId - The tool call ID.
3851
+ * @param options.execute - The function to execute.
3699
3852
  */
3700
- readonly toolsContext: InferToolSetContext<TOOLS>;
3853
+ executeTool?: <T>(options: {
3854
+ callId: string;
3855
+ toolCallId: string;
3856
+ execute: () => PromiseLike<T>;
3857
+ }) => PromiseLike<T>;
3858
+ }
3859
+
3860
+ declare global {
3701
3861
  /**
3702
- * User-defined runtime context.
3862
+ * The default provider to use for the AI SDK.
3863
+ * String model ids are resolved to the default provider and model id.
3864
+ *
3865
+ * If not set, the default provider is the Vercel AI gateway provider.
3866
+ *
3867
+ * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
3703
3868
  */
3704
- readonly runtimeContext: RUNTIME_CONTEXT;
3705
- } & LanguageModelCallOptions & StandardizedPrompt;
3706
- /**
3707
- * Event passed to the `onStepStart` callback.
3708
- *
3709
- * Called when a step (LLM call) begins, before the provider is called.
3710
- * Each step represents a single LLM invocation.
3711
- */
3712
- type GenerateTextStepStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = {
3713
- /** Unique identifier for this generation call, used to correlate events. */
3714
- readonly callId: string;
3715
- /** The provider identifier (e.g., 'openai', 'anthropic'). */
3716
- readonly provider: string;
3717
- /** The specific model identifier (e.g., 'gpt-4o'). */
3718
- readonly modelId: string;
3719
- /** Zero-based index of the current step. */
3720
- readonly stepNumber: number;
3721
- /** The tools available for this generation. */
3722
- readonly tools: TOOLS | undefined;
3723
- /** The tool choice configuration for this step. */
3724
- readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
3725
- /** Limits which tools are available for this step. */
3726
- readonly activeTools: ActiveTools<TOOLS>;
3727
- /** Array of results from previous steps (empty for first step). */
3728
- readonly steps: ReadonlyArray<StepResult<TOOLS, RUNTIME_CONTEXT>>;
3729
- /** Additional provider-specific options for this step. */
3730
- readonly providerOptions: ProviderOptions | undefined;
3731
- /** The output specification for structured outputs, if configured. */
3732
- readonly output: OUTPUT | undefined;
3869
+ var AI_SDK_DEFAULT_PROVIDER: ProviderV4 | ProviderV3 | ProviderV2 | undefined;
3733
3870
  /**
3734
- * Runtime context. May be updated from `prepareStep` between steps.
3871
+ * The warning logger to use for the AI SDK.
3872
+ *
3873
+ * If not set, the default logger is the console.warn function.
3874
+ *
3875
+ * If set to false, no warnings are logged.
3735
3876
  */
3736
- readonly runtimeContext: RUNTIME_CONTEXT;
3877
+ var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
3737
3878
  /**
3738
- * Tool context. May be updated from `prepareStep` between steps.
3879
+ * Globally registered telemetry integrations for the AI SDK.
3880
+ *
3881
+ * Integrations registered here receive lifecycle events (onStart, onStepStart,
3882
+ * etc.) from every `generateText`, `streamText`, and similar call.
3883
+ *
3884
+ * Prefer using `registerTelemetry()` from `'ai'` instead of
3885
+ * assigning this directly.
3739
3886
  */
3740
- readonly toolsContext: InferToolSetContext<TOOLS>;
3741
- } & StandardizedPrompt;
3742
- /**
3743
- * Event passed to the `onChunk` callback.
3744
- *
3745
- * Called for each chunk received during streaming (`streamText` only).
3746
- * The chunk is either a content part (text-delta, tool-call, etc.) or
3747
- * a stream lifecycle marker (`ai.stream.firstChunk` / `ai.stream.finish`).
3748
- */
3749
- type StreamTextChunkEvent<TOOLS extends ToolSet = ToolSet> = {
3750
- readonly chunk: TextStreamPart<TOOLS> | {
3751
- readonly type: 'ai.stream.firstChunk' | 'ai.stream.finish';
3752
- readonly callId: string;
3753
- readonly stepNumber: number;
3754
- readonly attributes?: Record<string, unknown>;
3755
- };
3756
- };
3757
- /**
3758
- * Event passed to the `onStepFinish` callback.
3759
- *
3760
- * Called when a step (LLM call) completes.
3761
- * Includes the StepResult for that step along with the call identifier.
3762
- */
3763
- type GenerateTextStepEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = StepResult<TOOLS, RUNTIME_CONTEXT>;
3764
- /**
3765
- * Event passed to the `onFinish` callback.
3766
- *
3767
- * Called when the entire generation completes (all steps finished).
3768
- * Includes the final step's result along with aggregated data from all steps.
3769
- */
3770
- type GenerateTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = StepResult<TOOLS, RUNTIME_CONTEXT> & {
3771
- /** Array containing results from all steps in the generation. */
3772
- readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
3773
- /** Aggregated token usage across all steps. */
3774
- readonly totalUsage: LanguageModelUsage;
3775
- };
3776
- /** @deprecated Use `GenerateTextStartEvent` instead. */
3777
- type OnStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = GenerateTextStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
3778
- /** @deprecated Use `GenerateTextStepStartEvent` instead. */
3779
- type OnStepStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = GenerateTextStepStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
3780
- /** @deprecated Use `StreamTextChunkEvent` instead. */
3781
- type OnChunkEvent<TOOLS extends ToolSet = ToolSet> = StreamTextChunkEvent<TOOLS>;
3782
- /** @deprecated Use `GenerateTextStepEndEvent` instead. */
3783
- type OnStepFinishEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = GenerateTextStepEndEvent<TOOLS, RUNTIME_CONTEXT>;
3784
- /** @deprecated Use `GenerateTextEndEvent` instead. */
3785
- type OnFinishEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = GenerateTextEndEvent<TOOLS, RUNTIME_CONTEXT>;
3786
- /**
3787
- * Callback that is set using the `experimental_onStart` option.
3788
- *
3789
- * Called when the generateText operation begins, before any LLM calls.
3790
- * Use this callback for logging, analytics, or initializing state at the
3791
- * start of a generation.
3792
- *
3793
- * @param event - The event object containing generation configuration.
3794
- */
3795
- type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = Callback<GenerateTextStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>>;
3796
- /**
3797
- * Callback that is set using the `experimental_onStepStart` option.
3798
- *
3799
- * Called when a step (LLM call) begins, before the provider is called.
3800
- * Each step represents a single LLM invocation. Multiple steps occur when
3801
- * using tool calls (the model may be called multiple times in a loop).
3802
- *
3803
- * @param event - The event object containing step configuration.
3804
- */
3805
- type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = Callback<GenerateTextStepStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>>;
3806
- /**
3807
- * Callback that is set using the `onStepFinish` option.
3808
- *
3809
- * Called when a step (LLM call) completes. The event includes all step result
3810
- * properties (text, tool calls, usage, etc.) along with additional metadata.
3811
- *
3812
- * @param stepResult - The result of the step.
3813
- */
3814
- type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = Callback<GenerateTextStepEndEvent<TOOLS, RUNTIME_CONTEXT>>;
3815
- /**
3816
- * Callback that is set using the `onFinish` option.
3817
- *
3818
- * Called when the entire generation completes (all steps finished).
3819
- * The event includes the final step's result properties along with
3820
- * aggregated data from all steps.
3821
- *
3822
- * @param event - The final result along with aggregated step data.
3823
- */
3824
- type GenerateTextOnFinishCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context> = Callback<GenerateTextEndEvent<TOOLS, RUNTIME_CONTEXT>>;
3887
+ var AI_SDK_TELEMETRY_INTEGRATIONS: Telemetry[] | undefined;
3888
+ }
3825
3889
 
3826
3890
  /**
3827
3891
  * The result of a `generateText` call.
@@ -6932,33 +6996,6 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
6932
6996
  }>;
6933
6997
  }): Promise<GenerateVideoResult>;
6934
6998
 
6935
- /**
6936
- * A function for logging warnings.
6937
- *
6938
- * You can assign it to the `AI_SDK_LOG_WARNINGS` global variable to use it as the default warning logger.
6939
- *
6940
- * @example
6941
- * ```ts
6942
- * globalThis.AI_SDK_LOG_WARNINGS = (options) => {
6943
- * console.log('WARNINGS:', options.warnings, options.provider, options.model);
6944
- * };
6945
- * ```
6946
- */
6947
- type LogWarningsFunction = (options: {
6948
- /**
6949
- * The warnings returned by the model provider.
6950
- */
6951
- warnings: Warning[];
6952
- /**
6953
- * The provider id used for the call, if scoped to a specific provider.
6954
- */
6955
- provider?: string;
6956
- /**
6957
- * The model id used for the call, if scoped to a specific provider.
6958
- */
6959
- model?: string;
6960
- }) => void;
6961
-
6962
6999
  /**
6963
7000
  * Applies default settings for an embedding model.
6964
7001
  */
@@ -7148,21 +7185,24 @@ declare function wrapProvider({ provider, languageModelMiddleware, imageModelMid
7148
7185
  }): ProviderV4;
7149
7186
 
7150
7187
  /**
7151
- * Creates a custom provider with specified language models, text embedding models, image models, transcription models, speech models, and an optional fallback provider.
7188
+ * Creates a custom provider with specified language models, text embedding models, image models, transcription models, speech models, file APIs, skill APIs, and an optional fallback provider.
7152
7189
  *
7153
7190
  * @param {Object} options - The options for creating the custom provider.
7154
- * @param {Record<string, LanguageModelV4>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModelV4 instances.
7155
- * @param {Record<string, EmbeddingModelV4>} [options.embeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModelV4 instances.
7156
- * @param {Record<string, ImageModelV4>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModelV4 instances.
7157
- * @param {Record<string, TranscriptionModelV4>} [options.transcriptionModels] - A record of transcription models, where keys are model IDs and values are TranscriptionModelV4 instances.
7158
- * @param {Record<string, SpeechModelV4>} [options.speechModels] - A record of speech models, where keys are model IDs and values are SpeechModelV4 instances.
7159
- * @param {Record<string, RerankingModelV4>} [options.rerankingModels] - A record of reranking models, where keys are model IDs and values are RerankingModelV4 instances.
7160
- * @param {ProviderV4} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
7161
- * @returns {ProviderV4} A ProviderV4 object with languageModel, embeddingModel, imageModel, transcriptionModel, and speechModel methods.
7191
+ * @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are language model instances.
7192
+ * @param {Record<string, EmbeddingModel>} [options.embeddingModels] - A record of text embedding models, where keys are model IDs and values are embedding model instances.
7193
+ * @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are image model instances.
7194
+ * @param {Record<string, TranscriptionModel>} [options.transcriptionModels] - A record of transcription models, where keys are model IDs and values are transcription model instances.
7195
+ * @param {Record<string, SpeechModel>} [options.speechModels] - A record of speech models, where keys are model IDs and values are speech model instances.
7196
+ * @param {Record<string, RerankingModel>} [options.rerankingModels] - A record of reranking models, where keys are model IDs and values are reranking model instances.
7197
+ * @param {Record<string, VideoModel>} [options.videoModels] - A record of video models, where keys are model IDs and values are video model instances.
7198
+ * @param {FilesV4} [options.files] - A files interface for uploading files.
7199
+ * @param {SkillsV4} [options.skills] - A skills interface for uploading skills.
7200
+ * @param {ProviderV2 | ProviderV3 | ProviderV4} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
7201
+ * @returns {ProviderV4} A ProviderV4 object with languageModel, embeddingModel, imageModel, transcriptionModel, speechModel, rerankingModel, and videoModel methods.
7162
7202
  *
7163
7203
  * @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
7164
7204
  */
7165
- declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV2 | LanguageModelV3 | LanguageModelV4>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV3 | EmbeddingModelV4>, IMAGE_MODELS extends Record<string, ImageModelV2 | ImageModelV3 | ImageModelV4>, TRANSCRIPTION_MODELS extends Record<string, TranscriptionModelV2 | TranscriptionModelV3 | TranscriptionModelV4>, SPEECH_MODELS extends Record<string, SpeechModelV2 | SpeechModelV3 | SpeechModelV4>, RERANKING_MODELS extends Record<string, RerankingModelV3 | RerankingModelV4>, VIDEO_MODELS extends Record<string, Experimental_VideoModelV3 | Experimental_VideoModelV4>, FILES extends FilesV4 | undefined = undefined, SKILLS extends SkillsV4 | undefined = undefined>({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, videoModels, files, skills, fallbackProvider: fallbackProviderArg, }: {
7205
+ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModel>, EMBEDDING_MODELS extends Record<string, EmbeddingModel>, IMAGE_MODELS extends Record<string, ImageModel>, TRANSCRIPTION_MODELS extends Record<string, TranscriptionModel>, SPEECH_MODELS extends Record<string, SpeechModel>, RERANKING_MODELS extends Record<string, RerankingModel>, VIDEO_MODELS extends Record<string, VideoModel>, FILES extends FilesV4 | undefined = undefined, SKILLS extends SkillsV4 | undefined = undefined, FALLBACK extends ProviderV2 | ProviderV3 | ProviderV4 | undefined = undefined>({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, videoModels, files, skills, fallbackProvider: fallbackProviderArg, }: {
7166
7206
  languageModels?: LANGUAGE_MODELS;
7167
7207
  embeddingModels?: EMBEDDING_MODELS;
7168
7208
  imageModels?: IMAGE_MODELS;
@@ -7172,7 +7212,7 @@ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageM
7172
7212
  videoModels?: VIDEO_MODELS;
7173
7213
  files?: FILES;
7174
7214
  skills?: SKILLS;
7175
- fallbackProvider?: ProviderV4 | ProviderV3 | ProviderV2;
7215
+ fallbackProvider?: FALLBACK;
7176
7216
  }): ProviderV4 & {
7177
7217
  languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModelV4;
7178
7218
  embeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModelV4;
@@ -7183,17 +7223,21 @@ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageM
7183
7223
  videoModel(modelId: ExtractModelId<VIDEO_MODELS>): Experimental_VideoModelV4;
7184
7224
  } & (FILES extends FilesV4 ? {
7185
7225
  files(): FilesV4;
7226
+ } : [FALLBACK] extends [{
7227
+ files: () => FilesV4;
7228
+ }] ? {
7229
+ files(): FilesV4;
7186
7230
  } : {
7187
7231
  files?(): FilesV4;
7188
7232
  }) & (SKILLS extends SkillsV4 ? {
7189
7233
  skills(): SkillsV4;
7234
+ } : [FALLBACK] extends [{
7235
+ skills: () => SkillsV4;
7236
+ }] ? {
7237
+ skills(): SkillsV4;
7190
7238
  } : {
7191
7239
  skills?(): SkillsV4;
7192
7240
  });
7193
- /**
7194
- * @deprecated Use `customProvider` instead.
7195
- */
7196
- declare const experimental_customProvider: typeof customProvider;
7197
7241
  type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
7198
7242
 
7199
7243
  declare const symbol: unique symbol;
@@ -7211,8 +7255,25 @@ declare class NoSuchProviderError extends NoSuchModelError {
7211
7255
  static isInstance(error: unknown): error is NoSuchProviderError;
7212
7256
  }
7213
7257
 
7214
- type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
7215
- interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV4> = Record<string, ProviderV4>, SEPARATOR extends string = ':'> {
7258
+ /**
7259
+ * If `text` is exactly the wide `string` type, there are no string literals to
7260
+ * preserve, so this resolves to `never`.
7261
+ *
7262
+ * If `text` is a string literal or a union of string literals, this resolves
7263
+ * to that literal union unchanged.
7264
+ *
7265
+ * This is used when building template-literal model identifiers (for example
7266
+ * `"provider:modelId"`) so that editors can suggest concrete `modelId` values
7267
+ * when the underlying method parameter is narrowed, while falling back to a
7268
+ * generic `"provider:${string}"` style overload when the parameter is only
7269
+ * typed as `string`.
7270
+ */
7271
+ type ExtractLiteralUnion<text> = text extends string ? string extends text ? never : text : never;
7272
+
7273
+ type ProviderVideoModelIdentifier<PROVIDER> = PROVIDER extends {
7274
+ videoModel: (...args: infer ARGS) => unknown;
7275
+ } ? ExtractLiteralUnion<ARGS[0]> : never;
7276
+ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV4 | ProviderV3> = Record<string, ProviderV4 | ProviderV3>, SEPARATOR extends string = ':'> {
7216
7277
  languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModelV4;
7217
7278
  languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModelV4;
7218
7279
  embeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['embeddingModel']>>[0]>}` : never): EmbeddingModelV4;
@@ -7225,9 +7286,10 @@ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV4>
7225
7286
  speechModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): SpeechModelV4;
7226
7287
  rerankingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['rerankingModel']>>[0]>}` : never): RerankingModelV4;
7227
7288
  rerankingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): RerankingModelV4;
7289
+ videoModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ProviderVideoModelIdentifier<PROVIDERS[KEY]>}` : never): Experimental_VideoModelV4;
7228
7290
  videoModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): Experimental_VideoModelV4;
7229
- files<KEY extends keyof PROVIDERS>(providerId: KEY & string): FilesV4;
7230
- skills<KEY extends keyof PROVIDERS>(providerId: KEY & string): SkillsV4;
7291
+ files<KEY extends keyof PROVIDERS>(id: KEY extends string ? KEY & string : never): FilesV4;
7292
+ skills<KEY extends keyof PROVIDERS>(id: KEY extends string ? KEY & string : never): SkillsV4;
7231
7293
  }
7232
7294
  /**
7233
7295
  * Creates a registry for the given providers with optional middleware functionality.
@@ -7242,13 +7304,11 @@ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV4>
7242
7304
  * @param options.imageModelMiddleware - Optional middleware to be applied to all image models from the registry. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
7243
7305
  * @returns A new ProviderRegistryProvider instance that provides access to all registered providers with optional middleware applied to language and image models.
7244
7306
  */
7245
- declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2 | ProviderV3 | ProviderV4>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, languageModelMiddleware, imageModelMiddleware, }?: {
7307
+ declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV4 | ProviderV3>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, languageModelMiddleware, imageModelMiddleware, }?: {
7246
7308
  separator?: SEPARATOR;
7247
7309
  languageModelMiddleware?: LanguageModelMiddleware | LanguageModelMiddleware[];
7248
7310
  imageModelMiddleware?: ImageModelMiddleware | ImageModelMiddleware[];
7249
- }): ProviderRegistryProvider<{
7250
- [K in keyof PROVIDERS]: ProviderV4;
7251
- }, SEPARATOR>;
7311
+ }): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
7252
7312
  /**
7253
7313
  * @deprecated Use `createProviderRegistry` instead.
7254
7314
  */
@@ -7402,6 +7462,13 @@ declare function rerank<VALUE extends JSONObject | string>({ model: modelArg, do
7402
7462
  */
7403
7463
  declare function registerTelemetry(...integrations: Telemetry[]): void;
7404
7464
 
7465
+ declare const AI_SDK_TELEMETRY_DIAGNOSTIC_CHANNEL = "aisdk:telemetry";
7466
+ type TelemetryDiagnosticEventType = 'onStart' | 'onStepStart' | 'onLanguageModelCallStart' | 'onLanguageModelCallEnd' | 'onToolExecutionStart' | 'onToolExecutionEnd' | 'onChunk' | 'onStepFinish' | 'onObjectStepStart' | 'onObjectStepFinish' | 'onEmbedStart' | 'onEmbedFinish' | 'onRerankStart' | 'onRerankFinish' | 'onFinish' | 'onError';
7467
+ type TelemetryDiagnosticChannelMessage<EVENT = unknown> = {
7468
+ readonly type: TelemetryDiagnosticEventType;
7469
+ readonly event: EVENT;
7470
+ };
7471
+
7405
7472
  /**
7406
7473
  * Creates a Response object from a text stream.
7407
7474
  * Each text chunk is encoded as UTF-8 and sent as a separate chunk.
@@ -7552,8 +7619,9 @@ interface UploadFileResult {
7552
7619
  * Uploads a file using a files API interface.
7553
7620
  *
7554
7621
  * @param api - The Files API interface to use for uploading.
7555
- * @param data - The file data to upload.
7556
- * @param mediaType - Optional IANA media type. Auto-detected from file bytes if not provided.
7622
+ * @param data - The file data to upload (tagged `{ type: 'data' | 'text' }`).
7623
+ * @param mediaType - Optional IANA media type. Auto-detected from file bytes
7624
+ * when omitted (falls back to `text/plain` for the `text` variant).
7557
7625
  * @param filename - Optional filename for the uploaded file.
7558
7626
  * @param providerOptions - Additional provider-specific options.
7559
7627
  *
@@ -7565,23 +7633,17 @@ declare function uploadFile({ api, data: dataArg, mediaType: mediaTypeArg, filen
7565
7633
  * Can be a `FilesV4` instance or a `ProviderV4` instance with a `files()` method.
7566
7634
  */
7567
7635
  api: FilesV4 | ProviderV4;
7636
+ } & Omit<FilesV4UploadFileCallOptions, 'mediaType' | 'data'> & {
7568
7637
  /**
7569
- * The file data to upload.
7638
+ * The file data. Accepts the tagged `{ type: 'data' | 'text' }` shapes, or
7639
+ * the shorthand `Uint8Array | string` (treated as `{ type: 'data', data }`).
7570
7640
  */
7571
- data: DataContent;
7641
+ data: FilesV4UploadFileCallOptions['data'] | Uint8Array | string;
7572
7642
  /**
7573
- * Optional IANA media type of the file.
7574
- * Auto-detected from file bytes if not provided.
7643
+ * Optional IANA media type of the file. Auto-detected from file bytes when
7644
+ * omitted; falls back to `text/plain` for the `text` variant.
7575
7645
  */
7576
7646
  mediaType?: string;
7577
- /**
7578
- * Optional filename for the uploaded file.
7579
- */
7580
- filename?: string;
7581
- /**
7582
- * Additional provider-specific options.
7583
- */
7584
- providerOptions?: ProviderOptions;
7585
7647
  }): Promise<UploadFileResult>;
7586
7648
 
7587
7649
  type UploadSkillResult = Omit<SkillsV4UploadSkillResult, 'providerReference' | 'warnings'> & {
@@ -7589,41 +7651,17 @@ type UploadSkillResult = Omit<SkillsV4UploadSkillResult, 'providerReference' | '
7589
7651
  readonly warnings: Warning[];
7590
7652
  };
7591
7653
 
7654
+ type UploadSkillFile = Omit<SkillsV4File, 'data'> & {
7655
+ /**
7656
+ * The file data. Accepts the tagged `{ type: 'data' | 'text' }` shapes, or
7657
+ * the shorthand `Uint8Array | string` (treated as `{ type: 'data', data }`).
7658
+ */
7659
+ data: SkillsV4File['data'] | Uint8Array | string;
7660
+ };
7592
7661
  declare function uploadSkill({ api, files, displayTitle, providerOptions, }: {
7593
7662
  api: SkillsV4 | ProviderV4;
7594
- files: SkillsV4File[];
7595
- displayTitle?: string;
7596
- providerOptions?: ProviderOptions;
7663
+ } & Omit<SkillsV4UploadSkillCallOptions, 'files'> & {
7664
+ files: UploadSkillFile[];
7597
7665
  }): Promise<UploadSkillResult>;
7598
7666
 
7599
- declare global {
7600
- /**
7601
- * The default provider to use for the AI SDK.
7602
- * String model ids are resolved to the default provider and model id.
7603
- *
7604
- * If not set, the default provider is the Vercel AI gateway provider.
7605
- *
7606
- * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
7607
- */
7608
- var AI_SDK_DEFAULT_PROVIDER: ProviderV4 | ProviderV3 | ProviderV2 | undefined;
7609
- /**
7610
- * The warning logger to use for the AI SDK.
7611
- *
7612
- * If not set, the default logger is the console.warn function.
7613
- *
7614
- * If set to false, no warnings are logged.
7615
- */
7616
- var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
7617
- /**
7618
- * Globally registered telemetry integrations for the AI SDK.
7619
- *
7620
- * Integrations registered here receive lifecycle events (onStart, onStepStart,
7621
- * etc.) from every `generateText`, `streamText`, and similar call.
7622
- *
7623
- * Prefer using `registerTelemetry()` from `'ai'` instead of
7624
- * assigning this directly.
7625
- */
7626
- var AI_SDK_TELEMETRY_INTEGRATIONS: Telemetry[] | undefined;
7627
- }
7628
-
7629
- export { AbstractChat, ActiveTools, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, CustomContentUIPart, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedEndEvent, EmbedManyResult, EmbedResult, EmbedStartEvent, Embedding, EmbeddingModel, EmbeddingModelCallEndEvent, EmbeddingModelCallStartEvent, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LanguageModelStreamPart as Experimental_LanguageModelStreamPart, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectEndEvent, GenerateObjectResult, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateTextEndEvent, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextResult, GenerateTextStartEvent, GenerateTextStepEndEvent, GenerateTextStepStartEvent, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, GenericToolApprovalFunction, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferTelemetryEvent, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelCallEndEvent, LanguageModelCallOptions, LanguageModelCallStartEvent, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, ModelInfo, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnChunkEvent, OnFinishEvent, OnLanguageModelCallEndCallback, OnLanguageModelCallStartCallback, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, OnToolExecutionEndCallback, OnToolExecutionStartCallback, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderReference, ProviderRegistryProvider, ReasoningFileOutput, ReasoningFileUIPart, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RequestOptions, RerankEndEvent, RerankResult, RerankStartEvent, RerankingModel, RerankingModelCallEndEvent, RerankingModelCallStartEvent, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SingleToolApprovalFunction, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextChunkEvent, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextResult, StreamTextTransform, Telemetry, TelemetryOptions, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalConfiguration, ToolApprovalRequestOutput, ToolApprovalResponseOutput, ToolApprovalStatus, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolLoopAgent, ToolLoopAgentSettings, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UploadFileResult, UploadSkillResult, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, filterActiveTools as experimental_filterActiveTools, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, streamLanguageModelCall as experimental_streamLanguageModelCall, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getChunkTimeoutMs, getStaticToolName, getStepTimeoutMs, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, getToolTimeoutMs, getTotalTimeoutMs, hasToolCall, isCustomContentUIPart, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningFileUIPart, isReasoningUIPart, isStaticToolUIPart, isStepCount, isTextUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetry, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, isStepCount as stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
7667
+ export { AI_SDK_TELEMETRY_DIAGNOSTIC_CHANNEL, AbstractChat, ActiveTools, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, CustomContentUIPart, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedEndEvent, EmbedManyResult, EmbedResult, EmbedStartEvent, Embedding, EmbeddingModel, EmbeddingModelCallEndEvent, EmbeddingModelCallStartEvent, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LanguageModelStreamPart as Experimental_LanguageModelStreamPart, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectEndEvent, GenerateObjectResult, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateTextEndEvent, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextResult, GenerateTextStartEvent, GenerateTextStepEndEvent, GenerateTextStepStartEvent, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, GenericToolApprovalFunction, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferTelemetryEvent, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelCallEndEvent, LanguageModelCallOptions, LanguageModelCallStartEvent, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, ModelInfo, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnChunkEvent, OnFinishEvent, OnLanguageModelCallEndCallback, OnLanguageModelCallStartCallback, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, OnToolExecutionEndCallback, OnToolExecutionStartCallback, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderReference, ProviderRegistryProvider, ReasoningFileOutput, ReasoningFileUIPart, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RequestOptions, RerankEndEvent, RerankResult, RerankStartEvent, RerankingModel, RerankingModelCallEndEvent, RerankingModelCallStartEvent, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SingleToolApprovalFunction, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextChunkEvent, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextResult, StreamTextTransform, Telemetry, TelemetryDiagnosticChannelMessage, TelemetryDiagnosticEventType, TelemetryOptions, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalConfiguration, ToolApprovalRequestOutput, ToolApprovalResponseOutput, ToolApprovalStatus, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolLoopAgent, ToolLoopAgentSettings, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UploadFileResult, UploadSkillResult, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, filterActiveTools as experimental_filterActiveTools, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, streamLanguageModelCall as experimental_streamLanguageModelCall, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getChunkTimeoutMs, getStaticToolName, getStepTimeoutMs, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, getToolTimeoutMs, getTotalTimeoutMs, hasToolCall, isCustomContentUIPart, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningFileUIPart, isReasoningUIPart, isStaticToolUIPart, isStepCount, isTextUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetry, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, isStepCount as stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };