@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
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { SharedV4Warning, TranscriptionModelV4 } from '@ai-sdk/provider';
|
|
2
|
+
import {
|
|
3
|
+
combineHeaders,
|
|
4
|
+
convertUint8ArrayToBase64,
|
|
5
|
+
createJsonResponseHandler,
|
|
6
|
+
parseProviderOptions,
|
|
7
|
+
postJsonToApi,
|
|
8
|
+
resolve,
|
|
9
|
+
serializeModelOptions,
|
|
10
|
+
WORKFLOW_DESERIALIZE,
|
|
11
|
+
WORKFLOW_SERIALIZE,
|
|
12
|
+
type FetchFunction,
|
|
13
|
+
type Resolvable,
|
|
14
|
+
} from '@ai-sdk/provider-utils';
|
|
15
|
+
import { z } from 'zod/v4';
|
|
16
|
+
import { googleVertexFailedResponseHandler } from './google-vertex-error';
|
|
17
|
+
import {
|
|
18
|
+
googleVertexTranscriptionProviderOptionsSchema,
|
|
19
|
+
type GoogleVertexTranscriptionModelId,
|
|
20
|
+
type GoogleVertexTranscriptionModelOptions,
|
|
21
|
+
} from './google-vertex-transcription-model-options';
|
|
22
|
+
|
|
23
|
+
interface GoogleVertexTranscriptionModelConfig {
|
|
24
|
+
provider: string;
|
|
25
|
+
/** Google Cloud project id. */
|
|
26
|
+
project: string;
|
|
27
|
+
/** Default Speech-to-Text region (overridable via provider options). */
|
|
28
|
+
location: string;
|
|
29
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
30
|
+
fetch?: FetchFunction;
|
|
31
|
+
_internal?: {
|
|
32
|
+
currentDate?: () => Date;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Speech-to-Text Durations are strings like `"1.200s"`; parse to seconds.
|
|
37
|
+
function parseDurationSeconds(
|
|
38
|
+
value: string | null | undefined,
|
|
39
|
+
): number | undefined {
|
|
40
|
+
if (value == null) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const seconds = Number.parseFloat(value);
|
|
44
|
+
return Number.isFinite(seconds) ? seconds : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function convertBcp47ToIso6391(
|
|
48
|
+
value: string | null | undefined,
|
|
49
|
+
): string | undefined {
|
|
50
|
+
if (value == null) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const language = new Intl.Locale(value).language;
|
|
56
|
+
return language.length === 2 ? language : undefined;
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class GoogleVertexTranscriptionModel implements TranscriptionModelV4 {
|
|
63
|
+
readonly specificationVersion = 'v4';
|
|
64
|
+
|
|
65
|
+
static [WORKFLOW_SERIALIZE](model: GoogleVertexTranscriptionModel) {
|
|
66
|
+
return serializeModelOptions({
|
|
67
|
+
modelId: model.modelId,
|
|
68
|
+
config: model.config,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
73
|
+
modelId: GoogleVertexTranscriptionModelId;
|
|
74
|
+
config: GoogleVertexTranscriptionModelConfig;
|
|
75
|
+
}) {
|
|
76
|
+
return new GoogleVertexTranscriptionModel(options.modelId, options.config);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get provider(): string {
|
|
80
|
+
return this.config.provider;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
constructor(
|
|
84
|
+
readonly modelId: GoogleVertexTranscriptionModelId,
|
|
85
|
+
private readonly config: GoogleVertexTranscriptionModelConfig,
|
|
86
|
+
) {}
|
|
87
|
+
|
|
88
|
+
async doGenerate(
|
|
89
|
+
options: Parameters<TranscriptionModelV4['doGenerate']>[0],
|
|
90
|
+
): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
|
|
91
|
+
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
92
|
+
const warnings: SharedV4Warning[] = [];
|
|
93
|
+
|
|
94
|
+
// Provider options may be passed under `googleVertex`, `vertex`, or `google`
|
|
95
|
+
// (matching the Vertex language + embedding models).
|
|
96
|
+
let googleOptions: GoogleVertexTranscriptionModelOptions | undefined;
|
|
97
|
+
for (const provider of ['googleVertex', 'vertex', 'google'] as const) {
|
|
98
|
+
googleOptions = await parseProviderOptions({
|
|
99
|
+
provider,
|
|
100
|
+
providerOptions: options.providerOptions,
|
|
101
|
+
schema: googleVertexTranscriptionProviderOptionsSchema,
|
|
102
|
+
});
|
|
103
|
+
if (googleOptions != null) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const region = googleOptions?.region ?? this.config.location;
|
|
109
|
+
const languageCodes = googleOptions?.languageCodes ?? ['auto'];
|
|
110
|
+
|
|
111
|
+
// The recognize API takes base64-encoded audio in the `content` field. A
|
|
112
|
+
// string audio input is already base64-encoded per the spec.
|
|
113
|
+
const content =
|
|
114
|
+
typeof options.audio === 'string'
|
|
115
|
+
? options.audio
|
|
116
|
+
: convertUint8ArrayToBase64(options.audio);
|
|
117
|
+
|
|
118
|
+
const requestBody = {
|
|
119
|
+
config: {
|
|
120
|
+
model: this.modelId,
|
|
121
|
+
languageCodes,
|
|
122
|
+
// Let Speech-to-Text auto-detect the audio encoding (wav/mp3/flac/…).
|
|
123
|
+
autoDecodingConfig: {},
|
|
124
|
+
features: {
|
|
125
|
+
// Word timing populates `segments`.
|
|
126
|
+
enableWordTimeOffsets: googleOptions?.enableWordTimeOffsets ?? true,
|
|
127
|
+
enableAutomaticPunctuation:
|
|
128
|
+
googleOptions?.enableAutomaticPunctuation ?? true,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
content,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const host =
|
|
135
|
+
region === 'global'
|
|
136
|
+
? 'speech.googleapis.com'
|
|
137
|
+
: `${region}-speech.googleapis.com`;
|
|
138
|
+
|
|
139
|
+
const url =
|
|
140
|
+
`https://${host}/v2/projects/` +
|
|
141
|
+
`${this.config.project}/locations/${region}/recognizers/_:recognize`;
|
|
142
|
+
|
|
143
|
+
const {
|
|
144
|
+
value: response,
|
|
145
|
+
responseHeaders,
|
|
146
|
+
rawValue: rawResponse,
|
|
147
|
+
} = await postJsonToApi({
|
|
148
|
+
url,
|
|
149
|
+
headers: combineHeaders(
|
|
150
|
+
this.config.headers ? await resolve(this.config.headers) : undefined,
|
|
151
|
+
options.headers,
|
|
152
|
+
),
|
|
153
|
+
body: requestBody,
|
|
154
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
155
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
156
|
+
googleVertexTranscriptionResponseSchema,
|
|
157
|
+
),
|
|
158
|
+
abortSignal: options.abortSignal,
|
|
159
|
+
fetch: this.config.fetch,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Results are sequential portions of the audio; concatenate their primary
|
|
163
|
+
// alternatives into the full transcript and collect word-level segments.
|
|
164
|
+
const results = response.results ?? [];
|
|
165
|
+
const text = results
|
|
166
|
+
.map(result => result.alternatives?.[0]?.transcript ?? '')
|
|
167
|
+
.join(' ')
|
|
168
|
+
.trim();
|
|
169
|
+
const segments = results.flatMap(
|
|
170
|
+
result =>
|
|
171
|
+
result.alternatives?.[0]?.words?.flatMap(word => {
|
|
172
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
173
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
174
|
+
|
|
175
|
+
return word.word == null || startSecond == null || endSecond == null
|
|
176
|
+
? []
|
|
177
|
+
: [{ text: word.word, startSecond, endSecond }];
|
|
178
|
+
}) ?? [],
|
|
179
|
+
);
|
|
180
|
+
const language = convertBcp47ToIso6391(results[0]?.languageCode);
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
text,
|
|
184
|
+
segments,
|
|
185
|
+
language,
|
|
186
|
+
durationInSeconds: parseDurationSeconds(
|
|
187
|
+
response.metadata?.totalBilledDuration,
|
|
188
|
+
),
|
|
189
|
+
warnings,
|
|
190
|
+
response: {
|
|
191
|
+
timestamp: currentDate,
|
|
192
|
+
modelId: this.modelId,
|
|
193
|
+
headers: responseHeaders,
|
|
194
|
+
body: rawResponse,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Minimal schema: only the fields the implementation reads, with `.nullish()`
|
|
201
|
+
// so provider API changes don't break parsing.
|
|
202
|
+
const googleVertexTranscriptionResponseSchema = z.object({
|
|
203
|
+
results: z
|
|
204
|
+
.array(
|
|
205
|
+
z.object({
|
|
206
|
+
alternatives: z
|
|
207
|
+
.array(
|
|
208
|
+
z.object({
|
|
209
|
+
transcript: z.string().nullish(),
|
|
210
|
+
words: z
|
|
211
|
+
.array(
|
|
212
|
+
z.object({
|
|
213
|
+
word: z.string().nullish(),
|
|
214
|
+
startOffset: z.string().nullish(),
|
|
215
|
+
endOffset: z.string().nullish(),
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
.nullish(),
|
|
219
|
+
}),
|
|
220
|
+
)
|
|
221
|
+
.nullish(),
|
|
222
|
+
languageCode: z.string().nullish(),
|
|
223
|
+
}),
|
|
224
|
+
)
|
|
225
|
+
.nullish(),
|
|
226
|
+
metadata: z
|
|
227
|
+
.object({
|
|
228
|
+
totalBilledDuration: z.string().nullish(),
|
|
229
|
+
})
|
|
230
|
+
.nullish(),
|
|
231
|
+
});
|
|
@@ -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
|
-
type FetchFunction,
|
|
12
|
-
lazySchema,
|
|
13
11
|
parseProviderOptions,
|
|
14
12
|
postJsonToApi,
|
|
15
|
-
type Resolvable,
|
|
16
13
|
resolve,
|
|
17
|
-
|
|
14
|
+
type FetchFunction,
|
|
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,33 @@
|
|
|
1
|
-
export type { GoogleVertexEmbeddingModelOptions } from './google-vertex-embedding-options';
|
|
1
|
+
export type { GoogleVertexEmbeddingModelOptions } from './google-vertex-embedding-model-options';
|
|
2
|
+
export type {
|
|
3
|
+
GoogleVertexTranscriptionModelId,
|
|
4
|
+
GoogleVertexTranscriptionModelOptions,
|
|
5
|
+
} from './google-vertex-transcription-model-options';
|
|
2
6
|
export type {
|
|
3
7
|
GoogleVertexImageModelOptions,
|
|
4
8
|
/** @deprecated Use `GoogleVertexImageModelOptions` instead. */
|
|
5
9
|
GoogleVertexImageModelOptions as GoogleVertexImageProviderOptions,
|
|
6
|
-
} from './google-vertex-image-model';
|
|
10
|
+
} from './google-vertex-image-model-options';
|
|
7
11
|
export type {
|
|
8
12
|
GoogleVertexVideoModelOptions,
|
|
9
13
|
/** @deprecated Use `GoogleVertexVideoModelOptions` instead. */
|
|
10
14
|
GoogleVertexVideoModelOptions as GoogleVertexVideoProviderOptions,
|
|
11
|
-
} from './google-vertex-video-model';
|
|
15
|
+
} from './google-vertex-video-model-options';
|
|
12
16
|
export type { GoogleVertexVideoModelId } from './google-vertex-video-settings';
|
|
13
|
-
export {
|
|
17
|
+
export type {
|
|
18
|
+
GoogleVertexSpeechModelId,
|
|
19
|
+
GoogleVertexSpeechModelOptions,
|
|
20
|
+
} from './google-vertex-speech-model-options';
|
|
21
|
+
export {
|
|
22
|
+
createGoogleVertex,
|
|
23
|
+
/** @deprecated Use `createGoogleVertex` instead. */
|
|
24
|
+
createGoogleVertex as createVertex,
|
|
25
|
+
googleVertex,
|
|
26
|
+
/** @deprecated Use `googleVertex` instead. */
|
|
27
|
+
googleVertex as vertex,
|
|
28
|
+
} from './google-vertex-provider';
|
|
14
29
|
export type {
|
|
15
30
|
GoogleVertexProvider,
|
|
16
31
|
GoogleVertexProviderSettings,
|
|
17
|
-
} from './google-vertex-provider
|
|
32
|
+
} from './google-vertex-provider';
|
|
18
33
|
export { VERSION } from './version';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
+
import {
|
|
3
|
+
generateAuthToken,
|
|
4
|
+
type GoogleCredentials,
|
|
5
|
+
} from '../../edge/google-vertex-auth-edge';
|
|
6
|
+
import {
|
|
7
|
+
createGoogleVertexMaas as createVertexMaasOriginal,
|
|
8
|
+
type GoogleVertexMaasProvider,
|
|
9
|
+
type GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,
|
|
10
|
+
} from '../google-vertex-maas-provider';
|
|
11
|
+
export type { GoogleVertexMaasProvider };
|
|
12
|
+
|
|
13
|
+
export interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {
|
|
14
|
+
/**
|
|
15
|
+
* Optional. The Google credentials for the Google Cloud service account. If
|
|
16
|
+
* not provided, the Google Vertex provider will use environment variables to
|
|
17
|
+
* load the credentials.
|
|
18
|
+
*/
|
|
19
|
+
googleCredentials?: GoogleCredentials;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance for Edge runtimes.
|
|
24
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
25
|
+
* Automatically handles Google Cloud authentication.
|
|
26
|
+
*
|
|
27
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
28
|
+
*/
|
|
29
|
+
export function createGoogleVertexMaas(
|
|
30
|
+
options: GoogleVertexMaasProviderSettings = {},
|
|
31
|
+
): GoogleVertexMaasProvider {
|
|
32
|
+
// Create a custom fetch wrapper that adds auth headers
|
|
33
|
+
const customFetch: FetchFunction = async (url, init) => {
|
|
34
|
+
const token = await generateAuthToken(options.googleCredentials);
|
|
35
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
36
|
+
const authHeaders = {
|
|
37
|
+
...resolvedHeaders,
|
|
38
|
+
Authorization: `Bearer ${token}`,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Merge auth headers with existing headers from init
|
|
42
|
+
const fetchInit = {
|
|
43
|
+
...init,
|
|
44
|
+
headers: {
|
|
45
|
+
...init?.headers,
|
|
46
|
+
...authHeaders,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Call the original fetch or user's custom fetch
|
|
51
|
+
return (options.fetch ?? fetch)(url, fetchInit);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return createVertexMaasOriginal({
|
|
55
|
+
...options,
|
|
56
|
+
fetch: customFetch,
|
|
57
|
+
headers: undefined, // Don't pass headers, we handle them in fetch
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Default Google Vertex AI MaaS provider instance for Edge runtimes.
|
|
63
|
+
*/
|
|
64
|
+
export const googleVertexMaas = createGoogleVertexMaas();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createGoogleVertexMaas,
|
|
3
|
+
/** @deprecated Use `createGoogleVertexMaas` instead. */
|
|
4
|
+
createGoogleVertexMaas as createVertexMaas,
|
|
5
|
+
googleVertexMaas,
|
|
6
|
+
/** @deprecated Use `googleVertexMaas` instead. */
|
|
7
|
+
googleVertexMaas as vertexMaas,
|
|
8
|
+
} from './google-vertex-maas-provider-edge';
|
|
9
|
+
export type {
|
|
10
|
+
GoogleVertexMaasProvider,
|
|
11
|
+
GoogleVertexMaasProviderSettings,
|
|
12
|
+
} from './google-vertex-maas-provider-edge';
|
|
13
|
+
export type { GoogleVertexMaasModelId } from '../google-vertex-maas-options';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
2
|
+
export type GoogleVertexMaasModelId =
|
|
3
|
+
| 'deepseek-ai/deepseek-r1-0528-maas'
|
|
4
|
+
| 'deepseek-ai/deepseek-v3.1-maas'
|
|
5
|
+
| 'deepseek-ai/deepseek-v3.2-maas'
|
|
6
|
+
| 'openai/gpt-oss-120b-maas'
|
|
7
|
+
| 'openai/gpt-oss-20b-maas'
|
|
8
|
+
| 'meta/llama-4-maverick-17b-128e-instruct-maas'
|
|
9
|
+
| 'meta/llama-4-scout-17b-16e-instruct-maas'
|
|
10
|
+
| 'minimax/minimax-m2-maas'
|
|
11
|
+
| 'qwen/qwen3-coder-480b-a35b-instruct-maas'
|
|
12
|
+
| 'qwen/qwen3-next-80b-a3b-instruct-maas'
|
|
13
|
+
| 'qwen/qwen3-next-80b-a3b-thinking-maas'
|
|
14
|
+
| 'moonshotai/kimi-k2-thinking-maas'
|
|
15
|
+
| (string & {});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
+
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
3
|
+
import { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';
|
|
4
|
+
import {
|
|
5
|
+
createGoogleVertexMaas as createVertexMaasOriginal,
|
|
6
|
+
type GoogleVertexMaasProvider,
|
|
7
|
+
type GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,
|
|
8
|
+
} from './google-vertex-maas-provider';
|
|
9
|
+
export type { GoogleVertexMaasProvider };
|
|
10
|
+
|
|
11
|
+
export interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {
|
|
12
|
+
/**
|
|
13
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
14
|
+
* Complete list of authentication options is documented in the
|
|
15
|
+
* GoogleAuthOptions interface:
|
|
16
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
17
|
+
*/
|
|
18
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance for Node.js.
|
|
23
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
24
|
+
* Automatically handles Google Cloud authentication.
|
|
25
|
+
*
|
|
26
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
27
|
+
*/
|
|
28
|
+
export function createGoogleVertexMaas(
|
|
29
|
+
options: GoogleVertexMaasProviderSettings = {},
|
|
30
|
+
): GoogleVertexMaasProvider {
|
|
31
|
+
const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);
|
|
32
|
+
|
|
33
|
+
// Create a custom fetch wrapper that adds auth headers
|
|
34
|
+
const customFetch: FetchFunction = async (url, init) => {
|
|
35
|
+
const token = await generateAuthToken();
|
|
36
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
37
|
+
const authHeaders = {
|
|
38
|
+
...resolvedHeaders,
|
|
39
|
+
Authorization: `Bearer ${token}`,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Merge auth headers with existing headers from init
|
|
43
|
+
const fetchInit = {
|
|
44
|
+
...init,
|
|
45
|
+
headers: {
|
|
46
|
+
...init?.headers,
|
|
47
|
+
...authHeaders,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Call the original fetch or user's custom fetch
|
|
52
|
+
return (options.fetch ?? fetch)(url, fetchInit);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return createVertexMaasOriginal({
|
|
56
|
+
...options,
|
|
57
|
+
fetch: customFetch,
|
|
58
|
+
headers: undefined, // Don't pass headers, we handle them in fetch
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Default Google Vertex AI MaaS provider instance for Node.js.
|
|
64
|
+
*/
|
|
65
|
+
export const googleVertexMaas = createGoogleVertexMaas();
|