@ai-sdk/google-vertex 5.0.98 → 5.0.100

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/anthropic/edge/index.d.ts +84 -80
  3. package/dist/anthropic/edge/index.d.ts.map +1 -0
  4. package/dist/anthropic/edge/index.js +238 -272
  5. package/dist/anthropic/edge/index.js.map +1 -1
  6. package/dist/anthropic/index.d.ts +69 -66
  7. package/dist/anthropic/index.d.ts.map +1 -0
  8. package/dist/anthropic/index.js +172 -177
  9. package/dist/anthropic/index.js.map +1 -1
  10. package/dist/edge/index.d.ts +206 -194
  11. package/dist/edge/index.d.ts.map +1 -0
  12. package/dist/edge/index.js +1428 -1846
  13. package/dist/edge/index.js.map +1 -1
  14. package/dist/index.d.ts +265 -252
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +1369 -1761
  17. package/dist/index.js.map +1 -1
  18. package/dist/maas/edge/index.d.ts +62 -59
  19. package/dist/maas/edge/index.d.ts.map +1 -0
  20. package/dist/maas/edge/index.js +174 -196
  21. package/dist/maas/edge/index.js.map +1 -1
  22. package/dist/maas/index.d.ts +47 -45
  23. package/dist/maas/index.d.ts.map +1 -0
  24. package/dist/maas/index.js +109 -102
  25. package/dist/maas/index.js.map +1 -1
  26. package/dist/xai/edge/index.d.ts +77 -73
  27. package/dist/xai/edge/index.d.ts.map +1 -0
  28. package/dist/xai/edge/index.js +203 -235
  29. package/dist/xai/edge/index.js.map +1 -1
  30. package/dist/xai/index.d.ts +62 -59
  31. package/dist/xai/index.d.ts.map +1 -0
  32. package/dist/xai/index.js +138 -141
  33. package/dist/xai/index.js.map +1 -1
  34. package/docs/16-google-vertex.mdx +3 -3
  35. package/package.json +11 -11
  36. package/src/anthropic/google-vertex-anthropic-provider.ts +14 -4
  37. package/src/gemini-transcription/google-vertex-gemini-transcription-model.ts +5 -1
  38. package/src/google-vertex-provider-base.ts +28 -15
  39. package/src/google-vertex-transcription-model-options.ts +2 -1
  40. package/src/google-vertex-transcription-model.ts +13 -1
  41. package/src/maas/google-vertex-maas-provider.ts +18 -6
@@ -6,16 +6,18 @@ import {
6
6
  type GoogleInteractionsModelId,
7
7
  type GoogleInteractionsModelInput,
8
8
  } from '@ai-sdk/google/internal';
