@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ae30443: fix(google): remove shut down `gemini-2.5-flash-image-preview`
|
|
8
|
+
|
|
9
|
+
## 3.0.20
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 53f6731: feat (ai, provider): experimental generate video support
|
|
14
|
+
- Updated dependencies [53f6731]
|
|
15
|
+
- @ai-sdk/provider@3.0.7
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.13
|
|
17
|
+
|
|
3
18
|
## 3.0.19
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
3
|
+
import { ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
6
6
|
error: {
|
|
@@ -11,7 +11,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
11
11
|
}>;
|
|
12
12
|
type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
|
|
13
13
|
|
|
14
|
-
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image
|
|
14
|
+
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
15
15
|
declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
16
16
|
responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
|
|
17
17
|
thinkingConfig?: {
|
|
@@ -181,6 +181,20 @@ declare const googleGenerativeAIEmbeddingProviderOptions: _ai_sdk_provider_utils
|
|
|
181
181
|
}>;
|
|
182
182
|
type GoogleGenerativeAIEmbeddingProviderOptions = InferSchema<typeof googleGenerativeAIEmbeddingProviderOptions>;
|
|
183
183
|
|
|
184
|
+
type GoogleGenerativeAIVideoModelId = 'veo-3.1-fast-generate-preview' | 'veo-3.1-generate-preview' | 'veo-3.1-generate' | 'veo-2.0-generate-001' | (string & {});
|
|
185
|
+
|
|
186
|
+
type GoogleGenerativeAIVideoProviderOptions = {
|
|
187
|
+
pollIntervalMs?: number | null;
|
|
188
|
+
pollTimeoutMs?: number | null;
|
|
189
|
+
personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all' | null;
|
|
190
|
+
negativePrompt?: string | null;
|
|
191
|
+
referenceImages?: Array<{
|
|
192
|
+
bytesBase64Encoded?: string;
|
|
193
|
+
gcsUri?: string;
|
|
194
|
+
}> | null;
|
|
195
|
+
[key: string]: unknown;
|
|
196
|
+
};
|
|
197
|
+
|
|
184
198
|
declare const googleTools: {
|
|
185
199
|
/**
|
|
186
200
|
* Creates a Google search tool that gives Google direct access to real-time web content.
|
|
@@ -265,6 +279,10 @@ interface GoogleGenerativeAIProvider extends ProviderV3 {
|
|
|
265
279
|
* Creates a model for image generation.
|
|
266
280
|
*/
|
|
267
281
|
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV3;
|
|
282
|
+
/**
|
|
283
|
+
* Creates a model for video generation.
|
|
284
|
+
*/
|
|
285
|
+
video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
|
|
268
286
|
/**
|
|
269
287
|
* @deprecated Use `chat()` instead.
|
|
270
288
|
*/
|
|
@@ -328,4 +346,4 @@ declare const google: GoogleGenerativeAIProvider;
|
|
|
328
346
|
|
|
329
347
|
declare const VERSION: string;
|
|
330
348
|
|
|
331
|
-
export { type GoogleErrorData, type GoogleGenerativeAIEmbeddingProviderOptions, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, VERSION, createGoogleGenerativeAI, google };
|
|
349
|
+
export { type GoogleErrorData, type GoogleGenerativeAIEmbeddingProviderOptions, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleGenerativeAIVideoProviderOptions, VERSION, createGoogleGenerativeAI, google };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
3
|
+
import { ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
6
6
|
error: {
|
|
@@ -11,7 +11,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
11
11
|
}>;
|
|
12
12
|
type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
|
|
13
13
|
|
|
14
|
-
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image
|
|
14
|
+
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
15
15
|
declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
16
16
|
responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
|
|
17
17
|
thinkingConfig?: {
|
|
@@ -181,6 +181,20 @@ declare const googleGenerativeAIEmbeddingProviderOptions: _ai_sdk_provider_utils
|
|
|
181
181
|
}>;
|
|
182
182
|
type GoogleGenerativeAIEmbeddingProviderOptions = InferSchema<typeof googleGenerativeAIEmbeddingProviderOptions>;
|
|
183
183
|
|
|
184
|
+
type GoogleGenerativeAIVideoModelId = 'veo-3.1-fast-generate-preview' | 'veo-3.1-generate-preview' | 'veo-3.1-generate' | 'veo-2.0-generate-001' | (string & {});
|
|
185
|
+
|
|
186
|
+
type GoogleGenerativeAIVideoProviderOptions = {
|
|
187
|
+
pollIntervalMs?: number | null;
|
|
188
|
+
pollTimeoutMs?: number | null;
|
|
189
|
+
personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all' | null;
|
|
190
|
+
negativePrompt?: string | null;
|
|
191
|
+
referenceImages?: Array<{
|
|
192
|
+
bytesBase64Encoded?: string;
|
|
193
|
+
gcsUri?: string;
|
|
194
|
+
}> | null;
|
|
195
|
+
[key: string]: unknown;
|
|
196
|
+
};
|
|
197
|
+
|
|
184
198
|
declare const googleTools: {
|
|
185
199
|
/**
|
|
186
200
|
* Creates a Google search tool that gives Google direct access to real-time web content.
|
|
@@ -265,6 +279,10 @@ interface GoogleGenerativeAIProvider extends ProviderV3 {
|
|
|
265
279
|
* Creates a model for image generation.
|
|
266
280
|
*/
|
|
267
281
|
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV3;
|
|
282
|
+
/**
|
|
283
|
+
* Creates a model for video generation.
|
|
284
|
+
*/
|
|
285
|
+
video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
|
|
268
286
|
/**
|
|
269
287
|
* @deprecated Use `chat()` instead.
|
|
270
288
|
*/
|
|
@@ -328,4 +346,4 @@ declare const google: GoogleGenerativeAIProvider;
|
|
|
328
346
|
|
|
329
347
|
declare const VERSION: string;
|
|
330
348
|
|
|
331
|
-
export { type GoogleErrorData, type GoogleGenerativeAIEmbeddingProviderOptions, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, VERSION, createGoogleGenerativeAI, google };
|
|
349
|
+
export { type GoogleErrorData, type GoogleGenerativeAIEmbeddingProviderOptions, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleGenerativeAIVideoProviderOptions, VERSION, createGoogleGenerativeAI, google };
|
package/dist/index.js
CHANGED
|
@@ -27,10 +27,10 @@ __export(src_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.21" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -1891,14 +1891,266 @@ var googleImageProviderOptionsSchema = (0, import_provider_utils14.lazySchema)(
|
|
|
1891
1891
|
)
|
|
1892
1892
|
);
|
|
1893
1893
|
|
|
1894
|
+
// src/google-generative-ai-video-model.ts
|
|
1895
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
1896
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
1897
|
+
var import_v414 = require("zod/v4");
|
|
1898
|
+
var GoogleGenerativeAIVideoModel = class {
|
|
1899
|
+
constructor(modelId, config) {
|
|
1900
|
+
this.modelId = modelId;
|
|
1901
|
+
this.config = config;
|
|
1902
|
+
this.specificationVersion = "v3";
|
|
1903
|
+
}
|
|
1904
|
+
get provider() {
|
|
1905
|
+
return this.config.provider;
|
|
1906
|
+
}
|
|
1907
|
+
get maxVideosPerCall() {
|
|
1908
|
+
return 4;
|
|
1909
|
+
}
|
|
1910
|
+
async doGenerate(options) {
|
|
1911
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1912
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1913
|
+
const warnings = [];
|
|
1914
|
+
const googleOptions = await (0, import_provider_utils15.parseProviderOptions)({
|
|
1915
|
+
provider: "google",
|
|
1916
|
+
providerOptions: options.providerOptions,
|
|
1917
|
+
schema: googleVideoProviderOptionsSchema
|
|
1918
|
+
});
|
|
1919
|
+
const instances = [{}];
|
|
1920
|
+
const instance = instances[0];
|
|
1921
|
+
if (options.prompt != null) {
|
|
1922
|
+
instance.prompt = options.prompt;
|
|
1923
|
+
}
|
|
1924
|
+
if (options.image != null) {
|
|
1925
|
+
if (options.image.type === "url") {
|
|
1926
|
+
warnings.push({
|
|
1927
|
+
type: "unsupported",
|
|
1928
|
+
feature: "URL-based image input",
|
|
1929
|
+
details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
|
|
1930
|
+
});
|
|
1931
|
+
} else {
|
|
1932
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils15.convertUint8ArrayToBase64)(options.image.data);
|
|
1933
|
+
instance.image = {
|
|
1934
|
+
inlineData: {
|
|
1935
|
+
mimeType: options.image.mediaType || "image/png",
|
|
1936
|
+
data: base64Data
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
if ((googleOptions == null ? void 0 : googleOptions.referenceImages) != null) {
|
|
1942
|
+
instance.referenceImages = googleOptions.referenceImages.map((refImg) => {
|
|
1943
|
+
if (refImg.bytesBase64Encoded) {
|
|
1944
|
+
return {
|
|
1945
|
+
inlineData: {
|
|
1946
|
+
mimeType: "image/png",
|
|
1947
|
+
data: refImg.bytesBase64Encoded
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
} else if (refImg.gcsUri) {
|
|
1951
|
+
return {
|
|
1952
|
+
gcsUri: refImg.gcsUri
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
return refImg;
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
const parameters = {
|
|
1959
|
+
sampleCount: options.n
|
|
1960
|
+
};
|
|
1961
|
+
if (options.aspectRatio) {
|
|
1962
|
+
parameters.aspectRatio = options.aspectRatio;
|
|
1963
|
+
}
|
|
1964
|
+
if (options.resolution) {
|
|
1965
|
+
const resolutionMap = {
|
|
1966
|
+
"1280x720": "720p",
|
|
1967
|
+
"1920x1080": "1080p",
|
|
1968
|
+
"3840x2160": "4k"
|
|
1969
|
+
};
|
|
1970
|
+
parameters.resolution = resolutionMap[options.resolution] || options.resolution;
|
|
1971
|
+
}
|
|
1972
|
+
if (options.duration) {
|
|
1973
|
+
parameters.durationSeconds = options.duration;
|
|
1974
|
+
}
|
|
1975
|
+
if (options.seed) {
|
|
1976
|
+
parameters.seed = options.seed;
|
|
1977
|
+
}
|
|
1978
|
+
if (googleOptions != null) {
|
|
1979
|
+
const opts = googleOptions;
|
|
1980
|
+
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
1981
|
+
parameters.personGeneration = opts.personGeneration;
|
|
1982
|
+
}
|
|
1983
|
+
if (opts.negativePrompt !== void 0 && opts.negativePrompt !== null) {
|
|
1984
|
+
parameters.negativePrompt = opts.negativePrompt;
|
|
1985
|
+
}
|
|
1986
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
1987
|
+
if (![
|
|
1988
|
+
"pollIntervalMs",
|
|
1989
|
+
"pollTimeoutMs",
|
|
1990
|
+
"personGeneration",
|
|
1991
|
+
"negativePrompt",
|
|
1992
|
+
"referenceImages"
|
|
1993
|
+
].includes(key)) {
|
|
1994
|
+
parameters[key] = value;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
const { value: operation } = await (0, import_provider_utils15.postJsonToApi)({
|
|
1999
|
+
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
2000
|
+
headers: (0, import_provider_utils15.combineHeaders)(
|
|
2001
|
+
await (0, import_provider_utils15.resolve)(this.config.headers),
|
|
2002
|
+
options.headers
|
|
2003
|
+
),
|
|
2004
|
+
body: {
|
|
2005
|
+
instances,
|
|
2006
|
+
parameters
|
|
2007
|
+
},
|
|
2008
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
2009
|
+
googleOperationSchema
|
|
2010
|
+
),
|
|
2011
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2012
|
+
abortSignal: options.abortSignal,
|
|
2013
|
+
fetch: this.config.fetch
|
|
2014
|
+
});
|
|
2015
|
+
const operationName = operation.name;
|
|
2016
|
+
if (!operationName) {
|
|
2017
|
+
throw new import_provider4.AISDKError({
|
|
2018
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2019
|
+
message: "No operation name returned from API"
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
const pollIntervalMs = (_d = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _d : 1e4;
|
|
2023
|
+
const pollTimeoutMs = (_e = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _e : 6e5;
|
|
2024
|
+
const startTime = Date.now();
|
|
2025
|
+
let finalOperation = operation;
|
|
2026
|
+
let responseHeaders;
|
|
2027
|
+
while (!finalOperation.done) {
|
|
2028
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2029
|
+
throw new import_provider4.AISDKError({
|
|
2030
|
+
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
2031
|
+
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
await (0, import_provider_utils15.delay)(pollIntervalMs);
|
|
2035
|
+
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
2036
|
+
throw new import_provider4.AISDKError({
|
|
2037
|
+
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
2038
|
+
message: "Video generation request was aborted"
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils15.getFromApi)({
|
|
2042
|
+
url: `${this.config.baseURL}/${operationName}`,
|
|
2043
|
+
headers: (0, import_provider_utils15.combineHeaders)(
|
|
2044
|
+
await (0, import_provider_utils15.resolve)(this.config.headers),
|
|
2045
|
+
options.headers
|
|
2046
|
+
),
|
|
2047
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
2048
|
+
googleOperationSchema
|
|
2049
|
+
),
|
|
2050
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2051
|
+
abortSignal: options.abortSignal,
|
|
2052
|
+
fetch: this.config.fetch
|
|
2053
|
+
});
|
|
2054
|
+
finalOperation = statusOperation;
|
|
2055
|
+
responseHeaders = pollHeaders;
|
|
2056
|
+
}
|
|
2057
|
+
if (finalOperation.error) {
|
|
2058
|
+
throw new import_provider4.AISDKError({
|
|
2059
|
+
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
2060
|
+
message: `Video generation failed: ${finalOperation.error.message}`
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
const response = finalOperation.response;
|
|
2064
|
+
if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
2065
|
+
throw new import_provider4.AISDKError({
|
|
2066
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2067
|
+
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
const videos = [];
|
|
2071
|
+
const videoMetadata = [];
|
|
2072
|
+
const resolvedHeaders = await (0, import_provider_utils15.resolve)(this.config.headers);
|
|
2073
|
+
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
2074
|
+
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
2075
|
+
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
2076
|
+
const urlWithAuth = apiKey ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
2077
|
+
videos.push({
|
|
2078
|
+
type: "url",
|
|
2079
|
+
url: urlWithAuth,
|
|
2080
|
+
mediaType: "video/mp4"
|
|
2081
|
+
});
|
|
2082
|
+
videoMetadata.push({
|
|
2083
|
+
uri: generatedSample.video.uri
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
if (videos.length === 0) {
|
|
2088
|
+
throw new import_provider4.AISDKError({
|
|
2089
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2090
|
+
message: "No valid videos in response"
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
return {
|
|
2094
|
+
videos,
|
|
2095
|
+
warnings,
|
|
2096
|
+
response: {
|
|
2097
|
+
timestamp: currentDate,
|
|
2098
|
+
modelId: this.modelId,
|
|
2099
|
+
headers: responseHeaders
|
|
2100
|
+
},
|
|
2101
|
+
providerMetadata: {
|
|
2102
|
+
google: {
|
|
2103
|
+
videos: videoMetadata
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
var googleOperationSchema = import_v414.z.object({
|
|
2110
|
+
name: import_v414.z.string().nullish(),
|
|
2111
|
+
done: import_v414.z.boolean().nullish(),
|
|
2112
|
+
error: import_v414.z.object({
|
|
2113
|
+
code: import_v414.z.number().nullish(),
|
|
2114
|
+
message: import_v414.z.string(),
|
|
2115
|
+
status: import_v414.z.string().nullish()
|
|
2116
|
+
}).nullish(),
|
|
2117
|
+
response: import_v414.z.object({
|
|
2118
|
+
generateVideoResponse: import_v414.z.object({
|
|
2119
|
+
generatedSamples: import_v414.z.array(
|
|
2120
|
+
import_v414.z.object({
|
|
2121
|
+
video: import_v414.z.object({
|
|
2122
|
+
uri: import_v414.z.string().nullish()
|
|
2123
|
+
}).nullish()
|
|
2124
|
+
})
|
|
2125
|
+
).nullish()
|
|
2126
|
+
}).nullish()
|
|
2127
|
+
}).nullish()
|
|
2128
|
+
});
|
|
2129
|
+
var googleVideoProviderOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
2130
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2131
|
+
import_v414.z.object({
|
|
2132
|
+
pollIntervalMs: import_v414.z.number().positive().nullish(),
|
|
2133
|
+
pollTimeoutMs: import_v414.z.number().positive().nullish(),
|
|
2134
|
+
personGeneration: import_v414.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2135
|
+
negativePrompt: import_v414.z.string().nullish(),
|
|
2136
|
+
referenceImages: import_v414.z.array(
|
|
2137
|
+
import_v414.z.object({
|
|
2138
|
+
bytesBase64Encoded: import_v414.z.string().nullish(),
|
|
2139
|
+
gcsUri: import_v414.z.string().nullish()
|
|
2140
|
+
})
|
|
2141
|
+
).nullish()
|
|
2142
|
+
}).passthrough()
|
|
2143
|
+
)
|
|
2144
|
+
);
|
|
2145
|
+
|
|
1894
2146
|
// src/google-provider.ts
|
|
1895
2147
|
function createGoogleGenerativeAI(options = {}) {
|
|
1896
2148
|
var _a, _b;
|
|
1897
|
-
const baseURL = (_a = (0,
|
|
2149
|
+
const baseURL = (_a = (0, import_provider_utils16.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
1898
2150
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
1899
|
-
const getHeaders = () => (0,
|
|
2151
|
+
const getHeaders = () => (0, import_provider_utils16.withUserAgentSuffix)(
|
|
1900
2152
|
{
|
|
1901
|
-
"x-goog-api-key": (0,
|
|
2153
|
+
"x-goog-api-key": (0, import_provider_utils16.loadApiKey)({
|
|
1902
2154
|
apiKey: options.apiKey,
|
|
1903
2155
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
1904
2156
|
description: "Google Generative AI"
|
|
@@ -1913,7 +2165,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1913
2165
|
provider: providerName,
|
|
1914
2166
|
baseURL,
|
|
1915
2167
|
headers: getHeaders,
|
|
1916
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
2168
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils16.generateId,
|
|
1917
2169
|
supportedUrls: () => ({
|
|
1918
2170
|
"*": [
|
|
1919
2171
|
// Google Generative Language "files" endpoint
|
|
@@ -1941,6 +2193,16 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1941
2193
|
headers: getHeaders,
|
|
1942
2194
|
fetch: options.fetch
|
|
1943
2195
|
});
|
|
2196
|
+
const createVideoModel = (modelId) => {
|
|
2197
|
+
var _a2;
|
|
2198
|
+
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
2199
|
+
provider: providerName,
|
|
2200
|
+
baseURL,
|
|
2201
|
+
headers: getHeaders,
|
|
2202
|
+
fetch: options.fetch,
|
|
2203
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils16.generateId
|
|
2204
|
+
});
|
|
2205
|
+
};
|
|
1944
2206
|
const provider = function(modelId) {
|
|
1945
2207
|
if (new.target) {
|
|
1946
2208
|
throw new Error(
|
|
@@ -1959,6 +2221,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1959
2221
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
1960
2222
|
provider.image = createImageModel;
|
|
1961
2223
|
provider.imageModel = createImageModel;
|
|
2224
|
+
provider.video = createVideoModel;
|
|
1962
2225
|
provider.tools = googleTools;
|
|
1963
2226
|
return provider;
|
|
1964
2227
|
}
|