@ai-sdk/google 4.0.0-beta.46 → 4.0.0-beta.48
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 +21 -0
- package/dist/index.js +123 -77
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +113 -70
- package/dist/internal/index.js.map +1 -1
- package/package.json +6 -5
- package/src/convert-google-usage.ts +1 -1
- package/src/convert-json-schema-to-openapi-schema.ts +1 -1
- package/src/convert-to-google-messages.ts +123 -82
- package/src/google-embedding-model.ts +3 -4
- package/src/google-embedding-options.ts +1 -1
- package/src/google-error.ts +1 -1
- package/src/google-files.ts +3 -6
- package/src/google-image-model.ts +26 -17
- package/src/google-language-model.ts +14 -11
- package/src/google-options.ts +5 -1
- package/src/google-prepare-tools.ts +3 -3
- package/src/google-prompt.ts +2 -2
- package/src/google-provider.ts +6 -6
- package/src/google-video-model.ts +2 -2
- package/src/map-google-finish-reason.ts +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -179,7 +179,8 @@ import {
|
|
|
179
179
|
} from "@ai-sdk/provider";
|
|
180
180
|
import {
|
|
181
181
|
convertToBase64,
|
|
182
|
-
|
|
182
|
+
isFullMediaType,
|
|
183
|
+
resolveFullMediaType,
|
|
183
184
|
resolveProviderReference
|
|
184
185
|
} from "@ai-sdk/provider-utils";
|
|
185
186
|
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
@@ -317,36 +318,53 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
317
318
|
break;
|
|
318
319
|
}
|
|
319
320
|
case "file": {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
});
|
|
328
|
-
} else if (isProviderReference(part.data)) {
|
|
329
|
-
if (providerOptionsName === "vertex") {
|
|
330
|
-
throw new UnsupportedFunctionalityError({
|
|
331
|
-
functionality: "file parts with provider references"
|
|
321
|
+
switch (part.data.type) {
|
|
322
|
+
case "url": {
|
|
323
|
+
parts.push({
|
|
324
|
+
fileData: {
|
|
325
|
+
mimeType: resolveFullMediaType({ part }),
|
|
326
|
+
fileUri: part.data.url.toString()
|
|
327
|
+
}
|
|
332
328
|
});
|
|
329
|
+
break;
|
|
333
330
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
provider: "google"
|
|
340
|
-
})
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
} else {
|
|
344
|
-
parts.push({
|
|
345
|
-
inlineData: {
|
|
346
|
-
mimeType: mediaType,
|
|
347
|
-
data: convertToBase64(part.data)
|
|
331
|
+
case "reference": {
|
|
332
|
+
if (providerOptionsName === "vertex") {
|
|
333
|
+
throw new UnsupportedFunctionalityError({
|
|
334
|
+
functionality: "file parts with provider references"
|
|
335
|
+
});
|
|
348
336
|
}
|
|
349
|
-
|
|
337
|
+
parts.push({
|
|
338
|
+
fileData: {
|
|
339
|
+
mimeType: resolveFullMediaType({ part }),
|
|
340
|
+
fileUri: resolveProviderReference({
|
|
341
|
+
reference: part.data.reference,
|
|
342
|
+
provider: "google"
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
case "text": {
|
|
349
|
+
parts.push({
|
|
350
|
+
inlineData: {
|
|
351
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
352
|
+
data: convertToBase64(
|
|
353
|
+
new TextEncoder().encode(part.data.text)
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
case "data": {
|
|
360
|
+
parts.push({
|
|
361
|
+
inlineData: {
|
|
362
|
+
mimeType: resolveFullMediaType({ part }),
|
|
363
|
+
data: convertToBase64(part.data.data)
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
350
368
|
}
|
|
351
369
|
break;
|
|
352
370
|
}
|
|
@@ -378,52 +396,74 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
378
396
|
};
|
|
379
397
|
}
|
|
380
398
|
case "reasoning-file": {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
399
|
+
switch (part.data.type) {
|
|
400
|
+
case "url": {
|
|
401
|
+
throw new UnsupportedFunctionalityError({
|
|
402
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
case "data": {
|
|
406
|
+
return {
|
|
407
|
+
inlineData: {
|
|
408
|
+
mimeType: part.mediaType,
|
|
409
|
+
data: convertToBase64(part.data.data)
|
|
410
|
+
},
|
|
411
|
+
thought: true,
|
|
412
|
+
thoughtSignature
|
|
413
|
+
};
|
|
414
|
+
}
|
|
385
415
|
}
|
|
386
|
-
|
|
387
|
-
inlineData: {
|
|
388
|
-
mimeType: part.mediaType,
|
|
389
|
-
data: convertToBase64(part.data)
|
|
390
|
-
},
|
|
391
|
-
thought: true,
|
|
392
|
-
thoughtSignature
|
|
393
|
-
};
|
|
416
|
+
break;
|
|
394
417
|
}
|
|
395
418
|
case "file": {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
functionality: "File data URLs in assistant messages are not supported"
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
if (isProviderReference(part.data)) {
|
|
402
|
-
if (providerOptionsName === "vertex") {
|
|
419
|
+
switch (part.data.type) {
|
|
420
|
+
case "url": {
|
|
403
421
|
throw new UnsupportedFunctionalityError({
|
|
404
|
-
functionality: "
|
|
422
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
405
423
|
});
|
|
406
424
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
425
|
+
case "reference": {
|
|
426
|
+
if (providerOptionsName === "vertex") {
|
|
427
|
+
throw new UnsupportedFunctionalityError({
|
|
428
|
+
functionality: "file parts with provider references"
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
fileData: {
|
|
433
|
+
mimeType: part.mediaType,
|
|
434
|
+
fileUri: resolveProviderReference({
|
|
435
|
+
reference: part.data.reference,
|
|
436
|
+
provider: "google"
|
|
437
|
+
})
|
|
438
|
+
},
|
|
439
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
440
|
+
thoughtSignature
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
case "text": {
|
|
444
|
+
return {
|
|
445
|
+
inlineData: {
|
|
446
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
447
|
+
data: convertToBase64(
|
|
448
|
+
new TextEncoder().encode(part.data.text)
|
|
449
|
+
)
|
|
450
|
+
},
|
|
451
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
452
|
+
thoughtSignature
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
case "data": {
|
|
456
|
+
return {
|
|
457
|
+
inlineData: {
|
|
458
|
+
mimeType: part.mediaType,
|
|
459
|
+
data: convertToBase64(part.data.data)
|
|
460
|
+
},
|
|
461
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
462
|
+
thoughtSignature
|
|
463
|
+
};
|
|
464
|
+
}
|
|
418
465
|
}
|
|
419
|
-
|
|
420
|
-
inlineData: {
|
|
421
|
-
mimeType: part.mediaType,
|
|
422
|
-
data: convertToBase64(part.data)
|
|
423
|
-
},
|
|
424
|
-
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
425
|
-
thoughtSignature
|
|
426
|
-
};
|
|
466
|
+
break;
|
|
427
467
|
}
|
|
428
468
|
case "tool-call": {
|
|
429
469
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
@@ -559,7 +599,10 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
559
599
|
});
|
|
560
600
|
|
|
561
601
|
// src/google-options.ts
|
|
562
|
-
import {
|
|
602
|
+
import {
|
|
603
|
+
lazySchema as lazySchema2,
|
|
604
|
+
zodSchema as zodSchema2
|
|
605
|
+
} from "@ai-sdk/provider-utils";
|
|
563
606
|
import { z as z2 } from "zod/v4";
|
|
564
607
|
var googleLanguageModelOptions = lazySchema2(
|
|
565
608
|
() => zodSchema2(
|
|
@@ -1445,7 +1488,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1445
1488
|
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1446
1489
|
content.push({
|
|
1447
1490
|
type: hasThought ? "reasoning-file" : "file",
|
|
1448
|
-
data: part.inlineData.data,
|
|
1491
|
+
data: { type: "data", data: part.inlineData.data },
|
|
1449
1492
|
mediaType: part.inlineData.mimeType,
|
|
1450
1493
|
providerMetadata: hasThoughtSignature ? {
|
|
1451
1494
|
[providerOptionsName]: {
|
|
@@ -1735,7 +1778,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1735
1778
|
controller.enqueue({
|
|
1736
1779
|
type: hasThought ? "reasoning-file" : "file",
|
|
1737
1780
|
mediaType: part.inlineData.mimeType,
|
|
1738
|
-
data: part.inlineData.data,
|
|
1781
|
+
data: { type: "data", data: part.inlineData.data },
|
|
1739
1782
|
providerMetadata: fileMeta
|
|
1740
1783
|
});
|
|
1741
1784
|
} else if ("toolCall" in part && part.toolCall) {
|