9
- import type {
10
- Experimental_VideoModelV4,
11
- ImageModelV4,
12
- LanguageModelV4,
13
- ProviderV4,
14
- SpeechModelV4,
15
- TranscriptionModelV4,
9
+ import {
10
+ InvalidArgumentError,
11
+ type Experimental_VideoModelV4,
12
+ type ImageModelV4,
13
+ type LanguageModelV4,
14
+ type ProviderV4,
15
+ type SpeechModelV4,
16
+ type TranscriptionModelV4,
16
17
  } from '@ai-sdk/provider';
17
18
  import {
18
19
  generateId,
20
+ isValidHostnamePart,
19
21
  loadOptionalSetting,
20
22
  loadSetting,
21
23
  normalizeHeaders,
@@ -225,13 +227,22 @@ export function createGoogleVertex(
225
227
  description: 'Google Vertex project',
226
228
  });
227
229
 
228
- const loadGoogleVertexLocation = () =>
229
- loadSetting({
230
+ const loadGoogleVertexLocation = () => {
231
+ const location = loadSetting({
230
232
  settingValue: options.location,
231
233
  settingName: 'location',
232
234
  environmentVariableName: 'GOOGLE_VERTEX_LOCATION',
233
235
  description: 'Google Vertex location',
234
236
  });
237
+ if (!isValidHostnamePart(location)) {
238
+ throw new InvalidArgumentError({
239
+ argument: 'location',
240
+ message:
241
+ 'Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',
242
+ });
243
+ }
244
+ return location;
245
+ };
235
246
 
236
247
  // Tuned models are addressed via their deployed endpoint
237
248
  // `.../locations/{region}/endpoints/{id}` instead of the base-model
@@ -242,6 +253,11 @@ export function createGoogleVertex(
242
253
  return withoutTrailingSlash(options.baseURL) ?? EXPRESS_MODE_BASE_URL;
243
254
  }
244
255
 
256
+ const baseURL = withoutTrailingSlash(options.baseURL);
257
+ if (baseURL != null) {
258
+ return baseURL;
259
+ }
260
+
245
261
  const region = loadGoogleVertexLocation();
246
262
  const project = loadGoogleVertexProject();
247
263
 
@@ -255,12 +271,9 @@ export function createGoogleVertex(
255
271
  }
256
272
  };
257
273
 
258
- return (
259
- withoutTrailingSlash(options.baseURL) ??
260
- `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${
261
- endpoint ? '' : '/publishers/google'
262
- }`
263
- );
274
+ return `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${
275
+ endpoint ? '' : '/publishers/google'
276
+ }`;
264
277
  };
265
278
 
266
279
  const createConfig = (
@@ -32,7 +32,8 @@ export const googleVertexTranscriptionProviderOptionsSchema = z.object({
32
32
 
33
33
  /**
34
34
  * The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
35
- * `'us-central1'`). Defaults to the provider `location`.
35
+ * `'us-central1'`). Defaults to the provider `location`. Must be a single
36
+ * DNS label (letters, digits, and hyphens).
36
37
  *
37
38
  * Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
38
39
  * available in specific Speech-to-Text regions and is not available in the
@@ -1,8 +1,13 @@
1
- import type { SharedV4Warning, TranscriptionModelV4 } from '@ai-sdk/provider';
1
+ import {
2
+ InvalidArgumentError,
3
+ type SharedV4Warning,
4
+ type TranscriptionModelV4,
5
+ } from '@ai-sdk/provider';
2
6
  import {
3
7
  combineHeaders,
4
8
  convertUint8ArrayToBase64,
5
9
  createJsonResponseHandler,
10
+ isValidHostnamePart,
6
11
  parseProviderOptions,
7
12
  postJsonToApi,
8
13
  resolve,
@@ -106,6 +111,13 @@ export class GoogleVertexTranscriptionModel implements TranscriptionModelV4 {
106
111
  }
107
112
 
108
113
  const region = googleOptions?.region ?? this.config.location;
114
+ if (!isValidHostnamePart(region)) {
115
+ throw new InvalidArgumentError({
116
+ argument: googleOptions?.region != null ? 'region' : 'location',
117
+ message:
118
+ 'Invalid Google Cloud Speech-to-Text region. Expected a single DNS label (letters, digits, and hyphens).',
119
+ });
120
+ }
109
121
  const languageCodes = googleOptions?.languageCodes ?? ['auto'];
110
122
 
111
123
  // The recognize API takes base64-encoded audio in the `content` field. A
@@ -1,8 +1,10 @@
1
+ import { InvalidArgumentError } from '@ai-sdk/provider';
1
2
  import {
2
3
  createOpenAICompatible,
3
4
  type OpenAICompatibleProvider,
4
5
  } from '@ai-sdk/openai-compatible';
5
6
  import {
7
+ isValidHostnamePart,
6
8
  loadOptionalSetting,
7
9
  loadSetting,
8
10
  withoutTrailingSlash,
@@ -74,11 +76,21 @@ export function createGoogleVertexMaas(
74
76
  options: GoogleVertexMaasProviderSettings = {},
75
77
  ): GoogleVertexMaasProvider {
76
78
  // Lazy-load settings to support loading from environment variables at runtime
77
- const loadLocation = () =>
78
- loadOptionalSetting({
79
- settingValue: options.location,
80
- environmentVariableName: 'GOOGLE_VERTEX_LOCATION',
81
- });
79
+ const loadLocation = () => {
80
+ const location =
81
+ loadOptionalSetting({
82
+ settingValue: options.location,
83
+ environmentVariableName: 'GOOGLE_VERTEX_LOCATION',
84
+ }) ?? 'global';
85
+ if (!isValidHostnamePart(location)) {
86
+ throw new InvalidArgumentError({
87
+ argument: 'location',
88
+ message:
89
+ 'Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',
90
+ });
91
+ }
92
+ return location;
93
+ };
82
94
 
83
95
  const loadProject = () =>
84
96
  loadSetting({
@@ -100,7 +112,7 @@ export function createGoogleVertexMaas(
100
112
 
101
113
  const constructBaseURL = () => {
102
114
  const projectId = loadProject();
103
- const location = loadLocation() ?? 'global';
115
+ const location = loadLocation();
104
116
 
105
117
  return `https://${getHost(location)}/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
106
118
  };