@ai-sdk/google 4.0.74 → 4.0.75
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 +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -33
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +30 -25
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +2 -2
- package/package.json +2 -2
- package/src/convert-google-usage.ts +4 -2
- package/src/google-image-model.ts +1 -9
- package/src/google-image-settings.ts +1 -1
- package/src/google-language-model.ts +7 -2
package/dist/internal/index.js
CHANGED
|
@@ -22,18 +22,20 @@ import { z as z3 } from "zod/v4";
|
|
|
22
22
|
// src/convert-google-usage.ts
|
|
23
23
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
24
24
|
function convertGoogleUsage(usage) {
|
|
25
|
-
var _a, _b, _c, _d;
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
26
|
if (usage == null) {
|
|
27
27
|
return createNullLanguageModelUsage();
|
|
28
28
|
}
|
|
29
29
|
const promptTokens = (_a = usage.promptTokenCount) != null ? _a : 0;
|
|
30
30
|
const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
const toolUsePromptTokens = (_c = usage.toolUsePromptTokenCount) != null ? _c : 0;
|
|
32
|
+
const cachedContentTokens = (_d = usage.cachedContentTokenCount) != null ? _d : 0;
|
|
33
|
+
const thoughtsTokens = (_e = usage.thoughtsTokenCount) != null ? _e : 0;
|
|
34
|
+
const inputTokens = promptTokens + toolUsePromptTokens;
|
|
33
35
|
return {
|
|
34
36
|
inputTokens: {
|
|
35
|
-
total:
|
|
36
|
-
noCache:
|
|
37
|
+
total: inputTokens,
|
|
38
|
+
noCache: inputTokens - cachedContentTokens,
|
|
37
39
|
cacheRead: cachedContentTokens,
|
|
38
40
|
cacheWrite: void 0
|
|
39
41
|
},
|
|
@@ -1645,27 +1647,30 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1645
1647
|
providerOptionsNames,
|
|
1646
1648
|
toolNameMapping
|
|
1647
1649
|
}) {
|
|
1648
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t
|
|
1650
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1649
1651
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1650
1652
|
providerOptionsNames.map((name) => [name, payload])
|
|
1651
1653
|
);
|
|
1652
1654
|
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1653
1655
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1654
|
-
const
|
|
1655
|
-
|
|
1656
|
+
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1657
|
+
promptBlockReason
|
|
1658
|
+
) ? promptBlockReason : void 0;
|
|
1659
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
|
|
1660
|
+
const rawFinishReason = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : confirmedPromptBlockReason;
|
|
1656
1661
|
const content = [];
|
|
1657
|
-
const parts = (
|
|
1662
|
+
const parts = (_e = (_d = candidate == null ? void 0 : candidate.content) == null ? void 0 : _d.parts) != null ? _e : [];
|
|
1658
1663
|
const usageMetadata = response.usageMetadata;
|
|
1659
1664
|
let lastCodeExecutionToolCallId;
|
|
1660
1665
|
let lastServerToolCallId;
|
|
1661
1666
|
for (const part of parts) {
|
|
1662
|
-
if ("executableCode" in part && ((
|
|
1667
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
1663
1668
|
const toolCallId = config.generateId();
|
|
1664
1669
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1665
1670
|
content.push({
|
|
1666
1671
|
type: "tool-call",
|
|
1667
1672
|
toolCallId,
|
|
1668
|
-
toolName: (
|
|
1673
|
+
toolName: (_g = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _g : "code_execution",
|
|
1669
1674
|
input: JSON.stringify(part.executableCode),
|
|
1670
1675
|
providerExecuted: true
|
|
1671
1676
|
});
|
|
@@ -1674,10 +1679,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1674
1679
|
type: "tool-result",
|
|
1675
1680
|
// Results correspond to the most recent executable code part.
|
|
1676
1681
|
toolCallId: lastCodeExecutionToolCallId,
|
|
1677
|
-
toolName: (
|
|
1682
|
+
toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
|
|
1678
1683
|
result: {
|
|
1679
1684
|
outcome: part.codeExecutionResult.outcome,
|
|
1680
|
-
output: (
|
|
1685
|
+
output: (_i = part.codeExecutionResult.output) != null ? _i : ""
|
|
1681
1686
|
}
|
|
1682
1687
|
});
|
|
1683
1688
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1701,7 +1706,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1701
1706
|
type: "tool-call",
|
|
1702
1707
|
toolCallId: part.functionCall.id || config.generateId(),
|
|
1703
1708
|
toolName: part.functionCall.name,
|
|
1704
|
-
input: JSON.stringify((
|
|
1709
|
+
input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
|
|
1705
1710
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1706
1711
|
thoughtSignature: part.thoughtSignature
|
|
1707
1712
|
}) : void 0
|
|
@@ -1724,7 +1729,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1724
1729
|
type: "tool-call",
|
|
1725
1730
|
toolCallId,
|
|
1726
1731
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1727
|
-
input: JSON.stringify((
|
|
1732
|
+
input: JSON.stringify((_k = part.toolCall.args) != null ? _k : {}),
|
|
1728
1733
|
providerExecuted: true,
|
|
1729
1734
|
dynamic: true,
|
|
1730
1735
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -1742,7 +1747,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1742
1747
|
type: "tool-result",
|
|
1743
1748
|
toolCallId: responseToolCallId,
|
|
1744
1749
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1745
|
-
result: (
|
|
1750
|
+
result: (_l = part.toolResponse.response) != null ? _l : {},
|
|
1746
1751
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1747
1752
|
thoughtSignature: part.thoughtSignature,
|
|
1748
1753
|
serverToolCallId: responseToolCallId,
|
|
@@ -1755,10 +1760,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1755
1760
|
lastServerToolCallId = void 0;
|
|
1756
1761
|
}
|
|
1757
1762
|
}
|
|
1758
|
-
const sources = (
|
|
1763
|
+
const sources = (_m = extractSources({
|
|
1759
1764
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1760
1765
|
generateId: config.generateId
|
|
1761
|
-
})) != null ?
|
|
1766
|
+
})) != null ? _m : [];
|
|
1762
1767
|
for (const source of sources) {
|
|
1763
1768
|
content.push(source);
|
|
1764
1769
|
}
|
|
@@ -1777,17 +1782,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1777
1782
|
usage: convertGoogleUsage(usageMetadata),
|
|
1778
1783
|
warnings,
|
|
1779
1784
|
providerMetadata: wrapProviderMetadata({
|
|
1780
|
-
promptFeedback: (
|
|
1781
|
-
groundingMetadata: (
|
|
1782
|
-
urlContextMetadata: (
|
|
1783
|
-
safetyRatings: (
|
|
1785
|
+
promptFeedback: (_n = response.promptFeedback) != null ? _n : null,
|
|
1786
|
+
groundingMetadata: (_o = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _o : null,
|
|
1787
|
+
urlContextMetadata: (_p = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _p : null,
|
|
1788
|
+
safetyRatings: (_q = candidate == null ? void 0 : candidate.safetyRatings) != null ? _q : null,
|
|
1784
1789
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1785
|
-
finishMessage: (
|
|
1786
|
-
serviceTier: (
|
|
1790
|
+
finishMessage: (_r = candidate == null ? void 0 : candidate.finishMessage) != null ? _r : null,
|
|
1791
|
+
serviceTier: (_s = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _s : null
|
|
1787
1792
|
}),
|
|
1788
1793
|
response: {
|
|
1789
1794
|
// TODO timestamp, model id
|
|
1790
|
-
id: (
|
|
1795
|
+
id: (_t = response.responseId) != null ? _t : void 0
|
|
1791
1796
|
}
|
|
1792
1797
|
};
|
|
1793
1798
|
}
|