@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.
@@ -48,19 +48,22 @@ export function annotationToSource({
48
48
  }): LanguageModelV4Source | undefined {
49
49
  switch (annotation.type) {
50
50
  case 'url_citation': {
51
- const a = annotation as GoogleInteractionsURLCitation;
52
- if (a.url == null || a.url.length === 0) return undefined;
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: a.url,
58
- ...(a.title != null ? { title: a.title } : {}),
59
+ url: urlCitation.url,
60
+ ...(urlCitation.title != null ? { title: urlCitation.title } : {}),
59
61
  };
60
62
  }
61
63
  case 'file_citation': {
62
- const a = annotation as GoogleInteractionsFileCitation;
63
- const uri = a.url ?? a.document_uri ?? a.file_name;
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
- ...(a.file_name != null ? { title: a.file_name } : {}),
74
+ ...(fileCitation.file_name != null
75
+ ? { title: fileCitation.file_name }
76
+ : {}),
72
77
  };
73
78
  }
74
- const filename = a.file_name ?? basename(uri);
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: a.file_name ?? filename ?? uri,
86
+ title: fileCitation.file_name ?? filename ?? uri,
82
87
  ...(filename != null ? { filename } : {}),
83
88
  };
84
89
  }
85
90
  case 'place_citation': {
86
- const a = annotation as GoogleInteractionsPlaceCitation;
87
- if (a.url == null || a.url.length === 0) return undefined;
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: a.url,
93
- ...(a.name != null ? { title: a.name } : {}),
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 opts = await parseProviderOptions({
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 (opts?.responseFormat != null) {
211
- for (const entry of opts.responseFormat) {
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: opts?.previousInteractionId ?? undefined,
247
- store: opts?.store ?? undefined,
248
- mediaResolution: opts?.mediaResolution ?? undefined,
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 = opts?.systemInstruction ?? undefined;
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 (opts?.thinkingLevel != null) droppedFields.push('thinkingLevel');
288
- if (opts?.thinkingSummaries != null) {
288
+ if (googleOptions?.thinkingLevel != null)
289
+ droppedFields.push('thinkingLevel');
290
+ if (googleOptions?.thinkingSummaries != null) {
289
291
  droppedFields.push('thinkingSummaries');
290
292
  }
291
- if (opts?.imageConfig != null) droppedFields.push('imageConfig');
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: opts?.thinkingLevel ?? undefined,
310
- thinking_summaries: opts?.thinkingSummaries ?? undefined,
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 (opts?.imageConfig != null) {
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
- ...(opts.imageConfig.aspectRatio != null
335
- ? { aspect_ratio: opts.imageConfig.aspectRatio }
336
+ ...(googleOptions.imageConfig.aspectRatio != null
337
+ ? { aspect_ratio: googleOptions.imageConfig.aspectRatio }
336
338
  : {}),
337
- ...(opts.imageConfig.imageSize != null
338
- ? { image_size: opts.imageConfig.imageSize }
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 && opts?.agentConfig != null) {
347
- const ac = opts.agentConfig;
348
- if (ac.type === 'deep-research') {
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: ac.thinkingSummaries ?? undefined,
352
- visualization: ac.visualization ?? undefined,
353
- collaborative_planning: ac.collaborativePlanning ?? undefined,
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 (ac.type === 'dynamic') {
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 (opts?.environment != null) {
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 opts.environment === 'string') {
369
- environment = opts.environment;
371
+ } else if (typeof googleOptions.environment === 'string') {
372
+ environment = googleOptions.environment;
370
373
  } else {
371
- const env = opts.environment;
374
+ const environmentOptions = googleOptions.environment;
372
375
  const sources: Array<GoogleInteractionsEnvironmentSource> | undefined =
373
- env.sources?.map(s => {
374
- if (s.type === 'inline') {
376
+ environmentOptions.sources?.map(source => {
377
+ if (source.type === 'inline') {
375
378
  return {
376
379
  type: 'inline' as const,
377
- content: s.content,
378
- target: s.target,
380
+ content: source.content,
381
+ target: source.target,
379
382
  };
380
383
  }
381
384
  return pruneUndefined({
382
- type: s.type,
383
- source: s.source,
384
- target: s.target ?? undefined,
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 (env.network === 'disabled') {
391
+ if (environmentOptions.network === 'disabled') {
389
392
  network = 'disabled';
390
- } else if (env.network != null) {
393
+ } else if (environmentOptions.network != null) {
391
394
  network = {
392
- allowlist: env.network.allowlist.map(entry =>
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
- opts?.responseModalities != null
424
- ? (opts.responseModalities as Array<
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: opts?.previousInteractionId ?? undefined,
429
- service_tier: opts?.serviceTier ?? undefined,
430
- store: opts?.store ?? undefined,
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: opts?.background ?? undefined,
441
+ background: googleOptions?.background ?? undefined,
438
442
  });
439
443
 
440
444
  return {
441
445
  args,
442
446
  warnings,
443
447
  isAgent,
444
- isBackground: opts?.background === true,
445
- pollingTimeoutMs: opts?.pollingTimeoutMs ?? undefined,
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 ev = value.value as {
173
+ const streamEvent = value.value as {
174
174
  event_id?: string;
175
175
  event_type?: string;
176
176
  };
177
- if (typeof ev.event_id === 'string' && ev.event_id.length > 0) {
178
- lastEventId = ev.event_id;
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
- ev.event_type === 'interaction.completed' ||
182
- ev.event_type === 'error'
184
+ streamEvent.event_type === 'interaction.completed' ||
185
+ streamEvent.event_type === 'error'
183
186
  ) {
184
187
  complete = true;
185
188
  }