ai 6.0.106 → 6.0.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.108
4
+
5
+ ### Patch Changes
6
+
7
+ - 2a4f512: feat(ai): add telemetry interface and registry
8
+
9
+ ## 6.0.107
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [08336f1]
14
+ - @ai-sdk/provider-utils@4.0.17
15
+ - @ai-sdk/gateway@3.0.61
16
+
3
17
  ## 6.0.106
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -707,67 +707,6 @@ type Prompt = {
707
707
  prompt?: never;
708
708
  });
709
709
 
710
- /**
711
- * Telemetry configuration.
712
- */
713
- type TelemetrySettings = {
714
- /**
715
- * Enable or disable telemetry. Disabled by default while experimental.
716
- */
717
- isEnabled?: boolean;
718
- /**
719
- * Enable or disable input recording. Enabled by default.
720
- *
721
- * You might want to disable input recording to avoid recording sensitive
722
- * information, to reduce data transfers, or to increase performance.
723
- */
724
- recordInputs?: boolean;
725
- /**
726
- * Enable or disable output recording. Enabled by default.
727
- *
728
- * You might want to disable output recording to avoid recording sensitive
729
- * information, to reduce data transfers, or to increase performance.
730
- */
731
- recordOutputs?: boolean;
732
- /**
733
- * Identifier for this function. Used to group telemetry data by function.
734
- */
735
- functionId?: string;
736
- /**
737
- * Additional information to include in the telemetry data.
738
- */
739
- metadata?: Record<string, AttributeValue>;
740
- /**
741
- * A custom tracer to use for the telemetry data.
742
- */
743
- tracer?: Tracer;
744
- };
745
-
746
- /**
747
- * Experimental. Can change in patch versions without warning.
748
- *
749
- * Download function. Called with the array of URLs and a boolean indicating
750
- * whether the URL is supported by the model.
751
- *
752
- * The download function can decide for each URL:
753
- * - to return null (which means that the URL should be passed to the model)
754
- * - to download the asset and return the data (incl. retries, authentication, etc.)
755
- *
756
- * Should throw DownloadError if the download fails.
757
- *
758
- * Should return an array of objects sorted by the order of the requested downloads.
759
- * For each object, the data should be a Uint8Array if the URL was downloaded.
760
- * For each object, the mediaType should be the media type of the downloaded asset.
761
- * For each object, the data should be null if the URL should be passed through as is.
762
- */
763
- type DownloadFunction = (options: Array<{
764
- url: URL;
765
- isUrlSupportedByModel: boolean;
766
- }>) => PromiseLike<Array<{
767
- data: Uint8Array;
768
- mediaType: string | undefined;
769
- } | null>>;
770
-
771
710
  /**
772
711
  * A message that was generated during the generation process.
773
712
  * It can be either an assistant message or a tool message.
@@ -1140,6 +1079,87 @@ type OnFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS> & {
1140
1079
  readonly metadata: Record<string, unknown> | undefined;
1141
1080
  };
1142
1081
 
1082
+ /**
1083
+ * Implement this interface to create custom telemetry integrations.
1084
+ * Methods can be sync or return a PromiseLike.
1085
+ */
1086
+ interface TelemetryIntegration<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> {
1087
+ onStart?(event: OnStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1088
+ onStepStart?(event: OnStepStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1089
+ onToolCallStart?(event: OnToolCallStartEvent<TOOLS>): PromiseLike<void> | void;
1090
+ onToolCallFinish?(event: OnToolCallFinishEvent<TOOLS>): PromiseLike<void> | void;
1091
+ onStepFinish?(event: OnStepFinishEvent<TOOLS>): PromiseLike<void> | void;
1092
+ onFinish?(event: OnFinishEvent<TOOLS>): PromiseLike<void> | void;
1093
+ }
1094
+
1095
+ /**
1096
+ * Telemetry configuration.
1097
+ */
1098
+ type TelemetrySettings = {
1099
+ /**
1100
+ * Enable or disable telemetry. Disabled by default while experimental.
1101
+ */
1102
+ isEnabled?: boolean;
1103
+ /**
1104
+ * Enable or disable input recording. Enabled by default.
1105
+ *
1106
+ * You might want to disable input recording to avoid recording sensitive
1107
+ * information, to reduce data transfers, or to increase performance.
1108
+ */
1109
+ recordInputs?: boolean;
1110
+ /**
1111
+ * Enable or disable output recording. Enabled by default.
1112
+ *
1113
+ * You might want to disable output recording to avoid recording sensitive
1114
+ * information, to reduce data transfers, or to increase performance.
1115
+ */
1116
+ recordOutputs?: boolean;
1117
+ /**
1118
+ * Identifier for this function. Used to group telemetry data by function.
1119
+ */
1120
+ functionId?: string;
1121
+ /**
1122
+ * Additional information to include in the telemetry data.
1123
+ */
1124
+ metadata?: Record<string, AttributeValue>;
1125
+ /**
1126
+ * A custom tracer to use for the telemetry data.
1127
+ */
1128
+ tracer?: Tracer;
1129
+ /**
1130
+ * Per-call telemetry integrations that receive lifecycle events during generation.
1131
+ *
1132
+ * These integrations run after any globally registered integrations
1133
+ * (see `registerTelemetryIntegration`).
1134
+ */
1135
+ integrations?: TelemetryIntegration | TelemetryIntegration[];
1136
+ };
1137
+
1138
+ /**
1139
+ * Experimental. Can change in patch versions without warning.
1140
+ *
1141
+ * Download function. Called with the array of URLs and a boolean indicating
1142
+ * whether the URL is supported by the model.
1143
+ *
1144
+ * The download function can decide for each URL:
1145
+ * - to return null (which means that the URL should be passed to the model)
1146
+ * - to download the asset and return the data (incl. retries, authentication, etc.)
1147
+ *
1148
+ * Should throw DownloadError if the download fails.
1149
+ *
1150
+ * Should return an array of objects sorted by the order of the requested downloads.
1151
+ * For each object, the data should be a Uint8Array if the URL was downloaded.
1152
+ * For each object, the mediaType should be the media type of the downloaded asset.
1153
+ * For each object, the data should be null if the URL should be passed through as is.
1154
+ */
1155
+ type DownloadFunction = (options: Array<{
1156
+ url: URL;
1157
+ isUrlSupportedByModel: boolean;
1158
+ }>) => PromiseLike<Array<{
1159
+ data: Uint8Array;
1160
+ mediaType: string | undefined;
1161
+ } | null>>;
1162
+
1143
1163
  /**
1144
1164
  * Function that you can use to provide different settings for a step.
1145
1165
  *
@@ -6360,6 +6380,18 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
6360
6380
  }>;
6361
6381
  }): Promise<TranscriptionResult>;
6362
6382
 
6383
+ /**
6384
+ * Wraps a telemetry integration with bound methods.
6385
+ * Use this when creating class-based integrations to ensure methods
6386
+ * work correctly when passed as callbacks.
6387
+ */
6388
+ declare function bindTelemetryIntegration(integration: TelemetryIntegration): TelemetryIntegration;
6389
+
6390
+ /**
6391
+ * Registers a telemetry integration globally.
6392
+ */
6393
+ declare function registerTelemetryIntegration(integration: TelemetryIntegration): void;
6394
+
6363
6395
  declare global {
6364
6396
  /**
6365
6397
  * The default provider to use for the AI SDK.
@@ -6378,6 +6410,16 @@ declare global {
6378
6410
  * If set to false, no warnings are logged.
6379
6411
  */
6380
6412
  var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
6413
+ /**
6414
+ * Globally registered telemetry integrations for the AI SDK.
6415
+ *
6416
+ * Integrations registered here receive lifecycle events (onStart, onStepStart,
6417
+ * etc.) from every `generateText`, `streamText`, and similar call.
6418
+ *
6419
+ * Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
6420
+ * assigning this directly.
6421
+ */
6422
+ var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
6381
6423
  }
6382
6424
 
6383
- export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, 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, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStartCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentOnStepStartCallback, ToolLoopAgentOnToolCallFinishCallback, ToolLoopAgentOnToolCallStartCallback, ToolLoopAgentSettings, ToolSet, 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, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
6425
+ export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, 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, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStartCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentOnStepStartCallback, ToolLoopAgentOnToolCallFinishCallback, ToolLoopAgentOnToolCallStartCallback, ToolLoopAgentSettings, ToolSet, 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, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
package/dist/index.d.ts CHANGED
@@ -707,67 +707,6 @@ type Prompt = {
707
707
  prompt?: never;
708
708
  });
709
709
 
710
- /**
711
- * Telemetry configuration.
712
- */
713
- type TelemetrySettings = {
714
- /**
715
- * Enable or disable telemetry. Disabled by default while experimental.
716
- */
717
- isEnabled?: boolean;
718
- /**
719
- * Enable or disable input recording. Enabled by default.
720
- *
721
- * You might want to disable input recording to avoid recording sensitive
722
- * information, to reduce data transfers, or to increase performance.
723
- */
724
- recordInputs?: boolean;
725
- /**
726
- * Enable or disable output recording. Enabled by default.
727
- *
728
- * You might want to disable output recording to avoid recording sensitive
729
- * information, to reduce data transfers, or to increase performance.
730
- */
731
- recordOutputs?: boolean;
732
- /**
733
- * Identifier for this function. Used to group telemetry data by function.
734
- */
735
- functionId?: string;
736
- /**
737
- * Additional information to include in the telemetry data.
738
- */
739
- metadata?: Record<string, AttributeValue>;
740
- /**
741
- * A custom tracer to use for the telemetry data.
742
- */
743
- tracer?: Tracer;
744
- };
745
-
746
- /**
747
- * Experimental. Can change in patch versions without warning.
748
- *
749
- * Download function. Called with the array of URLs and a boolean indicating
750
- * whether the URL is supported by the model.
751
- *
752
- * The download function can decide for each URL:
753
- * - to return null (which means that the URL should be passed to the model)
754
- * - to download the asset and return the data (incl. retries, authentication, etc.)
755
- *
756
- * Should throw DownloadError if the download fails.
757
- *
758
- * Should return an array of objects sorted by the order of the requested downloads.
759
- * For each object, the data should be a Uint8Array if the URL was downloaded.
760
- * For each object, the mediaType should be the media type of the downloaded asset.
761
- * For each object, the data should be null if the URL should be passed through as is.
762
- */
763
- type DownloadFunction = (options: Array<{
764
- url: URL;
765
- isUrlSupportedByModel: boolean;
766
- }>) => PromiseLike<Array<{
767
- data: Uint8Array;
768
- mediaType: string | undefined;
769
- } | null>>;
770
-
771
710
  /**
772
711
  * A message that was generated during the generation process.
773
712
  * It can be either an assistant message or a tool message.
@@ -1140,6 +1079,87 @@ type OnFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS> & {
1140
1079
  readonly metadata: Record<string, unknown> | undefined;
1141
1080
  };
1142
1081
 
1082
+ /**
1083
+ * Implement this interface to create custom telemetry integrations.
1084
+ * Methods can be sync or return a PromiseLike.
1085
+ */
1086
+ interface TelemetryIntegration<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> {
1087
+ onStart?(event: OnStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1088
+ onStepStart?(event: OnStepStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1089
+ onToolCallStart?(event: OnToolCallStartEvent<TOOLS>): PromiseLike<void> | void;
1090
+ onToolCallFinish?(event: OnToolCallFinishEvent<TOOLS>): PromiseLike<void> | void;
1091
+ onStepFinish?(event: OnStepFinishEvent<TOOLS>): PromiseLike<void> | void;
1092
+ onFinish?(event: OnFinishEvent<TOOLS>): PromiseLike<void> | void;
1093
+ }
1094
+
1095
+ /**
1096
+ * Telemetry configuration.
1097
+ */
1098
+ type TelemetrySettings = {
1099
+ /**
1100
+ * Enable or disable telemetry. Disabled by default while experimental.
1101
+ */
1102
+ isEnabled?: boolean;
1103
+ /**
1104
+ * Enable or disable input recording. Enabled by default.
1105
+ *
1106
+ * You might want to disable input recording to avoid recording sensitive
1107
+ * information, to reduce data transfers, or to increase performance.
1108
+ */
1109
+ recordInputs?: boolean;
1110
+ /**
1111
+ * Enable or disable output recording. Enabled by default.
1112
+ *
1113
+ * You might want to disable output recording to avoid recording sensitive
1114
+ * information, to reduce data transfers, or to increase performance.
1115
+ */
1116
+ recordOutputs?: boolean;
1117
+ /**
1118
+ * Identifier for this function. Used to group telemetry data by function.
1119
+ */
1120
+ functionId?: string;
1121
+ /**
1122
+ * Additional information to include in the telemetry data.
1123
+ */
1124
+ metadata?: Record<string, AttributeValue>;
1125
+ /**
1126
+ * A custom tracer to use for the telemetry data.
1127
+ */
1128
+ tracer?: Tracer;
1129
+ /**
1130
+ * Per-call telemetry integrations that receive lifecycle events during generation.
1131
+ *
1132
+ * These integrations run after any globally registered integrations
1133
+ * (see `registerTelemetryIntegration`).
1134
+ */
1135
+ integrations?: TelemetryIntegration | TelemetryIntegration[];
1136
+ };
1137
+
1138
+ /**
1139
+ * Experimental. Can change in patch versions without warning.
1140
+ *
1141
+ * Download function. Called with the array of URLs and a boolean indicating
1142
+ * whether the URL is supported by the model.
1143
+ *
1144
+ * The download function can decide for each URL:
1145
+ * - to return null (which means that the URL should be passed to the model)
1146
+ * - to download the asset and return the data (incl. retries, authentication, etc.)
1147
+ *
1148
+ * Should throw DownloadError if the download fails.
1149
+ *
1150
+ * Should return an array of objects sorted by the order of the requested downloads.
1151
+ * For each object, the data should be a Uint8Array if the URL was downloaded.
1152
+ * For each object, the mediaType should be the media type of the downloaded asset.
1153
+ * For each object, the data should be null if the URL should be passed through as is.
1154
+ */
1155
+ type DownloadFunction = (options: Array<{
1156
+ url: URL;
1157
+ isUrlSupportedByModel: boolean;
1158
+ }>) => PromiseLike<Array<{
1159
+ data: Uint8Array;
1160
+ mediaType: string | undefined;
1161
+ } | null>>;
1162
+
1143
1163
  /**
1144
1164
  * Function that you can use to provide different settings for a step.
1145
1165
  *
@@ -6360,6 +6380,18 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
6360
6380
  }>;
6361
6381
  }): Promise<TranscriptionResult>;
6362
6382
 
6383
+ /**
6384
+ * Wraps a telemetry integration with bound methods.
6385
+ * Use this when creating class-based integrations to ensure methods
6386
+ * work correctly when passed as callbacks.
6387
+ */
6388
+ declare function bindTelemetryIntegration(integration: TelemetryIntegration): TelemetryIntegration;
6389
+
6390
+ /**
6391
+ * Registers a telemetry integration globally.
6392
+ */
6393
+ declare function registerTelemetryIntegration(integration: TelemetryIntegration): void;
6394
+
6363
6395
  declare global {
6364
6396
  /**
6365
6397
  * The default provider to use for the AI SDK.
@@ -6378,6 +6410,16 @@ declare global {
6378
6410
  * If set to false, no warnings are logged.
6379
6411
  */
6380
6412
  var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
6413
+ /**
6414
+ * Globally registered telemetry integrations for the AI SDK.
6415
+ *
6416
+ * Integrations registered here receive lifecycle events (onStart, onStepStart,
6417
+ * etc.) from every `generateText`, `streamText`, and similar call.
6418
+ *
6419
+ * Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
6420
+ * assigning this directly.
6421
+ */
6422
+ var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
6381
6423
  }
6382
6424
 
6383
- export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, 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, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStartCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentOnStepStartCallback, ToolLoopAgentOnToolCallFinishCallback, ToolLoopAgentOnToolCallStartCallback, ToolLoopAgentSettings, ToolSet, 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, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
6425
+ export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, 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, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStartCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentOnStepStartCallback, ToolLoopAgentOnToolCallFinishCallback, ToolLoopAgentOnToolCallStartCallback, ToolLoopAgentSettings, ToolSet, 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, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ __export(src_exports, {
70
70
  addToolInputExamplesMiddleware: () => addToolInputExamplesMiddleware,
71
71
  asSchema: () => import_provider_utils39.asSchema,
72
72
  assistantModelMessageSchema: () => assistantModelMessageSchema,
73
+ bindTelemetryIntegration: () => bindTelemetryIntegration,
73
74
  callCompletionApi: () => callCompletionApi,
74
75
  consumeStream: () => consumeStream,
75
76
  convertFileListToFileUIParts: () => convertFileListToFileUIParts,
@@ -127,6 +128,7 @@ __export(src_exports, {
127
128
  pipeUIMessageStreamToResponse: () => pipeUIMessageStreamToResponse,
128
129
  pruneMessages: () => pruneMessages,
129
130
  readUIMessageStream: () => readUIMessageStream,
131
+ registerTelemetryIntegration: () => registerTelemetryIntegration,
130
132
  rerank: () => rerank,
131
133
  safeValidateUIMessages: () => safeValidateUIMessages,
132
134
  simulateReadableStream: () => simulateReadableStream,
@@ -1226,7 +1228,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1226
1228
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1227
1229
 
1228
1230
  // src/version.ts
1229
- var VERSION = true ? "6.0.106" : "0.0.0-test";
1231
+ var VERSION = true ? "6.0.108" : "0.0.0-test";
1230
1232
 
1231
1233
  // src/util/download/download.ts
1232
1234
  var download = async ({
@@ -13290,6 +13292,27 @@ var TextStreamChatTransport = class extends HttpChatTransport {
13290
13292
  });
13291
13293
  }
13292
13294
  };
13295
+
13296
+ // src/telemetry/telemetry-integration-registry.ts
13297
+ function registerTelemetryIntegration(integration) {
13298
+ if (!globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) {
13299
+ globalThis.AI_SDK_TELEMETRY_INTEGRATIONS = [];
13300
+ }
13301
+ globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(integration);
13302
+ }
13303
+
13304
+ // src/telemetry/get-global-telemetry-integration.ts
13305
+ function bindTelemetryIntegration(integration) {
13306
+ var _a21, _b, _c, _d, _e, _f;
13307
+ return {
13308
+ onStart: (_a21 = integration.onStart) == null ? void 0 : _a21.bind(integration),
13309
+ onStepStart: (_b = integration.onStepStart) == null ? void 0 : _b.bind(integration),
13310
+ onToolCallStart: (_c = integration.onToolCallStart) == null ? void 0 : _c.bind(integration),
13311
+ onToolCallFinish: (_d = integration.onToolCallFinish) == null ? void 0 : _d.bind(integration),
13312
+ onStepFinish: (_e = integration.onStepFinish) == null ? void 0 : _e.bind(integration),
13313
+ onFinish: (_f = integration.onFinish) == null ? void 0 : _f.bind(integration)
13314
+ };
13315
+ }
13293
13316
  // Annotate the CommonJS export names for ESM import in node:
13294
13317
  0 && (module.exports = {
13295
13318
  AISDKError,
@@ -13342,6 +13365,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
13342
13365
  addToolInputExamplesMiddleware,
13343
13366
  asSchema,
13344
13367
  assistantModelMessageSchema,
13368
+ bindTelemetryIntegration,
13345
13369
  callCompletionApi,
13346
13370
  consumeStream,
13347
13371
  convertFileListToFileUIParts,
@@ -13399,6 +13423,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
13399
13423
  pipeUIMessageStreamToResponse,
13400
13424
  pruneMessages,
13401
13425
  readUIMessageStream,
13426
+ registerTelemetryIntegration,
13402
13427
  rerank,
13403
13428
  safeValidateUIMessages,
13404
13429
  simulateReadableStream,