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