@ai-sdk/google 3.0.19 → 3.0.21
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 +15 -0
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +269 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +277 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +2 -2
- package/package.json +3 -3
- package/src/google-generative-ai-options.ts +1 -1
- package/src/google-generative-ai-video-model.ts +374 -0
- package/src/google-generative-ai-video-settings.ts +6 -0
- package/src/google-provider.ts +19 -1
- package/src/index.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.21" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -1927,6 +1927,271 @@ var googleImageProviderOptionsSchema = lazySchema11(
|
|
|
1927
1927
|
)
|
|
1928
1928
|
);
|
|
1929
1929
|
|
|
1930
|
+
// src/google-generative-ai-video-model.ts
|
|
1931
|
+
import {
|
|
1932
|
+
AISDKError
|
|
1933
|
+
} from "@ai-sdk/provider";
|
|
1934
|
+
import {
|
|
1935
|
+
combineHeaders as combineHeaders4,
|
|
1936
|
+
convertUint8ArrayToBase64,
|
|
1937
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1938
|
+
delay,
|
|
1939
|
+
getFromApi,
|
|
1940
|
+
lazySchema as lazySchema12,
|
|
1941
|
+
parseProviderOptions as parseProviderOptions4,
|
|
1942
|
+
postJsonToApi as postJsonToApi4,
|
|
1943
|
+
resolve as resolve4,
|
|
1944
|
+
zodSchema as zodSchema12
|
|
1945
|
+
} from "@ai-sdk/provider-utils";
|
|
1946
|
+
import { z as z14 } from "zod/v4";
|
|
1947
|
+
var GoogleGenerativeAIVideoModel = class {
|
|
1948
|
+
constructor(modelId, config) {
|
|
1949
|
+
this.modelId = modelId;
|
|
1950
|
+
this.config = config;
|
|
1951
|
+
this.specificationVersion = "v3";
|
|
1952
|
+
}
|
|
1953
|
+
get provider() {
|
|
1954
|
+
return this.config.provider;
|
|
1955
|
+
}
|
|
1956
|
+
get maxVideosPerCall() {
|
|
1957
|
+
return 4;
|
|
1958
|
+
}
|
|
1959
|
+
async doGenerate(options) {
|
|
1960
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1961
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1962
|
+
const warnings = [];
|
|
1963
|
+
const googleOptions = await parseProviderOptions4({
|
|
1964
|
+
provider: "google",
|
|
1965
|
+
providerOptions: options.providerOptions,
|
|
1966
|
+
schema: googleVideoProviderOptionsSchema
|
|
1967
|
+
});
|
|
1968
|
+
const instances = [{}];
|
|
1969
|
+
const instance = instances[0];
|
|
1970
|
+
if (options.prompt != null) {
|
|
1971
|
+
instance.prompt = options.prompt;
|
|
1972
|
+
}
|
|
1973
|
+
if (options.image != null) {
|
|
1974
|
+
if (options.image.type === "url") {
|
|
1975
|
+
warnings.push({
|
|
1976
|
+
type: "unsupported",
|
|
1977
|
+
feature: "URL-based image input",
|
|
1978
|
+
details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
|
|
1979
|
+
});
|
|
1980
|
+
} else {
|
|
1981
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
1982
|
+
instance.image = {
|
|
1983
|
+
inlineData: {
|
|
1984
|
+
mimeType: options.image.mediaType || "image/png",
|
|
1985
|
+
data: base64Data
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
if ((googleOptions == null ? void 0 : googleOptions.referenceImages) != null) {
|
|
1991
|
+
instance.referenceImages = googleOptions.referenceImages.map((refImg) => {
|
|
1992
|
+
if (refImg.bytesBase64Encoded) {
|
|
1993
|
+
return {
|
|
1994
|
+
inlineData: {
|
|
1995
|
+
mimeType: "image/png",
|
|
1996
|
+
data: refImg.bytesBase64Encoded
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
} else if (refImg.gcsUri) {
|
|
2000
|
+
return {
|
|
2001
|
+
gcsUri: refImg.gcsUri
|
|
2002
|
+
};
|
|
2003
|
+
}
|
|
2004
|
+
return refImg;
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
const parameters = {
|
|
2008
|
+
sampleCount: options.n
|
|
2009
|
+
};
|
|
2010
|
+
if (options.aspectRatio) {
|
|
2011
|
+
parameters.aspectRatio = options.aspectRatio;
|
|
2012
|
+
}
|
|
2013
|
+
if (options.resolution) {
|
|
2014
|
+
const resolutionMap = {
|
|
2015
|
+
"1280x720": "720p",
|
|
2016
|
+
"1920x1080": "1080p",
|
|
2017
|
+
"3840x2160": "4k"
|
|
2018
|
+
};
|
|
2019
|
+
parameters.resolution = resolutionMap[options.resolution] || options.resolution;
|
|
2020
|
+
}
|
|
2021
|
+
if (options.duration) {
|
|
2022
|
+
parameters.durationSeconds = options.duration;
|
|
2023
|
+
}
|
|
2024
|
+
if (options.seed) {
|
|
2025
|
+
parameters.seed = options.seed;
|
|
2026
|
+
}
|
|
2027
|
+
if (googleOptions != null) {
|
|
2028
|
+
const opts = googleOptions;
|
|
2029
|
+
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
2030
|
+
parameters.personGeneration = opts.personGeneration;
|
|
2031
|
+
}
|
|
2032
|
+
if (opts.negativePrompt !== void 0 && opts.negativePrompt !== null) {
|
|
2033
|
+
parameters.negativePrompt = opts.negativePrompt;
|
|
2034
|
+
}
|
|
2035
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
2036
|
+
if (![
|
|
2037
|
+
"pollIntervalMs",
|
|
2038
|
+
"pollTimeoutMs",
|
|
2039
|
+
"personGeneration",
|
|
2040
|
+
"negativePrompt",
|
|
2041
|
+
"referenceImages"
|
|
2042
|
+
].includes(key)) {
|
|
2043
|
+
parameters[key] = value;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
const { value: operation } = await postJsonToApi4({
|
|
2048
|
+
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
2049
|
+
headers: combineHeaders4(
|
|
2050
|
+
await resolve4(this.config.headers),
|
|
2051
|
+
options.headers
|
|
2052
|
+
),
|
|
2053
|
+
body: {
|
|
2054
|
+
instances,
|
|
2055
|
+
parameters
|
|
2056
|
+
},
|
|
2057
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2058
|
+
googleOperationSchema
|
|
2059
|
+
),
|
|
2060
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2061
|
+
abortSignal: options.abortSignal,
|
|
2062
|
+
fetch: this.config.fetch
|
|
2063
|
+
});
|
|
2064
|
+
const operationName = operation.name;
|
|
2065
|
+
if (!operationName) {
|
|
2066
|
+
throw new AISDKError({
|
|
2067
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2068
|
+
message: "No operation name returned from API"
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
const pollIntervalMs = (_d = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _d : 1e4;
|
|
2072
|
+
const pollTimeoutMs = (_e = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _e : 6e5;
|
|
2073
|
+
const startTime = Date.now();
|
|
2074
|
+
let finalOperation = operation;
|
|
2075
|
+
let responseHeaders;
|
|
2076
|
+
while (!finalOperation.done) {
|
|
2077
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2078
|
+
throw new AISDKError({
|
|
2079
|
+
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
2080
|
+
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2081
|
+
});
|
|
2082
|
+
}
|
|
2083
|
+
await delay(pollIntervalMs);
|
|
2084
|
+
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
2085
|
+
throw new AISDKError({
|
|
2086
|
+
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
2087
|
+
message: "Video generation request was aborted"
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await getFromApi({
|
|
2091
|
+
url: `${this.config.baseURL}/${operationName}`,
|
|
2092
|
+
headers: combineHeaders4(
|
|
2093
|
+
await resolve4(this.config.headers),
|
|
2094
|
+
options.headers
|
|
2095
|
+
),
|
|
2096
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2097
|
+
googleOperationSchema
|
|
2098
|
+
),
|
|
2099
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2100
|
+
abortSignal: options.abortSignal,
|
|
2101
|
+
fetch: this.config.fetch
|
|
2102
|
+
});
|
|
2103
|
+
finalOperation = statusOperation;
|
|
2104
|
+
responseHeaders = pollHeaders;
|
|
2105
|
+
}
|
|
2106
|
+
if (finalOperation.error) {
|
|
2107
|
+
throw new AISDKError({
|
|
2108
|
+
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
2109
|
+
message: `Video generation failed: ${finalOperation.error.message}`
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
const response = finalOperation.response;
|
|
2113
|
+
if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
2114
|
+
throw new AISDKError({
|
|
2115
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2116
|
+
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
const videos = [];
|
|
2120
|
+
const videoMetadata = [];
|
|
2121
|
+
const resolvedHeaders = await resolve4(this.config.headers);
|
|
2122
|
+
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
2123
|
+
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
2124
|
+
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
2125
|
+
const urlWithAuth = apiKey ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
2126
|
+
videos.push({
|
|
2127
|
+
type: "url",
|
|
2128
|
+
url: urlWithAuth,
|
|
2129
|
+
mediaType: "video/mp4"
|
|
2130
|
+
});
|
|
2131
|
+
videoMetadata.push({
|
|
2132
|
+
uri: generatedSample.video.uri
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
if (videos.length === 0) {
|
|
2137
|
+
throw new AISDKError({
|
|
2138
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2139
|
+
message: "No valid videos in response"
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
return {
|
|
2143
|
+
videos,
|
|
2144
|
+
warnings,
|
|
2145
|
+
response: {
|
|
2146
|
+
timestamp: currentDate,
|
|
2147
|
+
modelId: this.modelId,
|
|
2148
|
+
headers: responseHeaders
|
|
2149
|
+
},
|
|
2150
|
+
providerMetadata: {
|
|
2151
|
+
google: {
|
|
2152
|
+
videos: videoMetadata
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
var googleOperationSchema = z14.object({
|
|
2159
|
+
name: z14.string().nullish(),
|
|
2160
|
+
done: z14.boolean().nullish(),
|
|
2161
|
+
error: z14.object({
|
|
2162
|
+
code: z14.number().nullish(),
|
|
2163
|
+
message: z14.string(),
|
|
2164
|
+
status: z14.string().nullish()
|
|
2165
|
+
}).nullish(),
|
|
2166
|
+
response: z14.object({
|
|
2167
|
+
generateVideoResponse: z14.object({
|
|
2168
|
+
generatedSamples: z14.array(
|
|
2169
|
+
z14.object({
|
|
2170
|
+
video: z14.object({
|
|
2171
|
+
uri: z14.string().nullish()
|
|
2172
|
+
}).nullish()
|
|
2173
|
+
})
|
|
2174
|
+
).nullish()
|
|
2175
|
+
}).nullish()
|
|
2176
|
+
}).nullish()
|
|
2177
|
+
});
|
|
2178
|
+
var googleVideoProviderOptionsSchema = lazySchema12(
|
|
2179
|
+
() => zodSchema12(
|
|
2180
|
+
z14.object({
|
|
2181
|
+
pollIntervalMs: z14.number().positive().nullish(),
|
|
2182
|
+
pollTimeoutMs: z14.number().positive().nullish(),
|
|
2183
|
+
personGeneration: z14.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2184
|
+
negativePrompt: z14.string().nullish(),
|
|
2185
|
+
referenceImages: z14.array(
|
|
2186
|
+
z14.object({
|
|
2187
|
+
bytesBase64Encoded: z14.string().nullish(),
|
|
2188
|
+
gcsUri: z14.string().nullish()
|
|
2189
|
+
})
|
|
2190
|
+
).nullish()
|
|
2191
|
+
}).passthrough()
|
|
2192
|
+
)
|
|
2193
|
+
);
|
|
2194
|
+
|
|
1930
2195
|
// src/google-provider.ts
|
|
1931
2196
|
function createGoogleGenerativeAI(options = {}) {
|
|
1932
2197
|
var _a, _b;
|
|
@@ -1977,6 +2242,16 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1977
2242
|
headers: getHeaders,
|
|
1978
2243
|
fetch: options.fetch
|
|
1979
2244
|
});
|
|
2245
|
+
const createVideoModel = (modelId) => {
|
|
2246
|
+
var _a2;
|
|
2247
|
+
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
2248
|
+
provider: providerName,
|
|
2249
|
+
baseURL,
|
|
2250
|
+
headers: getHeaders,
|
|
2251
|
+
fetch: options.fetch,
|
|
2252
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
|
|
2253
|
+
});
|
|
2254
|
+
};
|
|
1980
2255
|
const provider = function(modelId) {
|
|
1981
2256
|
if (new.target) {
|
|
1982
2257
|
throw new Error(
|
|
@@ -1995,6 +2270,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1995
2270
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
1996
2271
|
provider.image = createImageModel;
|
|
1997
2272
|
provider.imageModel = createImageModel;
|
|
2273
|
+
provider.video = createVideoModel;
|
|
1998
2274
|
provider.tools = googleTools;
|
|
1999
2275
|
return provider;
|
|
2000
2276
|
}
|