@ai-sdk/google 4.0.0-beta.22 → 4.0.0-beta.23
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 +9 -0
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +250 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -52
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +40 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +45 -6
- package/dist/internal/index.mjs.map +1 -1
- 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-prompt.ts +10 -2
- package/src/google-provider.ts +13 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
|
|
8
|
+
- Updated dependencies [c29a26f]
|
|
9
|
+
- @ai-sdk/provider-utils@5.0.0-beta.10
|
|
10
|
+
- @ai-sdk/provider@4.0.0-beta.6
|
|
11
|
+
|
|
3
12
|
## 4.0.0-beta.22
|
|
4
13
|
|
|
5
14
|
### 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: {
|
|
@@ -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: {
|
|
@@ -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.23" : "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,
|
|
@@ -2499,10 +2534,163 @@ var googleImageModelOptionsSchema = (0, import_provider_utils14.lazySchema)(
|
|
|
2499
2534
|
)
|
|
2500
2535
|
);
|
|
2501
2536
|
|
|
2502
|
-
// src/google-generative-ai-
|
|
2537
|
+
// src/google-generative-ai-files.ts
|
|
2503
2538
|
var import_provider4 = require("@ai-sdk/provider");
|
|
2504
2539
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2505
2540
|
var import_v414 = require("zod/v4");
|
|
2541
|
+
var GoogleGenerativeAIFiles = class {
|
|
2542
|
+
constructor(config) {
|
|
2543
|
+
this.config = config;
|
|
2544
|
+
this.specificationVersion = "v4";
|
|
2545
|
+
}
|
|
2546
|
+
get provider() {
|
|
2547
|
+
return this.config.provider;
|
|
2548
|
+
}
|
|
2549
|
+
async uploadFile(options) {
|
|
2550
|
+
var _a, _b, _c, _d;
|
|
2551
|
+
const googleOptions = await (0, import_provider_utils15.parseProviderOptions)({
|
|
2552
|
+
provider: "google",
|
|
2553
|
+
providerOptions: options.providerOptions,
|
|
2554
|
+
schema: googleFilesUploadOptionsSchema
|
|
2555
|
+
});
|
|
2556
|
+
const resolvedHeaders = this.config.headers();
|
|
2557
|
+
const fetchFn = (_a = this.config.fetch) != null ? _a : globalThis.fetch;
|
|
2558
|
+
const warnings = [];
|
|
2559
|
+
if (options.filename != null) {
|
|
2560
|
+
warnings.push({ type: "unsupported", feature: "filename" });
|
|
2561
|
+
}
|
|
2562
|
+
const data = options.data;
|
|
2563
|
+
const fileBytes = data instanceof Uint8Array ? data : Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
|
|
2564
|
+
const mediaType = options.mediaType;
|
|
2565
|
+
const displayName = googleOptions == null ? void 0 : googleOptions.displayName;
|
|
2566
|
+
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|
|
2567
|
+
const initResponse = await fetchFn(`${baseOrigin}/upload/v1beta/files`, {
|
|
2568
|
+
method: "POST",
|
|
2569
|
+
headers: {
|
|
2570
|
+
...resolvedHeaders,
|
|
2571
|
+
"X-Goog-Upload-Protocol": "resumable",
|
|
2572
|
+
"X-Goog-Upload-Command": "start",
|
|
2573
|
+
"X-Goog-Upload-Header-Content-Length": String(fileBytes.length),
|
|
2574
|
+
"X-Goog-Upload-Header-Content-Type": mediaType,
|
|
2575
|
+
"Content-Type": "application/json"
|
|
2576
|
+
},
|
|
2577
|
+
body: JSON.stringify({
|
|
2578
|
+
file: {
|
|
2579
|
+
...displayName != null ? { display_name: displayName } : {}
|
|
2580
|
+
}
|
|
2581
|
+
})
|
|
2582
|
+
});
|
|
2583
|
+
if (!initResponse.ok) {
|
|
2584
|
+
const errorBody = await initResponse.text();
|
|
2585
|
+
throw new import_provider4.AISDKError({
|
|
2586
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2587
|
+
message: `Failed to initiate resumable upload: ${initResponse.status} ${errorBody}`
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
const uploadUrl = initResponse.headers.get("x-goog-upload-url");
|
|
2591
|
+
if (!uploadUrl) {
|
|
2592
|
+
throw new import_provider4.AISDKError({
|
|
2593
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2594
|
+
message: "No upload URL returned from initiation request"
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
const uploadResponse = await fetchFn(uploadUrl, {
|
|
2598
|
+
method: "POST",
|
|
2599
|
+
headers: {
|
|
2600
|
+
"Content-Length": String(fileBytes.length),
|
|
2601
|
+
"X-Goog-Upload-Offset": "0",
|
|
2602
|
+
"X-Goog-Upload-Command": "upload, finalize"
|
|
2603
|
+
},
|
|
2604
|
+
body: fileBytes
|
|
2605
|
+
});
|
|
2606
|
+
if (!uploadResponse.ok) {
|
|
2607
|
+
const errorBody = await uploadResponse.text();
|
|
2608
|
+
throw new import_provider4.AISDKError({
|
|
2609
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2610
|
+
message: `Failed to upload file data: ${uploadResponse.status} ${errorBody}`
|
|
2611
|
+
});
|
|
2612
|
+
}
|
|
2613
|
+
const uploadResult = await uploadResponse.json();
|
|
2614
|
+
let file = uploadResult.file;
|
|
2615
|
+
const pollIntervalMs = (_b = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _b : 2e3;
|
|
2616
|
+
const pollTimeoutMs = (_c = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _c : 3e5;
|
|
2617
|
+
const startTime = Date.now();
|
|
2618
|
+
while (file.state === "PROCESSING") {
|
|
2619
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2620
|
+
throw new import_provider4.AISDKError({
|
|
2621
|
+
name: "GOOGLE_FILES_UPLOAD_TIMEOUT",
|
|
2622
|
+
message: `File processing timed out after ${pollTimeoutMs}ms`
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
await (0, import_provider_utils15.delay)(pollIntervalMs);
|
|
2626
|
+
const { value: fileStatus } = await (0, import_provider_utils15.getFromApi)({
|
|
2627
|
+
url: `${this.config.baseURL}/${file.name}`,
|
|
2628
|
+
headers: (0, import_provider_utils15.combineHeaders)(resolvedHeaders),
|
|
2629
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
2630
|
+
googleFileResponseSchema
|
|
2631
|
+
),
|
|
2632
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2633
|
+
fetch: this.config.fetch
|
|
2634
|
+
});
|
|
2635
|
+
file = fileStatus;
|
|
2636
|
+
}
|
|
2637
|
+
if (file.state === "FAILED") {
|
|
2638
|
+
throw new import_provider4.AISDKError({
|
|
2639
|
+
name: "GOOGLE_FILES_UPLOAD_FAILED",
|
|
2640
|
+
message: `File processing failed for ${file.name}`
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
return {
|
|
2644
|
+
warnings,
|
|
2645
|
+
providerReference: { google: file.uri },
|
|
2646
|
+
mediaType: (_d = file.mimeType) != null ? _d : options.mediaType,
|
|
2647
|
+
providerMetadata: {
|
|
2648
|
+
google: {
|
|
2649
|
+
name: file.name,
|
|
2650
|
+
displayName: file.displayName,
|
|
2651
|
+
mimeType: file.mimeType,
|
|
2652
|
+
sizeBytes: file.sizeBytes,
|
|
2653
|
+
state: file.state,
|
|
2654
|
+
uri: file.uri,
|
|
2655
|
+
...file.createTime != null ? { createTime: file.createTime } : {},
|
|
2656
|
+
...file.updateTime != null ? { updateTime: file.updateTime } : {},
|
|
2657
|
+
...file.expirationTime != null ? { expirationTime: file.expirationTime } : {},
|
|
2658
|
+
...file.sha256Hash != null ? { sha256Hash: file.sha256Hash } : {}
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
};
|
|
2664
|
+
var googleFileResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
2665
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2666
|
+
import_v414.z.object({
|
|
2667
|
+
name: import_v414.z.string(),
|
|
2668
|
+
displayName: import_v414.z.string().nullish(),
|
|
2669
|
+
mimeType: import_v414.z.string(),
|
|
2670
|
+
sizeBytes: import_v414.z.string().nullish(),
|
|
2671
|
+
createTime: import_v414.z.string().nullish(),
|
|
2672
|
+
updateTime: import_v414.z.string().nullish(),
|
|
2673
|
+
expirationTime: import_v414.z.string().nullish(),
|
|
2674
|
+
sha256Hash: import_v414.z.string().nullish(),
|
|
2675
|
+
uri: import_v414.z.string(),
|
|
2676
|
+
state: import_v414.z.string()
|
|
2677
|
+
})
|
|
2678
|
+
)
|
|
2679
|
+
);
|
|
2680
|
+
var googleFilesUploadOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
2681
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2682
|
+
import_v414.z.object({
|
|
2683
|
+
displayName: import_v414.z.string().nullish(),
|
|
2684
|
+
pollIntervalMs: import_v414.z.number().positive().nullish(),
|
|
2685
|
+
pollTimeoutMs: import_v414.z.number().positive().nullish()
|
|
2686
|
+
}).passthrough()
|
|
2687
|
+
)
|
|
2688
|
+
);
|
|
2689
|
+
|
|
2690
|
+
// src/google-generative-ai-video-model.ts
|
|
2691
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
2692
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2693
|
+
var import_v415 = require("zod/v4");
|
|
2506
2694
|
var GoogleGenerativeAIVideoModel = class {
|
|
2507
2695
|
constructor(modelId, config) {
|
|
2508
2696
|
this.modelId = modelId;
|
|
@@ -2519,7 +2707,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2519
2707
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2520
2708
|
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
2709
|
const warnings = [];
|
|
2522
|
-
const googleOptions = await (0,
|
|
2710
|
+
const googleOptions = await (0, import_provider_utils16.parseProviderOptions)({
|
|
2523
2711
|
provider: "google",
|
|
2524
2712
|
providerOptions: options.providerOptions,
|
|
2525
2713
|
schema: googleVideoModelOptionsSchema
|
|
@@ -2537,7 +2725,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2537
2725
|
details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
|
|
2538
2726
|
});
|
|
2539
2727
|
} else {
|
|
2540
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
2728
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils16.convertUint8ArrayToBase64)(options.image.data);
|
|
2541
2729
|
instance.image = {
|
|
2542
2730
|
inlineData: {
|
|
2543
2731
|
mimeType: options.image.mediaType || "image/png",
|
|
@@ -2603,17 +2791,17 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2603
2791
|
}
|
|
2604
2792
|
}
|
|
2605
2793
|
}
|
|
2606
|
-
const { value: operation } = await (0,
|
|
2794
|
+
const { value: operation } = await (0, import_provider_utils16.postJsonToApi)({
|
|
2607
2795
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
2608
|
-
headers: (0,
|
|
2609
|
-
await (0,
|
|
2796
|
+
headers: (0, import_provider_utils16.combineHeaders)(
|
|
2797
|
+
await (0, import_provider_utils16.resolve)(this.config.headers),
|
|
2610
2798
|
options.headers
|
|
2611
2799
|
),
|
|
2612
2800
|
body: {
|
|
2613
2801
|
instances,
|
|
2614
2802
|
parameters
|
|
2615
2803
|
},
|
|
2616
|
-
successfulResponseHandler: (0,
|
|
2804
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
2617
2805
|
googleOperationSchema
|
|
2618
2806
|
),
|
|
2619
2807
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2622,7 +2810,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2622
2810
|
});
|
|
2623
2811
|
const operationName = operation.name;
|
|
2624
2812
|
if (!operationName) {
|
|
2625
|
-
throw new
|
|
2813
|
+
throw new import_provider5.AISDKError({
|
|
2626
2814
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2627
2815
|
message: "No operation name returned from API"
|
|
2628
2816
|
});
|
|
@@ -2634,25 +2822,25 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2634
2822
|
let responseHeaders;
|
|
2635
2823
|
while (!finalOperation.done) {
|
|
2636
2824
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2637
|
-
throw new
|
|
2825
|
+
throw new import_provider5.AISDKError({
|
|
2638
2826
|
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
2639
2827
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2640
2828
|
});
|
|
2641
2829
|
}
|
|
2642
|
-
await (0,
|
|
2830
|
+
await (0, import_provider_utils16.delay)(pollIntervalMs);
|
|
2643
2831
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
2644
|
-
throw new
|
|
2832
|
+
throw new import_provider5.AISDKError({
|
|
2645
2833
|
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
2646
2834
|
message: "Video generation request was aborted"
|
|
2647
2835
|
});
|
|
2648
2836
|
}
|
|
2649
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
2837
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils16.getFromApi)({
|
|
2650
2838
|
url: `${this.config.baseURL}/${operationName}`,
|
|
2651
|
-
headers: (0,
|
|
2652
|
-
await (0,
|
|
2839
|
+
headers: (0, import_provider_utils16.combineHeaders)(
|
|
2840
|
+
await (0, import_provider_utils16.resolve)(this.config.headers),
|
|
2653
2841
|
options.headers
|
|
2654
2842
|
),
|
|
2655
|
-
successfulResponseHandler: (0,
|
|
2843
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
2656
2844
|
googleOperationSchema
|
|
2657
2845
|
),
|
|
2658
2846
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2663,21 +2851,21 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2663
2851
|
responseHeaders = pollHeaders;
|
|
2664
2852
|
}
|
|
2665
2853
|
if (finalOperation.error) {
|
|
2666
|
-
throw new
|
|
2854
|
+
throw new import_provider5.AISDKError({
|
|
2667
2855
|
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
2668
2856
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
2669
2857
|
});
|
|
2670
2858
|
}
|
|
2671
2859
|
const response = finalOperation.response;
|
|
2672
2860
|
if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
2673
|
-
throw new
|
|
2861
|
+
throw new import_provider5.AISDKError({
|
|
2674
2862
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2675
2863
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
2676
2864
|
});
|
|
2677
2865
|
}
|
|
2678
2866
|
const videos = [];
|
|
2679
2867
|
const videoMetadata = [];
|
|
2680
|
-
const resolvedHeaders = await (0,
|
|
2868
|
+
const resolvedHeaders = await (0, import_provider_utils16.resolve)(this.config.headers);
|
|
2681
2869
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
2682
2870
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
2683
2871
|
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
@@ -2693,7 +2881,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2693
2881
|
}
|
|
2694
2882
|
}
|
|
2695
2883
|
if (videos.length === 0) {
|
|
2696
|
-
throw new
|
|
2884
|
+
throw new import_provider5.AISDKError({
|
|
2697
2885
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2698
2886
|
message: "No valid videos in response"
|
|
2699
2887
|
});
|
|
@@ -2714,37 +2902,37 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2714
2902
|
};
|
|
2715
2903
|
}
|
|
2716
2904
|
};
|
|
2717
|
-
var googleOperationSchema =
|
|
2718
|
-
name:
|
|
2719
|
-
done:
|
|
2720
|
-
error:
|
|
2721
|
-
code:
|
|
2722
|
-
message:
|
|
2723
|
-
status:
|
|
2905
|
+
var googleOperationSchema = import_v415.z.object({
|
|
2906
|
+
name: import_v415.z.string().nullish(),
|
|
2907
|
+
done: import_v415.z.boolean().nullish(),
|
|
2908
|
+
error: import_v415.z.object({
|
|
2909
|
+
code: import_v415.z.number().nullish(),
|
|
2910
|
+
message: import_v415.z.string(),
|
|
2911
|
+
status: import_v415.z.string().nullish()
|
|
2724
2912
|
}).nullish(),
|
|
2725
|
-
response:
|
|
2726
|
-
generateVideoResponse:
|
|
2727
|
-
generatedSamples:
|
|
2728
|
-
|
|
2729
|
-
video:
|
|
2730
|
-
uri:
|
|
2913
|
+
response: import_v415.z.object({
|
|
2914
|
+
generateVideoResponse: import_v415.z.object({
|
|
2915
|
+
generatedSamples: import_v415.z.array(
|
|
2916
|
+
import_v415.z.object({
|
|
2917
|
+
video: import_v415.z.object({
|
|
2918
|
+
uri: import_v415.z.string().nullish()
|
|
2731
2919
|
}).nullish()
|
|
2732
2920
|
})
|
|
2733
2921
|
).nullish()
|
|
2734
2922
|
}).nullish()
|
|
2735
2923
|
}).nullish()
|
|
2736
2924
|
});
|
|
2737
|
-
var googleVideoModelOptionsSchema = (0,
|
|
2738
|
-
() => (0,
|
|
2739
|
-
|
|
2740
|
-
pollIntervalMs:
|
|
2741
|
-
pollTimeoutMs:
|
|
2742
|
-
personGeneration:
|
|
2743
|
-
negativePrompt:
|
|
2744
|
-
referenceImages:
|
|
2745
|
-
|
|
2746
|
-
bytesBase64Encoded:
|
|
2747
|
-
gcsUri:
|
|
2925
|
+
var googleVideoModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
2926
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
2927
|
+
import_v415.z.object({
|
|
2928
|
+
pollIntervalMs: import_v415.z.number().positive().nullish(),
|
|
2929
|
+
pollTimeoutMs: import_v415.z.number().positive().nullish(),
|
|
2930
|
+
personGeneration: import_v415.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2931
|
+
negativePrompt: import_v415.z.string().nullish(),
|
|
2932
|
+
referenceImages: import_v415.z.array(
|
|
2933
|
+
import_v415.z.object({
|
|
2934
|
+
bytesBase64Encoded: import_v415.z.string().nullish(),
|
|
2935
|
+
gcsUri: import_v415.z.string().nullish()
|
|
2748
2936
|
})
|
|
2749
2937
|
).nullish()
|
|
2750
2938
|
}).passthrough()
|
|
@@ -2754,11 +2942,11 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
|
2754
2942
|
// src/google-provider.ts
|
|
2755
2943
|
function createGoogleGenerativeAI(options = {}) {
|
|
2756
2944
|
var _a, _b;
|
|
2757
|
-
const baseURL = (_a = (0,
|
|
2945
|
+
const baseURL = (_a = (0, import_provider_utils17.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
2758
2946
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
2759
|
-
const getHeaders = () => (0,
|
|
2947
|
+
const getHeaders = () => (0, import_provider_utils17.withUserAgentSuffix)(
|
|
2760
2948
|
{
|
|
2761
|
-
"x-goog-api-key": (0,
|
|
2949
|
+
"x-goog-api-key": (0, import_provider_utils17.loadApiKey)({
|
|
2762
2950
|
apiKey: options.apiKey,
|
|
2763
2951
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
2764
2952
|
description: "Google Generative AI"
|
|
@@ -2773,7 +2961,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2773
2961
|
provider: providerName,
|
|
2774
2962
|
baseURL,
|
|
2775
2963
|
headers: getHeaders,
|
|
2776
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
2964
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils17.generateId,
|
|
2777
2965
|
supportedUrls: () => ({
|
|
2778
2966
|
"*": [
|
|
2779
2967
|
// Google Generative Language "files" endpoint
|
|
@@ -2801,6 +2989,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2801
2989
|
headers: getHeaders,
|
|
2802
2990
|
fetch: options.fetch
|
|
2803
2991
|
});
|
|
2992
|
+
const createFiles = () => new GoogleGenerativeAIFiles({
|
|
2993
|
+
provider: providerName,
|
|
2994
|
+
baseURL,
|
|
2995
|
+
headers: getHeaders,
|
|
2996
|
+
fetch: options.fetch
|
|
2997
|
+
});
|
|
2804
2998
|
const createVideoModel = (modelId) => {
|
|
2805
2999
|
var _a2;
|
|
2806
3000
|
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
@@ -2808,7 +3002,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2808
3002
|
baseURL,
|
|
2809
3003
|
headers: getHeaders,
|
|
2810
3004
|
fetch: options.fetch,
|
|
2811
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
3005
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils17.generateId
|
|
2812
3006
|
});
|
|
2813
3007
|
};
|
|
2814
3008
|
const provider = function(modelId) {
|
|
@@ -2831,6 +3025,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2831
3025
|
provider.imageModel = createImageModel;
|
|
2832
3026
|
provider.video = createVideoModel;
|
|
2833
3027
|
provider.videoModel = createVideoModel;
|
|
3028
|
+
provider.files = createFiles;
|
|
2834
3029
|
provider.tools = googleTools;
|
|
2835
3030
|
return provider;
|
|
2836
3031
|
}
|