@ai-sdk/google 3.0.122 → 3.0.124
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 +12 -0
- package/dist/index.js +82 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -76
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +81 -75
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +81 -75
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/google-generative-ai-language-model.ts +70 -53
package/dist/internal/index.js
CHANGED
|
@@ -1674,7 +1674,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1674
1674
|
};
|
|
1675
1675
|
}
|
|
1676
1676
|
async doGenerate(options) {
|
|
1677
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u
|
|
1677
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
1678
1678
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
1679
1679
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
1680
1680
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
@@ -1698,15 +1698,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1698
1698
|
});
|
|
1699
1699
|
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1700
1700
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1701
|
-
const
|
|
1702
|
-
|
|
1701
|
+
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1702
|
+
promptBlockReason
|
|
1703
|
+
) ? promptBlockReason : void 0;
|
|
1704
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
|
|
1705
|
+
const rawFinishReason = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : confirmedPromptBlockReason;
|
|
1703
1706
|
const content = [];
|
|
1704
|
-
const parts = (
|
|
1707
|
+
const parts = (_e = (_d = candidate == null ? void 0 : candidate.content) == null ? void 0 : _d.parts) != null ? _e : [];
|
|
1705
1708
|
const usageMetadata = response.usageMetadata;
|
|
1706
1709
|
let lastCodeExecutionToolCallId;
|
|
1707
1710
|
let lastServerToolCallId;
|
|
1708
1711
|
for (const part of parts) {
|
|
1709
|
-
if ("executableCode" in part && ((
|
|
1712
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
1710
1713
|
const toolCallId = this.config.generateId();
|
|
1711
1714
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1712
1715
|
content.push({
|
|
@@ -1724,7 +1727,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1724
1727
|
toolName: "code_execution",
|
|
1725
1728
|
result: {
|
|
1726
1729
|
outcome: part.codeExecutionResult.outcome,
|
|
1727
|
-
output: (
|
|
1730
|
+
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|
|
1728
1731
|
}
|
|
1729
1732
|
});
|
|
1730
1733
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1748,9 +1751,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1748
1751
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1749
1752
|
content.push({
|
|
1750
1753
|
type: "tool-call",
|
|
1751
|
-
toolCallId: (
|
|
1754
|
+
toolCallId: (_h = part.functionCall.id) != null ? _h : this.config.generateId(),
|
|
1752
1755
|
toolName: part.functionCall.name,
|
|
1753
|
-
input: JSON.stringify((
|
|
1756
|
+
input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
|
|
1754
1757
|
providerMetadata: part.thoughtSignature ? {
|
|
1755
1758
|
[providerOptionsName]: {
|
|
1756
1759
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1772,13 +1775,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1772
1775
|
} : void 0
|
|
1773
1776
|
});
|
|
1774
1777
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1775
|
-
const toolCallId = (
|
|
1778
|
+
const toolCallId = (_j = part.toolCall.id) != null ? _j : this.config.generateId();
|
|
1776
1779
|
lastServerToolCallId = toolCallId;
|
|
1777
1780
|
content.push({
|
|
1778
1781
|
type: "tool-call",
|
|
1779
1782
|
toolCallId,
|
|
1780
1783
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1781
|
-
input: JSON.stringify((
|
|
1784
|
+
input: JSON.stringify((_k = part.toolCall.args) != null ? _k : {}),
|
|
1782
1785
|
providerExecuted: true,
|
|
1783
1786
|
dynamic: true,
|
|
1784
1787
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1795,12 +1798,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1795
1798
|
}
|
|
1796
1799
|
});
|
|
1797
1800
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1798
|
-
const responseToolCallId = (
|
|
1801
|
+
const responseToolCallId = (_l = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _l : this.config.generateId();
|
|
1799
1802
|
content.push({
|
|
1800
1803
|
type: "tool-result",
|
|
1801
1804
|
toolCallId: responseToolCallId,
|
|
1802
1805
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1803
|
-
result: (
|
|
1806
|
+
result: (_m = part.toolResponse.response) != null ? _m : {},
|
|
1804
1807
|
providerMetadata: part.thoughtSignature ? {
|
|
1805
1808
|
[providerOptionsName]: {
|
|
1806
1809
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1817,10 +1820,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1817
1820
|
lastServerToolCallId = void 0;
|
|
1818
1821
|
}
|
|
1819
1822
|
}
|
|
1820
|
-
const sources = (
|
|
1823
|
+
const sources = (_n = extractSources({
|
|
1821
1824
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1822
1825
|
generateId: this.config.generateId
|
|
1823
|
-
})) != null ?
|
|
1826
|
+
})) != null ? _n : [];
|
|
1824
1827
|
for (const source of sources) {
|
|
1825
1828
|
content.push(source);
|
|
1826
1829
|
}
|
|
@@ -1840,19 +1843,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1840
1843
|
warnings,
|
|
1841
1844
|
providerMetadata: {
|
|
1842
1845
|
[providerOptionsName]: {
|
|
1843
|
-
promptFeedback: (
|
|
1844
|
-
groundingMetadata: (
|
|
1845
|
-
urlContextMetadata: (
|
|
1846
|
-
safetyRatings: (
|
|
1846
|
+
promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
|
|
1847
|
+
groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
|
|
1848
|
+
urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
|
|
1849
|
+
safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
|
|
1847
1850
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1848
|
-
finishMessage: (
|
|
1849
|
-
serviceTier: (
|
|
1851
|
+
finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
|
|
1852
|
+
serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
|
|
1850
1853
|
}
|
|
1851
1854
|
},
|
|
1852
1855
|
request: { body: args },
|
|
1853
1856
|
response: {
|
|
1854
1857
|
// TODO timestamp, model id
|
|
1855
|
-
id: (
|
|
1858
|
+
id: (_u = response.responseId) != null ? _u : void 0,
|
|
1856
1859
|
headers: responseHeaders,
|
|
1857
1860
|
body: rawResponse
|
|
1858
1861
|
}
|
|
@@ -1881,9 +1884,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1881
1884
|
raw: void 0
|
|
1882
1885
|
};
|
|
1883
1886
|
let usage = void 0;
|
|
1884
|
-
let
|
|
1887
|
+
let promptFeedback = null;
|
|
1885
1888
|
let lastGroundingMetadata = null;
|
|
1886
1889
|
let lastUrlContextMetadata = null;
|
|
1890
|
+
let lastSafetyRatings = null;
|
|
1891
|
+
let lastFinishMessage = null;
|
|
1892
|
+
let confirmedPromptBlockReason;
|
|
1887
1893
|
const generateId2 = this.config.generateId;
|
|
1888
1894
|
let hasToolCalls = false;
|
|
1889
1895
|
let hasEmittedResponseMetadata = false;
|
|
@@ -1929,7 +1935,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1929
1935
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1930
1936
|
},
|
|
1931
1937
|
transform(chunk, controller) {
|
|
1932
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
1938
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1933
1939
|
if (options.includeRawChunks) {
|
|
1934
1940
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1935
1941
|
}
|
|
@@ -1949,35 +1955,35 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1949
1955
|
if (usageMetadata != null) {
|
|
1950
1956
|
usage = usageMetadata;
|
|
1951
1957
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1958
|
+
if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
|
|
1959
|
+
promptFeedback = value.promptFeedback;
|
|
1960
|
+
if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
|
|
1961
|
+
confirmedPromptBlockReason = value.promptFeedback.blockReason;
|
|
1956
1962
|
finishReason = {
|
|
1957
1963
|
unified: "content-filter",
|
|
1958
|
-
raw:
|
|
1959
|
-
};
|
|
1960
|
-
providerMetadata = {
|
|
1961
|
-
[providerOptionsName]: {
|
|
1962
|
-
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
1963
|
-
groundingMetadata: lastGroundingMetadata,
|
|
1964
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
1965
|
-
safetyRatings: null,
|
|
1966
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1967
|
-
finishMessage: null,
|
|
1968
|
-
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
1969
|
-
}
|
|
1964
|
+
raw: confirmedPromptBlockReason
|
|
1970
1965
|
};
|
|
1971
1966
|
}
|
|
1972
|
-
return;
|
|
1973
1967
|
}
|
|
1974
|
-
const
|
|
1975
|
-
if (candidate
|
|
1976
|
-
|
|
1968
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1969
|
+
if (candidate != null) {
|
|
1970
|
+
if (candidate.groundingMetadata != null) {
|
|
1971
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
1972
|
+
}
|
|
1973
|
+
if (candidate.urlContextMetadata != null) {
|
|
1974
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
1975
|
+
}
|
|
1976
|
+
if (candidate.safetyRatings != null) {
|
|
1977
|
+
lastSafetyRatings = candidate.safetyRatings;
|
|
1978
|
+
}
|
|
1979
|
+
if (candidate.finishMessage != null) {
|
|
1980
|
+
lastFinishMessage = candidate.finishMessage;
|
|
1981
|
+
}
|
|
1977
1982
|
}
|
|
1978
|
-
if (
|
|
1979
|
-
|
|
1983
|
+
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
1984
|
+
return;
|
|
1980
1985
|
}
|
|
1986
|
+
const content = candidate.content;
|
|
1981
1987
|
const sources = extractSources({
|
|
1982
1988
|
groundingMetadata: candidate.groundingMetadata,
|
|
1983
1989
|
generateId: generateId2
|
|
@@ -1991,9 +1997,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1991
1997
|
}
|
|
1992
1998
|
}
|
|
1993
1999
|
if (content != null) {
|
|
1994
|
-
const parts = (
|
|
2000
|
+
const parts = (_b = content.parts) != null ? _b : [];
|
|
1995
2001
|
for (const part of parts) {
|
|
1996
|
-
if ("executableCode" in part && ((
|
|
2002
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
1997
2003
|
const toolCallId = generateId2();
|
|
1998
2004
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1999
2005
|
controller.enqueue({
|
|
@@ -2012,7 +2018,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2012
2018
|
toolName: "code_execution",
|
|
2013
2019
|
result: {
|
|
2014
2020
|
outcome: part.codeExecutionResult.outcome,
|
|
2015
|
-
output: (
|
|
2021
|
+
output: (_d = part.codeExecutionResult.output) != null ? _d : ""
|
|
2016
2022
|
}
|
|
2017
2023
|
});
|
|
2018
2024
|
}
|
|
@@ -2106,7 +2112,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2106
2112
|
providerMetadata: fileMeta
|
|
2107
2113
|
});
|
|
2108
2114
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2109
|
-
const toolCallId = (
|
|
2115
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
2110
2116
|
lastServerToolCallId = toolCallId;
|
|
2111
2117
|
const serverMeta = {
|
|
2112
2118
|
[providerOptionsName]: {
|
|
@@ -2119,13 +2125,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2119
2125
|
type: "tool-call",
|
|
2120
2126
|
toolCallId,
|
|
2121
2127
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2122
|
-
input: JSON.stringify((
|
|
2128
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
2123
2129
|
providerExecuted: true,
|
|
2124
2130
|
dynamic: true,
|
|
2125
2131
|
providerMetadata: serverMeta
|
|
2126
2132
|
});
|
|
2127
2133
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2128
|
-
const responseToolCallId = (
|
|
2134
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
2129
2135
|
const serverMeta = {
|
|
2130
2136
|
[providerOptionsName]: {
|
|
2131
2137
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2137,7 +2143,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2137
2143
|
type: "tool-result",
|
|
2138
2144
|
toolCallId: responseToolCallId,
|
|
2139
2145
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2140
|
-
result: (
|
|
2146
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
2141
2147
|
providerMetadata: serverMeta
|
|
2142
2148
|
});
|
|
2143
2149
|
lastServerToolCallId = void 0;
|
|
@@ -2156,7 +2162,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2156
2162
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2157
2163
|
if (isStreamingChunk) {
|
|
2158
2164
|
if (part.functionCall.name != null) {
|
|
2159
|
-
const toolCallId = (
|
|
2165
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
|
|
2160
2166
|
const accumulator = new GoogleJSONAccumulator();
|
|
2161
2167
|
activeStreamingToolCalls.push({
|
|
2162
2168
|
toolCallId,
|
|
@@ -2204,9 +2210,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2204
2210
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2205
2211
|
finishActiveStreamingToolCall(controller);
|
|
2206
2212
|
} else if (isCompleteCall) {
|
|
2207
|
-
const toolCallId = (
|
|
2213
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
|
|
2208
2214
|
const toolName = part.functionCall.name;
|
|
2209
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2215
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2210
2216
|
controller.enqueue({
|
|
2211
2217
|
type: "tool-input-start",
|
|
2212
2218
|
id: toolCallId,
|
|
@@ -2233,7 +2239,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2233
2239
|
});
|
|
2234
2240
|
hasToolCalls = true;
|
|
2235
2241
|
} else if (isNoArgsCompleteCall) {
|
|
2236
|
-
const toolCallId = (
|
|
2242
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
2237
2243
|
const toolName = part.functionCall.name;
|
|
2238
2244
|
controller.enqueue({
|
|
2239
2245
|
type: "tool-input-start",
|
|
@@ -2257,31 +2263,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2257
2263
|
}
|
|
2258
2264
|
}
|
|
2259
2265
|
}
|
|
2260
|
-
|
|
2261
|
-
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2262
|
-
const rawFinishReason = (_r = (_q = candidate.finishReason) != null ? _q : promptBlockReason) != null ? _r : void 0;
|
|
2263
|
-
if (rawFinishReason != null) {
|
|
2266
|
+
if (candidate.finishReason != null) {
|
|
2264
2267
|
finishReason = {
|
|
2265
|
-
unified:
|
|
2266
|
-
finishReason:
|
|
2268
|
+
unified: mapGoogleGenerativeAIFinishReason({
|
|
2269
|
+
finishReason: candidate.finishReason,
|
|
2267
2270
|
hasToolCalls
|
|
2268
2271
|
}),
|
|
2269
|
-
raw:
|
|
2270
|
-
};
|
|
2271
|
-
providerMetadata = {
|
|
2272
|
-
[providerOptionsName]: {
|
|
2273
|
-
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2274
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2275
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2276
|
-
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2277
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2278
|
-
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2279
|
-
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2280
|
-
}
|
|
2272
|
+
raw: candidate.finishReason
|
|
2281
2273
|
};
|
|
2282
2274
|
}
|
|
2283
2275
|
},
|
|
2284
2276
|
flush(controller) {
|
|
2277
|
+
var _a;
|
|
2285
2278
|
if (currentTextBlockId !== null) {
|
|
2286
2279
|
controller.enqueue({
|
|
2287
2280
|
type: "text-end",
|
|
@@ -2298,7 +2291,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2298
2291
|
type: "finish",
|
|
2299
2292
|
finishReason,
|
|
2300
2293
|
usage: convertGoogleGenerativeAIUsage(usage),
|
|
2301
|
-
providerMetadata
|
|
2294
|
+
providerMetadata: {
|
|
2295
|
+
[providerOptionsName]: {
|
|
2296
|
+
promptFeedback,
|
|
2297
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2298
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2299
|
+
safetyRatings: lastSafetyRatings,
|
|
2300
|
+
usageMetadata: usage != null ? usage : null,
|
|
2301
|
+
finishMessage: lastFinishMessage,
|
|
2302
|
+
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2302
2305
|
});
|
|
2303
2306
|
}
|
|
2304
2307
|
})
|
|
@@ -2595,6 +2598,9 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
2595
2598
|
})
|
|
2596
2599
|
)
|
|
2597
2600
|
);
|
|
2601
|
+
function isConfirmedPromptBlockReason(blockReason) {
|
|
2602
|
+
return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
|
|
2603
|
+
}
|
|
2598
2604
|
|
|
2599
2605
|
// src/tool/code-execution.ts
|
|
2600
2606
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|