ai 7.0.49 → 7.0.50
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 +19 -0
- package/dist/index.d.ts +68 -14
- package/dist/index.js +196 -62
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/test/index.d.ts +7 -1
- package/dist/test/index.js +8 -10
- package/dist/test/index.js.map +1 -1
- package/docs/03-ai-sdk-core/18-code-mode.mdx +14 -11
- package/docs/03-ai-sdk-core/38-video-generation.mdx +44 -15
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +42 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
- package/package.json +4 -4
- package/src/generate-text/index.ts +1 -4
- package/src/generate-text/tool-caller-configuration.ts +17 -45
- package/src/generate-video/generate-video.ts +328 -48
- package/src/test/mock-video-model-v4.ts +22 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.50
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 79e133c: async APIs for generateVideo (poll, webhook)
|
|
8
|
+
|
|
9
|
+
Adds an asynchronous start/status flow to the experimental video model
|
|
10
|
+
interface (`VideoModelV4`): models may now implement `doStart`, `doStatus`,
|
|
11
|
+
and `handleWebhookOption` instead of (or in addition to) `doGenerate`, and
|
|
12
|
+
`experimental_generateVideo` accepts `poll` and `webhook` options to
|
|
13
|
+
orchestrate completion via polling or webhooks. Polling configuration can use
|
|
14
|
+
a custom delay implementation for durable workflow compatibility.
|
|
15
|
+
|
|
16
|
+
- da64b51: feat(code-mode): simplify tool caller configuration
|
|
17
|
+
- Updated dependencies [79e133c]
|
|
18
|
+
- @ai-sdk/provider@4.0.5
|
|
19
|
+
- @ai-sdk/gateway@4.0.39
|
|
20
|
+
- @ai-sdk/provider-utils@5.0.19
|
|
21
|
+
|
|
3
22
|
## 7.0.49
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, Experimental_VideoModelV4FrameType, EmbeddingModelV4CallOptions, Experimental_RealtimeFactoryV4, Experimental_RealtimeFactoryV4GetTokenOptions, Experimental_RealtimeFactoryV4GetTokenResult, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4SessionConfig, Experimental_RealtimeModelV4ToolDefinition, FilesV4, SkillsV4, NoSuchModelError, SharedV4AudioFormat, Experimental_SpeechTranslationModelV4, Experimental_SpeechTranslationModelV4Usage, FilesV4UploadFileCallOptions, SkillsV4UploadSkillResult, SkillsV4UploadSkillCallOptions, SkillsV4File } from '@ai-sdk/provider';
|
|
1
|
+
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, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, Experimental_VideoModelV4FrameType, Experimental_VideoModelV4OperationWebhook, EmbeddingModelV4CallOptions, Experimental_RealtimeFactoryV4, Experimental_RealtimeFactoryV4GetTokenOptions, Experimental_RealtimeFactoryV4GetTokenResult, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4SessionConfig, Experimental_RealtimeModelV4ToolDefinition, FilesV4, SkillsV4, NoSuchModelError, SharedV4AudioFormat, Experimental_SpeechTranslationModelV4, Experimental_SpeechTranslationModelV4Usage, FilesV4UploadFileCallOptions, SkillsV4UploadSkillResult, SkillsV4UploadSkillCallOptions, SkillsV4File } from '@ai-sdk/provider';
|
|
2
2
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
3
3
|
import { GatewayModelId } from '@ai-sdk/gateway';
|
|
4
4
|
export { GatewayModelId, createGateway, gateway } from '@ai-sdk/gateway';
|
|
@@ -3019,19 +3019,11 @@ type ToolApprovalConfiguration<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Co
|
|
|
3019
3019
|
[key in keyof TOOLS]?: ToolApprovalStatus | SingleToolApprovalFunction<InferToolInput<TOOLS[key]>, InferToolContext<TOOLS[key]>, RUNTIME_CONTEXT>;
|
|
3020
3020
|
};
|
|
3021
3021
|
|
|
3022
|
-
interface Experimental_ToolCallerReference<NAME extends string = string> {
|
|
3023
|
-
readonly toolName: NAME;
|
|
3024
|
-
}
|
|
3025
3022
|
type ToolCallerName<TOOLS extends ToolSet> = {
|
|
3026
3023
|
[NAME in keyof TOOLS]: TOOLS[NAME] extends Experimental_ToolCallerTool ? NAME : never;
|
|
3027
3024
|
}[keyof TOOLS] & string;
|
|
3028
|
-
type
|
|
3029
|
-
[NAME in
|
|
3030
|
-
}[ToolCallerName<TOOLS>];
|
|
3031
|
-
type Experimental_ToolCallers<TOOLS extends ToolSet> = (callers: {
|
|
3032
|
-
[NAME in ToolCallerName<TOOLS>]: Experimental_ToolCallerReference<NAME>;
|
|
3033
|
-
}) => {
|
|
3034
|
-
[NAME in keyof TOOLS]?: ReadonlyArray<'direct' | ToolCallerReferenceUnion<TOOLS>>;
|
|
3025
|
+
type Experimental_ToolCallers<TOOLS extends ToolSet> = {
|
|
3026
|
+
[NAME in keyof TOOLS]?: ReadonlyArray<'AI_SDK_DIRECT_TOOL_CALL' | ToolCallerName<TOOLS>>;
|
|
3035
3027
|
};
|
|
3036
3028
|
|
|
3037
3029
|
declare const symbol$l: unique symbol;
|
|
@@ -7881,7 +7873,48 @@ type GenerateVideoPrompt = string | {
|
|
|
7881
7873
|
image: DataContent;
|
|
7882
7874
|
text?: string;
|
|
7883
7875
|
};
|
|
7884
|
-
|
|
7876
|
+
/**
|
|
7877
|
+
* Polling configuration for models that support the asynchronous
|
|
7878
|
+
* start/status flow.
|
|
7879
|
+
*
|
|
7880
|
+
* When used with `webhook`, `timeoutMs` also limits how long the SDK waits for
|
|
7881
|
+
* the webhook notification. If the model does not support webhooks, these
|
|
7882
|
+
* options configure the automatic polling fallback.
|
|
7883
|
+
*/
|
|
7884
|
+
type GenerateVideoPollOptions = {
|
|
7885
|
+
/**
|
|
7886
|
+
* Interval between status checks in milliseconds.
|
|
7887
|
+
*
|
|
7888
|
+
* @default 5000
|
|
7889
|
+
*/
|
|
7890
|
+
intervalMs?: number;
|
|
7891
|
+
/**
|
|
7892
|
+
* Maximum time to wait for completion in milliseconds.
|
|
7893
|
+
*
|
|
7894
|
+
* @default 600000 (10 minutes)
|
|
7895
|
+
*/
|
|
7896
|
+
timeoutMs?: number;
|
|
7897
|
+
/**
|
|
7898
|
+
* Custom delay implementation for polling intervals and webhook timeouts.
|
|
7899
|
+
* This can be used with durable workflow sleep functions.
|
|
7900
|
+
*
|
|
7901
|
+
* @default the built-in timer-based delay
|
|
7902
|
+
*/
|
|
7903
|
+
delay?: (delayInMs: number, options?: {
|
|
7904
|
+
abortSignal?: AbortSignal;
|
|
7905
|
+
}) => PromiseLike<void>;
|
|
7906
|
+
};
|
|
7907
|
+
/**
|
|
7908
|
+
* Webhook factory for models that support the asynchronous start/status flow.
|
|
7909
|
+
*
|
|
7910
|
+
* The factory should return a URL for the provider to send notifications to,
|
|
7911
|
+
* and a `received` promise that resolves when the notification arrives.
|
|
7912
|
+
*/
|
|
7913
|
+
type GenerateVideoWebhookFactory = () => PromiseLike<{
|
|
7914
|
+
url: string;
|
|
7915
|
+
received: PromiseLike<Experimental_VideoModelV4OperationWebhook>;
|
|
7916
|
+
}>;
|
|
7917
|
+
declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, frameImages, inputReferences, generateAudio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, poll, webhook, }: {
|
|
7885
7918
|
/**
|
|
7886
7919
|
* The video model to use.
|
|
7887
7920
|
*/
|
|
@@ -7903,7 +7936,7 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
|
|
|
7903
7936
|
*/
|
|
7904
7937
|
aspectRatio?: `${number}:${number}`;
|
|
7905
7938
|
/**
|
|
7906
|
-
* Resolution of the videos to generate. Must have the format `{width}x{height}`.
|
|
7939
|
+
* Resolution of the videos to generate. Must have the format `{width}x${height}`.
|
|
7907
7940
|
*/
|
|
7908
7941
|
resolution?: `${number}x${number}`;
|
|
7909
7942
|
/**
|
|
@@ -7985,6 +8018,27 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
|
|
|
7985
8018
|
data: Uint8Array;
|
|
7986
8019
|
mediaType: string | undefined;
|
|
7987
8020
|
}>;
|
|
8021
|
+
/**
|
|
8022
|
+
* Polling configuration for models that support the asynchronous
|
|
8023
|
+
* start/status flow. When provided and the model implements `doStart`
|
|
8024
|
+
* and `doStatus`, the SDK will orchestrate polling automatically.
|
|
8025
|
+
*
|
|
8026
|
+
* This option can be combined with `webhook`: `timeoutMs` limits the webhook
|
|
8027
|
+
* wait, and the polling settings apply if the model does not support
|
|
8028
|
+
* webhooks.
|
|
8029
|
+
*/
|
|
8030
|
+
poll?: GenerateVideoPollOptions;
|
|
8031
|
+
/**
|
|
8032
|
+
* Webhook factory for models that support the asynchronous
|
|
8033
|
+
* start/status flow. When provided and the model implements `doStart`
|
|
8034
|
+
* and `doStatus`, the SDK will use webhooks instead of polling.
|
|
8035
|
+
*
|
|
8036
|
+
* The factory should return a URL for the provider to send notifications to,
|
|
8037
|
+
* and a `received` promise that resolves when the notification arrives.
|
|
8038
|
+
* `poll` can also be provided to configure the webhook timeout and polling
|
|
8039
|
+
* fallback.
|
|
8040
|
+
*/
|
|
8041
|
+
webhook?: GenerateVideoWebhookFactory;
|
|
7988
8042
|
}): Promise<GenerateVideoResult>;
|
|
7989
8043
|
|
|
7990
8044
|
/**
|
|
@@ -9125,4 +9179,4 @@ declare function uploadSkill({ api, files, displayTitle, providerOptions, }: {
|
|
|
9125
9179
|
files: UploadSkillFile[];
|
|
9126
9180
|
}): Promise<UploadSkillResult>;
|
|
9127
9181
|
|
|
9128
|
-
export { AI_SDK_TELEMETRY_TRACING_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, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LanguageModelStreamPart as Experimental_LanguageModelStreamPart, LogWarningsFunction as Experimental_LogWarningsFunction, RealtimeClientEvent as Experimental_RealtimeClientEvent, RealtimeFactory as Experimental_RealtimeFactory, RealtimeFactoryGetTokenOptions as Experimental_RealtimeFactoryGetTokenOptions, RealtimeFactoryGetTokenResult as Experimental_RealtimeFactoryGetTokenResult, RealtimeModel as Experimental_RealtimeModel, RealtimeServerEvent as Experimental_RealtimeServerEvent, RealtimeSessionConfig as Experimental_RealtimeSessionConfig, RealtimeSessionOptions as Experimental_RealtimeSessionOptions, RealtimeSetupResponse as Experimental_RealtimeSetupResponse, RealtimeState as Experimental_RealtimeState, RealtimeStatus as Experimental_RealtimeStatus, RealtimeToolDefinition as Experimental_RealtimeToolDefinition, Experimental_SpeechResult, StreamTranslationResult as Experimental_StreamTranslationResult,
|
|
9182
|
+
export { AI_SDK_TELEMETRY_TRACING_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, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LanguageModelStreamPart as Experimental_LanguageModelStreamPart, LogWarningsFunction as Experimental_LogWarningsFunction, RealtimeClientEvent as Experimental_RealtimeClientEvent, RealtimeFactory as Experimental_RealtimeFactory, RealtimeFactoryGetTokenOptions as Experimental_RealtimeFactoryGetTokenOptions, RealtimeFactoryGetTokenResult as Experimental_RealtimeFactoryGetTokenResult, RealtimeModel as Experimental_RealtimeModel, RealtimeServerEvent as Experimental_RealtimeServerEvent, RealtimeSessionConfig as Experimental_RealtimeSessionConfig, RealtimeSessionOptions as Experimental_RealtimeSessionOptions, RealtimeSetupResponse as Experimental_RealtimeSetupResponse, RealtimeState as Experimental_RealtimeState, RealtimeStatus as Experimental_RealtimeStatus, RealtimeToolDefinition as Experimental_RealtimeToolDefinition, Experimental_SpeechResult, StreamTranslationResult as Experimental_StreamTranslationResult, Experimental_ToolCallers, Experimental_TranscriptionResult, TranslationStreamPart as Experimental_TranslationStreamPart, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectEndEvent, GenerateObjectResult, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateTextAbortEvent, GenerateTextEndEvent, GenerateTextInclude, GenerateTextOnAbortCallback, GenerateTextOnEndCallback, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepEndCallback, 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, Instructions, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelCallEndEvent, LanguageModelCallOptions, LanguageModelCallStartEvent, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, ModelInfo, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnLanguageModelCallEndCallback, OnLanguageModelCallStartCallback, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, OnToolExecutionEndCallback, OnToolExecutionStartCallback, output as Output, OutputChunkTimingStats, 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, SpeechResult, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepResultPerformance, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextInclude, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextResult, StreamTextTransform, StreamTranscriptionResult, Telemetry, TelemetryOptions, TelemetryTracingChannelMessage, TelemetryTracingEventType, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToUIMessageChunkOptions, ToolApprovalConfiguration, ToolApprovalRequestOutput, ToolApprovalResponseOutput, ToolApprovalStatus, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolInputRefinement, ToolLoopAgent, ToolLoopAgentSettings, ToolOrder, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionResult, TranscriptionStreamPart, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnEndCallback, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepEndCallback, 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, detectToolDrift, embed, embedMany, experimental_createProviderRegistry, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio, filterActiveTools as experimental_filterActiveTools, experimental_generateSpeech, experimental_generateVideo, getRealtimeToolDefinitions as experimental_getRealtimeToolDefinitions, resampleAudio as experimental_resampleAudio, streamLanguageModelCall as experimental_streamLanguageModelCall, streamTranscribe as experimental_streamTranscribe, streamTranslate as experimental_streamTranslate, experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, fingerprintTools, generateImage, generateObject, generateSpeech, generateText, getChunkTimeoutMs, getFirstChunkTimeoutMs, 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, toTextStream, toUIMessageChunk, toUIMessageStream, toolModelMessageSchema, transcribe, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|
package/dist/index.js
CHANGED
|
@@ -1143,7 +1143,7 @@ import {
|
|
|
1143
1143
|
} from "@ai-sdk/provider-utils";
|
|
1144
1144
|
|
|
1145
1145
|
// src/version.ts
|
|
1146
|
-
var VERSION = true ? "7.0.
|
|
1146
|
+
var VERSION = true ? "7.0.50" : "0.0.0-test";
|
|
1147
1147
|
|
|
1148
1148
|
// src/util/download/download.ts
|
|
1149
1149
|
var download = async ({
|
|
@@ -4881,6 +4881,7 @@ function sortToolResultContentByToolCallOrder({
|
|
|
4881
4881
|
import {
|
|
4882
4882
|
experimental_getToolCaller
|
|
4883
4883
|
} from "@ai-sdk/provider-utils";
|
|
4884
|
+
var DIRECT_TOOL_CALL = "AI_SDK_DIRECT_TOOL_CALL";
|
|
4884
4885
|
function resolveToolCallerConfiguration({
|
|
4885
4886
|
tools,
|
|
4886
4887
|
toolCallers
|
|
@@ -4888,46 +4889,34 @@ function resolveToolCallerConfiguration({
|
|
|
4888
4889
|
if (tools == null || toolCallers == null) {
|
|
4889
4890
|
return void 0;
|
|
4890
4891
|
}
|
|
4891
|
-
const namesByReference = /* @__PURE__ */ new WeakMap();
|
|
4892
|
-
const callerReferences = {};
|
|
4893
|
-
for (const [toolName, tool2] of Object.entries(tools)) {
|
|
4894
|
-
if (experimental_getToolCaller(tool2) == null) {
|
|
4895
|
-
continue;
|
|
4896
|
-
}
|
|
4897
|
-
const reference = Object.freeze({ toolName });
|
|
4898
|
-
namesByReference.set(reference, toolName);
|
|
4899
|
-
callerReferences[toolName] = reference;
|
|
4900
|
-
}
|
|
4901
|
-
const configuration = toolCallers(callerReferences);
|
|
4902
4892
|
const resolved = {};
|
|
4903
|
-
for (const [toolName, callers] of Object.entries(
|
|
4893
|
+
for (const [toolName, callers] of Object.entries(toolCallers)) {
|
|
4904
4894
|
if (!Object.prototype.hasOwnProperty.call(tools, toolName)) {
|
|
4905
4895
|
throw new InvalidArgumentError({
|
|
4906
4896
|
parameter: "experimental_toolCallers",
|
|
4907
|
-
value:
|
|
4897
|
+
value: toolCallers,
|
|
4908
4898
|
message: `unknown tool "${toolName}".`
|
|
4909
4899
|
});
|
|
4910
4900
|
}
|
|
4911
4901
|
if (!Array.isArray(callers)) {
|
|
4912
4902
|
throw new InvalidArgumentError({
|
|
4913
4903
|
parameter: "experimental_toolCallers",
|
|
4914
|
-
value:
|
|
4904
|
+
value: toolCallers,
|
|
4915
4905
|
message: `callers for tool "${toolName}" must be an array.`
|
|
4916
4906
|
});
|
|
4917
4907
|
}
|
|
4918
4908
|
resolved[toolName] = callers.map((caller) => {
|
|
4919
|
-
if (caller ===
|
|
4909
|
+
if (caller === DIRECT_TOOL_CALL) {
|
|
4920
4910
|
return caller;
|
|
4921
4911
|
}
|
|
4922
|
-
|
|
4923
|
-
if (callerName == null) {
|
|
4912
|
+
if (typeof caller !== "string" || !Object.prototype.hasOwnProperty.call(tools, caller) || experimental_getToolCaller(tools[caller]) == null) {
|
|
4924
4913
|
throw new InvalidArgumentError({
|
|
4925
4914
|
parameter: "experimental_toolCallers",
|
|
4926
|
-
value:
|
|
4927
|
-
message: `tool "${toolName}" contains an invalid caller
|
|
4915
|
+
value: toolCallers,
|
|
4916
|
+
message: `tool "${toolName}" contains an invalid caller.`
|
|
4928
4917
|
});
|
|
4929
4918
|
}
|
|
4930
|
-
return
|
|
4919
|
+
return caller;
|
|
4931
4920
|
});
|
|
4932
4921
|
}
|
|
4933
4922
|
return resolved;
|
|
@@ -4952,7 +4941,7 @@ function prepareToolsForToolCallers({
|
|
|
4952
4941
|
let availableToProvider = false;
|
|
4953
4942
|
let preparedTool = tool2;
|
|
4954
4943
|
for (const callerName of callerNames) {
|
|
4955
|
-
if (callerName ===
|
|
4944
|
+
if (callerName === DIRECT_TOOL_CALL) {
|
|
4956
4945
|
availableDirectly = true;
|
|
4957
4946
|
continue;
|
|
4958
4947
|
}
|
|
@@ -13895,6 +13884,7 @@ function detectToolDrift(current, baseline) {
|
|
|
13895
13884
|
// src/generate-video/generate-video.ts
|
|
13896
13885
|
import {
|
|
13897
13886
|
convertBase64ToUint8Array as convertBase64ToUint8Array5,
|
|
13887
|
+
delay as defaultDelay,
|
|
13898
13888
|
withUserAgentSuffix as withUserAgentSuffix9,
|
|
13899
13889
|
detectMediaType as detectMediaType4
|
|
13900
13890
|
} from "@ai-sdk/provider-utils";
|
|
@@ -13916,7 +13906,9 @@ async function experimental_generateVideo({
|
|
|
13916
13906
|
maxRetries: maxRetriesArg,
|
|
13917
13907
|
abortSignal,
|
|
13918
13908
|
headers,
|
|
13919
|
-
download: downloadFn = defaultDownload
|
|
13909
|
+
download: downloadFn = defaultDownload,
|
|
13910
|
+
poll,
|
|
13911
|
+
webhook
|
|
13920
13912
|
}) {
|
|
13921
13913
|
var _a23, _b;
|
|
13922
13914
|
const model = resolveVideoModel(modelArg);
|
|
@@ -13956,32 +13948,59 @@ async function experimental_generateVideo({
|
|
|
13956
13948
|
}
|
|
13957
13949
|
const resolvedImage = firstFrameImage != null ? firstFrameImage : image;
|
|
13958
13950
|
const maxVideosPerCallWithDefault = (_b = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _b : 1;
|
|
13951
|
+
const hasStartStatus = model.doStart != null && model.doStatus != null;
|
|
13952
|
+
const useStartStatus = hasStartStatus && (poll != null || webhook != null || model.doGenerate == null);
|
|
13953
|
+
if (model.doGenerate == null && !hasStartStatus) {
|
|
13954
|
+
throw new Error(
|
|
13955
|
+
`Video model ${model.modelId} does not implement doGenerate or doStart/doStatus.`
|
|
13956
|
+
);
|
|
13957
|
+
}
|
|
13958
|
+
if ((poll != null || webhook != null) && !hasStartStatus) {
|
|
13959
|
+
logWarnings({
|
|
13960
|
+
warnings: [
|
|
13961
|
+
{
|
|
13962
|
+
type: "other",
|
|
13963
|
+
message: "poll/webhook options were provided but the model does not support doStart/doStatus. Falling back to doGenerate."
|
|
13964
|
+
}
|
|
13965
|
+
],
|
|
13966
|
+
provider: model.provider,
|
|
13967
|
+
model: model.modelId
|
|
13968
|
+
});
|
|
13969
|
+
}
|
|
13959
13970
|
const callCount = Math.ceil(n / maxVideosPerCallWithDefault);
|
|
13960
13971
|
const callVideoCounts = Array.from({ length: callCount }, (_, index) => {
|
|
13961
13972
|
const remaining = n - index * maxVideosPerCallWithDefault;
|
|
13962
13973
|
return Math.min(remaining, maxVideosPerCallWithDefault);
|
|
13963
13974
|
});
|
|
13964
13975
|
const results = await Promise.all(
|
|
13965
|
-
callVideoCounts.map(
|
|
13966
|
-
|
|
13967
|
-
|
|
13968
|
-
|
|
13969
|
-
|
|
13970
|
-
|
|
13971
|
-
|
|
13972
|
-
|
|
13973
|
-
|
|
13974
|
-
|
|
13975
|
-
|
|
13976
|
-
|
|
13977
|
-
|
|
13978
|
-
|
|
13979
|
-
|
|
13980
|
-
|
|
13981
|
-
|
|
13982
|
-
|
|
13983
|
-
|
|
13984
|
-
|
|
13976
|
+
callVideoCounts.map(async (callVideoCount) => {
|
|
13977
|
+
const callOptions = {
|
|
13978
|
+
prompt,
|
|
13979
|
+
n: callVideoCount,
|
|
13980
|
+
aspectRatio,
|
|
13981
|
+
resolution,
|
|
13982
|
+
duration,
|
|
13983
|
+
fps,
|
|
13984
|
+
seed,
|
|
13985
|
+
image: resolvedImage,
|
|
13986
|
+
frameImages: normalizedFrameImages,
|
|
13987
|
+
inputReferences: effectiveInputReferences,
|
|
13988
|
+
generateAudio,
|
|
13989
|
+
providerOptions: providerOptions != null ? providerOptions : {},
|
|
13990
|
+
headers: headersWithUserAgent,
|
|
13991
|
+
abortSignal
|
|
13992
|
+
};
|
|
13993
|
+
if (useStartStatus) {
|
|
13994
|
+
return executeStartStatusFlow({
|
|
13995
|
+
model,
|
|
13996
|
+
callOptions,
|
|
13997
|
+
poll,
|
|
13998
|
+
webhook,
|
|
13999
|
+
retry
|
|
14000
|
+
});
|
|
14001
|
+
}
|
|
14002
|
+
return retry(() => model.doGenerate(callOptions));
|
|
14003
|
+
})
|
|
13985
14004
|
);
|
|
13986
14005
|
const videos = [];
|
|
13987
14006
|
const responses = [];
|
|
@@ -14039,25 +14058,7 @@ async function experimental_generateVideo({
|
|
|
14039
14058
|
providerMetadata: result.providerMetadata
|
|
14040
14059
|
});
|
|
14041
14060
|
if (result.providerMetadata != null) {
|
|
14042
|
-
|
|
14043
|
-
result.providerMetadata
|
|
14044
|
-
)) {
|
|
14045
|
-
const existingMetadata = providerMetadata[providerName];
|
|
14046
|
-
if (existingMetadata != null && typeof existingMetadata === "object") {
|
|
14047
|
-
providerMetadata[providerName] = {
|
|
14048
|
-
...existingMetadata,
|
|
14049
|
-
...metadata
|
|
14050
|
-
};
|
|
14051
|
-
if ("videos" in existingMetadata && Array.isArray(existingMetadata.videos) && "videos" in metadata && Array.isArray(metadata.videos)) {
|
|
14052
|
-
providerMetadata[providerName].videos = [
|
|
14053
|
-
...existingMetadata.videos,
|
|
14054
|
-
...metadata.videos
|
|
14055
|
-
];
|
|
14056
|
-
}
|
|
14057
|
-
} else {
|
|
14058
|
-
providerMetadata[providerName] = metadata;
|
|
14059
|
-
}
|
|
14060
|
-
}
|
|
14061
|
+
mergeProviderMetadata(providerMetadata, result.providerMetadata);
|
|
14061
14062
|
}
|
|
14062
14063
|
}
|
|
14063
14064
|
if (videos.length === 0) {
|
|
@@ -14078,6 +14079,139 @@ async function experimental_generateVideo({
|
|
|
14078
14079
|
providerMetadata
|
|
14079
14080
|
};
|
|
14080
14081
|
}
|
|
14082
|
+
async function executeStartStatusFlow({
|
|
14083
|
+
model,
|
|
14084
|
+
callOptions,
|
|
14085
|
+
poll: pollConfig,
|
|
14086
|
+
webhook: webhookFactory,
|
|
14087
|
+
retry
|
|
14088
|
+
}) {
|
|
14089
|
+
var _a23, _b, _c;
|
|
14090
|
+
const earlyWarnings = [];
|
|
14091
|
+
let webhookUrl;
|
|
14092
|
+
let webhookReceived;
|
|
14093
|
+
if (webhookFactory != null) {
|
|
14094
|
+
if (model.handleWebhookOption != null) {
|
|
14095
|
+
const result = await model.handleWebhookOption({
|
|
14096
|
+
webhook: webhookFactory
|
|
14097
|
+
});
|
|
14098
|
+
webhookUrl = result.webhookUrl;
|
|
14099
|
+
webhookReceived = result.received;
|
|
14100
|
+
} else {
|
|
14101
|
+
earlyWarnings.push({
|
|
14102
|
+
type: "unsupported",
|
|
14103
|
+
feature: "webhook",
|
|
14104
|
+
details: "This model does not support webhooks. Falling back to polling."
|
|
14105
|
+
});
|
|
14106
|
+
}
|
|
14107
|
+
}
|
|
14108
|
+
const startResult = await retry(
|
|
14109
|
+
() => model.doStart({
|
|
14110
|
+
...callOptions,
|
|
14111
|
+
webhookUrl
|
|
14112
|
+
})
|
|
14113
|
+
);
|
|
14114
|
+
const allWarnings = [...earlyWarnings, ...startResult.warnings];
|
|
14115
|
+
let operationProviderMetadata = startResult.providerMetadata == null ? void 0 : { ...startResult.providerMetadata };
|
|
14116
|
+
const intervalMs = (_a23 = pollConfig == null ? void 0 : pollConfig.intervalMs) != null ? _a23 : 5e3;
|
|
14117
|
+
const timeoutMs = (_b = pollConfig == null ? void 0 : pollConfig.timeoutMs) != null ? _b : 6e5;
|
|
14118
|
+
const delay = (_c = pollConfig == null ? void 0 : pollConfig.delay) != null ? _c : defaultDelay;
|
|
14119
|
+
const startTime = Date.now();
|
|
14120
|
+
if (webhookReceived != null) {
|
|
14121
|
+
await waitForWebhook({
|
|
14122
|
+
received: webhookReceived,
|
|
14123
|
+
timeoutMs,
|
|
14124
|
+
abortSignal: callOptions.abortSignal,
|
|
14125
|
+
delay
|
|
14126
|
+
});
|
|
14127
|
+
}
|
|
14128
|
+
while (true) {
|
|
14129
|
+
if (webhookReceived == null) {
|
|
14130
|
+
const elapsedMs = Date.now() - startTime;
|
|
14131
|
+
if (elapsedMs >= timeoutMs) {
|
|
14132
|
+
throw new Error(`Video generation timed out after ${timeoutMs}ms.`);
|
|
14133
|
+
}
|
|
14134
|
+
await delay(Math.min(intervalMs, timeoutMs - elapsedMs), {
|
|
14135
|
+
abortSignal: callOptions.abortSignal
|
|
14136
|
+
});
|
|
14137
|
+
if (Date.now() - startTime >= timeoutMs) {
|
|
14138
|
+
throw new Error(`Video generation timed out after ${timeoutMs}ms.`);
|
|
14139
|
+
}
|
|
14140
|
+
}
|
|
14141
|
+
const statusResult = await retry(
|
|
14142
|
+
() => model.doStatus({
|
|
14143
|
+
operation: startResult.operation,
|
|
14144
|
+
abortSignal: callOptions.abortSignal,
|
|
14145
|
+
headers: callOptions.headers
|
|
14146
|
+
})
|
|
14147
|
+
);
|
|
14148
|
+
if (statusResult.status === "error") {
|
|
14149
|
+
throw new Error(statusResult.error);
|
|
14150
|
+
}
|
|
14151
|
+
if (statusResult.warnings != null) {
|
|
14152
|
+
allWarnings.push(...statusResult.warnings);
|
|
14153
|
+
}
|
|
14154
|
+
if (statusResult.providerMetadata != null) {
|
|
14155
|
+
operationProviderMetadata != null ? operationProviderMetadata : operationProviderMetadata = {};
|
|
14156
|
+
mergeProviderMetadata(
|
|
14157
|
+
operationProviderMetadata,
|
|
14158
|
+
statusResult.providerMetadata
|
|
14159
|
+
);
|
|
14160
|
+
}
|
|
14161
|
+
if (statusResult.status === "completed") {
|
|
14162
|
+
return {
|
|
14163
|
+
videos: statusResult.videos,
|
|
14164
|
+
warnings: allWarnings,
|
|
14165
|
+
providerMetadata: operationProviderMetadata,
|
|
14166
|
+
response: statusResult.response
|
|
14167
|
+
};
|
|
14168
|
+
}
|
|
14169
|
+
if (webhookReceived != null) {
|
|
14170
|
+
throw new Error(
|
|
14171
|
+
"Video generation did not complete after webhook notification."
|
|
14172
|
+
);
|
|
14173
|
+
}
|
|
14174
|
+
}
|
|
14175
|
+
}
|
|
14176
|
+
async function waitForWebhook({
|
|
14177
|
+
received,
|
|
14178
|
+
timeoutMs,
|
|
14179
|
+
abortSignal,
|
|
14180
|
+
delay
|
|
14181
|
+
}) {
|
|
14182
|
+
const timeoutController = typeof globalThis.AbortController === "function" ? new globalThis.AbortController() : void 0;
|
|
14183
|
+
try {
|
|
14184
|
+
await Promise.race([
|
|
14185
|
+
received,
|
|
14186
|
+
delay(timeoutMs, {
|
|
14187
|
+
abortSignal: timeoutController == null ? abortSignal : mergeAbortSignals(abortSignal, timeoutController.signal)
|
|
14188
|
+
}).then(() => {
|
|
14189
|
+
throw new Error(`Video generation timed out after ${timeoutMs}ms.`);
|
|
14190
|
+
})
|
|
14191
|
+
]);
|
|
14192
|
+
} finally {
|
|
14193
|
+
timeoutController == null ? void 0 : timeoutController.abort();
|
|
14194
|
+
}
|
|
14195
|
+
}
|
|
14196
|
+
function mergeProviderMetadata(target, source) {
|
|
14197
|
+
for (const [providerName, metadataValue] of Object.entries(source)) {
|
|
14198
|
+
const existingMetadata = target[providerName];
|
|
14199
|
+
if (existingMetadata != null && typeof existingMetadata === "object" && metadataValue != null && typeof metadataValue === "object") {
|
|
14200
|
+
target[providerName] = {
|
|
14201
|
+
...existingMetadata,
|
|
14202
|
+
...metadataValue
|
|
14203
|
+
};
|
|
14204
|
+
if ("videos" in existingMetadata && Array.isArray(existingMetadata.videos) && "videos" in metadataValue && Array.isArray(metadataValue.videos)) {
|
|
14205
|
+
target[providerName].videos = [
|
|
14206
|
+
...existingMetadata.videos,
|
|
14207
|
+
...metadataValue.videos
|
|
14208
|
+
];
|
|
14209
|
+
}
|
|
14210
|
+
} else {
|
|
14211
|
+
target[providerName] = metadataValue;
|
|
14212
|
+
}
|
|
14213
|
+
}
|
|
14214
|
+
}
|
|
14081
14215
|
function normalizePrompt2(promptArg) {
|
|
14082
14216
|
if (typeof promptArg === "string") {
|
|
14083
14217
|
return {
|