@ai-sdk/google 4.0.0-beta.22 → 4.0.0-beta.23

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.
@@ -174,7 +174,11 @@ function isEmptyObjectSchema(jsonSchema) {
174
174
  import {
175
175
  UnsupportedFunctionalityError
176
176
  } from "@ai-sdk/provider";
177
- import { convertToBase64 } from "@ai-sdk/provider-utils";
177
+ import {
178
+ convertToBase64,
179
+ isProviderReference,
180
+ resolveProviderReference
181
+ } from "@ai-sdk/provider-utils";
178
182
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
179
183
  function parseBase64DataUrl(value) {
180
184
  const match = dataUrlRegex.exec(value);
@@ -309,19 +313,36 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
309
313
  }
310
314
  case "file": {
311
315
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
312
- parts.push(
313
- part.data instanceof URL ? {
316
+ if (part.data instanceof URL) {
317
+ parts.push({
314
318
  fileData: {
315
319
  mimeType: mediaType,
316
320
  fileUri: part.data.toString()
317
321
  }
318
- } : {
322
+ });
323
+ } else if (isProviderReference(part.data)) {
324
+ if (providerOptionsName === "vertex") {
325
+ throw new UnsupportedFunctionalityError({
326
+ functionality: "file parts with provider references"
327
+ });
328
+ }
329
+ parts.push({
330
+ fileData: {
331
+ mimeType: mediaType,
332
+ fileUri: resolveProviderReference({
333
+ reference: part.data,
334
+ provider: "google"
335
+ })
336
+ }
337
+ });
338
+ } else {
339
+ parts.push({
319
340
  inlineData: {
320
341
  mimeType: mediaType,
321
342
  data: convertToBase64(part.data)
322
343
  }
323
- }
324
- );
344
+ });
345
+ }
325
346
  break;
326
347
  }
327
348
  }
@@ -372,6 +393,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
372
393
  functionality: "File data URLs in assistant messages are not supported"
373
394
  });
374
395
  }
396
+ if (isProviderReference(part.data)) {
397
+ if (providerOptionsName === "vertex") {
398
+ throw new UnsupportedFunctionalityError({
399
+ functionality: "file parts with provider references"
400
+ });
401
+ }
402
+ return {
403
+ fileData: {
404
+ mimeType: part.mediaType,
405
+ fileUri: resolveProviderReference({
406
+ reference: part.data,
407
+ provider: "google"
408
+ })
409
+ },
410
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
411
+ thoughtSignature
412
+ };
413
+ }
375
414
  return {
376
415
  inlineData: {
377
416
  mimeType: part.mediaType,