@ai-sdk/google-vertex 5.0.0-beta.11 → 5.0.0-beta.112
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 +954 -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 +49 -20
- package/dist/edge/index.js +629 -278
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +61 -23
- package/dist/index.js +638 -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 +90 -7
- package/src/google-vertex-image-model-options.ts +74 -0
- package/src/google-vertex-image-model.ts +89 -116
- 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 +38 -71
- 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.112" : "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,39 +87,60 @@ 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
101
|
this.specificationVersion = "v4";
|
|
107
|
-
this.maxEmbeddingsPerCall = 2048;
|
|
108
102
|
this.supportsParallelCalls = true;
|
|
109
103
|
this.modelId = modelId;
|
|
110
104
|
this.config = config;
|
|
111
105
|
}
|
|
106
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
107
|
+
return serializeModelOptions({
|
|
108
|
+
modelId: model.modelId,
|
|
109
|
+
config: model.config
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
113
|
+
return new _GoogleVertexEmbeddingModel(options.modelId, options.config);
|
|
114
|
+
}
|
|
112
115
|
get provider() {
|
|
113
116
|
return this.config.provider;
|
|
114
117
|
}
|
|
118
|
+
// gemini-embedding-2 models only support :embedContent (one value per call),
|
|
119
|
+
// not the :predict batch endpoint. https://github.com/vercel/ai/issues/15853
|
|
120
|
+
get maxEmbeddingsPerCall() {
|
|
121
|
+
return usesEmbedContentEndpoint(this.modelId) ? 1 : 2048;
|
|
122
|
+
}
|
|
115
123
|
async doEmbed({
|
|
116
124
|
values,
|
|
117
125
|
headers,
|
|
118
126
|
abortSignal,
|
|
119
127
|
providerOptions
|
|
120
128
|
}) {
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
var _a;
|
|
130
|
+
let googleOptions = await parseProviderOptions({
|
|
131
|
+
provider: "googleVertex",
|
|
123
132
|
providerOptions,
|
|
124
133
|
schema: googleVertexEmbeddingModelOptions
|
|
125
134
|
});
|
|
126
135
|
if (googleOptions == null) {
|
|
127
|
-
googleOptions = await
|
|
136
|
+
googleOptions = await parseProviderOptions({
|
|
137
|
+
provider: "vertex",
|
|
138
|
+
providerOptions,
|
|
139
|
+
schema: googleVertexEmbeddingModelOptions
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (googleOptions == null) {
|
|
143
|
+
googleOptions = await parseProviderOptions({
|
|
128
144
|
provider: "google",
|
|
129
145
|
providerOptions,
|
|
130
146
|
schema: googleVertexEmbeddingModelOptions
|
|
@@ -132,23 +148,54 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
132
148
|
}
|
|
133
149
|
googleOptions = googleOptions != null ? googleOptions : {};
|
|
134
150
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
135
|
-
throw new
|
|
151
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
136
152
|
provider: this.provider,
|
|
137
153
|
modelId: this.modelId,
|
|
138
154
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
139
155
|
values
|
|
140
156
|
});
|
|
141
157
|
}
|
|
142
|
-
const mergedHeaders =
|
|
143
|
-
await
|
|
158
|
+
const mergedHeaders = combineHeaders(
|
|
159
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
144
160
|
headers
|
|
145
161
|
);
|
|
162
|
+
if (usesEmbedContentEndpoint(this.modelId)) {
|
|
163
|
+
const {
|
|
164
|
+
responseHeaders: responseHeaders2,
|
|
165
|
+
value: response2,
|
|
166
|
+
rawValue: rawValue2
|
|
167
|
+
} = await postJsonToApi({
|
|
168
|
+
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
|
169
|
+
headers: mergedHeaders,
|
|
170
|
+
body: {
|
|
171
|
+
content: { parts: [{ text: values[0] }] },
|
|
172
|
+
embedContentConfig: {
|
|
173
|
+
outputDimensionality: googleOptions.outputDimensionality,
|
|
174
|
+
taskType: googleOptions.taskType,
|
|
175
|
+
title: googleOptions.title,
|
|
176
|
+
autoTruncate: googleOptions.autoTruncate
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
180
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
181
|
+
googleVertexEmbedContentResponseSchema
|
|
182
|
+
),
|
|
183
|
+
abortSignal,
|
|
184
|
+
fetch: this.config.fetch
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
warnings: [],
|
|
188
|
+
embeddings: [response2.embedding.values],
|
|
189
|
+
usage: ((_a = response2.usageMetadata) == null ? void 0 : _a.promptTokenCount) == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
|
|
190
|
+
response: { headers: responseHeaders2, body: rawValue2 }
|
|
191
|
+
};
|
|
192
|
+
}
|
|
146
193
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
147
194
|
const {
|
|
148
195
|
responseHeaders,
|
|
149
196
|
value: response,
|
|
150
197
|
rawValue
|
|
151
|
-
} = await
|
|
198
|
+
} = await postJsonToApi({
|
|
152
199
|
url,
|
|
153
200
|
headers: mergedHeaders,
|
|
154
201
|
body: {
|
|
@@ -163,7 +210,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
163
210
|
}
|
|
164
211
|
},
|
|
165
212
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
166
|
-
successfulResponseHandler:
|
|
213
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
167
214
|
googleVertexTextEmbeddingResponseSchema
|
|
168
215
|
),
|
|
169
216
|
abortSignal,
|
|
@@ -184,29 +231,122 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
184
231
|
};
|
|
185
232
|
}
|
|
186
233
|
};
|
|
187
|
-
var googleVertexTextEmbeddingResponseSchema =
|
|
188
|
-
predictions:
|
|
189
|
-
|
|
190
|
-
embeddings:
|
|
191
|
-
values:
|
|
192
|
-
statistics:
|
|
193
|
-
token_count:
|
|
234
|
+
var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
235
|
+
predictions: z3.array(
|
|
236
|
+
z3.object({
|
|
237
|
+
embeddings: z3.object({
|
|
238
|
+
values: z3.array(z3.number()),
|
|
239
|
+
statistics: z3.object({
|
|
240
|
+
token_count: z3.number()
|
|
194
241
|
})
|
|
195
242
|
})
|
|
196
243
|
})
|
|
197
244
|
)
|
|
198
245
|
});
|
|
246
|
+
var googleVertexEmbedContentResponseSchema = z3.object({
|
|
247
|
+
embedding: z3.object({
|
|
248
|
+
values: z3.array(z3.number())
|
|
249
|
+
}),
|
|
250
|
+
usageMetadata: z3.object({
|
|
251
|
+
promptTokenCount: z3.number().nullish()
|
|
252
|
+
}).nullish()
|
|
253
|
+
});
|
|
254
|
+
function usesEmbedContentEndpoint(modelId) {
|
|
255
|
+
return modelId === "gemini-embedding-2" || modelId === "gemini-embedding-2-preview";
|
|
256
|
+
}
|
|
199
257
|
|
|
200
258
|
// src/google-vertex-image-model.ts
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
259
|
+
import { GoogleLanguageModel } from "@ai-sdk/google/internal";
|
|
260
|
+
import {
|
|
261
|
+
combineHeaders as combineHeaders2,
|
|
262
|
+
convertToBase64,
|
|
263
|
+
convertUint8ArrayToBase64,
|
|
264
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
265
|
+
generateId as defaultGenerateId,
|
|
266
|
+
parseProviderOptions as parseProviderOptions2,
|
|
267
|
+
postJsonToApi as postJsonToApi2,
|
|
268
|
+
resolve as resolve2,
|
|
269
|
+
serializeModelOptions as serializeModelOptions2,
|
|
270
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
271
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
272
|
+
} from "@ai-sdk/provider-utils";
|
|
273
|
+
import { z as z5 } from "zod/v4";
|
|
274
|
+
|
|
275
|
+
// src/google-vertex-image-model-options.ts
|
|
276
|
+
import { z as z4 } from "zod/v4";
|
|
277
|
+
var googleVertexImageModelOptionsSchema = z4.object({
|
|
278
|
+
negativePrompt: z4.string().nullish(),
|
|
279
|
+
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
280
|
+
safetySetting: z4.enum([
|
|
281
|
+
"block_low_and_above",
|
|
282
|
+
"block_medium_and_above",
|
|
283
|
+
"block_only_high",
|
|
284
|
+
"block_none"
|
|
285
|
+
]).nullish(),
|
|
286
|
+
addWatermark: z4.boolean().nullish(),
|
|
287
|
+
storageUri: z4.string().nullish(),
|
|
288
|
+
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
289
|
+
/**
|
|
290
|
+
* Configuration for image editing operations
|
|
291
|
+
*/
|
|
292
|
+
edit: z4.object({
|
|
293
|
+
/**
|
|
294
|
+
* An integer that represents the number of sampling steps.
|
|
295
|
+
* A higher value offers better image quality, a lower value offers better latency.
|
|
296
|
+
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
297
|
+
* increase the value towards an upper limit of 75.
|
|
298
|
+
*/
|
|
299
|
+
baseSteps: z4.number().nullish(),
|
|
300
|
+
// Edit mode options
|
|
301
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
302
|
+
mode: z4.enum([
|
|
303
|
+
"EDIT_MODE_INPAINT_INSERTION",
|
|
304
|
+
"EDIT_MODE_INPAINT_REMOVAL",
|
|
305
|
+
"EDIT_MODE_OUTPAINT",
|
|
306
|
+
"EDIT_MODE_CONTROLLED_EDITING",
|
|
307
|
+
"EDIT_MODE_PRODUCT_IMAGE",
|
|
308
|
+
"EDIT_MODE_BGSWAP"
|
|
309
|
+
]).nullish(),
|
|
310
|
+
/**
|
|
311
|
+
* The mask mode to use.
|
|
312
|
+
* - `MASK_MODE_DEFAULT` - Default value for mask mode.
|
|
313
|
+
* - `MASK_MODE_USER_PROVIDED` - User provided mask. No segmentation needed.
|
|
314
|
+
* - `MASK_MODE_DETECTION_BOX` - Mask from detected bounding boxes.
|
|
315
|
+
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
316
|
+
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
317
|
+
*/
|
|
318
|
+
maskMode: z4.enum([
|
|
319
|
+
"MASK_MODE_DEFAULT",
|
|
320
|
+
"MASK_MODE_USER_PROVIDED",
|
|
321
|
+
"MASK_MODE_DETECTION_BOX",
|
|
322
|
+
"MASK_MODE_CLOTHING_AREA",
|
|
323
|
+
"MASK_MODE_PARSED_PERSON"
|
|
324
|
+
]).nullish(),
|
|
325
|
+
/**
|
|
326
|
+
* Optional. A float value between 0 and 1, inclusive, that represents the
|
|
327
|
+
* percentage of the image width to grow the mask by. Using dilation helps
|
|
328
|
+
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
329
|
+
*/
|
|
330
|
+
maskDilation: z4.number().nullish()
|
|
331
|
+
}).nullish()
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// src/google-vertex-image-model.ts
|
|
335
|
+
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
205
336
|
constructor(modelId, config) {
|
|
206
337
|
this.modelId = modelId;
|
|
207
338
|
this.config = config;
|
|
208
339
|
this.specificationVersion = "v4";
|
|
209
340
|
}
|
|
341
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
342
|
+
return serializeModelOptions2({
|
|
343
|
+
modelId: model.modelId,
|
|
344
|
+
config: model.config
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
348
|
+
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
349
|
+
}
|
|
210
350
|
get maxImagesPerCall() {
|
|
211
351
|
if (isGeminiModel(this.modelId)) {
|
|
212
352
|
return 10;
|
|
@@ -234,7 +374,7 @@ var GoogleVertexImageModel = class {
|
|
|
234
374
|
files,
|
|
235
375
|
mask
|
|
236
376
|
}) {
|
|
237
|
-
var _a, _b, _c, _d, _e, _f
|
|
377
|
+
var _a, _b, _c, _d, _e, _f;
|
|
238
378
|
const warnings = [];
|
|
239
379
|
if (size != null) {
|
|
240
380
|
warnings.push({
|
|
@@ -243,12 +383,16 @@ var GoogleVertexImageModel = class {
|
|
|
243
383
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
244
384
|
});
|
|
245
385
|
}
|
|
246
|
-
const
|
|
386
|
+
const googleVertexImageOptions = (_a = await parseProviderOptions2({
|
|
387
|
+
provider: "googleVertex",
|
|
388
|
+
providerOptions,
|
|
389
|
+
schema: googleVertexImageModelOptionsSchema
|
|
390
|
+
})) != null ? _a : await parseProviderOptions2({
|
|
247
391
|
provider: "vertex",
|
|
248
392
|
providerOptions,
|
|
249
393
|
schema: googleVertexImageModelOptionsSchema
|
|
250
394
|
});
|
|
251
|
-
const { edit, ...otherOptions } =
|
|
395
|
+
const { edit, ...otherOptions } = googleVertexImageOptions != null ? googleVertexImageOptions : {};
|
|
252
396
|
const { mode: editMode, baseSteps, maskMode, maskDilation } = edit != null ? edit : {};
|
|
253
397
|
const isEditMode = files != null && files.length > 0;
|
|
254
398
|
let body;
|
|
@@ -304,39 +448,44 @@ var GoogleVertexImageModel = class {
|
|
|
304
448
|
}
|
|
305
449
|
};
|
|
306
450
|
}
|
|
307
|
-
const currentDate = (
|
|
308
|
-
const { value: response, responseHeaders } = await (
|
|
451
|
+
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
452
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
309
453
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
310
|
-
headers: (
|
|
454
|
+
headers: combineHeaders2(
|
|
455
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
456
|
+
headers
|
|
457
|
+
),
|
|
311
458
|
body,
|
|
312
459
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
313
|
-
successfulResponseHandler: (
|
|
314
|
-
|
|
460
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
461
|
+
googleVertexImageResponseSchema
|
|
315
462
|
),
|
|
316
463
|
abortSignal,
|
|
317
464
|
fetch: this.config.fetch
|
|
318
465
|
});
|
|
319
466
|
return {
|
|
320
|
-
images: (
|
|
467
|
+
images: (_f = (_e = response.predictions) == null ? void 0 : _e.map(
|
|
321
468
|
({ bytesBase64Encoded }) => bytesBase64Encoded
|
|
322
|
-
)) != null ?
|
|
469
|
+
)) != null ? _f : [],
|
|
323
470
|
warnings,
|
|
324
471
|
response: {
|
|
325
472
|
timestamp: currentDate,
|
|
326
473
|
modelId: this.modelId,
|
|
327
474
|
headers: responseHeaders
|
|
328
475
|
},
|
|
329
|
-
providerMetadata: {
|
|
330
|
-
|
|
331
|
-
|
|
476
|
+
providerMetadata: (() => {
|
|
477
|
+
var _a2, _b2;
|
|
478
|
+
const payload = {
|
|
479
|
+
images: (_b2 = (_a2 = response.predictions) == null ? void 0 : _a2.map((prediction) => {
|
|
332
480
|
const {
|
|
333
481
|
// normalize revised prompt property
|
|
334
482
|
prompt: revisedPrompt
|
|
335
483
|
} = prediction;
|
|
336
484
|
return { ...revisedPrompt != null && { revisedPrompt } };
|
|
337
|
-
})) != null ?
|
|
338
|
-
}
|
|
339
|
-
|
|
485
|
+
})) != null ? _b2 : []
|
|
486
|
+
};
|
|
487
|
+
return { googleVertex: payload, vertex: payload };
|
|
488
|
+
})()
|
|
340
489
|
};
|
|
341
490
|
}
|
|
342
491
|
async doGenerateGemini({
|
|
@@ -379,13 +528,16 @@ var GoogleVertexImageModel = class {
|
|
|
379
528
|
if (file.type === "url") {
|
|
380
529
|
userContent.push({
|
|
381
530
|
type: "file",
|
|
382
|
-
data: new URL(file.url),
|
|
531
|
+
data: { type: "url", url: new URL(file.url) },
|
|
383
532
|
mediaType: "image/*"
|
|
384
533
|
});
|
|
385
534
|
} else {
|
|
386
535
|
userContent.push({
|
|
387
536
|
type: "file",
|
|
388
|
-
data:
|
|
537
|
+
data: {
|
|
538
|
+
type: "data",
|
|
539
|
+
data: typeof file.data === "string" ? file.data : new Uint8Array(file.data)
|
|
540
|
+
},
|
|
389
541
|
mediaType: file.mediaType
|
|
390
542
|
});
|
|
391
543
|
}
|
|
@@ -394,27 +546,30 @@ var GoogleVertexImageModel = class {
|
|
|
394
546
|
const languageModelPrompt = [
|
|
395
547
|
{ role: "user", content: userContent }
|
|
396
548
|
];
|
|
397
|
-
const languageModel = new
|
|
549
|
+
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
398
550
|
provider: this.config.provider,
|
|
399
551
|
baseURL: this.config.baseURL,
|
|
400
552
|
headers: (_a = this.config.headers) != null ? _a : {},
|
|
401
553
|
fetch: this.config.fetch,
|
|
402
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
554
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
|
|
403
555
|
supportedUrls: () => ({
|
|
404
556
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
405
557
|
})
|
|
406
558
|
});
|
|
559
|
+
const userVertexOptions = (_c = providerOptions == null ? void 0 : providerOptions.googleVertex) != null ? _c : providerOptions == null ? void 0 : providerOptions.vertex;
|
|
560
|
+
const innerVertexOptions = {
|
|
561
|
+
responseModalities: ["IMAGE"],
|
|
562
|
+
imageConfig: aspectRatio ? {
|
|
563
|
+
aspectRatio
|
|
564
|
+
} : void 0,
|
|
565
|
+
...userVertexOptions != null ? userVertexOptions : {}
|
|
566
|
+
};
|
|
407
567
|
const result = await languageModel.doGenerate({
|
|
408
568
|
prompt: languageModelPrompt,
|
|
409
569
|
seed,
|
|
410
570
|
providerOptions: {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
imageConfig: aspectRatio ? {
|
|
414
|
-
aspectRatio
|
|
415
|
-
} : void 0,
|
|
416
|
-
...(_c = providerOptions == null ? void 0 : providerOptions.vertex) != null ? _c : {}
|
|
417
|
-
}
|
|
571
|
+
googleVertex: innerVertexOptions,
|
|
572
|
+
vertex: innerVertexOptions
|
|
418
573
|
},
|
|
419
574
|
headers,
|
|
420
575
|
abortSignal
|
|
@@ -422,17 +577,19 @@ var GoogleVertexImageModel = class {
|
|
|
422
577
|
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
578
|
const images = [];
|
|
424
579
|
for (const part of result.content) {
|
|
425
|
-
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
426
|
-
images.push(
|
|
580
|
+
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
581
|
+
images.push(convertToBase64(part.data.data));
|
|
427
582
|
}
|
|
428
583
|
}
|
|
584
|
+
const geminiPayload = {
|
|
585
|
+
images: images.map(() => ({}))
|
|
586
|
+
};
|
|
429
587
|
return {
|
|
430
588
|
images,
|
|
431
589
|
warnings,
|
|
432
590
|
providerMetadata: {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
591
|
+
googleVertex: geminiPayload,
|
|
592
|
+
vertex: geminiPayload
|
|
436
593
|
},
|
|
437
594
|
response: {
|
|
438
595
|
timestamp: currentDate,
|
|
@@ -450,71 +607,15 @@ var GoogleVertexImageModel = class {
|
|
|
450
607
|
function isGeminiModel(modelId) {
|
|
451
608
|
return modelId.startsWith("gemini-");
|
|
452
609
|
}
|
|
453
|
-
var
|
|
454
|
-
predictions:
|
|
455
|
-
|
|
456
|
-
bytesBase64Encoded:
|
|
457
|
-
mimeType:
|
|
458
|
-
prompt:
|
|
610
|
+
var googleVertexImageResponseSchema = z5.object({
|
|
611
|
+
predictions: z5.array(
|
|
612
|
+
z5.object({
|
|
613
|
+
bytesBase64Encoded: z5.string(),
|
|
614
|
+
mimeType: z5.string(),
|
|
615
|
+
prompt: z5.string().nullish()
|
|
459
616
|
})
|
|
460
617
|
).nullish()
|
|
461
618
|
});
|
|
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
619
|
function getBase64Data(file) {
|
|
519
620
|
if (file.type === "url") {
|
|
520
621
|
throw new Error(
|
|
@@ -524,25 +625,250 @@ function getBase64Data(file) {
|
|
|
524
625
|
if (typeof file.data === "string") {
|
|
525
626
|
return file.data;
|
|
526
627
|
}
|
|
527
|
-
return
|
|
628
|
+
return convertUint8ArrayToBase64(file.data);
|
|
528
629
|
}
|
|
529
630
|
|
|
530
631
|
// src/google-vertex-tools.ts
|
|
531
|
-
|
|
632
|
+
import { googleTools } from "@ai-sdk/google/internal";
|
|
532
633
|
var googleVertexTools = {
|
|
533
|
-
googleSearch:
|
|
534
|
-
enterpriseWebSearch:
|
|
535
|
-
googleMaps:
|
|
536
|
-
urlContext:
|
|
537
|
-
fileSearch:
|
|
538
|
-
codeExecution:
|
|
539
|
-
vertexRagStore:
|
|
634
|
+
googleSearch: googleTools.googleSearch,
|
|
635
|
+
enterpriseWebSearch: googleTools.enterpriseWebSearch,
|
|
636
|
+
googleMaps: googleTools.googleMaps,
|
|
637
|
+
urlContext: googleTools.urlContext,
|
|
638
|
+
fileSearch: googleTools.fileSearch,
|
|
639
|
+
codeExecution: googleTools.codeExecution,
|
|
640
|
+
vertexRagStore: googleTools.vertexRagStore
|
|
540
641
|
};
|
|
541
642
|
|
|
643
|
+
// src/google-vertex-transcription-model.ts
|
|
644
|
+
import {
|
|
645
|
+
combineHeaders as combineHeaders3,
|
|
646
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
647
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
648
|
+
parseProviderOptions as parseProviderOptions3,
|
|
649
|
+
postJsonToApi as postJsonToApi3,
|
|
650
|
+
resolve as resolve3,
|
|
651
|
+
serializeModelOptions as serializeModelOptions3,
|
|
652
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
653
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
654
|
+
} from "@ai-sdk/provider-utils";
|
|
655
|
+
import { z as z7 } from "zod/v4";
|
|
656
|
+
|
|
657
|
+
// src/google-vertex-transcription-model-options.ts
|
|
658
|
+
import { z as z6 } from "zod/v4";
|
|
659
|
+
var googleVertexTranscriptionProviderOptionsSchema = z6.object({
|
|
660
|
+
/**
|
|
661
|
+
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
662
|
+
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
663
|
+
* `telephony`, pass a supported explicit language code.
|
|
664
|
+
*/
|
|
665
|
+
languageCodes: z6.array(z6.string()).optional(),
|
|
666
|
+
/**
|
|
667
|
+
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
668
|
+
*/
|
|
669
|
+
enableAutomaticPunctuation: z6.boolean().optional(),
|
|
670
|
+
/**
|
|
671
|
+
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
672
|
+
* transcription result can include segments.
|
|
673
|
+
*
|
|
674
|
+
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
675
|
+
* for Chirp models.
|
|
676
|
+
*/
|
|
677
|
+
enableWordTimeOffsets: z6.boolean().optional(),
|
|
678
|
+
/**
|
|
679
|
+
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
680
|
+
* `'us-central1'`). Defaults to the provider `location`.
|
|
681
|
+
*
|
|
682
|
+
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
683
|
+
* available in specific Speech-to-Text regions and is not available in the
|
|
684
|
+
* `global` location.
|
|
685
|
+
*/
|
|
686
|
+
region: z6.string().optional()
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
// src/google-vertex-transcription-model.ts
|
|
690
|
+
function parseDurationSeconds(value) {
|
|
691
|
+
if (value == null) {
|
|
692
|
+
return void 0;
|
|
693
|
+
}
|
|
694
|
+
const seconds = Number.parseFloat(value);
|
|
695
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
696
|
+
}
|
|
697
|
+
function convertBcp47ToIso6391(value) {
|
|
698
|
+
if (value == null) {
|
|
699
|
+
return void 0;
|
|
700
|
+
}
|
|
701
|
+
try {
|
|
702
|
+
const language = new Intl.Locale(value).language;
|
|
703
|
+
return language.length === 2 ? language : void 0;
|
|
704
|
+
} catch (e) {
|
|
705
|
+
return void 0;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
709
|
+
constructor(modelId, config) {
|
|
710
|
+
this.modelId = modelId;
|
|
711
|
+
this.config = config;
|
|
712
|
+
this.specificationVersion = "v4";
|
|
713
|
+
}
|
|
714
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
715
|
+
return serializeModelOptions3({
|
|
716
|
+
modelId: model.modelId,
|
|
717
|
+
config: model.config
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
721
|
+
return new _GoogleVertexTranscriptionModel(options.modelId, options.config);
|
|
722
|
+
}
|
|
723
|
+
get provider() {
|
|
724
|
+
return this.config.provider;
|
|
725
|
+
}
|
|
726
|
+
async doGenerate(options) {
|
|
727
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
728
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
729
|
+
const warnings = [];
|
|
730
|
+
let googleOptions;
|
|
731
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
732
|
+
googleOptions = await parseProviderOptions3({
|
|
733
|
+
provider,
|
|
734
|
+
providerOptions: options.providerOptions,
|
|
735
|
+
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
736
|
+
});
|
|
737
|
+
if (googleOptions != null) {
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
742
|
+
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
743
|
+
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase642(options.audio);
|
|
744
|
+
const requestBody = {
|
|
745
|
+
config: {
|
|
746
|
+
model: this.modelId,
|
|
747
|
+
languageCodes,
|
|
748
|
+
// Let Speech-to-Text auto-detect the audio encoding (wav/mp3/flac/…).
|
|
749
|
+
autoDecodingConfig: {},
|
|
750
|
+
features: {
|
|
751
|
+
// Word timing populates `segments`.
|
|
752
|
+
enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
|
|
753
|
+
enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
content
|
|
757
|
+
};
|
|
758
|
+
const host = region === "global" ? "speech.googleapis.com" : `${region}-speech.googleapis.com`;
|
|
759
|
+
const url = `https://${host}/v2/projects/${this.config.project}/locations/${region}/recognizers/_:recognize`;
|
|
760
|
+
const {
|
|
761
|
+
value: response,
|
|
762
|
+
responseHeaders,
|
|
763
|
+
rawValue: rawResponse
|
|
764
|
+
} = await postJsonToApi3({
|
|
765
|
+
url,
|
|
766
|
+
headers: combineHeaders3(
|
|
767
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
768
|
+
options.headers
|
|
769
|
+
),
|
|
770
|
+
body: requestBody,
|
|
771
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
772
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
773
|
+
googleVertexTranscriptionResponseSchema
|
|
774
|
+
),
|
|
775
|
+
abortSignal: options.abortSignal,
|
|
776
|
+
fetch: this.config.fetch
|
|
777
|
+
});
|
|
778
|
+
const results = (_h = response.results) != null ? _h : [];
|
|
779
|
+
const text = results.map((result) => {
|
|
780
|
+
var _a2, _b2, _c2;
|
|
781
|
+
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
782
|
+
}).join(" ").trim();
|
|
783
|
+
const segments = results.flatMap(
|
|
784
|
+
(result) => {
|
|
785
|
+
var _a2, _b2, _c2, _d2;
|
|
786
|
+
return (_d2 = (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.words) == null ? void 0 : _c2.flatMap((word) => {
|
|
787
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
788
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
789
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
790
|
+
})) != null ? _d2 : [];
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
|
|
794
|
+
return {
|
|
795
|
+
text,
|
|
796
|
+
segments,
|
|
797
|
+
language,
|
|
798
|
+
durationInSeconds: parseDurationSeconds(
|
|
799
|
+
(_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
|
|
800
|
+
),
|
|
801
|
+
warnings,
|
|
802
|
+
response: {
|
|
803
|
+
timestamp: currentDate,
|
|
804
|
+
modelId: this.modelId,
|
|
805
|
+
headers: responseHeaders,
|
|
806
|
+
body: rawResponse
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
var googleVertexTranscriptionResponseSchema = z7.object({
|
|
812
|
+
results: z7.array(
|
|
813
|
+
z7.object({
|
|
814
|
+
alternatives: z7.array(
|
|
815
|
+
z7.object({
|
|
816
|
+
transcript: z7.string().nullish(),
|
|
817
|
+
words: z7.array(
|
|
818
|
+
z7.object({
|
|
819
|
+
word: z7.string().nullish(),
|
|
820
|
+
startOffset: z7.string().nullish(),
|
|
821
|
+
endOffset: z7.string().nullish()
|
|
822
|
+
})
|
|
823
|
+
).nullish()
|
|
824
|
+
})
|
|
825
|
+
).nullish(),
|
|
826
|
+
languageCode: z7.string().nullish()
|
|
827
|
+
})
|
|
828
|
+
).nullish(),
|
|
829
|
+
metadata: z7.object({
|
|
830
|
+
totalBilledDuration: z7.string().nullish()
|
|
831
|
+
}).nullish()
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
// src/google-vertex-video-model.ts
|
|
835
|
+
import {
|
|
836
|
+
AISDKError
|
|
837
|
+
} from "@ai-sdk/provider";
|
|
838
|
+
import {
|
|
839
|
+
combineHeaders as combineHeaders4,
|
|
840
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
|
|
841
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
842
|
+
delay,
|
|
843
|
+
parseProviderOptions as parseProviderOptions4,
|
|
844
|
+
postJsonToApi as postJsonToApi4,
|
|
845
|
+
resolve as resolve4
|
|
846
|
+
} from "@ai-sdk/provider-utils";
|
|
847
|
+
import { z as z9 } from "zod/v4";
|
|
848
|
+
|
|
849
|
+
// src/google-vertex-video-model-options.ts
|
|
850
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
851
|
+
import { z as z8 } from "zod/v4";
|
|
852
|
+
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
853
|
+
() => zodSchema(
|
|
854
|
+
z8.object({
|
|
855
|
+
pollIntervalMs: z8.number().positive().nullish(),
|
|
856
|
+
pollTimeoutMs: z8.number().positive().nullish(),
|
|
857
|
+
personGeneration: z8.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
858
|
+
negativePrompt: z8.string().nullish(),
|
|
859
|
+
generateAudio: z8.boolean().nullish(),
|
|
860
|
+
gcsOutputDirectory: z8.string().nullish(),
|
|
861
|
+
referenceImages: z8.array(
|
|
862
|
+
z8.object({
|
|
863
|
+
bytesBase64Encoded: z8.string().nullish(),
|
|
864
|
+
gcsUri: z8.string().nullish()
|
|
865
|
+
})
|
|
866
|
+
).nullish()
|
|
867
|
+
}).passthrough()
|
|
868
|
+
)
|
|
869
|
+
);
|
|
870
|
+
|
|
542
871
|
// 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
872
|
var GoogleVertexVideoModel = class {
|
|
547
873
|
constructor(modelId, config) {
|
|
548
874
|
this.modelId = modelId;
|
|
@@ -556,10 +882,14 @@ var GoogleVertexVideoModel = class {
|
|
|
556
882
|
return 4;
|
|
557
883
|
}
|
|
558
884
|
async doGenerate(options) {
|
|
559
|
-
var _a, _b, _c, _d, _e, _f;
|
|
885
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
560
886
|
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
887
|
const warnings = [];
|
|
562
|
-
const
|
|
888
|
+
const googleVertexOptions = (_d = await parseProviderOptions4({
|
|
889
|
+
provider: "googleVertex",
|
|
890
|
+
providerOptions: options.providerOptions,
|
|
891
|
+
schema: googleVertexVideoModelOptionsSchema
|
|
892
|
+
})) != null ? _d : await parseProviderOptions4({
|
|
563
893
|
provider: "vertex",
|
|
564
894
|
providerOptions: options.providerOptions,
|
|
565
895
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -577,15 +907,15 @@ var GoogleVertexVideoModel = class {
|
|
|
577
907
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
578
908
|
});
|
|
579
909
|
} else {
|
|
580
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (
|
|
910
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase643(options.image.data);
|
|
581
911
|
instance.image = {
|
|
582
912
|
bytesBase64Encoded: base64Data,
|
|
583
913
|
mimeType: options.image.mediaType
|
|
584
914
|
};
|
|
585
915
|
}
|
|
586
916
|
}
|
|
587
|
-
if ((
|
|
588
|
-
instance.referenceImages =
|
|
917
|
+
if ((googleVertexOptions == null ? void 0 : googleVertexOptions.referenceImages) != null) {
|
|
918
|
+
instance.referenceImages = googleVertexOptions.referenceImages;
|
|
589
919
|
}
|
|
590
920
|
const parameters = {
|
|
591
921
|
sampleCount: options.n
|
|
@@ -607,17 +937,18 @@ var GoogleVertexVideoModel = class {
|
|
|
607
937
|
if (options.seed) {
|
|
608
938
|
parameters.seed = options.seed;
|
|
609
939
|
}
|
|
610
|
-
|
|
611
|
-
|
|
940
|
+
const generateAudio = (_e = options.generateAudio) != null ? _e : googleVertexOptions == null ? void 0 : googleVertexOptions.generateAudio;
|
|
941
|
+
if (generateAudio != null) {
|
|
942
|
+
parameters.generateAudio = generateAudio;
|
|
943
|
+
}
|
|
944
|
+
if (googleVertexOptions != null) {
|
|
945
|
+
const opts = googleVertexOptions;
|
|
612
946
|
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
613
947
|
parameters.personGeneration = opts.personGeneration;
|
|
614
948
|
}
|
|
615
949
|
if (opts.negativePrompt !== void 0 && opts.negativePrompt !== null) {
|
|
616
950
|
parameters.negativePrompt = opts.negativePrompt;
|
|
617
951
|
}
|
|
618
|
-
if (opts.generateAudio !== void 0 && opts.generateAudio !== null) {
|
|
619
|
-
parameters.generateAudio = opts.generateAudio;
|
|
620
|
-
}
|
|
621
952
|
if (opts.gcsOutputDirectory !== void 0 && opts.gcsOutputDirectory !== null) {
|
|
622
953
|
parameters.gcsOutputDirectory = opts.gcsOutputDirectory;
|
|
623
954
|
}
|
|
@@ -635,18 +966,18 @@ var GoogleVertexVideoModel = class {
|
|
|
635
966
|
}
|
|
636
967
|
}
|
|
637
968
|
}
|
|
638
|
-
const { value: operation } = await (
|
|
969
|
+
const { value: operation } = await postJsonToApi4({
|
|
639
970
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
640
|
-
headers: (
|
|
641
|
-
await (
|
|
971
|
+
headers: combineHeaders4(
|
|
972
|
+
await resolve4(this.config.headers),
|
|
642
973
|
options.headers
|
|
643
974
|
),
|
|
644
975
|
body: {
|
|
645
976
|
instances,
|
|
646
977
|
parameters
|
|
647
978
|
},
|
|
648
|
-
successfulResponseHandler: (
|
|
649
|
-
|
|
979
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
980
|
+
googleVertexOperationSchema
|
|
650
981
|
),
|
|
651
982
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
652
983
|
abortSignal: options.abortSignal,
|
|
@@ -654,41 +985,41 @@ var GoogleVertexVideoModel = class {
|
|
|
654
985
|
});
|
|
655
986
|
const operationName = operation.name;
|
|
656
987
|
if (!operationName) {
|
|
657
|
-
throw new
|
|
988
|
+
throw new AISDKError({
|
|
658
989
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
659
990
|
message: "No operation name returned from API"
|
|
660
991
|
});
|
|
661
992
|
}
|
|
662
|
-
const pollIntervalMs = (
|
|
663
|
-
const pollTimeoutMs = (
|
|
993
|
+
const pollIntervalMs = (_f = googleVertexOptions == null ? void 0 : googleVertexOptions.pollIntervalMs) != null ? _f : 1e4;
|
|
994
|
+
const pollTimeoutMs = (_g = googleVertexOptions == null ? void 0 : googleVertexOptions.pollTimeoutMs) != null ? _g : 6e5;
|
|
664
995
|
const startTime = Date.now();
|
|
665
996
|
let finalOperation = operation;
|
|
666
997
|
let responseHeaders;
|
|
667
998
|
while (!finalOperation.done) {
|
|
668
999
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
669
|
-
throw new
|
|
1000
|
+
throw new AISDKError({
|
|
670
1001
|
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
671
1002
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
672
1003
|
});
|
|
673
1004
|
}
|
|
674
|
-
await
|
|
675
|
-
if ((
|
|
676
|
-
throw new
|
|
1005
|
+
await delay(pollIntervalMs);
|
|
1006
|
+
if ((_h = options.abortSignal) == null ? void 0 : _h.aborted) {
|
|
1007
|
+
throw new AISDKError({
|
|
677
1008
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
678
1009
|
message: "Video generation request was aborted"
|
|
679
1010
|
});
|
|
680
1011
|
}
|
|
681
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (
|
|
1012
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi4({
|
|
682
1013
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
683
|
-
headers: (
|
|
684
|
-
await (
|
|
1014
|
+
headers: combineHeaders4(
|
|
1015
|
+
await resolve4(this.config.headers),
|
|
685
1016
|
options.headers
|
|
686
1017
|
),
|
|
687
1018
|
body: {
|
|
688
1019
|
operationName
|
|
689
1020
|
},
|
|
690
|
-
successfulResponseHandler: (
|
|
691
|
-
|
|
1021
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1022
|
+
googleVertexOperationSchema
|
|
692
1023
|
),
|
|
693
1024
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
694
1025
|
abortSignal: options.abortSignal,
|
|
@@ -698,14 +1029,14 @@ var GoogleVertexVideoModel = class {
|
|
|
698
1029
|
responseHeaders = pollHeaders;
|
|
699
1030
|
}
|
|
700
1031
|
if (finalOperation.error) {
|
|
701
|
-
throw new
|
|
1032
|
+
throw new AISDKError({
|
|
702
1033
|
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
703
1034
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
704
1035
|
});
|
|
705
1036
|
}
|
|
706
1037
|
const response = finalOperation.response;
|
|
707
1038
|
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
708
|
-
throw new
|
|
1039
|
+
throw new AISDKError({
|
|
709
1040
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
710
1041
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
711
1042
|
});
|
|
@@ -735,7 +1066,7 @@ var GoogleVertexVideoModel = class {
|
|
|
735
1066
|
}
|
|
736
1067
|
}
|
|
737
1068
|
if (videos.length === 0) {
|
|
738
|
-
throw new
|
|
1069
|
+
throw new AISDKError({
|
|
739
1070
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
740
1071
|
message: "No valid videos in response"
|
|
741
1072
|
});
|
|
@@ -748,78 +1079,64 @@ var GoogleVertexVideoModel = class {
|
|
|
748
1079
|
modelId: this.modelId,
|
|
749
1080
|
headers: responseHeaders
|
|
750
1081
|
},
|
|
751
|
-
providerMetadata: {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
1082
|
+
providerMetadata: /* @__PURE__ */ (() => {
|
|
1083
|
+
const payload = { videos: videoMetadata };
|
|
1084
|
+
return {
|
|
1085
|
+
googleVertex: payload,
|
|
1086
|
+
// Legacy keys preserved for backward compatibility.
|
|
1087
|
+
"google-vertex": payload,
|
|
1088
|
+
vertex: payload
|
|
1089
|
+
};
|
|
1090
|
+
})()
|
|
756
1091
|
};
|
|
757
1092
|
}
|
|
758
1093
|
};
|
|
759
|
-
var
|
|
760
|
-
name:
|
|
761
|
-
done:
|
|
762
|
-
error:
|
|
763
|
-
code:
|
|
764
|
-
message:
|
|
765
|
-
status:
|
|
1094
|
+
var googleVertexOperationSchema = z9.object({
|
|
1095
|
+
name: z9.string().nullish(),
|
|
1096
|
+
done: z9.boolean().nullish(),
|
|
1097
|
+
error: z9.object({
|
|
1098
|
+
code: z9.number().nullish(),
|
|
1099
|
+
message: z9.string(),
|
|
1100
|
+
status: z9.string().nullish()
|
|
766
1101
|
}).nullish(),
|
|
767
|
-
response:
|
|
768
|
-
videos:
|
|
769
|
-
|
|
770
|
-
bytesBase64Encoded:
|
|
771
|
-
gcsUri:
|
|
772
|
-
mimeType:
|
|
1102
|
+
response: z9.object({
|
|
1103
|
+
videos: z9.array(
|
|
1104
|
+
z9.object({
|
|
1105
|
+
bytesBase64Encoded: z9.string().nullish(),
|
|
1106
|
+
gcsUri: z9.string().nullish(),
|
|
1107
|
+
mimeType: z9.string().nullish()
|
|
773
1108
|
})
|
|
774
1109
|
).nullish(),
|
|
775
|
-
raiMediaFilteredCount:
|
|
1110
|
+
raiMediaFilteredCount: z9.number().nullish()
|
|
776
1111
|
}).nullish()
|
|
777
1112
|
});
|
|
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
1113
|
|
|
797
|
-
// src/google-vertex-provider.ts
|
|
1114
|
+
// src/google-vertex-provider-base.ts
|
|
798
1115
|
var EXPRESS_MODE_BASE_URL = "https://aiplatform.googleapis.com/v1/publishers/google";
|
|
799
1116
|
function createExpressModeFetch(apiKey, customFetch) {
|
|
800
1117
|
return async (url, init) => {
|
|
801
1118
|
const modifiedInit = {
|
|
802
1119
|
...init,
|
|
803
1120
|
headers: {
|
|
804
|
-
...(init == null ? void 0 : init.headers) ?
|
|
1121
|
+
...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
|
|
805
1122
|
"x-goog-api-key": apiKey
|
|
806
1123
|
}
|
|
807
1124
|
};
|
|
808
1125
|
return (customFetch != null ? customFetch : fetch)(url.toString(), modifiedInit);
|
|
809
1126
|
};
|
|
810
1127
|
}
|
|
811
|
-
function
|
|
812
|
-
const apiKey =
|
|
1128
|
+
function createGoogleVertex(options = {}) {
|
|
1129
|
+
const apiKey = loadOptionalSetting({
|
|
813
1130
|
settingValue: options.apiKey,
|
|
814
1131
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
815
1132
|
});
|
|
816
|
-
const
|
|
1133
|
+
const loadGoogleVertexProject = () => loadSetting({
|
|
817
1134
|
settingValue: options.project,
|
|
818
1135
|
settingName: "project",
|
|
819
1136
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
820
1137
|
description: "Google Vertex project"
|
|
821
1138
|
});
|
|
822
|
-
const
|
|
1139
|
+
const loadGoogleVertexLocation = () => loadSetting({
|
|
823
1140
|
settingValue: options.location,
|
|
824
1141
|
settingName: "location",
|
|
825
1142
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -828,18 +1145,26 @@ function createVertex(options = {}) {
|
|
|
828
1145
|
const loadBaseURL = () => {
|
|
829
1146
|
var _a, _b;
|
|
830
1147
|
if (apiKey) {
|
|
831
|
-
return (_a =
|
|
1148
|
+
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
832
1149
|
}
|
|
833
|
-
const region =
|
|
834
|
-
const project =
|
|
835
|
-
const
|
|
836
|
-
|
|
1150
|
+
const region = loadGoogleVertexLocation();
|
|
1151
|
+
const project = loadGoogleVertexProject();
|
|
1152
|
+
const getHost = () => {
|
|
1153
|
+
if (region === "global") {
|
|
1154
|
+
return "aiplatform.googleapis.com";
|
|
1155
|
+
} else if (region === "eu" || region === "us") {
|
|
1156
|
+
return `aiplatform.${region}.rep.googleapis.com`;
|
|
1157
|
+
} else {
|
|
1158
|
+
return `${region}-aiplatform.googleapis.com`;
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${getHost()}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
837
1162
|
};
|
|
838
1163
|
const createConfig = (name) => {
|
|
839
1164
|
const getHeaders = async () => {
|
|
840
1165
|
var _a;
|
|
841
|
-
const originalHeaders = await (
|
|
842
|
-
return
|
|
1166
|
+
const originalHeaders = await resolve5((_a = options.headers) != null ? _a : {});
|
|
1167
|
+
return withUserAgentSuffix(
|
|
843
1168
|
originalHeaders,
|
|
844
1169
|
`ai-sdk/google-vertex/${VERSION}`
|
|
845
1170
|
);
|
|
@@ -853,9 +1178,9 @@ function createVertex(options = {}) {
|
|
|
853
1178
|
};
|
|
854
1179
|
const createChatModel = (modelId) => {
|
|
855
1180
|
var _a;
|
|
856
|
-
return new
|
|
1181
|
+
return new GoogleLanguageModel2(modelId, {
|
|
857
1182
|
...createConfig("chat"),
|
|
858
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1183
|
+
generateId: (_a = options.generateId) != null ? _a : generateId,
|
|
859
1184
|
supportedUrls: () => ({
|
|
860
1185
|
"*": [
|
|
861
1186
|
// HTTP URLs:
|
|
@@ -871,14 +1196,30 @@ function createVertex(options = {}) {
|
|
|
871
1196
|
var _a;
|
|
872
1197
|
return new GoogleVertexImageModel(modelId, {
|
|
873
1198
|
...createConfig("image"),
|
|
874
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1199
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
875
1200
|
});
|
|
876
1201
|
};
|
|
877
1202
|
const createVideoModel = (modelId) => {
|
|
878
1203
|
var _a;
|
|
879
1204
|
return new GoogleVertexVideoModel(modelId, {
|
|
880
1205
|
...createConfig("video"),
|
|
881
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
1206
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
1207
|
+
});
|
|
1208
|
+
};
|
|
1209
|
+
const createSpeechModel = (modelId) => new GoogleSpeechModel(modelId, createConfig("speech"));
|
|
1210
|
+
const createTranscriptionModel = (modelId) => {
|
|
1211
|
+
if (apiKey) {
|
|
1212
|
+
throw new Error(
|
|
1213
|
+
"Google Vertex transcription models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
const config = createConfig("transcription");
|
|
1217
|
+
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1218
|
+
provider: config.provider,
|
|
1219
|
+
headers: config.headers,
|
|
1220
|
+
fetch: config.fetch,
|
|
1221
|
+
project: loadGoogleVertexProject(),
|
|
1222
|
+
location: loadGoogleVertexLocation()
|
|
882
1223
|
});
|
|
883
1224
|
};
|
|
884
1225
|
const provider = function(modelId) {
|
|
@@ -897,28 +1238,37 @@ function createVertex(options = {}) {
|
|
|
897
1238
|
provider.imageModel = createImageModel;
|
|
898
1239
|
provider.video = createVideoModel;
|
|
899
1240
|
provider.videoModel = createVideoModel;
|
|
1241
|
+
provider.speech = createSpeechModel;
|
|
1242
|
+
provider.speechModel = createSpeechModel;
|
|
1243
|
+
provider.transcription = createTranscriptionModel;
|
|
1244
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
900
1245
|
provider.tools = googleVertexTools;
|
|
901
1246
|
return provider;
|
|
902
1247
|
}
|
|
903
1248
|
|
|
904
1249
|
// src/edge/google-vertex-auth-edge.ts
|
|
905
|
-
|
|
1250
|
+
import {
|
|
1251
|
+
loadOptionalSetting as loadOptionalSetting2,
|
|
1252
|
+
loadSetting as loadSetting2,
|
|
1253
|
+
withUserAgentSuffix as withUserAgentSuffix2,
|
|
1254
|
+
getRuntimeEnvironmentUserAgent
|
|
1255
|
+
} from "@ai-sdk/provider-utils";
|
|
906
1256
|
var loadCredentials = async () => {
|
|
907
1257
|
try {
|
|
908
1258
|
return {
|
|
909
|
-
clientEmail: (
|
|
1259
|
+
clientEmail: loadSetting2({
|
|
910
1260
|
settingValue: void 0,
|
|
911
1261
|
settingName: "clientEmail",
|
|
912
1262
|
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
913
1263
|
description: "Google client email"
|
|
914
1264
|
}),
|
|
915
|
-
privateKey: (
|
|
1265
|
+
privateKey: loadSetting2({
|
|
916
1266
|
settingValue: void 0,
|
|
917
1267
|
settingName: "privateKey",
|
|
918
1268
|
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
919
1269
|
description: "Google private key"
|
|
920
1270
|
}),
|
|
921
|
-
privateKeyId: (
|
|
1271
|
+
privateKeyId: loadOptionalSetting2({
|
|
922
1272
|
settingValue: void 0,
|
|
923
1273
|
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
924
1274
|
})
|
|
@@ -987,10 +1337,10 @@ async function generateAuthToken(credentials) {
|
|
|
987
1337
|
const jwt = await buildJwt(creds);
|
|
988
1338
|
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
989
1339
|
method: "POST",
|
|
990
|
-
headers: (
|
|
1340
|
+
headers: withUserAgentSuffix2(
|
|
991
1341
|
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
992
1342
|
`ai-sdk/google-vertex/${VERSION}`,
|
|
993
|
-
|
|
1343
|
+
getRuntimeEnvironmentUserAgent()
|
|
994
1344
|
),
|
|
995
1345
|
body: new URLSearchParams({
|
|
996
1346
|
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
@@ -1008,28 +1358,29 @@ async function generateAuthToken(credentials) {
|
|
|
1008
1358
|
}
|
|
1009
1359
|
|
|
1010
1360
|
// src/edge/google-vertex-provider-edge.ts
|
|
1011
|
-
function
|
|
1012
|
-
const apiKey = (
|
|
1361
|
+
function createGoogleVertex2(options = {}) {
|
|
1362
|
+
const apiKey = loadOptionalSetting3({
|
|
1013
1363
|
settingValue: options.apiKey,
|
|
1014
1364
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
1015
1365
|
});
|
|
1016
1366
|
if (apiKey) {
|
|
1017
|
-
return
|
|
1367
|
+
return createGoogleVertex(options);
|
|
1018
1368
|
}
|
|
1019
|
-
return
|
|
1369
|
+
return createGoogleVertex({
|
|
1020
1370
|
...options,
|
|
1021
1371
|
headers: async () => ({
|
|
1022
1372
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1023
1373
|
options.googleCredentials
|
|
1024
1374
|
)}`,
|
|
1025
|
-
...await (
|
|
1375
|
+
...await resolve6(options.headers)
|
|
1026
1376
|
})
|
|
1027
1377
|
});
|
|
1028
1378
|
}
|
|
1029
|
-
var
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
createVertex,
|
|
1033
|
-
|
|
1034
|
-
|
|
1379
|
+
var googleVertex = createGoogleVertex2();
|
|
1380
|
+
export {
|
|
1381
|
+
createGoogleVertex2 as createGoogleVertex,
|
|
1382
|
+
createGoogleVertex2 as createVertex,
|
|
1383
|
+
googleVertex,
|
|
1384
|
+
googleVertex as vertex
|
|
1385
|
+
};
|
|
1035
1386
|
//# sourceMappingURL=index.js.map
|