@ai-sdk/google-vertex 4.0.231 → 4.0.233

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.
@@ -1,4 +1,8 @@
1
- import type { SharedV3Warning, TranscriptionModelV3 } from '@ai-sdk/provider';
1
+ import {
2
+ InvalidArgumentError,
3
+ type SharedV3Warning,
4
+ type TranscriptionModelV3,
5
+ } from '@ai-sdk/provider';
2
6
  import {
3
7
  lazySchema,
4
8
  zodSchema,
@@ -91,6 +95,16 @@ export class GoogleVertexTranscriptionModel implements TranscriptionModelV3 {
91
95
  }
92
96
 
93
97
  const region = googleOptions?.region ?? this.config.location;
98
+ // Compare the full match because `$` also matches before a final newline.
99
+ if (
100
+ /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.exec(region)?.[0] !== region
101
+ ) {
102
+ throw new InvalidArgumentError({
103
+ argument: googleOptions?.region != null ? 'region' : 'location',
104
+ message:
105
+ 'Invalid Google Cloud Speech-to-Text region. Expected a single DNS label (letters, digits, and hyphens).',
106
+ });
107
+ }
94
108
  const languageCodes = googleOptions?.languageCodes ?? ['auto'];
95
109
 
96
110
  // The recognize API takes base64-encoded audio in the `content` field. A
@@ -125,6 +139,13 @@ export class GoogleVertexTranscriptionModel implements TranscriptionModelV3 {
125
139
  `https://${host}/v2/projects/` +
126
140
  `${this.config.project}/locations/${region}/recognizers/_:recognize`;
127
141
 
142
+ if (new URL(url).origin !== `https://${host.toLowerCase()}`) {
143
+ throw new InvalidArgumentError({
144
+ argument: googleOptions?.region != null ? 'region' : 'location',
145
+ message: 'Invalid Google Cloud Speech-to-Text endpoint origin.',
146
+ });
147
+ }
148
+
128
149
  const {
129
150
  value: response,
130
151
  responseHeaders,