@ai-sdk/google 4.0.0-canary.74 → 4.0.0-canary.76
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 +12 -0
- package/dist/index.d.ts +27 -4
- package/dist/index.js +638 -366
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +10 -10
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +78 -0
- package/package.json +1 -1
- package/src/google-embedding-model-options.ts +1 -0
- package/src/google-json-accumulator.ts +10 -10
- package/src/google-language-model-options.ts +2 -0
- package/src/google-provider.ts +23 -0
- package/src/google-speech-api.ts +36 -0
- package/src/google-speech-model-options.ts +48 -0
- package/src/google-speech-model.ts +286 -0
- package/src/index.ts +4 -0
- package/src/interactions/build-google-interactions-stream-transform.ts +7 -7
- package/src/interactions/extract-google-interactions-sources.ts +20 -13
- package/src/interactions/google-interactions-language-model.ts +50 -46
- package/src/interactions/stream-google-interactions.ts +8 -5
|
@@ -48,19 +48,22 @@ export function annotationToSource({
|
|
|
48
48
|
}): LanguageModelV4Source | undefined {
|
|
49
49
|
switch (annotation.type) {
|
|
50
50
|
case 'url_citation': {
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
51
|
+
const urlCitation = annotation as GoogleInteractionsURLCitation;
|
|
52
|
+
if (urlCitation.url == null || urlCitation.url.length === 0) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
53
55
|
return {
|
|
54
56
|
type: 'source',
|
|
55
57
|
sourceType: 'url',
|
|
56
58
|
id: generateId(),
|
|
57
|
-
url:
|
|
58
|
-
...(
|
|
59
|
+
url: urlCitation.url,
|
|
60
|
+
...(urlCitation.title != null ? { title: urlCitation.title } : {}),
|
|
59
61
|
};
|
|
60
62
|
}
|
|
61
63
|
case 'file_citation': {
|
|
62
|
-
const
|
|
63
|
-
const uri =
|
|
64
|
+
const fileCitation = annotation as GoogleInteractionsFileCitation;
|
|
65
|
+
const uri =
|
|
66
|
+
fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
|
|
64
67
|
if (uri == null || uri.length === 0) return undefined;
|
|
65
68
|
if (uri.startsWith('http://') || uri.startsWith('https://')) {
|
|
66
69
|
return {
|
|
@@ -68,29 +71,33 @@ export function annotationToSource({
|
|
|
68
71
|
sourceType: 'url',
|
|
69
72
|
id: generateId(),
|
|
70
73
|
url: uri,
|
|
71
|
-
...(
|
|
74
|
+
...(fileCitation.file_name != null
|
|
75
|
+
? { title: fileCitation.file_name }
|
|
76
|
+
: {}),
|
|
72
77
|
};
|
|
73
78
|
}
|
|
74
|
-
const filename =
|
|
79
|
+
const filename = fileCitation.file_name ?? basename(uri);
|
|
75
80
|
const mediaType = inferDocMediaType(uri);
|
|
76
81
|
return {
|
|
77
82
|
type: 'source',
|
|
78
83
|
sourceType: 'document',
|
|
79
84
|
id: generateId(),
|
|
80
85
|
mediaType,
|
|
81
|
-
title:
|
|
86
|
+
title: fileCitation.file_name ?? filename ?? uri,
|
|
82
87
|
...(filename != null ? { filename } : {}),
|
|
83
88
|
};
|
|
84
89
|
}
|
|
85
90
|
case 'place_citation': {
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
91
|
+
const placeCitation = annotation as GoogleInteractionsPlaceCitation;
|
|
92
|
+
if (placeCitation.url == null || placeCitation.url.length === 0) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
88
95
|
return {
|
|
89
96
|
type: 'source',
|
|
90
97
|
sourceType: 'url',
|
|
91
98
|
id: generateId(),
|
|
92
|
-
url:
|
|
93
|
-
...(
|
|
99
|
+
url: placeCitation.url,
|
|
100
|
+
...(placeCitation.name != null ? { title: placeCitation.name } : {}),
|
|
94
101
|
};
|
|
95
102
|
}
|
|
96
103
|
default:
|
|
@@ -142,7 +142,7 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
142
142
|
private async getArgs(options: LanguageModelV4CallOptions) {
|
|
143
143
|
const warnings: Array<SharedV4Warning> = [];
|
|
144
144
|
|
|
145
|
-
const
|
|
145
|
+
const googleOptions = await parseProviderOptions({
|
|
146
146
|
provider: 'google',
|
|
147
147
|
providerOptions: options.providerOptions,
|
|
148
148
|
schema: googleInteractionsLanguageModelOptions,
|
|
@@ -207,8 +207,8 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
if (
|
|
211
|
-
for (const entry of
|
|
210
|
+
if (googleOptions?.responseFormat != null) {
|
|
211
|
+
for (const entry of googleOptions.responseFormat) {
|
|
212
212
|
if (entry.type === 'text') {
|
|
213
213
|
responseFormatEntries.push(
|
|
214
214
|
pruneUndefined({
|
|
@@ -243,15 +243,16 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
243
243
|
warnings: convWarnings,
|
|
244
244
|
} = convertToGoogleInteractionsInput({
|
|
245
245
|
prompt: options.prompt,
|
|
246
|
-
previousInteractionId:
|
|
247
|
-
store:
|
|
248
|
-
mediaResolution:
|
|
246
|
+
previousInteractionId: googleOptions?.previousInteractionId ?? undefined,
|
|
247
|
+
store: googleOptions?.store ?? undefined,
|
|
248
|
+
mediaResolution: googleOptions?.mediaResolution ?? undefined,
|
|
249
249
|
});
|
|
250
250
|
|
|
251
251
|
warnings.push(...convWarnings);
|
|
252
252
|
|
|
253
253
|
let systemInstruction = convertedSystemInstruction;
|
|
254
|
-
const optionSystemInstruction =
|
|
254
|
+
const optionSystemInstruction =
|
|
255
|
+
googleOptions?.systemInstruction ?? undefined;
|
|
255
256
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
256
257
|
warnings.push({
|
|
257
258
|
type: 'other',
|
|
@@ -284,11 +285,12 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
284
285
|
}
|
|
285
286
|
if (options.maxOutputTokens != null)
|
|
286
287
|
droppedFields.push('maxOutputTokens');
|
|
287
|
-
if (
|
|
288
|
-
|
|
288
|
+
if (googleOptions?.thinkingLevel != null)
|
|
289
|
+
droppedFields.push('thinkingLevel');
|
|
290
|
+
if (googleOptions?.thinkingSummaries != null) {
|
|
289
291
|
droppedFields.push('thinkingSummaries');
|
|
290
292
|
}
|
|
291
|
-
if (
|
|
293
|
+
if (googleOptions?.imageConfig != null) droppedFields.push('imageConfig');
|
|
292
294
|
if (droppedFields.length > 0) {
|
|
293
295
|
warnings.push({
|
|
294
296
|
type: 'other',
|
|
@@ -306,8 +308,8 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
306
308
|
? options.stopSequences
|
|
307
309
|
: undefined,
|
|
308
310
|
max_output_tokens: options.maxOutputTokens ?? undefined,
|
|
309
|
-
thinking_level:
|
|
310
|
-
thinking_summaries:
|
|
311
|
+
thinking_level: googleOptions?.thinkingLevel ?? undefined,
|
|
312
|
+
thinking_summaries: googleOptions?.thinkingSummaries ?? undefined,
|
|
311
313
|
tool_choice: toolChoiceForBody,
|
|
312
314
|
});
|
|
313
315
|
|
|
@@ -317,7 +319,7 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
317
319
|
* always emitted when `imageConfig` is set so callers migrate to the
|
|
318
320
|
* `responseFormat` shape.
|
|
319
321
|
*/
|
|
320
|
-
if (
|
|
322
|
+
if (googleOptions?.imageConfig != null) {
|
|
321
323
|
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
322
324
|
entry => entry.type === 'image',
|
|
323
325
|
);
|
|
@@ -331,11 +333,11 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
331
333
|
responseFormatEntries.push({
|
|
332
334
|
type: 'image',
|
|
333
335
|
mime_type: 'image/png',
|
|
334
|
-
...(
|
|
335
|
-
? { aspect_ratio:
|
|
336
|
+
...(googleOptions.imageConfig.aspectRatio != null
|
|
337
|
+
? { aspect_ratio: googleOptions.imageConfig.aspectRatio }
|
|
336
338
|
: {}),
|
|
337
|
-
...(
|
|
338
|
-
? { image_size:
|
|
339
|
+
...(googleOptions.imageConfig.imageSize != null
|
|
340
|
+
? { image_size: googleOptions.imageConfig.imageSize }
|
|
339
341
|
: {}),
|
|
340
342
|
});
|
|
341
343
|
}
|
|
@@ -343,53 +345,54 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
343
345
|
}
|
|
344
346
|
|
|
345
347
|
let agentConfig: GoogleInteractionsAgentConfig | undefined;
|
|
346
|
-
if (isAgent &&
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
348
|
+
if (isAgent && googleOptions?.agentConfig != null) {
|
|
349
|
+
const agentConfigOptions = googleOptions.agentConfig;
|
|
350
|
+
if (agentConfigOptions.type === 'deep-research') {
|
|
349
351
|
agentConfig = pruneUndefined({
|
|
350
352
|
type: 'deep-research',
|
|
351
|
-
thinking_summaries:
|
|
352
|
-
visualization:
|
|
353
|
-
collaborative_planning:
|
|
353
|
+
thinking_summaries: agentConfigOptions.thinkingSummaries ?? undefined,
|
|
354
|
+
visualization: agentConfigOptions.visualization ?? undefined,
|
|
355
|
+
collaborative_planning:
|
|
356
|
+
agentConfigOptions.collaborativePlanning ?? undefined,
|
|
354
357
|
}) as GoogleInteractionsAgentConfig;
|
|
355
|
-
} else if (
|
|
358
|
+
} else if (agentConfigOptions.type === 'dynamic') {
|
|
356
359
|
agentConfig = { type: 'dynamic' };
|
|
357
360
|
}
|
|
358
361
|
}
|
|
359
362
|
|
|
360
363
|
let environment: GoogleInteractionsRequestBody['environment'];
|
|
361
|
-
if (
|
|
364
|
+
if (googleOptions?.environment != null) {
|
|
362
365
|
if (!isAgent) {
|
|
363
366
|
warnings.push({
|
|
364
367
|
type: 'other',
|
|
365
368
|
message:
|
|
366
369
|
'google.interactions: environment is only supported when an agent is set; environment will be omitted from the request body.',
|
|
367
370
|
});
|
|
368
|
-
} else if (typeof
|
|
369
|
-
environment =
|
|
371
|
+
} else if (typeof googleOptions.environment === 'string') {
|
|
372
|
+
environment = googleOptions.environment;
|
|
370
373
|
} else {
|
|
371
|
-
const
|
|
374
|
+
const environmentOptions = googleOptions.environment;
|
|
372
375
|
const sources: Array<GoogleInteractionsEnvironmentSource> | undefined =
|
|
373
|
-
|
|
374
|
-
if (
|
|
376
|
+
environmentOptions.sources?.map(source => {
|
|
377
|
+
if (source.type === 'inline') {
|
|
375
378
|
return {
|
|
376
379
|
type: 'inline' as const,
|
|
377
|
-
content:
|
|
378
|
-
target:
|
|
380
|
+
content: source.content,
|
|
381
|
+
target: source.target,
|
|
379
382
|
};
|
|
380
383
|
}
|
|
381
384
|
return pruneUndefined({
|
|
382
|
-
type:
|
|
383
|
-
source:
|
|
384
|
-
target:
|
|
385
|
+
type: source.type,
|
|
386
|
+
source: source.source,
|
|
387
|
+
target: source.target ?? undefined,
|
|
385
388
|
}) as GoogleInteractionsEnvironmentSource;
|
|
386
389
|
});
|
|
387
390
|
let network: GoogleInteractionsNetworkConfig | undefined;
|
|
388
|
-
if (
|
|
391
|
+
if (environmentOptions.network === 'disabled') {
|
|
389
392
|
network = 'disabled';
|
|
390
|
-
} else if (
|
|
393
|
+
} else if (environmentOptions.network != null) {
|
|
391
394
|
network = {
|
|
392
|
-
allowlist:
|
|
395
|
+
allowlist: environmentOptions.network.allowlist.map(entry =>
|
|
393
396
|
pruneUndefined({
|
|
394
397
|
domain: entry.domain,
|
|
395
398
|
transform: entry.transform ?? undefined,
|
|
@@ -420,29 +423,30 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
|
|
|
420
423
|
response_format:
|
|
421
424
|
responseFormatEntries.length > 0 ? responseFormatEntries : undefined,
|
|
422
425
|
response_modalities:
|
|
423
|
-
|
|
424
|
-
? (
|
|
426
|
+
googleOptions?.responseModalities != null
|
|
427
|
+
? (googleOptions.responseModalities as Array<
|
|
425
428
|
'text' | 'image' | 'audio' | 'video' | 'document'
|
|
426
429
|
>)
|
|
427
430
|
: undefined,
|
|
428
|
-
previous_interaction_id:
|
|
429
|
-
|
|
430
|
-
|
|
431
|
+
previous_interaction_id:
|
|
432
|
+
googleOptions?.previousInteractionId ?? undefined,
|
|
433
|
+
service_tier: googleOptions?.serviceTier ?? undefined,
|
|
434
|
+
store: googleOptions?.store ?? undefined,
|
|
431
435
|
generation_config:
|
|
432
436
|
generationConfig != null && Object.keys(generationConfig).length > 0
|
|
433
437
|
? generationConfig
|
|
434
438
|
: undefined,
|
|
435
439
|
agent_config: agentConfig,
|
|
436
440
|
environment,
|
|
437
|
-
background:
|
|
441
|
+
background: googleOptions?.background ?? undefined,
|
|
438
442
|
});
|
|
439
443
|
|
|
440
444
|
return {
|
|
441
445
|
args,
|
|
442
446
|
warnings,
|
|
443
447
|
isAgent,
|
|
444
|
-
isBackground:
|
|
445
|
-
pollingTimeoutMs:
|
|
448
|
+
isBackground: googleOptions?.background === true,
|
|
449
|
+
pollingTimeoutMs: googleOptions?.pollingTimeoutMs ?? undefined,
|
|
446
450
|
};
|
|
447
451
|
}
|
|
448
452
|
|
|
@@ -170,16 +170,19 @@ export function streamGoogleInteractionEvents({
|
|
|
170
170
|
receivedAnyEventThisAttempt = true;
|
|
171
171
|
|
|
172
172
|
if (value.success) {
|
|
173
|
-
const
|
|
173
|
+
const streamEvent = value.value as {
|
|
174
174
|
event_id?: string;
|
|
175
175
|
event_type?: string;
|
|
176
176
|
};
|
|
177
|
-
if (
|
|
178
|
-
|
|
177
|
+
if (
|
|
178
|
+
typeof streamEvent.event_id === 'string' &&
|
|
179
|
+
streamEvent.event_id.length > 0
|
|
180
|
+
) {
|
|
181
|
+
lastEventId = streamEvent.event_id;
|
|
179
182
|
}
|
|
180
183
|
if (
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
streamEvent.event_type === 'interaction.completed' ||
|
|
185
|
+
streamEvent.event_type === 'error'
|
|
183
186
|
) {
|
|
184
187
|
complete = true;
|
|
185
188
|
}
|