@ai-sdk/google-vertex 5.0.0-beta.62 → 5.0.0-beta.63
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 +18 -0
- package/dist/anthropic/edge/index.d.ts +10 -5
- package/dist/anthropic/edge/index.js +15 -13
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +10 -5
- package/dist/anthropic/index.js +14 -12
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +190 -153
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +192 -155
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +3 -3
- package/dist/maas/edge/index.js +9 -7
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.d.ts +3 -3
- package/dist/maas/index.js +8 -6
- package/dist/maas/index.js.map +1 -1
- package/docs/16-google-vertex.mdx +75 -75
- package/package.json +5 -5
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +13 -7
- package/src/anthropic/edge/index.ts +6 -2
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +13 -7
- package/src/anthropic/google-vertex-anthropic-provider.ts +5 -5
- package/src/anthropic/index.ts +6 -2
- package/src/edge/google-vertex-provider-edge.ts +6 -6
- package/src/edge/index.ts +8 -1
- package/src/google-vertex-embedding-model.ts +10 -2
- package/src/google-vertex-image-model-options.ts +74 -0
- package/src/google-vertex-image-model.ts +42 -102
- package/src/google-vertex-provider-base.ts +245 -0
- package/src/google-vertex-provider.ts +35 -233
- package/src/google-vertex-video-model-options.ts +49 -0
- package/src/google-vertex-video-model.ts +30 -66
- package/src/index.ts +12 -5
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +3 -3
- package/src/maas/edge/index.ts +6 -2
- package/src/maas/google-vertex-maas-provider-node.ts +3 -3
- package/src/maas/google-vertex-maas-provider.ts +1 -1
- package/src/maas/index.ts +6 -2
- package/src/google-vertex-provider-node.ts +0 -47
- /package/src/{google-vertex-embedding-options.ts → google-vertex-embedding-model-options.ts} +0 -0
|
@@ -1,136 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
ImageModelV4,
|
|
5
|
-
LanguageModelV4,
|
|
6
|
-
ProviderV4,
|
|
7
|
-
} from '@ai-sdk/provider';
|
|
1
|
+
import { loadOptionalSetting, resolve } from '@ai-sdk/provider-utils';
|
|
2
|
+
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
3
|
+
import { generateAuthToken } from './google-vertex-auth-google-auth-library';
|
|
8
4
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import { GoogleVertexEmbeddingModel } from './google-vertex-embedding-model';
|
|
22
|
-
import type { GoogleVertexEmbeddingModelId } from './google-vertex-embedding-options';
|
|
23
|
-
import { GoogleVertexImageModel } from './google-vertex-image-model';
|
|
24
|
-
import type { GoogleVertexImageModelId } from './google-vertex-image-settings';
|
|
25
|
-
import type { GoogleVertexModelId } from './google-vertex-options';
|
|
26
|
-
import { googleVertexTools } from './google-vertex-tools';
|
|
27
|
-
import { GoogleVertexVideoModel } from './google-vertex-video-model';
|
|
28
|
-
import type { GoogleVertexVideoModelId } from './google-vertex-video-settings';
|
|
29
|
-
|
|
30
|
-
const EXPRESS_MODE_BASE_URL =
|
|
31
|
-
'https://aiplatform.googleapis.com/v1/publishers/google';
|
|
32
|
-
|
|
33
|
-
// set `x-goog-api-key` header to API key for express mode
|
|
34
|
-
function createExpressModeFetch(
|
|
35
|
-
apiKey: string,
|
|
36
|
-
customFetch?: FetchFunction,
|
|
37
|
-
): FetchFunction {
|
|
38
|
-
return async (url, init) => {
|
|
39
|
-
const modifiedInit: RequestInit = {
|
|
40
|
-
...init,
|
|
41
|
-
headers: {
|
|
42
|
-
...(init?.headers ? normalizeHeaders(init.headers) : {}),
|
|
43
|
-
'x-goog-api-key': apiKey,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
return (customFetch ?? fetch)(url.toString(), modifiedInit);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface GoogleVertexProvider extends ProviderV4 {
|
|
51
|
-
/**
|
|
52
|
-
* Creates a model for text generation.
|
|
53
|
-
*/
|
|
54
|
-
(modelId: GoogleVertexModelId): LanguageModelV4;
|
|
55
|
-
|
|
56
|
-
languageModel: (modelId: GoogleVertexModelId) => LanguageModelV4;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Creates a model for image generation.
|
|
60
|
-
*/
|
|
61
|
-
image(modelId: GoogleVertexImageModelId): ImageModelV4;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a model for image generation.
|
|
65
|
-
*/
|
|
66
|
-
imageModel(modelId: GoogleVertexImageModelId): ImageModelV4;
|
|
67
|
-
|
|
68
|
-
tools: typeof googleVertexTools;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated Use `embeddingModel` instead.
|
|
72
|
-
*/
|
|
73
|
-
textEmbeddingModel(
|
|
74
|
-
modelId: GoogleVertexEmbeddingModelId,
|
|
75
|
-
): GoogleVertexEmbeddingModel;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Creates a model for video generation.
|
|
79
|
-
*/
|
|
80
|
-
video(modelId: GoogleVertexVideoModelId): Experimental_VideoModelV4;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Creates a model for video generation.
|
|
84
|
-
*/
|
|
85
|
-
videoModel(modelId: GoogleVertexVideoModelId): Experimental_VideoModelV4;
|
|
5
|
+
createGoogleVertex as createGoogleVertexOriginal,
|
|
6
|
+
type GoogleVertexProvider,
|
|
7
|
+
type GoogleVertexProviderSettings as GoogleVertexProviderSettingsOriginal,
|
|
8
|
+
} from './google-vertex-provider-base';
|
|
9
|
+
export interface GoogleVertexProviderSettings extends GoogleVertexProviderSettingsOriginal {
|
|
10
|
+
/**
|
|
11
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
12
|
+
* Complete list of authentication options is documented in the
|
|
13
|
+
* GoogleAuthOptions interface:
|
|
14
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
15
|
+
*/
|
|
16
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
86
17
|
}
|
|
87
18
|
|
|
88
|
-
export
|
|
89
|
-
/**
|
|
90
|
-
* Optional. The API key for the Google Cloud project. If provided, the
|
|
91
|
-
* provider will use express mode with API key authentication. Defaults to
|
|
92
|
-
* the value of the `GOOGLE_VERTEX_API_KEY` environment variable.
|
|
93
|
-
*/
|
|
94
|
-
apiKey?: string;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Your Google Vertex location. Defaults to the environment variable `GOOGLE_VERTEX_LOCATION`.
|
|
98
|
-
*/
|
|
99
|
-
location?: string;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Your Google Vertex project. Defaults to the environment variable `GOOGLE_VERTEX_PROJECT`.
|
|
103
|
-
*/
|
|
104
|
-
project?: string;
|
|
19
|
+
export type { GoogleVertexProvider };
|
|
105
20
|
|
|
106
|
-
|
|
107
|
-
* Headers to use for requests. Can be:
|
|
108
|
-
* - A headers object
|
|
109
|
-
* - A Promise that resolves to a headers object
|
|
110
|
-
* - A function that returns a headers object
|
|
111
|
-
* - A function that returns a Promise of a headers object
|
|
112
|
-
*/
|
|
113
|
-
headers?: Resolvable<Record<string, string | undefined>>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
117
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
118
|
-
*/
|
|
119
|
-
fetch?: FetchFunction;
|
|
120
|
-
|
|
121
|
-
// for testing
|
|
122
|
-
generateId?: () => string;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Base URL for the Google Vertex API calls.
|
|
126
|
-
*/
|
|
127
|
-
baseURL?: string;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Create a Google Vertex AI provider instance.
|
|
132
|
-
*/
|
|
133
|
-
export function createVertex(
|
|
21
|
+
export function createGoogleVertex(
|
|
134
22
|
options: GoogleVertexProviderSettings = {},
|
|
135
23
|
): GoogleVertexProvider {
|
|
136
24
|
const apiKey = loadOptionalSetting({
|
|
@@ -138,108 +26,22 @@ export function createVertex(
|
|
|
138
26
|
environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
|
|
139
27
|
});
|
|
140
28
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
description: 'Google Vertex location',
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const loadBaseURL = () => {
|
|
158
|
-
if (apiKey) {
|
|
159
|
-
return withoutTrailingSlash(options.baseURL) ?? EXPRESS_MODE_BASE_URL;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const region = loadVertexLocation();
|
|
163
|
-
const project = loadVertexProject();
|
|
164
|
-
|
|
165
|
-
// For global region, use aiplatform.googleapis.com directly
|
|
166
|
-
// For other regions, use region-aiplatform.googleapis.com
|
|
167
|
-
const baseHost = `${region === 'global' ? '' : region + '-'}aiplatform.googleapis.com`;
|
|
168
|
-
|
|
169
|
-
return (
|
|
170
|
-
withoutTrailingSlash(options.baseURL) ??
|
|
171
|
-
`https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`
|
|
172
|
-
);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const createConfig = (name: string): GoogleVertexConfig => {
|
|
176
|
-
const getHeaders = async () => {
|
|
177
|
-
const originalHeaders = await resolve(options.headers ?? {});
|
|
178
|
-
return withUserAgentSuffix(
|
|
179
|
-
originalHeaders,
|
|
180
|
-
`ai-sdk/google-vertex/${VERSION}`,
|
|
181
|
-
);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
provider: `google.vertex.${name}`,
|
|
186
|
-
headers: getHeaders,
|
|
187
|
-
fetch: apiKey
|
|
188
|
-
? createExpressModeFetch(apiKey, options.fetch)
|
|
189
|
-
: options.fetch,
|
|
190
|
-
baseURL: loadBaseURL(),
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const createChatModel = (modelId: GoogleVertexModelId) => {
|
|
195
|
-
return new GoogleLanguageModel(modelId, {
|
|
196
|
-
...createConfig('chat'),
|
|
197
|
-
generateId: options.generateId ?? generateId,
|
|
198
|
-
supportedUrls: () => ({
|
|
199
|
-
'*': [
|
|
200
|
-
// HTTP URLs:
|
|
201
|
-
/^https?:\/\/.*$/,
|
|
202
|
-
// Google Cloud Storage URLs:
|
|
203
|
-
/^gs:\/\/.*$/,
|
|
204
|
-
],
|
|
205
|
-
}),
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const createEmbeddingModel = (modelId: GoogleVertexEmbeddingModelId) =>
|
|
210
|
-
new GoogleVertexEmbeddingModel(modelId, createConfig('embedding'));
|
|
211
|
-
|
|
212
|
-
const createImageModel = (modelId: GoogleVertexImageModelId) =>
|
|
213
|
-
new GoogleVertexImageModel(modelId, {
|
|
214
|
-
...createConfig('image'),
|
|
215
|
-
generateId: options.generateId ?? generateId,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
const createVideoModel = (modelId: GoogleVertexVideoModelId) =>
|
|
219
|
-
new GoogleVertexVideoModel(modelId, {
|
|
220
|
-
...createConfig('video'),
|
|
221
|
-
generateId: options.generateId ?? generateId,
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
const provider = function (modelId: GoogleVertexModelId) {
|
|
225
|
-
if (new.target) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
'The Google Vertex AI model function cannot be called with the new keyword.',
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return createChatModel(modelId);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
provider.specificationVersion = 'v4' as const;
|
|
235
|
-
provider.languageModel = createChatModel;
|
|
236
|
-
provider.embeddingModel = createEmbeddingModel;
|
|
237
|
-
provider.textEmbeddingModel = createEmbeddingModel;
|
|
238
|
-
provider.image = createImageModel;
|
|
239
|
-
provider.imageModel = createImageModel;
|
|
240
|
-
provider.video = createVideoModel;
|
|
241
|
-
provider.videoModel = createVideoModel;
|
|
242
|
-
provider.tools = googleVertexTools;
|
|
243
|
-
|
|
244
|
-
return provider;
|
|
29
|
+
if (apiKey) {
|
|
30
|
+
return createGoogleVertexOriginal(options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return createGoogleVertexOriginal({
|
|
34
|
+
...options,
|
|
35
|
+
headers: async () => ({
|
|
36
|
+
Authorization: `Bearer ${await generateAuthToken(
|
|
37
|
+
options.googleAuthOptions,
|
|
38
|
+
)}`,
|
|
39
|
+
...(await resolve(options.headers)),
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
245
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Default Google Vertex AI provider instance.
|
|
46
|
+
*/
|
|
47
|
+
export const googleVertex = createGoogleVertex();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
export type GoogleVertexVideoModelOptions = {
|
|
5
|
+
// Polling configuration
|
|
6
|
+
pollIntervalMs?: number | null;
|
|
7
|
+
pollTimeoutMs?: number | null;
|
|
8
|
+
|
|
9
|
+
// Video generation options
|
|
10
|
+
personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all' | null;
|
|
11
|
+
negativePrompt?: string | null;
|
|
12
|
+
generateAudio?: boolean | null;
|
|
13
|
+
|
|
14
|
+
// Output configuration
|
|
15
|
+
gcsOutputDirectory?: string | null;
|
|
16
|
+
|
|
17
|
+
// Reference images (for style/asset reference)
|
|
18
|
+
referenceImages?: Array<{
|
|
19
|
+
bytesBase64Encoded?: string;
|
|
20
|
+
gcsUri?: string;
|
|
21
|
+
}> | null;
|
|
22
|
+
|
|
23
|
+
[key: string]: unknown; // For passthrough
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const googleVertexVideoModelOptionsSchema = lazySchema(() =>
|
|
27
|
+
zodSchema(
|
|
28
|
+
z
|
|
29
|
+
.object({
|
|
30
|
+
pollIntervalMs: z.number().positive().nullish(),
|
|
31
|
+
pollTimeoutMs: z.number().positive().nullish(),
|
|
32
|
+
personGeneration: z
|
|
33
|
+
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
34
|
+
.nullish(),
|
|
35
|
+
negativePrompt: z.string().nullish(),
|
|
36
|
+
generateAudio: z.boolean().nullish(),
|
|
37
|
+
gcsOutputDirectory: z.string().nullish(),
|
|
38
|
+
referenceImages: z
|
|
39
|
+
.array(
|
|
40
|
+
z.object({
|
|
41
|
+
bytesBase64Encoded: z.string().nullish(),
|
|
42
|
+
gcsUri: z.string().nullish(),
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.nullish(),
|
|
46
|
+
})
|
|
47
|
+
.passthrough(),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
@@ -8,40 +8,20 @@ import {
|
|
|
8
8
|
convertUint8ArrayToBase64,
|
|
9
9
|
createJsonResponseHandler,
|
|
10
10
|
delay,
|
|
11
|
-
lazySchema,
|
|
12
11
|
parseProviderOptions,
|
|
13
12
|
postJsonToApi,
|
|
14
13
|
resolve,
|
|
15
|
-
zodSchema,
|
|
16
14
|
type FetchFunction,
|
|
17
15
|
type Resolvable,
|
|
18
16
|
} from '@ai-sdk/provider-utils';
|
|
19
17
|
import { z } from 'zod/v4';
|
|
20
18
|
import { googleVertexFailedResponseHandler } from './google-vertex-error';
|
|
19
|
+
import {
|
|
20
|
+
googleVertexVideoModelOptionsSchema,
|
|
21
|
+
type GoogleVertexVideoModelOptions,
|
|
22
|
+
} from './google-vertex-video-model-options';
|
|
21
23
|
import type { GoogleVertexVideoModelId } from './google-vertex-video-settings';
|
|
22
24
|
|
|
23
|
-
export type GoogleVertexVideoModelOptions = {
|
|
24
|
-
// Polling configuration
|
|
25
|
-
pollIntervalMs?: number | null;
|
|
26
|
-
pollTimeoutMs?: number | null;
|
|
27
|
-
|
|
28
|
-
// Video generation options
|
|
29
|
-
personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all' | null;
|
|
30
|
-
negativePrompt?: string | null;
|
|
31
|
-
generateAudio?: boolean | null;
|
|
32
|
-
|
|
33
|
-
// Output configuration
|
|
34
|
-
gcsOutputDirectory?: string | null;
|
|
35
|
-
|
|
36
|
-
// Reference images (for style/asset reference)
|
|
37
|
-
referenceImages?: Array<{
|
|
38
|
-
bytesBase64Encoded?: string;
|
|
39
|
-
gcsUri?: string;
|
|
40
|
-
}> | null;
|
|
41
|
-
|
|
42
|
-
[key: string]: unknown; // For passthrough
|
|
43
|
-
};
|
|
44
|
-
|
|
45
25
|
interface GoogleVertexVideoModelConfig {
|
|
46
26
|
provider: string;
|
|
47
27
|
baseURL: string;
|
|
@@ -76,11 +56,16 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
76
56
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
77
57
|
const warnings: SharedV4Warning[] = [];
|
|
78
58
|
|
|
79
|
-
const
|
|
80
|
-
provider: '
|
|
59
|
+
const googleVertexOptions = ((await parseProviderOptions({
|
|
60
|
+
provider: 'googleVertex',
|
|
81
61
|
providerOptions: options.providerOptions,
|
|
82
62
|
schema: googleVertexVideoModelOptionsSchema,
|
|
83
|
-
}))
|
|
63
|
+
})) ??
|
|
64
|
+
(await parseProviderOptions({
|
|
65
|
+
provider: 'vertex',
|
|
66
|
+
providerOptions: options.providerOptions,
|
|
67
|
+
schema: googleVertexVideoModelOptionsSchema,
|
|
68
|
+
}))) as GoogleVertexVideoModelOptions | undefined;
|
|
84
69
|
|
|
85
70
|
const instances: Array<Record<string, unknown>> = [{}];
|
|
86
71
|
const instance = instances[0];
|
|
@@ -110,8 +95,8 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
110
95
|
}
|
|
111
96
|
}
|
|
112
97
|
|
|
113
|
-
if (
|
|
114
|
-
instance.referenceImages =
|
|
98
|
+
if (googleVertexOptions?.referenceImages != null) {
|
|
99
|
+
instance.referenceImages = googleVertexOptions.referenceImages;
|
|
115
100
|
}
|
|
116
101
|
|
|
117
102
|
const parameters: Record<string, unknown> = {
|
|
@@ -140,8 +125,8 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
140
125
|
parameters.seed = options.seed;
|
|
141
126
|
}
|
|
142
127
|
|
|
143
|
-
if (
|
|
144
|
-
const opts =
|
|
128
|
+
if (googleVertexOptions != null) {
|
|
129
|
+
const opts = googleVertexOptions;
|
|
145
130
|
|
|
146
131
|
if (
|
|
147
132
|
opts.personGeneration !== undefined &&
|
|
@@ -190,7 +175,7 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
190
175
|
parameters,
|
|
191
176
|
},
|
|
192
177
|
successfulResponseHandler: createJsonResponseHandler(
|
|
193
|
-
|
|
178
|
+
googleVertexOperationSchema,
|
|
194
179
|
),
|
|
195
180
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
196
181
|
abortSignal: options.abortSignal,
|
|
@@ -205,8 +190,8 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
205
190
|
});
|
|
206
191
|
}
|
|
207
192
|
|
|
208
|
-
const pollIntervalMs =
|
|
209
|
-
const pollTimeoutMs =
|
|
193
|
+
const pollIntervalMs = googleVertexOptions?.pollIntervalMs ?? 10000; // 10 seconds
|
|
194
|
+
const pollTimeoutMs = googleVertexOptions?.pollTimeoutMs ?? 600000; // 10 minutes
|
|
210
195
|
|
|
211
196
|
const startTime = Date.now();
|
|
212
197
|
let finalOperation = operation;
|
|
@@ -240,7 +225,7 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
240
225
|
operationName,
|
|
241
226
|
},
|
|
242
227
|
successfulResponseHandler: createJsonResponseHandler(
|
|
243
|
-
|
|
228
|
+
googleVertexOperationSchema,
|
|
244
229
|
),
|
|
245
230
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
246
231
|
abortSignal: options.abortSignal,
|
|
@@ -314,16 +299,20 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
|
|
|
314
299
|
modelId: this.modelId,
|
|
315
300
|
headers: responseHeaders,
|
|
316
301
|
},
|
|
317
|
-
providerMetadata: {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
302
|
+
providerMetadata: (() => {
|
|
303
|
+
const payload = { videos: videoMetadata };
|
|
304
|
+
return {
|
|
305
|
+
googleVertex: payload,
|
|
306
|
+
// Legacy keys preserved for backward compatibility.
|
|
307
|
+
'google-vertex': payload,
|
|
308
|
+
vertex: payload,
|
|
309
|
+
};
|
|
310
|
+
})(),
|
|
322
311
|
};
|
|
323
312
|
}
|
|
324
313
|
}
|
|
325
314
|
|
|
326
|
-
const
|
|
315
|
+
const googleVertexOperationSchema = z.object({
|
|
327
316
|
name: z.string().nullish(),
|
|
328
317
|
done: z.boolean().nullish(),
|
|
329
318
|
error: z
|
|
@@ -348,28 +337,3 @@ const vertexOperationSchema = z.object({
|
|
|
348
337
|
})
|
|
349
338
|
.nullish(),
|
|
350
339
|
});
|
|
351
|
-
|
|
352
|
-
const googleVertexVideoModelOptionsSchema = lazySchema(() =>
|
|
353
|
-
zodSchema(
|
|
354
|
-
z
|
|
355
|
-
.object({
|
|
356
|
-
pollIntervalMs: z.number().positive().nullish(),
|
|
357
|
-
pollTimeoutMs: z.number().positive().nullish(),
|
|
358
|
-
personGeneration: z
|
|
359
|
-
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
360
|
-
.nullish(),
|
|
361
|
-
negativePrompt: z.string().nullish(),
|
|
362
|
-
generateAudio: z.boolean().nullish(),
|
|
363
|
-
gcsOutputDirectory: z.string().nullish(),
|
|
364
|
-
referenceImages: z
|
|
365
|
-
.array(
|
|
366
|
-
z.object({
|
|
367
|
-
bytesBase64Encoded: z.string().nullish(),
|
|
368
|
-
gcsUri: z.string().nullish(),
|
|
369
|
-
}),
|
|
370
|
-
)
|
|
371
|
-
.nullish(),
|
|
372
|
-
})
|
|
373
|
-
.passthrough(),
|
|
374
|
-
),
|
|
375
|
-
);
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
export type { GoogleVertexEmbeddingModelOptions } from './google-vertex-embedding-options';
|
|
1
|
+
export type { GoogleVertexEmbeddingModelOptions } from './google-vertex-embedding-model-options';
|
|
2
2
|
export type {
|
|
3
3
|
GoogleVertexImageModelOptions,
|
|
4
4
|
/** @deprecated Use `GoogleVertexImageModelOptions` instead. */
|
|
5
5
|
GoogleVertexImageModelOptions as GoogleVertexImageProviderOptions,
|
|
6
|
-
} from './google-vertex-image-model';
|
|
6
|
+
} from './google-vertex-image-model-options';
|
|
7
7
|
export type {
|
|
8
8
|
GoogleVertexVideoModelOptions,
|
|
9
9
|
/** @deprecated Use `GoogleVertexVideoModelOptions` instead. */
|
|
10
10
|
GoogleVertexVideoModelOptions as GoogleVertexVideoProviderOptions,
|
|
11
|
-
} from './google-vertex-video-model';
|
|
11
|
+
} from './google-vertex-video-model-options';
|
|
12
12
|
export type { GoogleVertexVideoModelId } from './google-vertex-video-settings';
|
|
13
|
-
export {
|
|
13
|
+
export {
|
|
14
|
+
createGoogleVertex,
|
|
15
|
+
/** @deprecated Use `createGoogleVertex` instead. */
|
|
16
|
+
createGoogleVertex as createVertex,
|
|
17
|
+
googleVertex,
|
|
18
|
+
/** @deprecated Use `googleVertex` instead. */
|
|
19
|
+
googleVertex as vertex,
|
|
20
|
+
} from './google-vertex-provider';
|
|
14
21
|
export type {
|
|
15
22
|
GoogleVertexProvider,
|
|
16
23
|
GoogleVertexProviderSettings,
|
|
17
|
-
} from './google-vertex-provider
|
|
24
|
+
} from './google-vertex-provider';
|
|
18
25
|
export { VERSION } from './version';
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type GoogleCredentials,
|
|
5
5
|
} from '../../edge/google-vertex-auth-edge';
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
createGoogleVertexMaas as createVertexMaasOriginal,
|
|
8
8
|
type GoogleVertexMaasProvider,
|
|
9
9
|
type GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,
|
|
10
10
|
} from '../google-vertex-maas-provider';
|
|
@@ -26,7 +26,7 @@ export interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProvid
|
|
|
26
26
|
*
|
|
27
27
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
28
28
|
*/
|
|
29
|
-
export function
|
|
29
|
+
export function createGoogleVertexMaas(
|
|
30
30
|
options: GoogleVertexMaasProviderSettings = {},
|
|
31
31
|
): GoogleVertexMaasProvider {
|
|
32
32
|
// Create a custom fetch wrapper that adds auth headers
|
|
@@ -61,4 +61,4 @@ export function createVertexMaas(
|
|
|
61
61
|
/**
|
|
62
62
|
* Default Google Vertex AI MaaS provider instance for Edge runtimes.
|
|
63
63
|
*/
|
|
64
|
-
export const
|
|
64
|
+
export const googleVertexMaas = createGoogleVertexMaas();
|
package/src/maas/edge/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
createGoogleVertexMaas,
|
|
3
|
+
/** @deprecated Use `createGoogleVertexMaas` instead. */
|
|
4
|
+
createGoogleVertexMaas as createVertexMaas,
|
|
5
|
+
googleVertexMaas,
|
|
6
|
+
/** @deprecated Use `googleVertexMaas` instead. */
|
|
7
|
+
googleVertexMaas as vertexMaas,
|
|
4
8
|
} from './google-vertex-maas-provider-edge';
|
|
5
9
|
export type {
|
|
6
10
|
GoogleVertexMaasProvider,
|
|
@@ -2,7 +2,7 @@ import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
2
2
|
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
3
3
|
import { generateAuthToken } from '../google-vertex-auth-google-auth-library';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
createGoogleVertexMaas as createVertexMaasOriginal,
|
|
6
6
|
type GoogleVertexMaasProvider,
|
|
7
7
|
type GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,
|
|
8
8
|
} from './google-vertex-maas-provider';
|
|
@@ -25,7 +25,7 @@ export interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProvid
|
|
|
25
25
|
*
|
|
26
26
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function createGoogleVertexMaas(
|
|
29
29
|
options: GoogleVertexMaasProviderSettings = {},
|
|
30
30
|
): GoogleVertexMaasProvider {
|
|
31
31
|
// Create a custom fetch wrapper that adds auth headers
|
|
@@ -60,4 +60,4 @@ export function createVertexMaas(
|
|
|
60
60
|
/**
|
|
61
61
|
* Default Google Vertex AI MaaS provider instance for Node.js.
|
|
62
62
|
*/
|
|
63
|
-
export const
|
|
63
|
+
export const googleVertexMaas = createGoogleVertexMaas();
|
|
@@ -57,7 +57,7 @@ export interface GoogleVertexMaasProviderSettings {
|
|
|
57
57
|
*
|
|
58
58
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
59
59
|
*/
|
|
60
|
-
export function
|
|
60
|
+
export function createGoogleVertexMaas(
|
|
61
61
|
options: GoogleVertexMaasProviderSettings = {},
|
|
62
62
|
): GoogleVertexMaasProvider {
|
|
63
63
|
// Lazy-load settings to support loading from environment variables at runtime
|
package/src/maas/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
createGoogleVertexMaas,
|
|
3
|
+
/** @deprecated Use `createGoogleVertexMaas` instead. */
|
|
4
|
+
createGoogleVertexMaas as createVertexMaas,
|
|
5
|
+
googleVertexMaas,
|
|
6
|
+
/** @deprecated Use `googleVertexMaas` instead. */
|
|
7
|
+
googleVertexMaas as vertexMaas,
|
|
4
8
|
} from './google-vertex-maas-provider-node';
|
|
5
9
|
export type {
|
|
6
10
|
GoogleVertexMaasProvider,
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { loadOptionalSetting, resolve } from '@ai-sdk/provider-utils';
|
|
2
|
-
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
3
|
-
import { generateAuthToken } from './google-vertex-auth-google-auth-library';
|
|
4
|
-
import {
|
|
5
|
-
createVertex as createVertexOriginal,
|
|
6
|
-
type GoogleVertexProvider,
|
|
7
|
-
type GoogleVertexProviderSettings as GoogleVertexProviderSettingsOriginal,
|
|
8
|
-
} from './google-vertex-provider';
|
|
9
|
-
export interface GoogleVertexProviderSettings extends GoogleVertexProviderSettingsOriginal {
|
|
10
|
-
/**
|
|
11
|
-
* Optional. The Authentication options provided by google-auth-library.
|
|
12
|
-
* Complete list of authentication options is documented in the
|
|
13
|
-
* GoogleAuthOptions interface:
|
|
14
|
-
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
15
|
-
*/
|
|
16
|
-
googleAuthOptions?: GoogleAuthOptions;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type { GoogleVertexProvider };
|
|
20
|
-
|
|
21
|
-
export function createVertex(
|
|
22
|
-
options: GoogleVertexProviderSettings = {},
|
|
23
|
-
): GoogleVertexProvider {
|
|
24
|
-
const apiKey = loadOptionalSetting({
|
|
25
|
-
settingValue: options.apiKey,
|
|
26
|
-
environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
if (apiKey) {
|
|
30
|
-
return createVertexOriginal(options);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return createVertexOriginal({
|
|
34
|
-
...options,
|
|
35
|
-
headers: async () => ({
|
|
36
|
-
Authorization: `Bearer ${await generateAuthToken(
|
|
37
|
-
options.googleAuthOptions,
|
|
38
|
-
)}`,
|
|
39
|
-
...(await resolve(options.headers)),
|
|
40
|
-
}),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Default Google Vertex AI provider instance.
|
|
46
|
-
*/
|
|
47
|
-
export const vertex = createVertex();
|
/package/src/{google-vertex-embedding-options.ts → google-vertex-embedding-model-options.ts}
RENAMED
|
File without changes
|