@ai-sdk/google-vertex 4.0.40 → 4.0.41
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 +11 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/anthropic/edge/index.mjs +1 -1
- package/dist/edge/index.d.mts +7 -1
- package/dist/edge/index.d.ts +7 -1
- package/dist/edge/index.js +282 -20
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +279 -5
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +276 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +279 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/google-vertex-provider.ts +20 -1
- package/src/google-vertex-video-model.ts +374 -0
- package/src/google-vertex-video-settings.ts +16 -0
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ai-sdk/google-vertex
|
|
2
2
|
|
|
3
|
+
## 4.0.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 53f6731: feat (ai, provider): experimental generate video support
|
|
8
|
+
- Updated dependencies [53f6731]
|
|
9
|
+
- @ai-sdk/provider@3.0.7
|
|
10
|
+
- @ai-sdk/google@3.0.20
|
|
11
|
+
- @ai-sdk/anthropic@3.0.35
|
|
12
|
+
- @ai-sdk/provider-utils@4.0.13
|
|
13
|
+
|
|
3
14
|
## 4.0.40
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -32,7 +32,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
32
32
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "4.0.
|
|
35
|
+
var VERSION = true ? "4.0.41" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/edge/google-vertex-auth-edge.ts
|
|
38
38
|
var loadCredentials = async () => {
|
package/dist/edge/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
@@ -53,6 +53,8 @@ declare const googleVertexTools: {
|
|
|
53
53
|
}>;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
+
type GoogleVertexVideoModelId = 'veo-001' | 'veo-002' | 'veo-003' | 'veo-2.0-generate-001' | 'veo-2.0-generate-exp' | 'veo-2.0-generate-preview' | 'veo-3.0-generate-001' | 'veo-3.0-fast-generate-001' | 'veo-3.0-generate-preview' | 'veo-3.0-fast-generate-preview' | 'veo-3.1-generate-001' | 'veo-3.1-fast-generate-001' | 'veo-3.1-generate-preview' | 'veo-3.1-fast-generate-preview' | (string & {});
|
|
57
|
+
|
|
56
58
|
interface GoogleVertexProvider extends ProviderV3 {
|
|
57
59
|
/**
|
|
58
60
|
* Creates a model for text generation.
|
|
@@ -67,6 +69,10 @@ interface GoogleVertexProvider extends ProviderV3 {
|
|
|
67
69
|
* Creates a model for image generation.
|
|
68
70
|
*/
|
|
69
71
|
imageModel(modelId: GoogleVertexImageModelId): ImageModelV3;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a model for video generation.
|
|
74
|
+
*/
|
|
75
|
+
video(modelId: GoogleVertexVideoModelId): Experimental_VideoModelV3;
|
|
70
76
|
tools: typeof googleVertexTools;
|
|
71
77
|
/**
|
|
72
78
|
* @deprecated Use `embeddingModel` instead.
|
package/dist/edge/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { EmbeddingModelV3, ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
@@ -53,6 +53,8 @@ declare const googleVertexTools: {
|
|
|
53
53
|
}>;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
+
type GoogleVertexVideoModelId = 'veo-001' | 'veo-002' | 'veo-003' | 'veo-2.0-generate-001' | 'veo-2.0-generate-exp' | 'veo-2.0-generate-preview' | 'veo-3.0-generate-001' | 'veo-3.0-fast-generate-001' | 'veo-3.0-generate-preview' | 'veo-3.0-fast-generate-preview' | 'veo-3.1-generate-001' | 'veo-3.1-fast-generate-001' | 'veo-3.1-generate-preview' | 'veo-3.1-fast-generate-preview' | (string & {});
|
|
57
|
+
|
|
56
58
|
interface GoogleVertexProvider extends ProviderV3 {
|
|
57
59
|
/**
|
|
58
60
|
* Creates a model for text generation.
|
|
@@ -67,6 +69,10 @@ interface GoogleVertexProvider extends ProviderV3 {
|
|
|
67
69
|
* Creates a model for image generation.
|
|
68
70
|
*/
|
|
69
71
|
imageModel(modelId: GoogleVertexImageModelId): ImageModelV3;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a model for video generation.
|
|
74
|
+
*/
|
|
75
|
+
video(modelId: GoogleVertexVideoModelId): Experimental_VideoModelV3;
|
|
70
76
|
tools: typeof googleVertexTools;
|
|
71
77
|
/**
|
|
72
78
|
* @deprecated Use `embeddingModel` instead.
|
package/dist/edge/index.js
CHANGED
|
@@ -26,14 +26,14 @@ __export(edge_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(edge_exports);
|
|
27
27
|
|
|
28
28
|
// src/edge/google-vertex-provider-edge.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/google-vertex-provider.ts
|
|
32
32
|
var import_internal2 = require("@ai-sdk/google/internal");
|
|
33
|
-
var
|
|
33
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
34
34
|
|
|
35
35
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "4.0.
|
|
36
|
+
var VERSION = true ? "4.0.41" : "0.0.0-test";
|
|
37
37
|
|
|
38
38
|
// src/google-vertex-embedding-model.ts
|
|
39
39
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -418,6 +418,260 @@ var googleVertexTools = {
|
|
|
418
418
|
vertexRagStore: import_internal.googleTools.vertexRagStore
|
|
419
419
|
};
|
|
420
420
|
|
|
421
|
+
// src/google-vertex-video-model.ts
|
|
422
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
423
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
424
|
+
var import_v45 = require("zod/v4");
|
|
425
|
+
var GoogleVertexVideoModel = class {
|
|
426
|
+
constructor(modelId, config) {
|
|
427
|
+
this.modelId = modelId;
|
|
428
|
+
this.config = config;
|
|
429
|
+
this.specificationVersion = "v3";
|
|
430
|
+
}
|
|
431
|
+
get provider() {
|
|
432
|
+
return this.config.provider;
|
|
433
|
+
}
|
|
434
|
+
get maxVideosPerCall() {
|
|
435
|
+
return 4;
|
|
436
|
+
}
|
|
437
|
+
async doGenerate(options) {
|
|
438
|
+
var _a, _b, _c, _d, _e, _f;
|
|
439
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
440
|
+
const warnings = [];
|
|
441
|
+
const vertexOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
442
|
+
provider: "vertex",
|
|
443
|
+
providerOptions: options.providerOptions,
|
|
444
|
+
schema: vertexVideoProviderOptionsSchema
|
|
445
|
+
});
|
|
446
|
+
const instances = [{}];
|
|
447
|
+
const instance = instances[0];
|
|
448
|
+
if (options.prompt != null) {
|
|
449
|
+
instance.prompt = options.prompt;
|
|
450
|
+
}
|
|
451
|
+
if (options.image != null) {
|
|
452
|
+
if (options.image.type === "url") {
|
|
453
|
+
warnings.push({
|
|
454
|
+
type: "unsupported",
|
|
455
|
+
feature: "URL-based image input",
|
|
456
|
+
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
457
|
+
});
|
|
458
|
+
} else {
|
|
459
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils4.convertUint8ArrayToBase64)(options.image.data);
|
|
460
|
+
instance.image = {
|
|
461
|
+
bytesBase64Encoded: base64Data
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if ((vertexOptions == null ? void 0 : vertexOptions.referenceImages) != null) {
|
|
466
|
+
instance.referenceImages = vertexOptions.referenceImages;
|
|
467
|
+
}
|
|
468
|
+
const parameters = {
|
|
469
|
+
sampleCount: options.n
|
|
470
|
+
};
|
|
471
|
+
if (options.aspectRatio) {
|
|
472
|
+
parameters.aspectRatio = options.aspectRatio;
|
|
473
|
+
}
|
|
474
|
+
if (options.resolution) {
|
|
475
|
+
const resolutionMap = {
|
|
476
|
+
"1280x720": "720p",
|
|
477
|
+
"1920x1080": "1080p",
|
|
478
|
+
"3840x2160": "4k"
|
|
479
|
+
};
|
|
480
|
+
parameters.resolution = resolutionMap[options.resolution] || options.resolution;
|
|
481
|
+
}
|
|
482
|
+
if (options.duration) {
|
|
483
|
+
parameters.durationSeconds = options.duration;
|
|
484
|
+
}
|
|
485
|
+
if (options.seed) {
|
|
486
|
+
parameters.seed = options.seed;
|
|
487
|
+
}
|
|
488
|
+
if (vertexOptions != null) {
|
|
489
|
+
const opts = vertexOptions;
|
|
490
|
+
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
491
|
+
parameters.personGeneration = opts.personGeneration;
|
|
492
|
+
}
|
|
493
|
+
if (opts.negativePrompt !== void 0 && opts.negativePrompt !== null) {
|
|
494
|
+
parameters.negativePrompt = opts.negativePrompt;
|
|
495
|
+
}
|
|
496
|
+
if (opts.generateAudio !== void 0 && opts.generateAudio !== null) {
|
|
497
|
+
parameters.generateAudio = opts.generateAudio;
|
|
498
|
+
}
|
|
499
|
+
if (opts.gcsOutputDirectory !== void 0 && opts.gcsOutputDirectory !== null) {
|
|
500
|
+
parameters.gcsOutputDirectory = opts.gcsOutputDirectory;
|
|
501
|
+
}
|
|
502
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
503
|
+
if (![
|
|
504
|
+
"pollIntervalMs",
|
|
505
|
+
"pollTimeoutMs",
|
|
506
|
+
"personGeneration",
|
|
507
|
+
"negativePrompt",
|
|
508
|
+
"generateAudio",
|
|
509
|
+
"gcsOutputDirectory",
|
|
510
|
+
"referenceImages"
|
|
511
|
+
].includes(key)) {
|
|
512
|
+
parameters[key] = value;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const { value: operation } = await (0, import_provider_utils4.postJsonToApi)({
|
|
517
|
+
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
518
|
+
headers: (0, import_provider_utils4.combineHeaders)(
|
|
519
|
+
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
520
|
+
options.headers
|
|
521
|
+
),
|
|
522
|
+
body: {
|
|
523
|
+
instances,
|
|
524
|
+
parameters
|
|
525
|
+
},
|
|
526
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
527
|
+
vertexOperationSchema
|
|
528
|
+
),
|
|
529
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
530
|
+
abortSignal: options.abortSignal,
|
|
531
|
+
fetch: this.config.fetch
|
|
532
|
+
});
|
|
533
|
+
const operationName = operation.name;
|
|
534
|
+
if (!operationName) {
|
|
535
|
+
throw new import_provider2.AISDKError({
|
|
536
|
+
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
537
|
+
message: "No operation name returned from API"
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
const pollIntervalMs = (_d = vertexOptions == null ? void 0 : vertexOptions.pollIntervalMs) != null ? _d : 1e4;
|
|
541
|
+
const pollTimeoutMs = (_e = vertexOptions == null ? void 0 : vertexOptions.pollTimeoutMs) != null ? _e : 6e5;
|
|
542
|
+
const startTime = Date.now();
|
|
543
|
+
let finalOperation = operation;
|
|
544
|
+
let responseHeaders;
|
|
545
|
+
while (!finalOperation.done) {
|
|
546
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
547
|
+
throw new import_provider2.AISDKError({
|
|
548
|
+
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
549
|
+
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
await (0, import_provider_utils4.delay)(pollIntervalMs);
|
|
553
|
+
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
554
|
+
throw new import_provider2.AISDKError({
|
|
555
|
+
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
556
|
+
message: "Video generation request was aborted"
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils4.postJsonToApi)({
|
|
560
|
+
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
561
|
+
headers: (0, import_provider_utils4.combineHeaders)(
|
|
562
|
+
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
563
|
+
options.headers
|
|
564
|
+
),
|
|
565
|
+
body: {
|
|
566
|
+
operationName
|
|
567
|
+
},
|
|
568
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
569
|
+
vertexOperationSchema
|
|
570
|
+
),
|
|
571
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
572
|
+
abortSignal: options.abortSignal,
|
|
573
|
+
fetch: this.config.fetch
|
|
574
|
+
});
|
|
575
|
+
finalOperation = statusOperation;
|
|
576
|
+
responseHeaders = pollHeaders;
|
|
577
|
+
}
|
|
578
|
+
if (finalOperation.error) {
|
|
579
|
+
throw new import_provider2.AISDKError({
|
|
580
|
+
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
581
|
+
message: `Video generation failed: ${finalOperation.error.message}`
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
const response = finalOperation.response;
|
|
585
|
+
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
586
|
+
throw new import_provider2.AISDKError({
|
|
587
|
+
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
588
|
+
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
const videos = [];
|
|
592
|
+
const videoMetadata = [];
|
|
593
|
+
for (const video of response.videos) {
|
|
594
|
+
if (video.bytesBase64Encoded) {
|
|
595
|
+
videos.push({
|
|
596
|
+
type: "base64",
|
|
597
|
+
data: video.bytesBase64Encoded,
|
|
598
|
+
mediaType: video.mimeType || "video/mp4"
|
|
599
|
+
});
|
|
600
|
+
videoMetadata.push({
|
|
601
|
+
mimeType: video.mimeType
|
|
602
|
+
});
|
|
603
|
+
} else if (video.gcsUri) {
|
|
604
|
+
videos.push({
|
|
605
|
+
type: "url",
|
|
606
|
+
url: video.gcsUri,
|
|
607
|
+
mediaType: video.mimeType || "video/mp4"
|
|
608
|
+
});
|
|
609
|
+
videoMetadata.push({
|
|
610
|
+
gcsUri: video.gcsUri,
|
|
611
|
+
mimeType: video.mimeType
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (videos.length === 0) {
|
|
616
|
+
throw new import_provider2.AISDKError({
|
|
617
|
+
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
618
|
+
message: "No valid videos in response"
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
videos,
|
|
623
|
+
warnings,
|
|
624
|
+
response: {
|
|
625
|
+
timestamp: currentDate,
|
|
626
|
+
modelId: this.modelId,
|
|
627
|
+
headers: responseHeaders
|
|
628
|
+
},
|
|
629
|
+
providerMetadata: {
|
|
630
|
+
"google-vertex": {
|
|
631
|
+
videos: videoMetadata
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
var vertexOperationSchema = import_v45.z.object({
|
|
638
|
+
name: import_v45.z.string().nullish(),
|
|
639
|
+
done: import_v45.z.boolean().nullish(),
|
|
640
|
+
error: import_v45.z.object({
|
|
641
|
+
code: import_v45.z.number().nullish(),
|
|
642
|
+
message: import_v45.z.string(),
|
|
643
|
+
status: import_v45.z.string().nullish()
|
|
644
|
+
}).nullish(),
|
|
645
|
+
response: import_v45.z.object({
|
|
646
|
+
videos: import_v45.z.array(
|
|
647
|
+
import_v45.z.object({
|
|
648
|
+
bytesBase64Encoded: import_v45.z.string().nullish(),
|
|
649
|
+
gcsUri: import_v45.z.string().nullish(),
|
|
650
|
+
mimeType: import_v45.z.string().nullish()
|
|
651
|
+
})
|
|
652
|
+
).nullish(),
|
|
653
|
+
raiMediaFilteredCount: import_v45.z.number().nullish()
|
|
654
|
+
}).nullish()
|
|
655
|
+
});
|
|
656
|
+
var vertexVideoProviderOptionsSchema = (0, import_provider_utils4.lazySchema)(
|
|
657
|
+
() => (0, import_provider_utils4.zodSchema)(
|
|
658
|
+
import_v45.z.object({
|
|
659
|
+
pollIntervalMs: import_v45.z.number().positive().nullish(),
|
|
660
|
+
pollTimeoutMs: import_v45.z.number().positive().nullish(),
|
|
661
|
+
personGeneration: import_v45.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
662
|
+
negativePrompt: import_v45.z.string().nullish(),
|
|
663
|
+
generateAudio: import_v45.z.boolean().nullish(),
|
|
664
|
+
gcsOutputDirectory: import_v45.z.string().nullish(),
|
|
665
|
+
referenceImages: import_v45.z.array(
|
|
666
|
+
import_v45.z.object({
|
|
667
|
+
bytesBase64Encoded: import_v45.z.string().nullish(),
|
|
668
|
+
gcsUri: import_v45.z.string().nullish()
|
|
669
|
+
})
|
|
670
|
+
).nullish()
|
|
671
|
+
}).passthrough()
|
|
672
|
+
)
|
|
673
|
+
);
|
|
674
|
+
|
|
421
675
|
// src/google-vertex-provider.ts
|
|
422
676
|
var EXPRESS_MODE_BASE_URL = "https://aiplatform.googleapis.com/v1/publishers/google";
|
|
423
677
|
function createExpressModeFetch(apiKey, customFetch) {
|
|
@@ -425,7 +679,7 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
425
679
|
const modifiedInit = {
|
|
426
680
|
...init,
|
|
427
681
|
headers: {
|
|
428
|
-
...(init == null ? void 0 : init.headers) ? (0,
|
|
682
|
+
...(init == null ? void 0 : init.headers) ? (0, import_provider_utils5.normalizeHeaders)(init.headers) : {},
|
|
429
683
|
"x-goog-api-key": apiKey
|
|
430
684
|
}
|
|
431
685
|
};
|
|
@@ -433,17 +687,17 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
433
687
|
};
|
|
434
688
|
}
|
|
435
689
|
function createVertex(options = {}) {
|
|
436
|
-
const apiKey = (0,
|
|
690
|
+
const apiKey = (0, import_provider_utils5.loadOptionalSetting)({
|
|
437
691
|
settingValue: options.apiKey,
|
|
438
692
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
439
693
|
});
|
|
440
|
-
const loadVertexProject = () => (0,
|
|
694
|
+
const loadVertexProject = () => (0, import_provider_utils5.loadSetting)({
|
|
441
695
|
settingValue: options.project,
|
|
442
696
|
settingName: "project",
|
|
443
697
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
444
698
|
description: "Google Vertex project"
|
|
445
699
|
});
|
|
446
|
-
const loadVertexLocation = () => (0,
|
|
700
|
+
const loadVertexLocation = () => (0, import_provider_utils5.loadSetting)({
|
|
447
701
|
settingValue: options.location,
|
|
448
702
|
settingName: "location",
|
|
449
703
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -452,18 +706,18 @@ function createVertex(options = {}) {
|
|
|
452
706
|
const loadBaseURL = () => {
|
|
453
707
|
var _a, _b;
|
|
454
708
|
if (apiKey) {
|
|
455
|
-
return (_a = (0,
|
|
709
|
+
return (_a = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
456
710
|
}
|
|
457
711
|
const region = loadVertexLocation();
|
|
458
712
|
const project = loadVertexProject();
|
|
459
713
|
const baseHost = `${region === "global" ? "" : region + "-"}aiplatform.googleapis.com`;
|
|
460
|
-
return (_b = (0,
|
|
714
|
+
return (_b = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _b : `https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
461
715
|
};
|
|
462
716
|
const createConfig = (name) => {
|
|
463
717
|
const getHeaders = async () => {
|
|
464
718
|
var _a;
|
|
465
|
-
const originalHeaders = await (0,
|
|
466
|
-
return (0,
|
|
719
|
+
const originalHeaders = await (0, import_provider_utils5.resolve)((_a = options.headers) != null ? _a : {});
|
|
720
|
+
return (0, import_provider_utils5.withUserAgentSuffix)(
|
|
467
721
|
originalHeaders,
|
|
468
722
|
`ai-sdk/google-vertex/${VERSION}`
|
|
469
723
|
);
|
|
@@ -479,7 +733,7 @@ function createVertex(options = {}) {
|
|
|
479
733
|
var _a;
|
|
480
734
|
return new import_internal2.GoogleGenerativeAILanguageModel(modelId, {
|
|
481
735
|
...createConfig("chat"),
|
|
482
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
736
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils5.generateId,
|
|
483
737
|
supportedUrls: () => ({
|
|
484
738
|
"*": [
|
|
485
739
|
// HTTP URLs:
|
|
@@ -492,6 +746,13 @@ function createVertex(options = {}) {
|
|
|
492
746
|
};
|
|
493
747
|
const createEmbeddingModel = (modelId) => new GoogleVertexEmbeddingModel(modelId, createConfig("embedding"));
|
|
494
748
|
const createImageModel = (modelId) => new GoogleVertexImageModel(modelId, createConfig("image"));
|
|
749
|
+
const createVideoModel = (modelId) => {
|
|
750
|
+
var _a;
|
|
751
|
+
return new GoogleVertexVideoModel(modelId, {
|
|
752
|
+
...createConfig("video"),
|
|
753
|
+
generateId: (_a = options.generateId) != null ? _a : import_provider_utils5.generateId
|
|
754
|
+
});
|
|
755
|
+
};
|
|
495
756
|
const provider = function(modelId) {
|
|
496
757
|
if (new.target) {
|
|
497
758
|
throw new Error(
|
|
@@ -506,28 +767,29 @@ function createVertex(options = {}) {
|
|
|
506
767
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
507
768
|
provider.image = createImageModel;
|
|
508
769
|
provider.imageModel = createImageModel;
|
|
770
|
+
provider.video = createVideoModel;
|
|
509
771
|
provider.tools = googleVertexTools;
|
|
510
772
|
return provider;
|
|
511
773
|
}
|
|
512
774
|
|
|
513
775
|
// src/edge/google-vertex-auth-edge.ts
|
|
514
|
-
var
|
|
776
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
515
777
|
var loadCredentials = async () => {
|
|
516
778
|
try {
|
|
517
779
|
return {
|
|
518
|
-
clientEmail: (0,
|
|
780
|
+
clientEmail: (0, import_provider_utils6.loadSetting)({
|
|
519
781
|
settingValue: void 0,
|
|
520
782
|
settingName: "clientEmail",
|
|
521
783
|
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
522
784
|
description: "Google client email"
|
|
523
785
|
}),
|
|
524
|
-
privateKey: (0,
|
|
786
|
+
privateKey: (0, import_provider_utils6.loadSetting)({
|
|
525
787
|
settingValue: void 0,
|
|
526
788
|
settingName: "privateKey",
|
|
527
789
|
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
528
790
|
description: "Google private key"
|
|
529
791
|
}),
|
|
530
|
-
privateKeyId: (0,
|
|
792
|
+
privateKeyId: (0, import_provider_utils6.loadOptionalSetting)({
|
|
531
793
|
settingValue: void 0,
|
|
532
794
|
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
533
795
|
})
|
|
@@ -596,10 +858,10 @@ async function generateAuthToken(credentials) {
|
|
|
596
858
|
const jwt = await buildJwt(creds);
|
|
597
859
|
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
598
860
|
method: "POST",
|
|
599
|
-
headers: (0,
|
|
861
|
+
headers: (0, import_provider_utils6.withUserAgentSuffix)(
|
|
600
862
|
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
601
863
|
`ai-sdk/google-vertex/${VERSION}`,
|
|
602
|
-
(0,
|
|
864
|
+
(0, import_provider_utils6.getRuntimeEnvironmentUserAgent)()
|
|
603
865
|
),
|
|
604
866
|
body: new URLSearchParams({
|
|
605
867
|
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
@@ -618,7 +880,7 @@ async function generateAuthToken(credentials) {
|
|
|
618
880
|
|
|
619
881
|
// src/edge/google-vertex-provider-edge.ts
|
|
620
882
|
function createVertex2(options = {}) {
|
|
621
|
-
const apiKey = (0,
|
|
883
|
+
const apiKey = (0, import_provider_utils7.loadOptionalSetting)({
|
|
622
884
|
settingValue: options.apiKey,
|
|
623
885
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
624
886
|
});
|
|
@@ -631,7 +893,7 @@ function createVertex2(options = {}) {
|
|
|
631
893
|
Authorization: `Bearer ${await generateAuthToken(
|
|
632
894
|
options.googleCredentials
|
|
633
895
|
)}`,
|
|
634
|
-
...await (0,
|
|
896
|
+
...await (0, import_provider_utils7.resolve)(options.headers)
|
|
635
897
|
})
|
|
636
898
|
});
|
|
637
899
|
}
|