@ai-sdk/google-vertex 5.0.0-beta.10 → 5.0.0-beta.109
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 +937 -8
- package/README.md +65 -2
- package/dist/anthropic/edge/index.d.ts +18 -151
- package/dist/anthropic/edge/index.js +88 -70
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +18 -151
- package/dist/anthropic/index.js +88 -81
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +58 -29
- package/dist/edge/index.js +581 -278
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +70 -32
- package/dist/index.js +590 -296
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +209 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +109 -0
- package/dist/maas/index.js.map +1 -0
- package/dist/xai/edge/index.d.ts +92 -0
- package/dist/xai/edge/index.js +259 -0
- package/dist/xai/edge/index.js.map +1 -0
- package/dist/xai/index.d.ts +76 -0
- package/dist/xai/index.js +159 -0
- package/dist/xai/index.js.map +1 -0
- package/docs/16-google-vertex.mdx +640 -102
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +49 -24
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +17 -13
- package/src/anthropic/edge/index.ts +6 -2
- package/src/anthropic/{google-vertex-anthropic-messages-options.ts → google-vertex-anthropic-options.ts} +4 -1
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +18 -13
- package/src/anthropic/google-vertex-anthropic-provider.ts +68 -19
- package/src/anthropic/index.ts +6 -2
- package/src/edge/google-vertex-provider-edge.ts +10 -12
- package/src/edge/index.ts +8 -1
- package/src/google-vertex-auth-google-auth-library.ts +13 -26
- package/src/google-vertex-config.ts +2 -2
- package/src/{google-vertex-embedding-options.ts → google-vertex-embedding-model-options.ts} +1 -0
- package/src/google-vertex-embedding-model.ts +35 -10
- package/src/google-vertex-image-model-options.ts +74 -0
- package/src/google-vertex-image-model.ts +106 -133
- package/src/google-vertex-options.ts +1 -1
- package/src/google-vertex-provider-base.ts +311 -0
- package/src/google-vertex-provider.ts +43 -233
- package/src/google-vertex-speech-model-options.ts +11 -0
- package/src/google-vertex-transcription-model-options.ts +46 -0
- package/src/google-vertex-transcription-model.ts +231 -0
- package/src/google-vertex-video-model-options.ts +49 -0
- package/src/google-vertex-video-model.ts +39 -75
- package/src/index.ts +20 -5
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +64 -0
- package/src/maas/edge/index.ts +13 -0
- package/src/maas/google-vertex-maas-options.ts +15 -0
- package/src/maas/google-vertex-maas-provider-node.ts +65 -0
- package/src/maas/google-vertex-maas-provider.ts +122 -0
- package/src/maas/index.ts +13 -0
- package/src/xai/edge/google-vertex-xai-provider-edge.ts +61 -0
- package/src/xai/edge/index.ts +9 -0
- package/src/xai/google-vertex-xai-options.ts +7 -0
- package/src/xai/google-vertex-xai-provider-node.ts +62 -0
- package/src/xai/google-vertex-xai-provider.ts +212 -0
- package/src/xai/index.ts +9 -0
- package/xai/edge.d.ts +1 -0
- package/xai/index.d.ts +1 -0
- package/dist/anthropic/edge/index.d.mts +0 -231
- package/dist/anthropic/edge/index.mjs +0 -259
- package/dist/anthropic/edge/index.mjs.map +0 -1
- package/dist/anthropic/index.d.mts +0 -215
- package/dist/anthropic/index.mjs +0 -164
- package/dist/anthropic/index.mjs.map +0 -1
- package/dist/edge/index.d.mts +0 -160
- package/dist/edge/index.mjs +0 -1049
- package/dist/edge/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -219
- package/dist/index.mjs +0 -960
- package/dist/index.mjs.map +0 -1
- package/src/google-vertex-provider-node.ts +0 -49
package/dist/edge/index.js
CHANGED
|
@@ -1,70 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/edge/index.ts
|
|
21
|
-
var edge_exports = {};
|
|
22
|
-
__export(edge_exports, {
|
|
23
|
-
createVertex: () => createVertex2,
|
|
24
|
-
vertex: () => vertex
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(edge_exports);
|
|
27
|
-
|
|
28
1
|
// src/edge/google-vertex-provider-edge.ts
|
|
29
|
-
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting3, resolve as resolve6 } from "@ai-sdk/provider-utils";
|
|
30
3
|
|
|
31
|
-
// src/google-vertex-provider.ts
|
|
32
|
-
|
|
33
|
-
|
|
4
|
+
// src/google-vertex-provider-base.ts
|
|
5
|
+
import {
|
|
6
|
+
GoogleLanguageModel as GoogleLanguageModel2,
|
|
7
|
+
GoogleSpeechModel
|
|
8
|
+
} from "@ai-sdk/google/internal";
|
|
9
|
+
import {
|
|
10
|
+
generateId,
|
|
11
|
+
loadOptionalSetting,
|
|
12
|
+
loadSetting,
|
|
13
|
+
normalizeHeaders,
|
|
14
|
+
resolve as resolve5,
|
|
15
|
+
withoutTrailingSlash,
|
|
16
|
+
withUserAgentSuffix
|
|
17
|
+
} from "@ai-sdk/provider-utils";
|
|
34
18
|
|
|
35
19
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "5.0.0-beta.
|
|
20
|
+
var VERSION = true ? "5.0.0-beta.109" : "0.0.0-test";
|
|
37
21
|
|
|
38
22
|
// src/google-vertex-embedding-model.ts
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
import {
|
|
24
|
+
TooManyEmbeddingValuesForCallError
|
|
25
|
+
} from "@ai-sdk/provider";
|
|
26
|
+
import {
|
|
27
|
+
combineHeaders,
|
|
28
|
+
createJsonResponseHandler,
|
|
29
|
+
postJsonToApi,
|
|
30
|
+
resolve,
|
|
31
|
+
parseProviderOptions,
|
|
32
|
+
serializeModelOptions,
|
|
33
|
+
WORKFLOW_SERIALIZE,
|
|
34
|
+
WORKFLOW_DESERIALIZE
|
|
35
|
+
} from "@ai-sdk/provider-utils";
|
|
36
|
+
import { z as z3 } from "zod/v4";
|
|
42
37
|
|
|
43
38
|
// src/google-vertex-error.ts
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var googleVertexErrorDataSchema =
|
|
47
|
-
error:
|
|
48
|
-
code:
|
|
49
|
-
message:
|
|
50
|
-
status:
|
|
39
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
40
|
+
import { z } from "zod/v4";
|
|
41
|
+
var googleVertexErrorDataSchema = z.object({
|
|
42
|
+
error: z.object({
|
|
43
|
+
code: z.number().nullable(),
|
|
44
|
+
message: z.string(),
|
|
45
|
+
status: z.string()
|
|
51
46
|
})
|
|
52
47
|
});
|
|
53
|
-
var googleVertexFailedResponseHandler =
|
|
48
|
+
var googleVertexFailedResponseHandler = createJsonErrorResponseHandler(
|
|
54
49
|
{
|
|
55
50
|
errorSchema: googleVertexErrorDataSchema,
|
|
56
51
|
errorToMessage: (data) => data.error.message
|
|
57
52
|
}
|
|
58
53
|
);
|
|
59
54
|
|
|
60
|
-
// src/google-vertex-embedding-options.ts
|
|
61
|
-
|
|
62
|
-
var googleVertexEmbeddingModelOptions =
|
|
55
|
+
// src/google-vertex-embedding-model-options.ts
|
|
56
|
+
import { z as z2 } from "zod/v4";
|
|
57
|
+
var googleVertexEmbeddingModelOptions = z2.object({
|
|
63
58
|
/**
|
|
64
59
|
* Optional. Optional reduced dimension for the output embedding.
|
|
65
60
|
* If set, excessive values in the output embedding are truncated from the end.
|
|
66
61
|
*/
|
|
67
|
-
outputDimensionality:
|
|
62
|
+
outputDimensionality: z2.number().optional(),
|
|
68
63
|
/**
|
|
69
64
|
* Optional. Specifies the task type for generating embeddings.
|
|
70
65
|
* Supported task types:
|
|
@@ -77,7 +72,7 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
77
72
|
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
78
73
|
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
79
74
|
*/
|
|
80
|
-
taskType:
|
|
75
|
+
taskType: z2.enum([
|
|
81
76
|
"SEMANTIC_SIMILARITY",
|
|
82
77
|
"CLASSIFICATION",
|
|
83
78
|
"CLUSTERING",
|
|
@@ -92,23 +87,32 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
92
87
|
* Only valid when task_type is set to 'RETRIEVAL_DOCUMENT'.
|
|
93
88
|
* Helps the model produce better embeddings by providing additional context.
|
|
94
89
|
*/
|
|
95
|
-
title:
|
|
90
|
+
title: z2.string().optional(),
|
|
96
91
|
/**
|
|
97
92
|
* Optional. When set to true, input text will be truncated. When set to false,
|
|
98
93
|
* an error is returned if the input text is longer than the maximum length supported by the model. Defaults to true.
|
|
99
94
|
*/
|
|
100
|
-
autoTruncate:
|
|
95
|
+
autoTruncate: z2.boolean().optional()
|
|
101
96
|
});
|
|
102
97
|
|
|
103
98
|
// src/google-vertex-embedding-model.ts
|
|
104
|
-
var GoogleVertexEmbeddingModel = class {
|
|
99
|
+
var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
105
100
|
constructor(modelId, config) {
|
|
106
|
-
this.specificationVersion = "
|
|
101
|
+
this.specificationVersion = "v4";
|
|
107
102
|
this.maxEmbeddingsPerCall = 2048;
|
|
108
103
|
this.supportsParallelCalls = true;
|
|
109
104
|
this.modelId = modelId;
|
|
110
105
|
this.config = config;
|
|
111
106
|
}
|
|
107
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
108
|
+
return serializeModelOptions({
|
|
109
|
+
modelId: model.modelId,
|
|
110
|
+
config: model.config
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
114
|
+
return new _GoogleVertexEmbeddingModel(options.modelId, options.config);
|
|
115
|
+
}
|
|
112
116
|
get provider() {
|
|
113
117
|
return this.config.provider;
|
|
114
118
|
}
|
|
@@ -118,13 +122,20 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
118
122
|
abortSignal,
|
|
119
123
|
providerOptions
|
|
120
124
|
}) {
|
|
121
|
-
let googleOptions = await
|
|
122
|
-
provider: "
|
|
125
|
+
let googleOptions = await parseProviderOptions({
|
|
126
|
+
provider: "googleVertex",
|
|
123
127
|
providerOptions,
|
|
124
128
|
schema: googleVertexEmbeddingModelOptions
|
|
125
129
|
});
|
|
126
130
|
if (googleOptions == null) {
|
|
127
|
-
googleOptions = await
|
|
131
|
+
googleOptions = await parseProviderOptions({
|
|
132
|
+
provider: "vertex",
|
|
133
|
+
providerOptions,
|
|
134
|
+
schema: googleVertexEmbeddingModelOptions
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (googleOptions == null) {
|
|
138
|
+
googleOptions = await parseProviderOptions({
|
|
128
139
|
provider: "google",
|
|
129
140
|
providerOptions,
|
|
130
141
|
schema: googleVertexEmbeddingModelOptions
|
|
@@ -132,15 +143,15 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
132
143
|
}
|
|
133
144
|
googleOptions = googleOptions != null ? googleOptions : {};
|
|
134
145
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
135
|
-
throw new
|
|
146
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
136
147
|
provider: this.provider,
|
|
137
148
|
modelId: this.modelId,
|
|
138
149
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
139
150
|
values
|
|
140
151
|
});
|
|
141
152
|
}
|
|
142
|
-
const mergedHeaders =
|
|
143
|
-
await
|
|
153
|
+
const mergedHeaders = combineHeaders(
|
|
154
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
144
155
|
headers
|
|
145
156
|
);
|
|
146
157
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
@@ -148,7 +159,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
148
159
|
responseHeaders,
|
|
149
160
|
value: response,
|
|
150
161
|
rawValue
|
|
151
|
-
} = await
|
|
162
|
+
} = await postJsonToApi({
|
|
152
163
|
url,
|
|
153
164
|
headers: mergedHeaders,
|
|
154
165
|
body: {
|
|
@@ -163,7 +174,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
163
174
|
}
|
|
164
175
|
},
|
|
165
176
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
166
|
-
successfulResponseHandler:
|
|
177
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
167
178
|
googleVertexTextEmbeddingResponseSchema
|
|
168
179
|
),
|
|
169
180
|
abortSignal,
|
|
@@ -184,13 +195,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
184
195
|
};
|
|
185
196
|
}
|
|
186
197
|
};
|
|
187
|
-
var googleVertexTextEmbeddingResponseSchema =
|
|
188
|
-
predictions:
|
|
189
|
-
|
|
190
|
-
embeddings:
|
|
191
|
-
values:
|
|
192
|
-
statistics:
|
|
193
|
-
token_count:
|
|
198
|
+
var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
199
|
+
predictions: z3.array(
|
|
200
|
+
z3.object({
|
|
201
|
+
embeddings: z3.object({
|
|
202
|
+
values: z3.array(z3.number()),
|
|
203
|
+
statistics: z3.object({
|
|
204
|
+
token_count: z3.number()
|
|
194
205
|
})
|
|
195
206
|
})
|
|
196
207
|
})
|
|
@@ -198,14 +209,96 @@ var googleVertexTextEmbeddingResponseSchema = import_v43.z.object({
|
|
|
198
209
|
});
|
|
199
210
|
|
|
200
211
|
// src/google-vertex-image-model.ts
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
212
|
+
import { GoogleLanguageModel } from "@ai-sdk/google/internal";
|
|
213
|
+
import {
|
|
214
|
+
combineHeaders as combineHeaders2,
|
|
215
|
+
convertToBase64,
|
|
216
|
+
convertUint8ArrayToBase64,
|
|
217
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
218
|
+
generateId as defaultGenerateId,
|
|
219
|
+
parseProviderOptions as parseProviderOptions2,
|
|
220
|
+
postJsonToApi as postJsonToApi2,
|
|
221
|
+
resolve as resolve2,
|
|
222
|
+
serializeModelOptions as serializeModelOptions2,
|
|
223
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
224
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
225
|
+
} from "@ai-sdk/provider-utils";
|
|
226
|
+
import { z as z5 } from "zod/v4";
|
|
227
|
+
|
|
228
|
+
// src/google-vertex-image-model-options.ts
|
|
229
|
+
import { z as z4 } from "zod/v4";
|
|
230
|
+
var googleVertexImageModelOptionsSchema = z4.object({
|
|
231
|
+
negativePrompt: z4.string().nullish(),
|
|
232
|
+
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
233
|
+
safetySetting: z4.enum([
|
|
234
|
+
"block_low_and_above",
|
|
235
|
+
"block_medium_and_above",
|
|
236
|
+
"block_only_high",
|
|
237
|
+
"block_none"
|
|
238
|
+
]).nullish(),
|
|
239
|
+
addWatermark: z4.boolean().nullish(),
|
|
240
|
+
storageUri: z4.string().nullish(),
|
|
241
|
+
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
242
|
+
/**
|
|
243
|
+
* Configuration for image editing operations
|
|
244
|
+
*/
|
|
245
|
+
edit: z4.object({
|
|
246
|
+
/**
|
|
247
|
+
* An integer that represents the number of sampling steps.
|
|
248
|
+
* A higher value offers better image quality, a lower value offers better latency.
|
|
249
|
+
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
250
|
+
* increase the value towards an upper limit of 75.
|
|
251
|
+
*/
|
|
252
|
+
baseSteps: z4.number().nullish(),
|
|
253
|
+
// Edit mode options
|
|
254
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
255
|
+
mode: z4.enum([
|
|
256
|
+
"EDIT_MODE_INPAINT_INSERTION",
|
|
257
|
+
"EDIT_MODE_INPAINT_REMOVAL",
|
|
258
|
+
"EDIT_MODE_OUTPAINT",
|
|
259
|
+
"EDIT_MODE_CONTROLLED_EDITING",
|
|
260
|
+
"EDIT_MODE_PRODUCT_IMAGE",
|
|
261
|
+
"EDIT_MODE_BGSWAP"
|
|
262
|
+
]).nullish(),
|
|
263
|
+
/**
|
|
264
|
+
* The mask mode to use.
|
|
265
|
+
* - `MASK_MODE_DEFAULT` - Default value for mask mode.
|
|
266
|
+
* - `MASK_MODE_USER_PROVIDED` - User provided mask. No segmentation needed.
|
|
267
|
+
* - `MASK_MODE_DETECTION_BOX` - Mask from detected bounding boxes.
|
|
268
|
+
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
269
|
+
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
270
|
+
*/
|
|
271
|
+
maskMode: z4.enum([
|
|
272
|
+
"MASK_MODE_DEFAULT",
|
|
273
|
+
"MASK_MODE_USER_PROVIDED",
|
|
274
|
+
"MASK_MODE_DETECTION_BOX",
|
|
275
|
+
"MASK_MODE_CLOTHING_AREA",
|
|
276
|
+
"MASK_MODE_PARSED_PERSON"
|
|
277
|
+
]).nullish(),
|
|
278
|
+
/**
|
|
279
|
+
* Optional. A float value between 0 and 1, inclusive, that represents the
|
|
280
|
+
* percentage of the image width to grow the mask by. Using dilation helps
|
|
281
|
+
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
282
|
+
*/
|
|
283
|
+
maskDilation: z4.number().nullish()
|
|
284
|
+
}).nullish()
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// src/google-vertex-image-model.ts
|
|
288
|
+
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
205
289
|
constructor(modelId, config) {
|
|
206
290
|
this.modelId = modelId;
|
|
207
291
|
this.config = config;
|
|
208
|
-
this.specificationVersion = "
|
|
292
|
+
this.specificationVersion = "v4";
|
|
293
|
+
}
|
|
294
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
295
|
+
return serializeModelOptions2({
|
|
296
|
+
modelId: model.modelId,
|
|
297
|
+
config: model.config
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
301
|
+
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
209
302
|
}
|
|
210
303
|
get maxImagesPerCall() {
|
|
211
304
|
if (isGeminiModel(this.modelId)) {
|
|
@@ -234,7 +327,7 @@ var GoogleVertexImageModel = class {
|
|
|
234
327
|
files,
|
|
235
328
|
mask
|
|
236
329
|
}) {
|
|
237
|
-
var _a, _b, _c, _d, _e, _f
|
|
330
|
+
var _a, _b, _c, _d, _e, _f;
|
|
238
331
|
const warnings = [];
|
|
239
332
|
if (size != null) {
|
|
240
333
|
warnings.push({
|
|
@@ -243,12 +336,16 @@ var GoogleVertexImageModel = class {
|
|
|
243
336
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
244
337
|
});
|
|
245
338
|
}
|
|
246
|
-
const
|
|
339
|
+
const googleVertexImageOptions = (_a = await parseProviderOptions2({
|
|
340
|
+
provider: "googleVertex",
|
|
341
|
+
providerOptions,
|
|
342
|
+
schema: googleVertexImageModelOptionsSchema
|
|
343
|
+
})) != null ? _a : await parseProviderOptions2({
|
|
247
344
|
provider: "vertex",
|
|
248
345
|
providerOptions,
|
|
249
346
|
schema: googleVertexImageModelOptionsSchema
|
|
250
347
|
});
|
|
251
|
-
const { edit, ...otherOptions } =
|
|
348
|
+
const { edit, ...otherOptions } = googleVertexImageOptions != null ? googleVertexImageOptions : {};
|
|
252
349
|
const { mode: editMode, baseSteps, maskMode, maskDilation } = edit != null ? edit : {};
|
|
253
350
|
const isEditMode = files != null && files.length > 0;
|
|
254
351
|
let body;
|
|
@@ -304,39 +401,44 @@ var GoogleVertexImageModel = class {
|
|
|
304
401
|
}
|
|
305
402
|
};
|
|
306
403
|
}
|
|
307
|
-
const currentDate = (
|
|
308
|
-
const { value: response, responseHeaders } = await (
|
|
404
|
+
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
405
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
309
406
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
310
|
-
headers: (
|
|
407
|
+
headers: combineHeaders2(
|
|
408
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
409
|
+
headers
|
|
410
|
+
),
|
|
311
411
|
body,
|
|
312
412
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
313
|
-
successfulResponseHandler: (
|
|
314
|
-
|
|
413
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
414
|
+
googleVertexImageResponseSchema
|
|
315
415
|
),
|
|
316
416
|
abortSignal,
|
|
317
417
|
fetch: this.config.fetch
|
|
318
418
|
});
|
|
319
419
|
return {
|
|
320
|
-
images: (
|
|
420
|
+
images: (_f = (_e = response.predictions) == null ? void 0 : _e.map(
|
|
321
421
|
({ bytesBase64Encoded }) => bytesBase64Encoded
|
|
322
|
-
)) != null ?
|
|
422
|
+
)) != null ? _f : [],
|
|
323
423
|
warnings,
|
|
324
424
|
response: {
|
|
325
425
|
timestamp: currentDate,
|
|
326
426
|
modelId: this.modelId,
|
|
327
427
|
headers: responseHeaders
|
|
328
428
|
},
|
|
329
|
-
providerMetadata: {
|
|
330
|
-
|
|
331
|
-
|
|
429
|
+
providerMetadata: (() => {
|
|
430
|
+
var _a2, _b2;
|
|
431
|
+
const payload = {
|
|
432
|
+
images: (_b2 = (_a2 = response.predictions) == null ? void 0 : _a2.map((prediction) => {
|
|
332
433
|
const {
|
|
333
434
|
// normalize revised prompt property
|
|
334
435
|
prompt: revisedPrompt
|
|
335
436
|
} = prediction;
|
|
336
437
|
return { ...revisedPrompt != null && { revisedPrompt } };
|
|
337
|
-
})) != null ?
|
|
338
|
-
}
|
|
339
|
-
|
|
438
|
+
})) != null ? _b2 : []
|
|
439
|
+
};
|
|
440
|
+
return { googleVertex: payload, vertex: payload };
|
|
441
|
+
})()
|
|
340
442
|
};
|
|
341
443
|
}
|
|
342
444
|
async doGenerateGemini({
|
|
@@ -379,13 +481,16 @@ var GoogleVertexImageModel = class {
|
|
|
379
481
|
if (file.type === "url") {
|
|
380
482
|
userContent.push({
|
|
381
483
|
type: "file",
|
|
382
|
-
data: new URL(file.url),
|
|
484
|
+
data: { type: "url", url: new URL(file.url) },
|
|
383
485
|
mediaType: "image/*"
|
|
384
486
|
});
|
|
385
487
|
} else {
|
|
386
488
|
userContent.push({
|
|
387
489
|
type: "file",
|
|
388
|
-
data:
|
|
490
|
+
data: {
|
|
491
|
+
type: "data",
|
|
492
|
+
data: typeof file.data === "string" ? file.data : new Uint8Array(file.data)
|
|
493
|
+
},
|
|
389
494
|
mediaType: file.mediaType
|
|
390
495
|
});
|
|
391
496
|
}
|
|
@@ -394,27 +499,30 @@ var GoogleVertexImageModel = class {
|
|
|
394
499
|
const languageModelPrompt = [
|
|
395
500
|
{ role: "user", content: userContent }
|
|
396
501
|
];
|
|
397
|
-
const languageModel = new
|
|
502
|
+
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
398
503
|
provider: this.config.provider,
|
|
399
504
|
baseURL: this.config.baseURL,
|
|
400
505
|
headers: (_a = this.config.headers) != null ? _a : {},
|
|
401
506
|
fetch: this.config.fetch,
|
|
402
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
507
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
|
|
403
508
|
supportedUrls: () => ({
|
|
404
509
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
405
510
|
})
|
|
406
511
|
});
|
|
512
|
+
const userVertexOptions = (_c = providerOptions == null ? void 0 : providerOptions.googleVertex) != null ? _c : providerOptions == null ? void 0 : providerOptions.vertex;
|
|
513
|
+
const innerVertexOptions = {
|
|
514
|
+
responseModalities: ["IMAGE"],
|
|
515
|
+
imageConfig: aspectRatio ? {
|
|
516
|
+
aspectRatio
|
|
517
|
+
} : void 0,
|
|
518
|
+
...userVertexOptions != null ? userVertexOptions : {}
|
|
519
|
+
};
|
|
407
520
|
const result = await languageModel.doGenerate({
|
|
408
521
|
prompt: languageModelPrompt,
|
|
409
522
|
seed,
|
|
410
523
|
providerOptions: {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
imageConfig: aspectRatio ? {
|
|
414
|
-
aspectRatio
|
|
415
|
-
} : void 0,
|
|
416
|
-
...(_c = providerOptions == null ? void 0 : providerOptions.vertex) != null ? _c : {}
|
|
417
|
-
}
|
|
524
|
+
googleVertex: innerVertexOptions,
|
|
525
|
+
vertex: innerVertexOptions
|
|
418
526
|
},
|
|
419
527
|
headers,
|
|
420
528
|
abortSignal
|
|
@@ -422,17 +530,19 @@ var GoogleVertexImageModel = class {
|
|
|
422
530
|
const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
|
|
423
531
|
const images = [];
|
|
424
532
|
for (const part of result.content) {
|
|
425
|
-
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
426
|
-
images.push(
|
|
533
|
+
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
534
|
+
images.push(convertToBase64(part.data.data));
|
|
427
535
|
}
|
|
428
536
|
}
|
|
537
|
+
const geminiPayload = {
|
|
538
|
+
images: images.map(() => ({}))
|
|
539
|
+
};
|
|
429
540
|
return {
|
|
430
541
|
images,
|
|
431
542
|
warnings,
|
|
432
543
|
providerMetadata: {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
544
|
+
googleVertex: geminiPayload,
|
|
545
|
+
vertex: geminiPayload
|
|
436
546
|
},
|
|
437
547
|
response: {
|
|
438
548
|
timestamp: currentDate,
|
|
@@ -450,71 +560,15 @@ var GoogleVertexImageModel = class {
|
|
|
450
560
|
function isGeminiModel(modelId) {
|
|
451
561
|
return modelId.startsWith("gemini-");
|
|
452
562
|
}
|
|
453
|
-
var
|
|
454
|
-
predictions:
|
|
455
|
-
|
|
456
|
-
bytesBase64Encoded:
|
|
457
|
-
mimeType:
|
|
458
|
-
prompt:
|
|
563
|
+
var googleVertexImageResponseSchema = z5.object({
|
|
564
|
+
predictions: z5.array(
|
|
565
|
+
z5.object({
|
|
566
|
+
bytesBase64Encoded: z5.string(),
|
|
567
|
+
mimeType: z5.string(),
|
|
568
|
+
prompt: z5.string().nullish()
|
|
459
569
|
})
|
|
460
570
|
).nullish()
|
|
461
571
|
});
|
|
462
|
-
var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
463
|
-
negativePrompt: import_v44.z.string().nullish(),
|
|
464
|
-
personGeneration: import_v44.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
465
|
-
safetySetting: import_v44.z.enum([
|
|
466
|
-
"block_low_and_above",
|
|
467
|
-
"block_medium_and_above",
|
|
468
|
-
"block_only_high",
|
|
469
|
-
"block_none"
|
|
470
|
-
]).nullish(),
|
|
471
|
-
addWatermark: import_v44.z.boolean().nullish(),
|
|
472
|
-
storageUri: import_v44.z.string().nullish(),
|
|
473
|
-
sampleImageSize: import_v44.z.enum(["1K", "2K"]).nullish(),
|
|
474
|
-
/**
|
|
475
|
-
* Configuration for image editing operations
|
|
476
|
-
*/
|
|
477
|
-
edit: import_v44.z.object({
|
|
478
|
-
/**
|
|
479
|
-
* An integer that represents the number of sampling steps.
|
|
480
|
-
* A higher value offers better image quality, a lower value offers better latency.
|
|
481
|
-
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
482
|
-
* increase the value towards an upper limit of 75.
|
|
483
|
-
*/
|
|
484
|
-
baseSteps: import_v44.z.number().nullish(),
|
|
485
|
-
// Edit mode options
|
|
486
|
-
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
487
|
-
mode: import_v44.z.enum([
|
|
488
|
-
"EDIT_MODE_INPAINT_INSERTION",
|
|
489
|
-
"EDIT_MODE_INPAINT_REMOVAL",
|
|
490
|
-
"EDIT_MODE_OUTPAINT",
|
|
491
|
-
"EDIT_MODE_CONTROLLED_EDITING",
|
|
492
|
-
"EDIT_MODE_PRODUCT_IMAGE",
|
|
493
|
-
"EDIT_MODE_BGSWAP"
|
|
494
|
-
]).nullish(),
|
|
495
|
-
/**
|
|
496
|
-
* The mask mode to use.
|
|
497
|
-
* - `MASK_MODE_DEFAULT` - Default value for mask mode.
|
|
498
|
-
* - `MASK_MODE_USER_PROVIDED` - User provided mask. No segmentation needed.
|
|
499
|
-
* - `MASK_MODE_DETECTION_BOX` - Mask from detected bounding boxes.
|
|
500
|
-
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
501
|
-
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
502
|
-
*/
|
|
503
|
-
maskMode: import_v44.z.enum([
|
|
504
|
-
"MASK_MODE_DEFAULT",
|
|
505
|
-
"MASK_MODE_USER_PROVIDED",
|
|
506
|
-
"MASK_MODE_DETECTION_BOX",
|
|
507
|
-
"MASK_MODE_CLOTHING_AREA",
|
|
508
|
-
"MASK_MODE_PARSED_PERSON"
|
|
509
|
-
]).nullish(),
|
|
510
|
-
/**
|
|
511
|
-
* Optional. A float value between 0 and 1, inclusive, that represents the
|
|
512
|
-
* percentage of the image width to grow the mask by. Using dilation helps
|
|
513
|
-
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
514
|
-
*/
|
|
515
|
-
maskDilation: import_v44.z.number().nullish()
|
|
516
|
-
}).nullish()
|
|
517
|
-
});
|
|
518
572
|
function getBase64Data(file) {
|
|
519
573
|
if (file.type === "url") {
|
|
520
574
|
throw new Error(
|
|
@@ -524,30 +578,255 @@ function getBase64Data(file) {
|
|
|
524
578
|
if (typeof file.data === "string") {
|
|
525
579
|
return file.data;
|
|
526
580
|
}
|
|
527
|
-
return
|
|
581
|
+
return convertUint8ArrayToBase64(file.data);
|
|
528
582
|
}
|
|
529
583
|
|
|
530
584
|
// src/google-vertex-tools.ts
|
|
531
|
-
|
|
585
|
+
import { googleTools } from "@ai-sdk/google/internal";
|
|
532
586
|
var googleVertexTools = {
|
|
533
|
-
googleSearch:
|
|
534
|
-
enterpriseWebSearch:
|
|
535
|
-
googleMaps:
|
|
536
|
-
urlContext:
|
|
537
|
-
fileSearch:
|
|
538
|
-
codeExecution:
|
|
539
|
-
vertexRagStore:
|
|
587
|
+
googleSearch: googleTools.googleSearch,
|
|
588
|
+
enterpriseWebSearch: googleTools.enterpriseWebSearch,
|
|
589
|
+
googleMaps: googleTools.googleMaps,
|
|
590
|
+
urlContext: googleTools.urlContext,
|
|
591
|
+
fileSearch: googleTools.fileSearch,
|
|
592
|
+
codeExecution: googleTools.codeExecution,
|
|
593
|
+
vertexRagStore: googleTools.vertexRagStore
|
|
540
594
|
};
|
|
541
595
|
|
|
596
|
+
// src/google-vertex-transcription-model.ts
|
|
597
|
+
import {
|
|
598
|
+
combineHeaders as combineHeaders3,
|
|
599
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
600
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
601
|
+
parseProviderOptions as parseProviderOptions3,
|
|
602
|
+
postJsonToApi as postJsonToApi3,
|
|
603
|
+
resolve as resolve3,
|
|
604
|
+
serializeModelOptions as serializeModelOptions3,
|
|
605
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
606
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
607
|
+
} from "@ai-sdk/provider-utils";
|
|
608
|
+
import { z as z7 } from "zod/v4";
|
|
609
|
+
|
|
610
|
+
// src/google-vertex-transcription-model-options.ts
|
|
611
|
+
import { z as z6 } from "zod/v4";
|
|
612
|
+
var googleVertexTranscriptionProviderOptionsSchema = z6.object({
|
|
613
|
+
/**
|
|
614
|
+
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
615
|
+
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
616
|
+
* `telephony`, pass a supported explicit language code.
|
|
617
|
+
*/
|
|
618
|
+
languageCodes: z6.array(z6.string()).optional(),
|
|
619
|
+
/**
|
|
620
|
+
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
621
|
+
*/
|
|
622
|
+
enableAutomaticPunctuation: z6.boolean().optional(),
|
|
623
|
+
/**
|
|
624
|
+
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
625
|
+
* transcription result can include segments.
|
|
626
|
+
*
|
|
627
|
+
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
628
|
+
* for Chirp models.
|
|
629
|
+
*/
|
|
630
|
+
enableWordTimeOffsets: z6.boolean().optional(),
|
|
631
|
+
/**
|
|
632
|
+
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
633
|
+
* `'us-central1'`). Defaults to the provider `location`.
|
|
634
|
+
*
|
|
635
|
+
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
636
|
+
* available in specific Speech-to-Text regions and is not available in the
|
|
637
|
+
* `global` location.
|
|
638
|
+
*/
|
|
639
|
+
region: z6.string().optional()
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
// src/google-vertex-transcription-model.ts
|
|
643
|
+
function parseDurationSeconds(value) {
|
|
644
|
+
if (value == null) {
|
|
645
|
+
return void 0;
|
|
646
|
+
}
|
|
647
|
+
const seconds = Number.parseFloat(value);
|
|
648
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
649
|
+
}
|
|
650
|
+
function convertBcp47ToIso6391(value) {
|
|
651
|
+
if (value == null) {
|
|
652
|
+
return void 0;
|
|
653
|
+
}
|
|
654
|
+
try {
|
|
655
|
+
const language = new Intl.Locale(value).language;
|
|
656
|
+
return language.length === 2 ? language : void 0;
|
|
657
|
+
} catch (e) {
|
|
658
|
+
return void 0;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
662
|
+
constructor(modelId, config) {
|
|
663
|
+
this.modelId = modelId;
|
|
664
|
+
this.config = config;
|
|
665
|
+
this.specificationVersion = "v4";
|
|
666
|
+
}
|
|
667
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
668
|
+
return serializeModelOptions3({
|
|
669
|
+
modelId: model.modelId,
|
|
670
|
+
config: model.config
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
674
|
+
return new _GoogleVertexTranscriptionModel(options.modelId, options.config);
|
|
675
|
+
}
|
|
676
|
+
get provider() {
|
|
677
|
+
return this.config.provider;
|
|
678
|
+
}
|
|
679
|
+
async doGenerate(options) {
|
|
680
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
681
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
682
|
+
const warnings = [];
|
|
683
|
+
let googleOptions;
|
|
684
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
685
|
+
googleOptions = await parseProviderOptions3({
|
|
686
|
+
provider,
|
|
687
|
+
providerOptions: options.providerOptions,
|
|
688
|
+
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
689
|
+
});
|
|
690
|
+
if (googleOptions != null) {
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
695
|
+
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
696
|
+
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase642(options.audio);
|
|
697
|
+
const requestBody = {
|
|
698
|
+
config: {
|
|
699
|
+
model: this.modelId,
|
|
700
|
+
languageCodes,
|
|
701
|
+
// Let Speech-to-Text auto-detect the audio encoding (wav/mp3/flac/…).
|
|
702
|
+
autoDecodingConfig: {},
|
|
703
|
+
features: {
|
|
704
|
+
// Word timing populates `segments`.
|
|
705
|
+
enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
|
|
706
|
+
enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
content
|
|
710
|
+
};
|
|
711
|
+
const host = region === "global" ? "speech.googleapis.com" : `${region}-speech.googleapis.com`;
|
|
712
|
+
const url = `https://${host}/v2/projects/${this.config.project}/locations/${region}/recognizers/_:recognize`;
|
|
713
|
+
const {
|
|
714
|
+
value: response,
|
|
715
|
+
responseHeaders,
|
|
716
|
+
rawValue: rawResponse
|
|
717
|
+
} = await postJsonToApi3({
|
|
718
|
+
url,
|
|
719
|
+
headers: combineHeaders3(
|
|
720
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
721
|
+
options.headers
|
|
722
|
+
),
|
|
723
|
+
body: requestBody,
|
|
724
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
725
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
726
|
+
googleVertexTranscriptionResponseSchema
|
|
727
|
+
),
|
|
728
|
+
abortSignal: options.abortSignal,
|
|
729
|
+
fetch: this.config.fetch
|
|
730
|
+
});
|
|
731
|
+
const results = (_h = response.results) != null ? _h : [];
|
|
732
|
+
const text = results.map((result) => {
|
|
733
|
+
var _a2, _b2, _c2;
|
|
734
|
+
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
735
|
+
}).join(" ").trim();
|
|
736
|
+
const segments = results.flatMap(
|
|
737
|
+
(result) => {
|
|
738
|
+
var _a2, _b2, _c2, _d2;
|
|
739
|
+
return (_d2 = (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.words) == null ? void 0 : _c2.flatMap((word) => {
|
|
740
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
741
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
742
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
743
|
+
})) != null ? _d2 : [];
|
|
744
|
+
}
|
|
745
|
+
);
|
|
746
|
+
const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
|
|
747
|
+
return {
|
|
748
|
+
text,
|
|
749
|
+
segments,
|
|
750
|
+
language,
|
|
751
|
+
durationInSeconds: parseDurationSeconds(
|
|
752
|
+
(_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
|
|
753
|
+
),
|
|
754
|
+
warnings,
|
|
755
|
+
response: {
|
|
756
|
+
timestamp: currentDate,
|
|
757
|
+
modelId: this.modelId,
|
|
758
|
+
headers: responseHeaders,
|
|
759
|
+
body: rawResponse
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
var googleVertexTranscriptionResponseSchema = z7.object({
|
|
765
|
+
results: z7.array(
|
|
766
|
+
z7.object({
|
|
767
|
+
alternatives: z7.array(
|
|
768
|
+
z7.object({
|
|
769
|
+
transcript: z7.string().nullish(),
|
|
770
|
+
words: z7.array(
|
|
771
|
+
z7.object({
|
|
772
|
+
word: z7.string().nullish(),
|
|
773
|
+
startOffset: z7.string().nullish(),
|
|
774
|
+
endOffset: z7.string().nullish()
|
|
775
|
+
})
|
|
776
|
+
).nullish()
|
|
777
|
+
})
|
|
778
|
+
).nullish(),
|
|
779
|
+
languageCode: z7.string().nullish()
|
|
780
|
+
})
|
|
781
|
+
).nullish(),
|
|
782
|
+
metadata: z7.object({
|
|
783
|
+
totalBilledDuration: z7.string().nullish()
|
|
784
|
+
}).nullish()
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
// src/google-vertex-video-model.ts
|
|
788
|
+
import {
|
|
789
|
+
AISDKError
|
|
790
|
+
} from "@ai-sdk/provider";
|
|
791
|
+
import {
|
|
792
|
+
combineHeaders as combineHeaders4,
|
|
793
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
|
|
794
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
795
|
+
delay,
|
|
796
|
+
parseProviderOptions as parseProviderOptions4,
|
|
797
|
+
postJsonToApi as postJsonToApi4,
|
|
798
|
+
resolve as resolve4
|
|
799
|
+
} from "@ai-sdk/provider-utils";
|
|
800
|
+
import { z as z9 } from "zod/v4";
|
|
801
|
+
|
|
802
|
+
// src/google-vertex-video-model-options.ts
|
|
803
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
804
|
+
import { z as z8 } from "zod/v4";
|
|
805
|
+
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
806
|
+
() => zodSchema(
|
|
807
|
+
z8.object({
|
|
808
|
+
pollIntervalMs: z8.number().positive().nullish(),
|
|
809
|
+
pollTimeoutMs: z8.number().positive().nullish(),
|
|
810
|
+
personGeneration: z8.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
811
|
+
negativePrompt: z8.string().nullish(),
|
|
812
|
+
generateAudio: z8.boolean().nullish(),
|
|
813
|
+
gcsOutputDirectory: z8.string().nullish(),
|
|
814
|
+
referenceImages: z8.array(
|
|
815
|
+
z8.object({
|
|
816
|
+
bytesBase64Encoded: z8.string().nullish(),
|
|
817
|
+
gcsUri: z8.string().nullish()
|
|
818
|
+
})
|
|
819
|
+
).nullish()
|
|
820
|
+
}).passthrough()
|
|
821
|
+
)
|
|
822
|
+
);
|
|
823
|
+
|
|
542
824
|
// src/google-vertex-video-model.ts
|
|
543
|
-
var import_provider2 = require("@ai-sdk/provider");
|
|
544
|
-
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
545
|
-
var import_v45 = require("zod/v4");
|
|
546
825
|
var GoogleVertexVideoModel = class {
|
|
547
826
|
constructor(modelId, config) {
|
|
548
827
|
this.modelId = modelId;
|
|
549
828
|
this.config = config;
|
|
550
|
-
this.specificationVersion = "
|
|
829
|
+
this.specificationVersion = "v4";
|
|
551
830
|
}
|
|
552
831
|
get provider() {
|
|
553
832
|
return this.config.provider;
|
|
@@ -556,10 +835,14 @@ var GoogleVertexVideoModel = class {
|
|
|
556
835
|
return 4;
|
|
557
836
|
}
|
|
558
837
|
async doGenerate(options) {
|
|
559
|
-
var _a, _b, _c, _d, _e, _f;
|
|
838
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
560
839
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
561
840
|
const warnings = [];
|
|
562
|
-
const
|
|
841
|
+
const googleVertexOptions = (_d = await parseProviderOptions4({
|
|
842
|
+
provider: "googleVertex",
|
|
843
|
+
providerOptions: options.providerOptions,
|
|
844
|
+
schema: googleVertexVideoModelOptionsSchema
|
|
845
|
+
})) != null ? _d : await parseProviderOptions4({
|
|
563
846
|
provider: "vertex",
|
|
564
847
|
providerOptions: options.providerOptions,
|
|
565
848
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -577,15 +860,15 @@ var GoogleVertexVideoModel = class {
|
|
|
577
860
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
578
861
|
});
|
|
579
862
|
} else {
|
|
580
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (
|
|
863
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase643(options.image.data);
|
|
581
864
|
instance.image = {
|
|
582
865
|
bytesBase64Encoded: base64Data,
|
|
583
866
|
mimeType: options.image.mediaType
|
|
584
867
|
};
|
|
585
868
|
}
|
|
586
869
|
}
|
|
587
|
-
if ((
|
|
588
|
-
instance.referenceImages =
|
|
870
|
+
if ((googleVertexOptions == null ? void 0 : googleVertexOptions.referenceImages) != null) {
|
|
871
|
+
instance.referenceImages = googleVertexOptions.referenceImages;
|
|
589
872
|
}
|
|
590
873
|
const parameters = {
|
|
591
874
|
sampleCount: options.n
|
|
@@ -607,8 +890,8 @@ var GoogleVertexVideoModel = class {
|
|
|
607
890
|
if (options.seed) {
|
|
608
891
|
parameters.seed = options.seed;
|
|
609
892
|
}
|
|
610
|
-
if (
|
|
611
|
-
const opts =
|
|
893
|
+
if (googleVertexOptions != null) {
|
|
894
|
+
const opts = googleVertexOptions;
|
|
612
895
|
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
613
896
|
parameters.personGeneration = opts.personGeneration;
|
|
614
897
|
}
|
|
@@ -635,18 +918,18 @@ var GoogleVertexVideoModel = class {
|
|
|
635
918
|
}
|
|
636
919
|
}
|
|
637
920
|
}
|
|
638
|
-
const { value: operation } = await (
|
|
921
|
+
const { value: operation } = await postJsonToApi4({
|
|
639
922
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
640
|
-
headers: (
|
|
641
|
-
await (
|
|
923
|
+
headers: combineHeaders4(
|
|
924
|
+
await resolve4(this.config.headers),
|
|
642
925
|
options.headers
|
|
643
926
|
),
|
|
644
927
|
body: {
|
|
645
928
|
instances,
|
|
646
929
|
parameters
|
|
647
930
|
},
|
|
648
|
-
successfulResponseHandler: (
|
|
649
|
-
|
|
931
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
932
|
+
googleVertexOperationSchema
|
|
650
933
|
),
|
|
651
934
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
652
935
|
abortSignal: options.abortSignal,
|
|
@@ -654,41 +937,41 @@ var GoogleVertexVideoModel = class {
|
|
|
654
937
|
});
|
|
655
938
|
const operationName = operation.name;
|
|
656
939
|
if (!operationName) {
|
|
657
|
-
throw new
|
|
940
|
+
throw new AISDKError({
|
|
658
941
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
659
942
|
message: "No operation name returned from API"
|
|
660
943
|
});
|
|
661
944
|
}
|
|
662
|
-
const pollIntervalMs = (
|
|
663
|
-
const pollTimeoutMs = (
|
|
945
|
+
const pollIntervalMs = (_e = googleVertexOptions == null ? void 0 : googleVertexOptions.pollIntervalMs) != null ? _e : 1e4;
|
|
946
|
+
const pollTimeoutMs = (_f = googleVertexOptions == null ? void 0 : googleVertexOptions.pollTimeoutMs) != null ? _f : 6e5;
|
|
664
947
|
const startTime = Date.now();
|
|
665
948
|
let finalOperation = operation;
|
|
666
949
|
let responseHeaders;
|
|
667
950
|
while (!finalOperation.done) {
|
|
668
951
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
669
|
-
throw new
|
|
952
|
+
throw new AISDKError({
|
|
670
953
|
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
671
954
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
672
955
|
});
|
|
673
956
|
}
|
|
674
|
-
await
|
|
675
|
-
if ((
|
|
676
|
-
throw new
|
|
957
|
+
await delay(pollIntervalMs);
|
|
958
|
+
if ((_g = options.abortSignal) == null ? void 0 : _g.aborted) {
|
|
959
|
+
throw new AISDKError({
|
|
677
960
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
678
961
|
message: "Video generation request was aborted"
|
|
679
962
|
});
|
|
680
963
|
}
|
|
681
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (
|
|
964
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi4({
|
|
682
965
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
683
|
-
headers: (
|
|
684
|
-
await (
|
|
966
|
+
headers: combineHeaders4(
|
|
967
|
+
await resolve4(this.config.headers),
|
|
685
968
|
options.headers
|
|
686
969
|
),
|
|
687
970
|
body: {
|
|
688
971
|
operationName
|
|
689
972
|
},
|
|
690
|
-
successfulResponseHandler: (
|
|
691
|
-
|
|
973
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
974
|
+
googleVertexOperationSchema
|
|
692
975
|
),
|
|
693
976
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
694
977
|
abortSignal: options.abortSignal,
|
|
@@ -698,14 +981,14 @@ var GoogleVertexVideoModel = class {
|
|
|
698
981
|
responseHeaders = pollHeaders;
|
|
699
982
|
}
|
|
700
983
|
if (finalOperation.error) {
|
|
701
|
-
throw new
|
|
984
|
+
throw new AISDKError({
|
|
702
985
|
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
703
986
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
704
987
|
});
|
|
705
988
|
}
|
|
706
989
|
const response = finalOperation.response;
|
|
707
990
|
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
708
|
-
throw new
|
|
991
|
+
throw new AISDKError({
|
|
709
992
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
710
993
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
711
994
|
});
|
|
@@ -735,7 +1018,7 @@ var GoogleVertexVideoModel = class {
|
|
|
735
1018
|
}
|
|
736
1019
|
}
|
|
737
1020
|
if (videos.length === 0) {
|
|
738
|
-
throw new
|
|
1021
|
+
throw new AISDKError({
|
|
739
1022
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
740
1023
|
message: "No valid videos in response"
|
|
741
1024
|
});
|
|
@@ -748,78 +1031,64 @@ var GoogleVertexVideoModel = class {
|
|
|
748
1031
|
modelId: this.modelId,
|
|
749
1032
|
headers: responseHeaders
|
|
750
1033
|
},
|
|
751
|
-
providerMetadata: {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
1034
|
+
providerMetadata: /* @__PURE__ */ (() => {
|
|
1035
|
+
const payload = { videos: videoMetadata };
|
|
1036
|
+
return {
|
|
1037
|
+
googleVertex: payload,
|
|
1038
|
+
// Legacy keys preserved for backward compatibility.
|
|
1039
|
+
"google-vertex": payload,
|
|
1040
|
+
vertex: payload
|
|
1041
|
+
};
|
|
1042
|
+
})()
|
|
756
1043
|
};
|
|
757
1044
|
}
|
|
758
1045
|
};
|
|
759
|
-
var
|
|
760
|
-
name:
|
|
761
|
-
done:
|
|
762
|
-
error:
|
|
763
|
-
code:
|
|
764
|
-
message:
|
|
765
|
-
status:
|
|
1046
|
+
var googleVertexOperationSchema = z9.object({
|
|
1047
|
+
name: z9.string().nullish(),
|
|
1048
|
+
done: z9.boolean().nullish(),
|
|
1049
|
+
error: z9.object({
|
|
1050
|
+
code: z9.number().nullish(),
|
|
1051
|
+
message: z9.string(),
|
|
1052
|
+
status: z9.string().nullish()
|
|
766
1053
|
}).nullish(),
|
|
767
|
-
response:
|
|
768
|
-
videos:
|
|
769
|
-
|
|
770
|
-
bytesBase64Encoded:
|
|
771
|
-
gcsUri:
|
|
772
|
-
mimeType:
|
|
1054
|
+
response: z9.object({
|
|
1055
|
+
videos: z9.array(
|
|
1056
|
+
z9.object({
|
|
1057
|
+
bytesBase64Encoded: z9.string().nullish(),
|
|
1058
|
+
gcsUri: z9.string().nullish(),
|
|
1059
|
+
mimeType: z9.string().nullish()
|
|
773
1060
|
})
|
|
774
1061
|
).nullish(),
|
|
775
|
-
raiMediaFilteredCount:
|
|
1062
|
+
raiMediaFilteredCount: z9.number().nullish()
|
|
776
1063
|
}).nullish()
|
|
777
1064
|
});
|
|
778
|
-
var googleVertexVideoModelOptionsSchema = (0, import_provider_utils4.lazySchema)(
|
|
779
|
-
() => (0, import_provider_utils4.zodSchema)(
|
|
780
|
-
import_v45.z.object({
|
|
781
|
-
pollIntervalMs: import_v45.z.number().positive().nullish(),
|
|
782
|
-
pollTimeoutMs: import_v45.z.number().positive().nullish(),
|
|
783
|
-
personGeneration: import_v45.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
784
|
-
negativePrompt: import_v45.z.string().nullish(),
|
|
785
|
-
generateAudio: import_v45.z.boolean().nullish(),
|
|
786
|
-
gcsOutputDirectory: import_v45.z.string().nullish(),
|
|
787
|
-
referenceImages: import_v45.z.array(
|
|
788
|
-
import_v45.z.object({
|
|
789
|
-
bytesBase64Encoded: import_v45.z.string().nullish(),
|
|
790
|
-
gcsUri: import_v45.z.string().nullish()
|
|
791
|
-
})
|
|
792
|
-
).nullish()
|
|
793
|
-
}).passthrough()
|
|
794
|
-
)
|
|
795
|
-
);
|
|
796
1065
|
|
|
797
|
-
// src/google-vertex-provider.ts
|
|
1066
|
+
// src/google-vertex-provider-base.ts
|
|
798
1067
|
var EXPRESS_MODE_BASE_URL = "https://aiplatform.googleapis.com/v1/publishers/google";
|
|
799
1068
|
function createExpressModeFetch(apiKey, customFetch) {
|
|
800
1069
|
return async (url, init) => {
|
|
801
1070
|
const modifiedInit = {
|
|
802
1071
|
...init,
|
|
803
1072
|
headers: {
|
|
804
|
-
...(init == null ? void 0 : init.headers) ?
|
|
1073
|
+
...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
|
|
805
1074
|
"x-goog-api-key": apiKey
|
|
806
1075
|
}
|
|
807
1076
|
};
|
|
808
1077
|
return (customFetch != null ? customFetch : fetch)(url.toString(), modifiedInit);
|
|
809
1078
|
};
|
|
810
1079
|
}
|
|
811
|
-
function
|
|
812
|
-
const apiKey =
|
|
1080
|
+
function createGoogleVertex(options = {}) {
|
|
1081
|
+
const apiKey = loadOptionalSetting({
|
|
813
1082
|
settingValue: options.apiKey,
|
|
814
1083
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
815
1084
|
});
|
|
816
|
-
const
|
|
1085
|
+
const loadGoogleVertexProject = () => loadSetting({
|
|
817
1086
|
settingValue: options.project,
|
|
818
1087
|
settingName: "project",
|
|
819
1088
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
820
1089
|
description: "Google Vertex project"
|
|
821
1090
|
});
|
|
822
|
-
const
|
|
1091
|
+
const loadGoogleVertexLocation = () => loadSetting({
|
|
823
1092
|
settingValue: options.location,
|
|
824
1093
|
settingName: "location",
|
|
825
1094
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -828,18 +1097,26 @@ function createVertex(options = {}) {
|
|
|
828
1097
|
const loadBaseURL = () => {
|
|
829
1098
|
var _a, _b;
|
|
830
1099
|
if (apiKey) {
|
|
831
|
-
return (_a =
|
|
1100
|
+
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
832
1101
|
}
|
|
833
|
-
const region =
|
|
834
|
-
const project =
|
|
835
|
-
const
|
|
836
|
-
|
|
1102
|
+
const region = loadGoogleVertexLocation();
|
|
1103
|
+
const project = loadGoogleVertexProject();
|
|
1104
|
+
const getHost = () => {
|
|
1105
|
+
if (region === "global") {
|
|
1106
|
+
return "aiplatform.googleapis.com";
|
|
1107
|
+
} else if (region === "eu" || region === "us") {
|
|
1108
|
+
return `aiplatform.${region}.rep.googleapis.com`;
|
|
1109
|
+
} else {
|
|
1110
|
+
return `${region}-aiplatform.googleapis.com`;
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${getHost()}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
837
1114
|
};
|
|
838
1115
|
const createConfig = (name) => {
|
|
839
1116
|
const getHeaders = async () => {
|
|
840
1117
|
var _a;
|
|
841
|
-
const originalHeaders = await (
|
|
842
|
-
return
|
|
1118
|
+
const originalHeaders = await resolve5((_a = options.headers) != null ? _a : {});
|
|
1119
|
+
return withUserAgentSuffix(
|
|
843
1120
|
originalHeaders,
|
|
844
1121
|
`ai-sdk/google-vertex/${VERSION}`
|
|
845
1122
|
);
|
|
@@ -853,9 +1130,9 @@ function createVertex(options = {}) {
|
|
|
853
1130
|
};
|
|
854
1131
|
const createChatModel = (modelId) => {
|
|
855
1132
|
var _a;
|
|
856
|
-
return new
|
|
1133
|
+
return new GoogleLanguageModel2(modelId, {
|
|
857
1134
|
...createConfig("chat"),
|
|
858
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1135
|
+
generateId: (_a = options.generateId) != null ? _a : generateId,
|
|
859
1136
|
supportedUrls: () => ({
|
|
860
1137
|
"*": [
|
|
861
1138
|
// HTTP URLs:
|
|
@@ -871,14 +1148,30 @@ function createVertex(options = {}) {
|
|
|
871
1148
|
var _a;
|
|
872
1149
|
return new GoogleVertexImageModel(modelId, {
|
|
873
1150
|
...createConfig("image"),
|
|
874
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1151
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
875
1152
|
});
|
|
876
1153
|
};
|
|
877
1154
|
const createVideoModel = (modelId) => {
|
|
878
1155
|
var _a;
|
|
879
1156
|
return new GoogleVertexVideoModel(modelId, {
|
|
880
1157
|
...createConfig("video"),
|
|
881
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1158
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
1159
|
+
});
|
|
1160
|
+
};
|
|
1161
|
+
const createSpeechModel = (modelId) => new GoogleSpeechModel(modelId, createConfig("speech"));
|
|
1162
|
+
const createTranscriptionModel = (modelId) => {
|
|
1163
|
+
if (apiKey) {
|
|
1164
|
+
throw new Error(
|
|
1165
|
+
"Google Vertex transcription models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
const config = createConfig("transcription");
|
|
1169
|
+
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1170
|
+
provider: config.provider,
|
|
1171
|
+
headers: config.headers,
|
|
1172
|
+
fetch: config.fetch,
|
|
1173
|
+
project: loadGoogleVertexProject(),
|
|
1174
|
+
location: loadGoogleVertexLocation()
|
|
882
1175
|
});
|
|
883
1176
|
};
|
|
884
1177
|
const provider = function(modelId) {
|
|
@@ -889,7 +1182,7 @@ function createVertex(options = {}) {
|
|
|
889
1182
|
}
|
|
890
1183
|
return createChatModel(modelId);
|
|
891
1184
|
};
|
|
892
|
-
provider.specificationVersion = "
|
|
1185
|
+
provider.specificationVersion = "v4";
|
|
893
1186
|
provider.languageModel = createChatModel;
|
|
894
1187
|
provider.embeddingModel = createEmbeddingModel;
|
|
895
1188
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
@@ -897,28 +1190,37 @@ function createVertex(options = {}) {
|
|
|
897
1190
|
provider.imageModel = createImageModel;
|
|
898
1191
|
provider.video = createVideoModel;
|
|
899
1192
|
provider.videoModel = createVideoModel;
|
|
1193
|
+
provider.speech = createSpeechModel;
|
|
1194
|
+
provider.speechModel = createSpeechModel;
|
|
1195
|
+
provider.transcription = createTranscriptionModel;
|
|
1196
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
900
1197
|
provider.tools = googleVertexTools;
|
|
901
1198
|
return provider;
|
|
902
1199
|
}
|
|
903
1200
|
|
|
904
1201
|
// src/edge/google-vertex-auth-edge.ts
|
|
905
|
-
|
|
1202
|
+
import {
|
|
1203
|
+
loadOptionalSetting as loadOptionalSetting2,
|
|
1204
|
+
loadSetting as loadSetting2,
|
|
1205
|
+
withUserAgentSuffix as withUserAgentSuffix2,
|
|
1206
|
+
getRuntimeEnvironmentUserAgent
|
|
1207
|
+
} from "@ai-sdk/provider-utils";
|
|
906
1208
|
var loadCredentials = async () => {
|
|
907
1209
|
try {
|
|
908
1210
|
return {
|
|
909
|
-
clientEmail: (
|
|
1211
|
+
clientEmail: loadSetting2({
|
|
910
1212
|
settingValue: void 0,
|
|
911
1213
|
settingName: "clientEmail",
|
|
912
1214
|
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
913
1215
|
description: "Google client email"
|
|
914
1216
|
}),
|
|
915
|
-
privateKey: (
|
|
1217
|
+
privateKey: loadSetting2({
|
|
916
1218
|
settingValue: void 0,
|
|
917
1219
|
settingName: "privateKey",
|
|
918
1220
|
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
919
1221
|
description: "Google private key"
|
|
920
1222
|
}),
|
|
921
|
-
privateKeyId: (
|
|
1223
|
+
privateKeyId: loadOptionalSetting2({
|
|
922
1224
|
settingValue: void 0,
|
|
923
1225
|
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
924
1226
|
})
|
|
@@ -987,10 +1289,10 @@ async function generateAuthToken(credentials) {
|
|
|
987
1289
|
const jwt = await buildJwt(creds);
|
|
988
1290
|
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
989
1291
|
method: "POST",
|
|
990
|
-
headers: (
|
|
1292
|
+
headers: withUserAgentSuffix2(
|
|
991
1293
|
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
992
1294
|
`ai-sdk/google-vertex/${VERSION}`,
|
|
993
|
-
|
|
1295
|
+
getRuntimeEnvironmentUserAgent()
|
|
994
1296
|
),
|
|
995
1297
|
body: new URLSearchParams({
|
|
996
1298
|
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
@@ -1008,28 +1310,29 @@ async function generateAuthToken(credentials) {
|
|
|
1008
1310
|
}
|
|
1009
1311
|
|
|
1010
1312
|
// src/edge/google-vertex-provider-edge.ts
|
|
1011
|
-
function
|
|
1012
|
-
const apiKey = (
|
|
1313
|
+
function createGoogleVertex2(options = {}) {
|
|
1314
|
+
const apiKey = loadOptionalSetting3({
|
|
1013
1315
|
settingValue: options.apiKey,
|
|
1014
1316
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
1015
1317
|
});
|
|
1016
1318
|
if (apiKey) {
|
|
1017
|
-
return
|
|
1319
|
+
return createGoogleVertex(options);
|
|
1018
1320
|
}
|
|
1019
|
-
return
|
|
1321
|
+
return createGoogleVertex({
|
|
1020
1322
|
...options,
|
|
1021
1323
|
headers: async () => ({
|
|
1022
1324
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1023
1325
|
options.googleCredentials
|
|
1024
1326
|
)}`,
|
|
1025
|
-
...await (
|
|
1327
|
+
...await resolve6(options.headers)
|
|
1026
1328
|
})
|
|
1027
1329
|
});
|
|
1028
1330
|
}
|
|
1029
|
-
var
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
createVertex,
|
|
1033
|
-
|
|
1034
|
-
|
|
1331
|
+
var googleVertex = createGoogleVertex2();
|
|
1332
|
+
export {
|
|
1333
|
+
createGoogleVertex2 as createGoogleVertex,
|
|
1334
|
+
createGoogleVertex2 as createVertex,
|
|
1335
|
+
googleVertex,
|
|
1336
|
+
googleVertex as vertex
|
|
1337
|
+
};
|
|
1035
1338
|
//# sourceMappingURL=index.js.map
|