@ai-sdk/google 4.0.0-beta.21 → 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.
- package/CHANGELOG.md +15 -0
- package/README.md +2 -0
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +250 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -52
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +40 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +45 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +58 -17
- package/src/google-generative-ai-files.ts +230 -0
- package/src/google-generative-ai-prompt.ts +10 -2
- package/src/google-provider.ts +13 -0
- package/src/index.ts +1 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -174,7 +174,11 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
174
174
|
import {
|
|
175
175
|
UnsupportedFunctionalityError
|
|
176
176
|
} from "@ai-sdk/provider";
|
|
177
|
-
import {
|
|
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
|
-
|
|
313
|
-
|
|
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,
|