@ai-sdk/google 4.0.0-beta.48 → 4.0.0-beta.49
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 +13 -0
- package/dist/index.d.ts +10 -10
- package/dist/index.js +186 -180
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +103 -110
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +4 -4
- package/package.json +2 -2
- package/src/convert-to-google-messages.ts +32 -14
- package/src/google-embedding-model.ts +1 -1
- package/src/google-image-model-options.ts +23 -0
- package/src/google-image-model.ts +2 -19
- package/src/google-language-model.ts +104 -110
- package/src/google-prepare-tools.ts +1 -1
- package/src/google-provider.ts +2 -2
- package/src/google-video-model-options.ts +43 -0
- package/src/google-video-model.ts +4 -43
- package/src/index.ts +4 -4
- package/src/internal/index.ts +1 -1
- /package/src/{google-embedding-options.ts → google-embedding-model-options.ts} +0 -0
- /package/src/{google-options.ts → google-language-model-options.ts} +0 -0
package/docs/15-google.mdx
CHANGED
|
@@ -625,10 +625,10 @@ the model has access to a compliance-focused web index designed for highly-regul
|
|
|
625
625
|
</Note>
|
|
626
626
|
|
|
627
627
|
```ts
|
|
628
|
-
import {
|
|
628
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
629
629
|
import { generateText } from 'ai';
|
|
630
630
|
|
|
631
|
-
const vertex =
|
|
631
|
+
const vertex = createGoogleVertex({
|
|
632
632
|
project: 'my-project',
|
|
633
633
|
location: 'us-central1',
|
|
634
634
|
});
|
|
@@ -848,11 +848,11 @@ This enables the model to provide answers based on your specific data sources an
|
|
|
848
848
|
</Note>
|
|
849
849
|
|
|
850
850
|
```ts highlight="8,17-20"
|
|
851
|
-
import {
|
|
851
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
852
852
|
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
853
853
|
import { generateText } from 'ai';
|
|
854
854
|
|
|
855
|
-
const vertex =
|
|
855
|
+
const vertex = createGoogleVertex({
|
|
856
856
|
project: 'my-project',
|
|
857
857
|
location: 'us-central1',
|
|
858
858
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.49",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.0-beta.14",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.30"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "20.17.24",
|
|
@@ -171,7 +171,13 @@ export function convertToGoogleMessages(
|
|
|
171
171
|
prompt: LanguageModelV4Prompt,
|
|
172
172
|
options?: {
|
|
173
173
|
isGemmaModel?: boolean;
|
|
174
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Names to look up under `providerOptions` when reading per-part metadata
|
|
176
|
+
* (e.g. thought signatures). Tried in order; first match wins. For the
|
|
177
|
+
* Vertex provider this is `['googleVertex', 'vertex']` (new key first,
|
|
178
|
+
* legacy key as fallback) and for the Google provider it is `['google']`.
|
|
179
|
+
*/
|
|
180
|
+
providerOptionsNames?: readonly string[];
|
|
175
181
|
supportsFunctionResponseParts?: boolean;
|
|
176
182
|
},
|
|
177
183
|
): GooglePrompt {
|
|
@@ -179,10 +185,30 @@ export function convertToGoogleMessages(
|
|
|
179
185
|
const contents: Array<GoogleContent> = [];
|
|
180
186
|
let systemMessagesAllowed = true;
|
|
181
187
|
const isGemmaModel = options?.isGemmaModel ?? false;
|
|
182
|
-
const
|
|
188
|
+
const providerOptionsNames = options?.providerOptionsNames ?? ['google'];
|
|
189
|
+
const isVertexLike = !providerOptionsNames.includes('google');
|
|
183
190
|
const supportsFunctionResponseParts =
|
|
184
191
|
options?.supportsFunctionResponseParts ?? true;
|
|
185
192
|
|
|
193
|
+
const readProviderOpts = (part: {
|
|
194
|
+
providerOptions?: Record<string, unknown> | undefined;
|
|
195
|
+
}): Record<string, unknown> | undefined => {
|
|
196
|
+
for (const name of providerOptionsNames) {
|
|
197
|
+
const v = part.providerOptions?.[name];
|
|
198
|
+
if (v != null) return v as Record<string, unknown>;
|
|
199
|
+
}
|
|
200
|
+
// Cross-namespace fallback (gateway interop): Vertex providers may receive
|
|
201
|
+
// metadata under `google`, and the Google provider may receive metadata
|
|
202
|
+
// under `googleVertex`/`vertex`.
|
|
203
|
+
if (isVertexLike) {
|
|
204
|
+
return part.providerOptions?.google as
|
|
205
|
+
| Record<string, unknown>
|
|
206
|
+
| undefined;
|
|
207
|
+
}
|
|
208
|
+
return (part.providerOptions?.googleVertex ??
|
|
209
|
+
part.providerOptions?.vertex) as Record<string, unknown> | undefined;
|
|
210
|
+
};
|
|
211
|
+
|
|
186
212
|
for (const { role, content } of prompt) {
|
|
187
213
|
switch (role) {
|
|
188
214
|
case 'system': {
|
|
@@ -221,7 +247,7 @@ export function convertToGoogleMessages(
|
|
|
221
247
|
break;
|
|
222
248
|
}
|
|
223
249
|
case 'reference': {
|
|
224
|
-
if (
|
|
250
|
+
if (isVertexLike) {
|
|
225
251
|
throw new UnsupportedFunctionalityError({
|
|
226
252
|
functionality: 'file parts with provider references',
|
|
227
253
|
});
|
|
@@ -278,11 +304,7 @@ export function convertToGoogleMessages(
|
|
|
278
304
|
role: 'model',
|
|
279
305
|
parts: content
|
|
280
306
|
.map(part => {
|
|
281
|
-
const providerOpts =
|
|
282
|
-
part.providerOptions?.[providerOptionsName] ??
|
|
283
|
-
(providerOptionsName !== 'google'
|
|
284
|
-
? part.providerOptions?.google
|
|
285
|
-
: part.providerOptions?.vertex);
|
|
307
|
+
const providerOpts = readProviderOpts(part);
|
|
286
308
|
const thoughtSignature =
|
|
287
309
|
providerOpts?.thoughtSignature != null
|
|
288
310
|
? String(providerOpts.thoughtSignature)
|
|
@@ -339,7 +361,7 @@ export function convertToGoogleMessages(
|
|
|
339
361
|
});
|
|
340
362
|
}
|
|
341
363
|
case 'reference': {
|
|
342
|
-
if (
|
|
364
|
+
if (isVertexLike) {
|
|
343
365
|
throw new UnsupportedFunctionalityError({
|
|
344
366
|
functionality: 'file parts with provider references',
|
|
345
367
|
});
|
|
@@ -466,11 +488,7 @@ export function convertToGoogleMessages(
|
|
|
466
488
|
continue;
|
|
467
489
|
}
|
|
468
490
|
|
|
469
|
-
const partProviderOpts =
|
|
470
|
-
part.providerOptions?.[providerOptionsName] ??
|
|
471
|
-
(providerOptionsName !== 'google'
|
|
472
|
-
? part.providerOptions?.google
|
|
473
|
-
: part.providerOptions?.vertex);
|
|
491
|
+
const partProviderOpts = readProviderOpts(part);
|
|
474
492
|
const serverToolCallId =
|
|
475
493
|
partProviderOpts?.serverToolCallId != null
|
|
476
494
|
? String(partProviderOpts.serverToolCallId)
|
|
@@ -20,7 +20,7 @@ import { googleFailedResponseHandler } from './google-error';
|
|
|
20
20
|
import {
|
|
21
21
|
googleEmbeddingModelOptions,
|
|
22
22
|
type GoogleEmbeddingModelId,
|
|
23
|
-
} from './google-embedding-options';
|
|
23
|
+
} from './google-embedding-model-options';
|
|
24
24
|
type GoogleEmbeddingConfig = {
|
|
25
25
|
provider: string;
|
|
26
26
|
baseURL: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
// Note: For the initial GA launch of Imagen 3, safety filters are not configurable.
|
|
9
|
+
// https://ai.google.dev/gemini-api/docs/imagen#imagen-model
|
|
10
|
+
export const googleImageModelOptionsSchema = lazySchema(() =>
|
|
11
|
+
zodSchema(
|
|
12
|
+
z.object({
|
|
13
|
+
personGeneration: z
|
|
14
|
+
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
15
|
+
.nullish(),
|
|
16
|
+
aspectRatio: z.enum(['1:1', '3:4', '4:3', '9:16', '16:9']).nullish(),
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export type GoogleImageModelOptions = InferSchema<
|
|
22
|
+
typeof googleImageModelOptionsSchema
|
|
23
|
+
>;
|
|
@@ -16,18 +16,18 @@ import {
|
|
|
16
16
|
WORKFLOW_SERIALIZE,
|
|
17
17
|
WORKFLOW_DESERIALIZE,
|
|
18
18
|
zodSchema,
|
|
19
|
-
type InferSchema,
|
|
20
19
|
type FetchFunction,
|
|
21
20
|
type Resolvable,
|
|
22
21
|
} from '@ai-sdk/provider-utils';
|
|
23
22
|
import { z } from 'zod/v4';
|
|
24
23
|
import { googleFailedResponseHandler } from './google-error';
|
|
24
|
+
import { googleImageModelOptionsSchema } from './google-image-model-options';
|
|
25
25
|
import type {
|
|
26
26
|
GoogleImageModelId,
|
|
27
27
|
GoogleImageSettings,
|
|
28
28
|
} from './google-image-settings';
|
|
29
29
|
import { GoogleLanguageModel } from './google-language-model';
|
|
30
|
-
import type { GoogleLanguageModelOptions } from './google-options';
|
|
30
|
+
import type { GoogleLanguageModelOptions } from './google-language-model-options';
|
|
31
31
|
|
|
32
32
|
interface GoogleImageModelConfig {
|
|
33
33
|
provider: string;
|
|
@@ -369,20 +369,3 @@ const googleImageResponseSchema = lazySchema(() =>
|
|
|
369
369
|
}),
|
|
370
370
|
),
|
|
371
371
|
);
|
|
372
|
-
|
|
373
|
-
// Note: For the initial GA launch of Imagen 3, safety filters are not configurable.
|
|
374
|
-
// https://ai.google.dev/gemini-api/docs/imagen#imagen-model
|
|
375
|
-
const googleImageModelOptionsSchema = lazySchema(() =>
|
|
376
|
-
zodSchema(
|
|
377
|
-
z.object({
|
|
378
|
-
personGeneration: z
|
|
379
|
-
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
380
|
-
.nullish(),
|
|
381
|
-
aspectRatio: z.enum(['1:1', '3:4', '4:3', '9:16', '16:9']).nullish(),
|
|
382
|
-
}),
|
|
383
|
-
),
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
export type GoogleImageModelOptions = InferSchema<
|
|
387
|
-
typeof googleImageModelOptionsSchema
|
|
388
|
-
>;
|
|
@@ -44,8 +44,9 @@ import { googleFailedResponseHandler } from './google-error';
|
|
|
44
44
|
import {
|
|
45
45
|
googleLanguageModelOptions,
|
|
46
46
|
VertexServiceTierMap,
|
|
47
|
+
type GoogleLanguageModelOptions,
|
|
47
48
|
type GoogleModelId,
|
|
48
|
-
} from './google-options';
|
|
49
|
+
} from './google-language-model-options';
|
|
49
50
|
import type { GoogleProviderMetadata } from './google-prompt';
|
|
50
51
|
import { prepareTools } from './google-prepare-tools';
|
|
51
52
|
import {
|
|
@@ -124,16 +125,28 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
124
125
|
) {
|
|
125
126
|
const warnings: SharedV4Warning[] = [];
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
// Names to look up in providerOptions and to write into providerMetadata.
|
|
129
|
+
// For the Vertex provider we read both the new `googleVertex` key and the
|
|
130
|
+
// legacy `vertex` key (new takes precedence) and write under both for
|
|
131
|
+
// backward compatibility. For other Google providers we use just `google`.
|
|
132
|
+
const providerOptionsNames: readonly string[] =
|
|
133
|
+
this.config.provider.includes('vertex')
|
|
134
|
+
? (['googleVertex', 'vertex'] as const)
|
|
135
|
+
: (['google'] as const);
|
|
136
|
+
|
|
137
|
+
let googleOptions: GoogleLanguageModelOptions | undefined;
|
|
138
|
+
for (const name of providerOptionsNames) {
|
|
139
|
+
googleOptions = await parseProviderOptions({
|
|
140
|
+
provider: name,
|
|
141
|
+
providerOptions,
|
|
142
|
+
schema: googleLanguageModelOptions,
|
|
143
|
+
});
|
|
144
|
+
if (googleOptions != null) break;
|
|
145
|
+
}
|
|
135
146
|
|
|
136
|
-
|
|
147
|
+
// Cross-namespace fallback: a Vertex provider may receive options under
|
|
148
|
+
// the `google` key (e.g. via the AI Gateway).
|
|
149
|
+
if (googleOptions == null && !providerOptionsNames.includes('google')) {
|
|
137
150
|
googleOptions = await parseProviderOptions({
|
|
138
151
|
provider: 'google',
|
|
139
152
|
providerOptions,
|
|
@@ -181,7 +194,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
181
194
|
|
|
182
195
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
183
196
|
isGemmaModel,
|
|
184
|
-
|
|
197
|
+
providerOptionsNames,
|
|
185
198
|
supportsFunctionResponseParts,
|
|
186
199
|
});
|
|
187
200
|
|
|
@@ -278,14 +291,19 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
278
291
|
serviceTier: sanitizedServiceTier,
|
|
279
292
|
},
|
|
280
293
|
warnings: [...warnings, ...toolWarnings],
|
|
281
|
-
|
|
294
|
+
providerOptionsNames,
|
|
282
295
|
};
|
|
283
296
|
}
|
|
284
297
|
|
|
285
298
|
async doGenerate(
|
|
286
299
|
options: LanguageModelV4CallOptions,
|
|
287
300
|
): Promise<LanguageModelV4GenerateResult> {
|
|
288
|
-
const { args, warnings,
|
|
301
|
+
const { args, warnings, providerOptionsNames } =
|
|
302
|
+
await this.getArgs(options);
|
|
303
|
+
const wrapProviderMetadata = (payload: Record<string, unknown>) =>
|
|
304
|
+
Object.fromEntries(
|
|
305
|
+
providerOptionsNames.map(name => [name, payload]),
|
|
306
|
+
) as SharedV4ProviderMetadata;
|
|
289
307
|
|
|
290
308
|
const mergedHeaders = combineHeaders(
|
|
291
309
|
this.config.headers ? await resolve(this.config.headers) : undefined,
|
|
@@ -349,11 +367,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
349
367
|
lastCodeExecutionToolCallId = undefined;
|
|
350
368
|
} else if ('text' in part && part.text != null) {
|
|
351
369
|
const thoughtSignatureMetadata = part.thoughtSignature
|
|
352
|
-
? {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
},
|
|
356
|
-
}
|
|
370
|
+
? wrapProviderMetadata({
|
|
371
|
+
thoughtSignature: part.thoughtSignature,
|
|
372
|
+
})
|
|
357
373
|
: undefined;
|
|
358
374
|
|
|
359
375
|
if (part.text.length === 0) {
|
|
@@ -379,11 +395,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
379
395
|
toolName: part.functionCall.name,
|
|
380
396
|
input: JSON.stringify(part.functionCall.args),
|
|
381
397
|
providerMetadata: part.thoughtSignature
|
|
382
|
-
? {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
},
|
|
386
|
-
}
|
|
398
|
+
? wrapProviderMetadata({
|
|
399
|
+
thoughtSignature: part.thoughtSignature,
|
|
400
|
+
})
|
|
387
401
|
: undefined,
|
|
388
402
|
});
|
|
389
403
|
} else if ('inlineData' in part) {
|
|
@@ -394,11 +408,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
394
408
|
data: { type: 'data', data: part.inlineData.data },
|
|
395
409
|
mediaType: part.inlineData.mimeType,
|
|
396
410
|
providerMetadata: hasThoughtSignature
|
|
397
|
-
? {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
},
|
|
401
|
-
}
|
|
411
|
+
? wrapProviderMetadata({
|
|
412
|
+
thoughtSignature: part.thoughtSignature,
|
|
413
|
+
})
|
|
402
414
|
: undefined,
|
|
403
415
|
});
|
|
404
416
|
} else if ('toolCall' in part && part.toolCall) {
|
|
@@ -412,19 +424,15 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
412
424
|
providerExecuted: true,
|
|
413
425
|
dynamic: true,
|
|
414
426
|
providerMetadata: part.thoughtSignature
|
|
415
|
-
? {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
serverToolCallId: toolCallId,
|
|
425
|
-
serverToolType: part.toolCall.toolType,
|
|
426
|
-
},
|
|
427
|
-
},
|
|
427
|
+
? wrapProviderMetadata({
|
|
428
|
+
thoughtSignature: part.thoughtSignature,
|
|
429
|
+
serverToolCallId: toolCallId,
|
|
430
|
+
serverToolType: part.toolCall.toolType,
|
|
431
|
+
})
|
|
432
|
+
: wrapProviderMetadata({
|
|
433
|
+
serverToolCallId: toolCallId,
|
|
434
|
+
serverToolType: part.toolCall.toolType,
|
|
435
|
+
}),
|
|
428
436
|
});
|
|
429
437
|
} else if ('toolResponse' in part && part.toolResponse) {
|
|
430
438
|
const responseToolCallId =
|
|
@@ -437,19 +445,15 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
437
445
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
438
446
|
result: (part.toolResponse.response ?? {}) as JSONObject,
|
|
439
447
|
providerMetadata: part.thoughtSignature
|
|
440
|
-
? {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
serverToolCallId: responseToolCallId,
|
|
450
|
-
serverToolType: part.toolResponse.toolType,
|
|
451
|
-
},
|
|
452
|
-
},
|
|
448
|
+
? wrapProviderMetadata({
|
|
449
|
+
thoughtSignature: part.thoughtSignature,
|
|
450
|
+
serverToolCallId: responseToolCallId,
|
|
451
|
+
serverToolType: part.toolResponse.toolType,
|
|
452
|
+
})
|
|
453
|
+
: wrapProviderMetadata({
|
|
454
|
+
serverToolCallId: responseToolCallId,
|
|
455
|
+
serverToolType: part.toolResponse.toolType,
|
|
456
|
+
}),
|
|
453
457
|
});
|
|
454
458
|
lastServerToolCallId = undefined;
|
|
455
459
|
}
|
|
@@ -478,17 +482,15 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
478
482
|
},
|
|
479
483
|
usage: convertGoogleUsage(usageMetadata),
|
|
480
484
|
warnings,
|
|
481
|
-
providerMetadata: {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
} satisfies GoogleProviderMetadata,
|
|
491
|
-
},
|
|
485
|
+
providerMetadata: wrapProviderMetadata({
|
|
486
|
+
promptFeedback: response.promptFeedback ?? null,
|
|
487
|
+
groundingMetadata: candidate.groundingMetadata ?? null,
|
|
488
|
+
urlContextMetadata: candidate.urlContextMetadata ?? null,
|
|
489
|
+
safetyRatings: candidate.safetyRatings ?? null,
|
|
490
|
+
usageMetadata: usageMetadata ?? null,
|
|
491
|
+
finishMessage: candidate.finishMessage ?? null,
|
|
492
|
+
serviceTier: response.serviceTier ?? null,
|
|
493
|
+
} satisfies GoogleProviderMetadata),
|
|
492
494
|
request: { body: args },
|
|
493
495
|
response: {
|
|
494
496
|
// TODO timestamp, model id, id
|
|
@@ -501,10 +503,14 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
501
503
|
async doStream(
|
|
502
504
|
options: LanguageModelV4CallOptions,
|
|
503
505
|
): Promise<LanguageModelV4StreamResult> {
|
|
504
|
-
const { args, warnings,
|
|
506
|
+
const { args, warnings, providerOptionsNames } = await this.getArgs(
|
|
505
507
|
options,
|
|
506
508
|
{ isStreaming: true },
|
|
507
509
|
);
|
|
510
|
+
const wrapProviderMetadata = (payload: Record<string, unknown>) =>
|
|
511
|
+
Object.fromEntries(
|
|
512
|
+
providerOptionsNames.map(name => [name, payload]),
|
|
513
|
+
) as SharedV4ProviderMetadata;
|
|
508
514
|
|
|
509
515
|
const headers = combineHeaders(
|
|
510
516
|
this.config.headers ? await resolve(this.config.headers) : undefined,
|
|
@@ -657,11 +663,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
657
663
|
}
|
|
658
664
|
} else if ('text' in part && part.text != null) {
|
|
659
665
|
const thoughtSignatureMetadata = part.thoughtSignature
|
|
660
|
-
? {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
},
|
|
664
|
-
}
|
|
666
|
+
? wrapProviderMetadata({
|
|
667
|
+
thoughtSignature: part.thoughtSignature,
|
|
668
|
+
})
|
|
665
669
|
: undefined;
|
|
666
670
|
|
|
667
671
|
if (part.text.length === 0) {
|
|
@@ -748,11 +752,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
748
752
|
const hasThought = part.thought === true;
|
|
749
753
|
const hasThoughtSignature = !!part.thoughtSignature;
|
|
750
754
|
const fileMeta = hasThoughtSignature
|
|
751
|
-
? {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
},
|
|
755
|
-
}
|
|
755
|
+
? wrapProviderMetadata({
|
|
756
|
+
thoughtSignature: part.thoughtSignature,
|
|
757
|
+
})
|
|
756
758
|
: undefined;
|
|
757
759
|
controller.enqueue({
|
|
758
760
|
type: hasThought ? 'reasoning-file' : 'file',
|
|
@@ -763,15 +765,13 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
763
765
|
} else if ('toolCall' in part && part.toolCall) {
|
|
764
766
|
const toolCallId = part.toolCall.id ?? generateId();
|
|
765
767
|
lastServerToolCallId = toolCallId;
|
|
766
|
-
const serverMeta = {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
},
|
|
774
|
-
};
|
|
768
|
+
const serverMeta = wrapProviderMetadata({
|
|
769
|
+
...(part.thoughtSignature
|
|
770
|
+
? { thoughtSignature: part.thoughtSignature }
|
|
771
|
+
: {}),
|
|
772
|
+
serverToolCallId: toolCallId,
|
|
773
|
+
serverToolType: part.toolCall.toolType,
|
|
774
|
+
});
|
|
775
775
|
|
|
776
776
|
controller.enqueue({
|
|
777
777
|
type: 'tool-call',
|
|
@@ -787,15 +787,13 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
787
787
|
lastServerToolCallId ??
|
|
788
788
|
part.toolResponse.id ??
|
|
789
789
|
generateId();
|
|
790
|
-
const serverMeta = {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
},
|
|
798
|
-
};
|
|
790
|
+
const serverMeta = wrapProviderMetadata({
|
|
791
|
+
...(part.thoughtSignature
|
|
792
|
+
? { thoughtSignature: part.thoughtSignature }
|
|
793
|
+
: {}),
|
|
794
|
+
serverToolCallId: responseToolCallId,
|
|
795
|
+
serverToolType: part.toolResponse.toolType,
|
|
796
|
+
});
|
|
799
797
|
|
|
800
798
|
controller.enqueue({
|
|
801
799
|
type: 'tool-result',
|
|
@@ -813,11 +811,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
813
811
|
if (!('functionCall' in part)) continue;
|
|
814
812
|
|
|
815
813
|
const providerMeta = part.thoughtSignature
|
|
816
|
-
? {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
},
|
|
820
|
-
}
|
|
814
|
+
? wrapProviderMetadata({
|
|
815
|
+
thoughtSignature: part.thoughtSignature,
|
|
816
|
+
})
|
|
821
817
|
: undefined;
|
|
822
818
|
|
|
823
819
|
const isStreamingChunk =
|
|
@@ -970,17 +966,15 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
970
966
|
raw: candidate.finishReason,
|
|
971
967
|
};
|
|
972
968
|
|
|
973
|
-
providerMetadata = {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
} satisfies GoogleProviderMetadata,
|
|
983
|
-
};
|
|
969
|
+
providerMetadata = wrapProviderMetadata({
|
|
970
|
+
promptFeedback: value.promptFeedback ?? null,
|
|
971
|
+
groundingMetadata: lastGroundingMetadata,
|
|
972
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
973
|
+
safetyRatings: candidate.safetyRatings ?? null,
|
|
974
|
+
usageMetadata: usageMetadata ?? null,
|
|
975
|
+
finishMessage: candidate.finishMessage ?? null,
|
|
976
|
+
serviceTier,
|
|
977
|
+
} satisfies GoogleProviderMetadata);
|
|
984
978
|
}
|
|
985
979
|
},
|
|
986
980
|
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
|
|
7
|
-
import type { GoogleModelId } from './google-options';
|
|
7
|
+
import type { GoogleModelId } from './google-language-model-options';
|
|
8
8
|
|
|
9
9
|
export function prepareTools({
|
|
10
10
|
tools,
|
package/src/google-provider.ts
CHANGED
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
} from '@ai-sdk/provider-utils';
|
|
16
16
|
import { VERSION } from './version';
|
|
17
17
|
import { GoogleEmbeddingModel } from './google-embedding-model';
|
|
18
|
-
import type { GoogleEmbeddingModelId } from './google-embedding-options';
|
|
18
|
+
import type { GoogleEmbeddingModelId } from './google-embedding-model-options';
|
|
19
19
|
import { GoogleLanguageModel } from './google-language-model';
|
|
20
|
-
import type { GoogleModelId } from './google-options';
|
|
20
|
+
import type { GoogleModelId } from './google-language-model-options';
|
|
21
21
|
import { googleTools } from './google-tools';
|
|
22
22
|
|
|
23
23
|
import type {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
export type GoogleVideoModelOptions = {
|
|
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
|
+
|
|
13
|
+
// Reference images (for style/asset reference)
|
|
14
|
+
referenceImages?: Array<{
|
|
15
|
+
bytesBase64Encoded?: string;
|
|
16
|
+
gcsUri?: string;
|
|
17
|
+
}> | null;
|
|
18
|
+
|
|
19
|
+
[key: string]: unknown; // For passthrough
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const googleVideoModelOptionsSchema = lazySchema(() =>
|
|
23
|
+
zodSchema(
|
|
24
|
+
z
|
|
25
|
+
.object({
|
|
26
|
+
pollIntervalMs: z.number().positive().nullish(),
|
|
27
|
+
pollTimeoutMs: z.number().positive().nullish(),
|
|
28
|
+
personGeneration: z
|
|
29
|
+
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
30
|
+
.nullish(),
|
|
31
|
+
negativePrompt: z.string().nullish(),
|
|
32
|
+
referenceImages: z
|
|
33
|
+
.array(
|
|
34
|
+
z.object({
|
|
35
|
+
bytesBase64Encoded: z.string().nullish(),
|
|
36
|
+
gcsUri: z.string().nullish(),
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
.nullish(),
|
|
40
|
+
})
|
|
41
|
+
.passthrough(),
|
|
42
|
+
),
|
|
43
|
+
);
|