@ai-sdk/google 4.0.0-beta.22 → 4.0.0-beta.24
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 +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +251 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +262 -57
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +41 -10
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +46 -11
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +3 -3
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +58 -17
- package/src/google-generative-ai-files.ts +230 -0
- package/src/google-generative-ai-options.ts +1 -7
- package/src/google-generative-ai-prompt.ts +10 -2
- package/src/google-provider.ts +13 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 55db546: fix(provider/google): fix Gemini service tier enum after upstream update
|
|
8
|
+
|
|
9
|
+
## 4.0.0-beta.23
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
|
|
14
|
+
- Updated dependencies [c29a26f]
|
|
15
|
+
- @ai-sdk/provider-utils@5.0.0-beta.10
|
|
16
|
+
- @ai-sdk/provider@4.0.0-beta.6
|
|
17
|
+
|
|
3
18
|
## 4.0.0-beta.22
|
|
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 { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
3
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4, FilesV4 } from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
6
6
|
error: {
|
|
@@ -39,7 +39,7 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
39
39
|
longitude: number;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
42
|
-
serviceTier?: "
|
|
42
|
+
serviceTier?: "standard" | "flex" | "priority" | undefined;
|
|
43
43
|
}>;
|
|
44
44
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
45
45
|
|
|
@@ -236,6 +236,13 @@ type GoogleVideoModelOptions = {
|
|
|
236
236
|
[key: string]: unknown;
|
|
237
237
|
};
|
|
238
238
|
|
|
239
|
+
type GoogleFilesUploadOptions = {
|
|
240
|
+
displayName?: string | null;
|
|
241
|
+
pollIntervalMs?: number | null;
|
|
242
|
+
pollTimeoutMs?: number | null;
|
|
243
|
+
[key: string]: unknown;
|
|
244
|
+
};
|
|
245
|
+
|
|
239
246
|
declare const googleTools: {
|
|
240
247
|
/**
|
|
241
248
|
* Creates a Google search tool that gives Google direct access to real-time web content.
|
|
@@ -355,6 +362,7 @@ interface GoogleGenerativeAIProvider extends ProviderV4 {
|
|
|
355
362
|
* Creates a model for video generation.
|
|
356
363
|
*/
|
|
357
364
|
videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
365
|
+
files(): FilesV4;
|
|
358
366
|
tools: typeof googleTools;
|
|
359
367
|
}
|
|
360
368
|
interface GoogleGenerativeAIProviderSettings {
|
|
@@ -398,4 +406,4 @@ declare const google: GoogleGenerativeAIProvider;
|
|
|
398
406
|
|
|
399
407
|
declare const VERSION: string;
|
|
400
408
|
|
|
401
|
-
export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleLanguageModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google };
|
|
409
|
+
export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleFilesUploadOptions, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleLanguageModelOptions, type GoogleVideoModelOptions, 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 { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
3
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4, FilesV4 } from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
6
6
|
error: {
|
|
@@ -39,7 +39,7 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
39
39
|
longitude: number;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
42
|
-
serviceTier?: "
|
|
42
|
+
serviceTier?: "standard" | "flex" | "priority" | undefined;
|
|
43
43
|
}>;
|
|
44
44
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
45
45
|
|
|
@@ -236,6 +236,13 @@ type GoogleVideoModelOptions = {
|
|
|
236
236
|
[key: string]: unknown;
|
|
237
237
|
};
|
|
238
238
|
|
|
239
|
+
type GoogleFilesUploadOptions = {
|
|
240
|
+
displayName?: string | null;
|
|
241
|
+
pollIntervalMs?: number | null;
|
|
242
|
+
pollTimeoutMs?: number | null;
|
|
243
|
+
[key: string]: unknown;
|
|
244
|
+
};
|
|
245
|
+
|
|
239
246
|
declare const googleTools: {
|
|
240
247
|
/**
|
|
241
248
|
* Creates a Google search tool that gives Google direct access to real-time web content.
|
|
@@ -355,6 +362,7 @@ interface GoogleGenerativeAIProvider extends ProviderV4 {
|
|
|
355
362
|
* Creates a model for video generation.
|
|
356
363
|
*/
|
|
357
364
|
videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
365
|
+
files(): FilesV4;
|
|
358
366
|
tools: typeof googleTools;
|
|
359
367
|
}
|
|
360
368
|
interface GoogleGenerativeAIProviderSettings {
|
|
@@ -398,4 +406,4 @@ declare const google: GoogleGenerativeAIProvider;
|
|
|
398
406
|
|
|
399
407
|
declare const VERSION: string;
|
|
400
408
|
|
|
401
|
-
export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleLanguageModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google };
|
|
409
|
+
export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleFilesUploadOptions, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleLanguageModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google };
|
package/dist/index.js
CHANGED
|
@@ -27,10 +27,10 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "4.0.0-beta.
|
|
33
|
+
var VERSION = true ? "4.0.0-beta.24" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -534,19 +534,36 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
534
534
|
}
|
|
535
535
|
case "file": {
|
|
536
536
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
537
|
-
|
|
538
|
-
|
|
537
|
+
if (part.data instanceof URL) {
|
|
538
|
+
parts.push({
|
|
539
539
|
fileData: {
|
|
540
540
|
mimeType: mediaType,
|
|
541
541
|
fileUri: part.data.toString()
|
|
542
542
|
}
|
|
543
|
-
}
|
|
543
|
+
});
|
|
544
|
+
} else if ((0, import_provider_utils4.isProviderReference)(part.data)) {
|
|
545
|
+
if (providerOptionsName === "vertex") {
|
|
546
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
547
|
+
functionality: "file parts with provider references"
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
parts.push({
|
|
551
|
+
fileData: {
|
|
552
|
+
mimeType: mediaType,
|
|
553
|
+
fileUri: (0, import_provider_utils4.resolveProviderReference)({
|
|
554
|
+
reference: part.data,
|
|
555
|
+
provider: "google"
|
|
556
|
+
})
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
} else {
|
|
560
|
+
parts.push({
|
|
544
561
|
inlineData: {
|
|
545
562
|
mimeType: mediaType,
|
|
546
563
|
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
|
547
564
|
}
|
|
548
|
-
}
|
|
549
|
-
|
|
565
|
+
});
|
|
566
|
+
}
|
|
550
567
|
break;
|
|
551
568
|
}
|
|
552
569
|
}
|
|
@@ -597,6 +614,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
597
614
|
functionality: "File data URLs in assistant messages are not supported"
|
|
598
615
|
});
|
|
599
616
|
}
|
|
617
|
+
if ((0, import_provider_utils4.isProviderReference)(part.data)) {
|
|
618
|
+
if (providerOptionsName === "vertex") {
|
|
619
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
620
|
+
functionality: "file parts with provider references"
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
return {
|
|
624
|
+
fileData: {
|
|
625
|
+
mimeType: part.mediaType,
|
|
626
|
+
fileUri: (0, import_provider_utils4.resolveProviderReference)({
|
|
627
|
+
reference: part.data,
|
|
628
|
+
provider: "google"
|
|
629
|
+
})
|
|
630
|
+
},
|
|
631
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
632
|
+
thoughtSignature
|
|
633
|
+
};
|
|
634
|
+
}
|
|
600
635
|
return {
|
|
601
636
|
inlineData: {
|
|
602
637
|
mimeType: part.mediaType,
|
|
@@ -837,11 +872,7 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
837
872
|
/**
|
|
838
873
|
* Optional. The service tier to use for the request.
|
|
839
874
|
*/
|
|
840
|
-
serviceTier: import_v44.z.enum([
|
|
841
|
-
"SERVICE_TIER_STANDARD",
|
|
842
|
-
"SERVICE_TIER_FLEX",
|
|
843
|
-
"SERVICE_TIER_PRIORITY"
|
|
844
|
-
]).optional()
|
|
875
|
+
serviceTier: import_v44.z.enum(["standard", "flex", "priority"]).optional()
|
|
845
876
|
})
|
|
846
877
|
)
|
|
847
878
|
);
|
|
@@ -2499,10 +2530,163 @@ var googleImageModelOptionsSchema = (0, import_provider_utils14.lazySchema)(
|
|
|
2499
2530
|
)
|
|
2500
2531
|
);
|
|
2501
2532
|
|
|
2502
|
-
// src/google-generative-ai-
|
|
2533
|
+
// src/google-generative-ai-files.ts
|
|
2503
2534
|
var import_provider4 = require("@ai-sdk/provider");
|
|
2504
2535
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2505
2536
|
var import_v414 = require("zod/v4");
|
|
2537
|
+
var GoogleGenerativeAIFiles = class {
|
|
2538
|
+
constructor(config) {
|
|
2539
|
+
this.config = config;
|
|
2540
|
+
this.specificationVersion = "v4";
|
|
2541
|
+
}
|
|
2542
|
+
get provider() {
|
|
2543
|
+
return this.config.provider;
|
|
2544
|
+
}
|
|
2545
|
+
async uploadFile(options) {
|
|
2546
|
+
var _a, _b, _c, _d;
|
|
2547
|
+
const googleOptions = await (0, import_provider_utils15.parseProviderOptions)({
|
|
2548
|
+
provider: "google",
|
|
2549
|
+
providerOptions: options.providerOptions,
|
|
2550
|
+
schema: googleFilesUploadOptionsSchema
|
|
2551
|
+
});
|
|
2552
|
+
const resolvedHeaders = this.config.headers();
|
|
2553
|
+
const fetchFn = (_a = this.config.fetch) != null ? _a : globalThis.fetch;
|
|
2554
|
+
const warnings = [];
|
|
2555
|
+
if (options.filename != null) {
|
|
2556
|
+
warnings.push({ type: "unsupported", feature: "filename" });
|
|
2557
|
+
}
|
|
2558
|
+
const data = options.data;
|
|
2559
|
+
const fileBytes = data instanceof Uint8Array ? data : Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
|
|
2560
|
+
const mediaType = options.mediaType;
|
|
2561
|
+
const displayName = googleOptions == null ? void 0 : googleOptions.displayName;
|
|
2562
|
+
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|
|
2563
|
+
const initResponse = await fetchFn(`${baseOrigin}/upload/v1beta/files`, {
|
|
2564
|
+
method: "POST",
|
|
2565
|
+
headers: {
|
|
2566
|
+
...resolvedHeaders,
|
|
2567
|
+
"X-Goog-Upload-Protocol": "resumable",
|
|
2568
|
+
"X-Goog-Upload-Command": "start",
|
|
2569
|
+
"X-Goog-Upload-Header-Content-Length": String(fileBytes.length),
|
|
2570
|
+
"X-Goog-Upload-Header-Content-Type": mediaType,
|
|
2571
|
+
"Content-Type": "application/json"
|
|
2572
|
+
},
|
|
2573
|
+
body: JSON.stringify({
|
|
2574
|
+
file: {
|
|
2575
|
+
...displayName != null ? { display_name: displayName } : {}
|
|
2576
|
+
}
|
|
2577
|
+
})
|
|
2578
|
+
});
|
|
2579
|
+
if (!initResponse.ok) {
|
|
2580
|
+
const errorBody = await initResponse.text();
|
|
2581
|
+
throw new import_provider4.AISDKError({
|
|
2582
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2583
|
+
message: `Failed to initiate resumable upload: ${initResponse.status} ${errorBody}`
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
const uploadUrl = initResponse.headers.get("x-goog-upload-url");
|
|
2587
|
+
if (!uploadUrl) {
|
|
2588
|
+
throw new import_provider4.AISDKError({
|
|
2589
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2590
|
+
message: "No upload URL returned from initiation request"
|
|
2591
|
+
});
|
|
2592
|
+
}
|
|
2593
|
+
const uploadResponse = await fetchFn(uploadUrl, {
|
|
2594
|
+
method: "POST",
|
|
2595
|
+
headers: {
|
|
2596
|
+
"Content-Length": String(fileBytes.length),
|
|
2597
|
+
"X-Goog-Upload-Offset": "0",
|
|
2598
|
+
"X-Goog-Upload-Command": "upload, finalize"
|
|
2599
|
+
},
|
|
2600
|
+
body: fileBytes
|
|
2601
|
+
});
|
|
2602
|
+
if (!uploadResponse.ok) {
|
|
2603
|
+
const errorBody = await uploadResponse.text();
|
|
2604
|
+
throw new import_provider4.AISDKError({
|
|
2605
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2606
|
+
message: `Failed to upload file data: ${uploadResponse.status} ${errorBody}`
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
const uploadResult = await uploadResponse.json();
|
|
2610
|
+
let file = uploadResult.file;
|
|
2611
|
+
const pollIntervalMs = (_b = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _b : 2e3;
|
|
2612
|
+
const pollTimeoutMs = (_c = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _c : 3e5;
|
|
2613
|
+
const startTime = Date.now();
|
|
2614
|
+
while (file.state === "PROCESSING") {
|
|
2615
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2616
|
+
throw new import_provider4.AISDKError({
|
|
2617
|
+
name: "GOOGLE_FILES_UPLOAD_TIMEOUT",
|
|
2618
|
+
message: `File processing timed out after ${pollTimeoutMs}ms`
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2621
|
+
await (0, import_provider_utils15.delay)(pollIntervalMs);
|
|
2622
|
+
const { value: fileStatus } = await (0, import_provider_utils15.getFromApi)({
|
|
2623
|
+
url: `${this.config.baseURL}/${file.name}`,
|
|
2624
|
+
headers: (0, import_provider_utils15.combineHeaders)(resolvedHeaders),
|
|
2625
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
2626
|
+
googleFileResponseSchema
|
|
2627
|
+
),
|
|
2628
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2629
|
+
fetch: this.config.fetch
|
|
2630
|
+
});
|
|
2631
|
+
file = fileStatus;
|
|
2632
|
+
}
|
|
2633
|
+
if (file.state === "FAILED") {
|
|
2634
|
+
throw new import_provider4.AISDKError({
|
|
2635
|
+
name: "GOOGLE_FILES_UPLOAD_FAILED",
|
|
2636
|
+
message: `File processing failed for ${file.name}`
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
return {
|
|
2640
|
+
warnings,
|
|
2641
|
+
providerReference: { google: file.uri },
|
|
2642
|
+
mediaType: (_d = file.mimeType) != null ? _d : options.mediaType,
|
|
2643
|
+
providerMetadata: {
|
|
2644
|
+
google: {
|
|
2645
|
+
name: file.name,
|
|
2646
|
+
displayName: file.displayName,
|
|
2647
|
+
mimeType: file.mimeType,
|
|
2648
|
+
sizeBytes: file.sizeBytes,
|
|
2649
|
+
state: file.state,
|
|
2650
|
+
uri: file.uri,
|
|
2651
|
+
...file.createTime != null ? { createTime: file.createTime } : {},
|
|
2652
|
+
...file.updateTime != null ? { updateTime: file.updateTime } : {},
|
|
2653
|
+
...file.expirationTime != null ? { expirationTime: file.expirationTime } : {},
|
|
2654
|
+
...file.sha256Hash != null ? { sha256Hash: file.sha256Hash } : {}
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
var googleFileResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
2661
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2662
|
+
import_v414.z.object({
|
|
2663
|
+
name: import_v414.z.string(),
|
|
2664
|
+
displayName: import_v414.z.string().nullish(),
|
|
2665
|
+
mimeType: import_v414.z.string(),
|
|
2666
|
+
sizeBytes: import_v414.z.string().nullish(),
|
|
2667
|
+
createTime: import_v414.z.string().nullish(),
|
|
2668
|
+
updateTime: import_v414.z.string().nullish(),
|
|
2669
|
+
expirationTime: import_v414.z.string().nullish(),
|
|
2670
|
+
sha256Hash: import_v414.z.string().nullish(),
|
|
2671
|
+
uri: import_v414.z.string(),
|
|
2672
|
+
state: import_v414.z.string()
|
|
2673
|
+
})
|
|
2674
|
+
)
|
|
2675
|
+
);
|
|
2676
|
+
var googleFilesUploadOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
2677
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2678
|
+
import_v414.z.object({
|
|
2679
|
+
displayName: import_v414.z.string().nullish(),
|
|
2680
|
+
pollIntervalMs: import_v414.z.number().positive().nullish(),
|
|
2681
|
+
pollTimeoutMs: import_v414.z.number().positive().nullish()
|
|
2682
|
+
}).passthrough()
|
|
2683
|
+
)
|
|
2684
|
+
);
|
|
2685
|
+
|
|
2686
|
+
// src/google-generative-ai-video-model.ts
|
|
2687
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
2688
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2689
|
+
var import_v415 = require("zod/v4");
|
|
2506
2690
|
var GoogleGenerativeAIVideoModel = class {
|
|
2507
2691
|
constructor(modelId, config) {
|
|
2508
2692
|
this.modelId = modelId;
|
|
@@ -2519,7 +2703,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2519
2703
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2520
2704
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2521
2705
|
const warnings = [];
|
|
2522
|
-
const googleOptions = await (0,
|
|
2706
|
+
const googleOptions = await (0, import_provider_utils16.parseProviderOptions)({
|
|
2523
2707
|
provider: "google",
|
|
2524
2708
|
providerOptions: options.providerOptions,
|
|
2525
2709
|
schema: googleVideoModelOptionsSchema
|
|
@@ -2537,7 +2721,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2537
2721
|
details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
|
|
2538
2722
|
});
|
|
2539
2723
|
} else {
|
|
2540
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
2724
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils16.convertUint8ArrayToBase64)(options.image.data);
|
|
2541
2725
|
instance.image = {
|
|
2542
2726
|
inlineData: {
|
|
2543
2727
|
mimeType: options.image.mediaType || "image/png",
|
|
@@ -2603,17 +2787,17 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2603
2787
|
}
|
|
2604
2788
|
}
|
|
2605
2789
|
}
|
|
2606
|
-
const { value: operation } = await (0,
|
|
2790
|
+
const { value: operation } = await (0, import_provider_utils16.postJsonToApi)({
|
|
2607
2791
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
2608
|
-
headers: (0,
|
|
2609
|
-
await (0,
|
|
2792
|
+
headers: (0, import_provider_utils16.combineHeaders)(
|
|
2793
|
+
await (0, import_provider_utils16.resolve)(this.config.headers),
|
|
2610
2794
|
options.headers
|
|
2611
2795
|
),
|
|
2612
2796
|
body: {
|
|
2613
2797
|
instances,
|
|
2614
2798
|
parameters
|
|
2615
2799
|
},
|
|
2616
|
-
successfulResponseHandler: (0,
|
|
2800
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
2617
2801
|
googleOperationSchema
|
|
2618
2802
|
),
|
|
2619
2803
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2622,7 +2806,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2622
2806
|
});
|
|
2623
2807
|
const operationName = operation.name;
|
|
2624
2808
|
if (!operationName) {
|
|
2625
|
-
throw new
|
|
2809
|
+
throw new import_provider5.AISDKError({
|
|
2626
2810
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2627
2811
|
message: "No operation name returned from API"
|
|
2628
2812
|
});
|
|
@@ -2634,25 +2818,25 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2634
2818
|
let responseHeaders;
|
|
2635
2819
|
while (!finalOperation.done) {
|
|
2636
2820
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2637
|
-
throw new
|
|
2821
|
+
throw new import_provider5.AISDKError({
|
|
2638
2822
|
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
2639
2823
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2640
2824
|
});
|
|
2641
2825
|
}
|
|
2642
|
-
await (0,
|
|
2826
|
+
await (0, import_provider_utils16.delay)(pollIntervalMs);
|
|
2643
2827
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
2644
|
-
throw new
|
|
2828
|
+
throw new import_provider5.AISDKError({
|
|
2645
2829
|
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
2646
2830
|
message: "Video generation request was aborted"
|
|
2647
2831
|
});
|
|
2648
2832
|
}
|
|
2649
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
2833
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils16.getFromApi)({
|
|
2650
2834
|
url: `${this.config.baseURL}/${operationName}`,
|
|
2651
|
-
headers: (0,
|
|
2652
|
-
await (0,
|
|
2835
|
+
headers: (0, import_provider_utils16.combineHeaders)(
|
|
2836
|
+
await (0, import_provider_utils16.resolve)(this.config.headers),
|
|
2653
2837
|
options.headers
|
|
2654
2838
|
),
|
|
2655
|
-
successfulResponseHandler: (0,
|
|
2839
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
2656
2840
|
googleOperationSchema
|
|
2657
2841
|
),
|
|
2658
2842
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2663,21 +2847,21 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2663
2847
|
responseHeaders = pollHeaders;
|
|
2664
2848
|
}
|
|
2665
2849
|
if (finalOperation.error) {
|
|
2666
|
-
throw new
|
|
2850
|
+
throw new import_provider5.AISDKError({
|
|
2667
2851
|
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
2668
2852
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
2669
2853
|
});
|
|
2670
2854
|
}
|
|
2671
2855
|
const response = finalOperation.response;
|
|
2672
2856
|
if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
2673
|
-
throw new
|
|
2857
|
+
throw new import_provider5.AISDKError({
|
|
2674
2858
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2675
2859
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
2676
2860
|
});
|
|
2677
2861
|
}
|
|
2678
2862
|
const videos = [];
|
|
2679
2863
|
const videoMetadata = [];
|
|
2680
|
-
const resolvedHeaders = await (0,
|
|
2864
|
+
const resolvedHeaders = await (0, import_provider_utils16.resolve)(this.config.headers);
|
|
2681
2865
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
2682
2866
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
2683
2867
|
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
@@ -2693,7 +2877,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2693
2877
|
}
|
|
2694
2878
|
}
|
|
2695
2879
|
if (videos.length === 0) {
|
|
2696
|
-
throw new
|
|
2880
|
+
throw new import_provider5.AISDKError({
|
|
2697
2881
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2698
2882
|
message: "No valid videos in response"
|
|
2699
2883
|
});
|
|
@@ -2714,37 +2898,37 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2714
2898
|
};
|
|
2715
2899
|
}
|
|
2716
2900
|
};
|
|
2717
|
-
var googleOperationSchema =
|
|
2718
|
-
name:
|
|
2719
|
-
done:
|
|
2720
|
-
error:
|
|
2721
|
-
code:
|
|
2722
|
-
message:
|
|
2723
|
-
status:
|
|
2901
|
+
var googleOperationSchema = import_v415.z.object({
|
|
2902
|
+
name: import_v415.z.string().nullish(),
|
|
2903
|
+
done: import_v415.z.boolean().nullish(),
|
|
2904
|
+
error: import_v415.z.object({
|
|
2905
|
+
code: import_v415.z.number().nullish(),
|
|
2906
|
+
message: import_v415.z.string(),
|
|
2907
|
+
status: import_v415.z.string().nullish()
|
|
2724
2908
|
}).nullish(),
|
|
2725
|
-
response:
|
|
2726
|
-
generateVideoResponse:
|
|
2727
|
-
generatedSamples:
|
|
2728
|
-
|
|
2729
|
-
video:
|
|
2730
|
-
uri:
|
|
2909
|
+
response: import_v415.z.object({
|
|
2910
|
+
generateVideoResponse: import_v415.z.object({
|
|
2911
|
+
generatedSamples: import_v415.z.array(
|
|
2912
|
+
import_v415.z.object({
|
|
2913
|
+
video: import_v415.z.object({
|
|
2914
|
+
uri: import_v415.z.string().nullish()
|
|
2731
2915
|
}).nullish()
|
|
2732
2916
|
})
|
|
2733
2917
|
).nullish()
|
|
2734
2918
|
}).nullish()
|
|
2735
2919
|
}).nullish()
|
|
2736
2920
|
});
|
|
2737
|
-
var googleVideoModelOptionsSchema = (0,
|
|
2738
|
-
() => (0,
|
|
2739
|
-
|
|
2740
|
-
pollIntervalMs:
|
|
2741
|
-
pollTimeoutMs:
|
|
2742
|
-
personGeneration:
|
|
2743
|
-
negativePrompt:
|
|
2744
|
-
referenceImages:
|
|
2745
|
-
|
|
2746
|
-
bytesBase64Encoded:
|
|
2747
|
-
gcsUri:
|
|
2921
|
+
var googleVideoModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
2922
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
2923
|
+
import_v415.z.object({
|
|
2924
|
+
pollIntervalMs: import_v415.z.number().positive().nullish(),
|
|
2925
|
+
pollTimeoutMs: import_v415.z.number().positive().nullish(),
|
|
2926
|
+
personGeneration: import_v415.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2927
|
+
negativePrompt: import_v415.z.string().nullish(),
|
|
2928
|
+
referenceImages: import_v415.z.array(
|
|
2929
|
+
import_v415.z.object({
|
|
2930
|
+
bytesBase64Encoded: import_v415.z.string().nullish(),
|
|
2931
|
+
gcsUri: import_v415.z.string().nullish()
|
|
2748
2932
|
})
|
|
2749
2933
|
).nullish()
|
|
2750
2934
|
}).passthrough()
|
|
@@ -2754,11 +2938,11 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
|
2754
2938
|
// src/google-provider.ts
|
|
2755
2939
|
function createGoogleGenerativeAI(options = {}) {
|
|
2756
2940
|
var _a, _b;
|
|
2757
|
-
const baseURL = (_a = (0,
|
|
2941
|
+
const baseURL = (_a = (0, import_provider_utils17.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
2758
2942
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
2759
|
-
const getHeaders = () => (0,
|
|
2943
|
+
const getHeaders = () => (0, import_provider_utils17.withUserAgentSuffix)(
|
|
2760
2944
|
{
|
|
2761
|
-
"x-goog-api-key": (0,
|
|
2945
|
+
"x-goog-api-key": (0, import_provider_utils17.loadApiKey)({
|
|
2762
2946
|
apiKey: options.apiKey,
|
|
2763
2947
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
2764
2948
|
description: "Google Generative AI"
|
|
@@ -2773,7 +2957,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2773
2957
|
provider: providerName,
|
|
2774
2958
|
baseURL,
|
|
2775
2959
|
headers: getHeaders,
|
|
2776
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
2960
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils17.generateId,
|
|
2777
2961
|
supportedUrls: () => ({
|
|
2778
2962
|
"*": [
|
|
2779
2963
|
// Google Generative Language "files" endpoint
|
|
@@ -2801,6 +2985,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2801
2985
|
headers: getHeaders,
|
|
2802
2986
|
fetch: options.fetch
|
|
2803
2987
|
});
|
|
2988
|
+
const createFiles = () => new GoogleGenerativeAIFiles({
|
|
2989
|
+
provider: providerName,
|
|
2990
|
+
baseURL,
|
|
2991
|
+
headers: getHeaders,
|
|
2992
|
+
fetch: options.fetch
|
|
2993
|
+
});
|
|
2804
2994
|
const createVideoModel = (modelId) => {
|
|
2805
2995
|
var _a2;
|
|
2806
2996
|
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
@@ -2808,7 +2998,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2808
2998
|
baseURL,
|
|
2809
2999
|
headers: getHeaders,
|
|
2810
3000
|
fetch: options.fetch,
|
|
2811
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
3001
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils17.generateId
|
|
2812
3002
|
});
|
|
2813
3003
|
};
|
|
2814
3004
|
const provider = function(modelId) {
|
|
@@ -2831,6 +3021,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2831
3021
|
provider.imageModel = createImageModel;
|
|
2832
3022
|
provider.video = createVideoModel;
|
|
2833
3023
|
provider.videoModel = createVideoModel;
|
|
3024
|
+
provider.files = createFiles;
|
|
2834
3025
|
provider.tools = googleTools;
|
|
2835
3026
|
return provider;
|
|
2836
3027
|
}
|