@ai-sdk/google 3.0.134 → 3.0.136
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 +13 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -27
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +48 -26
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +48 -26
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +8 -0
- package/package.json +2 -2
- package/src/google-generative-ai-language-model.ts +30 -2
- package/src/google-generative-ai-prompt.ts +2 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -1888,7 +1888,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1888
1888
|
};
|
|
1889
1889
|
}
|
|
1890
1890
|
async doGenerate(options) {
|
|
1891
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
|
|
1891
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
1892
1892
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
1893
1893
|
const mergedHeaders = combineHeaders(
|
|
1894
1894
|
await resolve(this.config.headers),
|
|
@@ -1912,18 +1912,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1912
1912
|
rawValue: rawResponse
|
|
1913
1913
|
} = await generateContent(args);
|
|
1914
1914
|
const continuedParts = [];
|
|
1915
|
+
const groundingMetadataPerRequest = [];
|
|
1915
1916
|
let continuedUsageMetadata;
|
|
1916
1917
|
const firstPromptTokenCount = (_a = response.usageMetadata) == null ? void 0 : _a.promptTokenCount;
|
|
1917
1918
|
while (true) {
|
|
1918
1919
|
const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
|
|
1920
|
+
groundingMetadataPerRequest.push((_c = candidate2 == null ? void 0 : candidate2.groundingMetadata) != null ? _c : null);
|
|
1919
1921
|
const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
|
|
1920
1922
|
if (continuationToken == null) {
|
|
1921
1923
|
break;
|
|
1922
1924
|
}
|
|
1923
|
-
continuedParts.push(...(
|
|
1925
|
+
continuedParts.push(...(_e = (_d = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _d.parts) != null ? _e : []);
|
|
1924
1926
|
continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
1925
1927
|
continuedUsageMetadata,
|
|
1926
|
-
(
|
|
1928
|
+
(_f = response.usageMetadata) != null ? _f : void 0
|
|
1927
1929
|
);
|
|
1928
1930
|
({
|
|
1929
1931
|
responseHeaders,
|
|
@@ -1931,23 +1933,23 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1931
1933
|
rawValue: rawResponse
|
|
1932
1934
|
} = await generateContent({ ...args, continuationToken }));
|
|
1933
1935
|
}
|
|
1934
|
-
const candidate = (
|
|
1935
|
-
const promptBlockReason = (
|
|
1936
|
+
const candidate = (_g = response.candidates) == null ? void 0 : _g[0];
|
|
1937
|
+
const promptBlockReason = (_h = response.promptFeedback) == null ? void 0 : _h.blockReason;
|
|
1936
1938
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1937
1939
|
promptBlockReason
|
|
1938
1940
|
) ? promptBlockReason : void 0;
|
|
1939
1941
|
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
|
|
1940
|
-
const rawFinishReason = (
|
|
1942
|
+
const rawFinishReason = (_i = candidate == null ? void 0 : candidate.finishReason) != null ? _i : confirmedPromptBlockReason;
|
|
1941
1943
|
const content = [];
|
|
1942
|
-
const parts = [...continuedParts, ...(
|
|
1944
|
+
const parts = [...continuedParts, ...(_k = (_j = candidate == null ? void 0 : candidate.content) == null ? void 0 : _j.parts) != null ? _k : []];
|
|
1943
1945
|
const usageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
1944
1946
|
continuedUsageMetadata,
|
|
1945
|
-
(
|
|
1947
|
+
(_l = response.usageMetadata) != null ? _l : void 0
|
|
1946
1948
|
);
|
|
1947
1949
|
let lastCodeExecutionToolCallId;
|
|
1948
1950
|
let lastServerToolCallId;
|
|
1949
1951
|
for (const part of parts) {
|
|
1950
|
-
if ("executableCode" in part && ((
|
|
1952
|
+
if ("executableCode" in part && ((_m = part.executableCode) == null ? void 0 : _m.code)) {
|
|
1951
1953
|
const toolCallId = this.config.generateId();
|
|
1952
1954
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1953
1955
|
content.push({
|
|
@@ -1965,7 +1967,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1965
1967
|
toolName: "code_execution",
|
|
1966
1968
|
result: {
|
|
1967
1969
|
outcome: part.codeExecutionResult.outcome,
|
|
1968
|
-
output: (
|
|
1970
|
+
output: (_n = part.codeExecutionResult.output) != null ? _n : ""
|
|
1969
1971
|
}
|
|
1970
1972
|
});
|
|
1971
1973
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1989,9 +1991,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1989
1991
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1990
1992
|
content.push({
|
|
1991
1993
|
type: "tool-call",
|
|
1992
|
-
toolCallId: (
|
|
1994
|
+
toolCallId: (_o = part.functionCall.id) != null ? _o : this.config.generateId(),
|
|
1993
1995
|
toolName: part.functionCall.name,
|
|
1994
|
-
input: JSON.stringify((
|
|
1996
|
+
input: JSON.stringify((_p = part.functionCall.args) != null ? _p : {}),
|
|
1995
1997
|
providerMetadata: part.thoughtSignature ? {
|
|
1996
1998
|
[providerOptionsName]: {
|
|
1997
1999
|
thoughtSignature: part.thoughtSignature
|
|
@@ -2013,13 +2015,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2013
2015
|
} : void 0
|
|
2014
2016
|
});
|
|
2015
2017
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2016
|
-
const toolCallId = (
|
|
2018
|
+
const toolCallId = (_q = part.toolCall.id) != null ? _q : this.config.generateId();
|
|
2017
2019
|
lastServerToolCallId = toolCallId;
|
|
2018
2020
|
content.push({
|
|
2019
2021
|
type: "tool-call",
|
|
2020
2022
|
toolCallId,
|
|
2021
2023
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2022
|
-
input: JSON.stringify((
|
|
2024
|
+
input: JSON.stringify((_r = part.toolCall.args) != null ? _r : {}),
|
|
2023
2025
|
providerExecuted: true,
|
|
2024
2026
|
dynamic: true,
|
|
2025
2027
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -2036,12 +2038,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2036
2038
|
}
|
|
2037
2039
|
});
|
|
2038
2040
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2039
|
-
const responseToolCallId = (
|
|
2041
|
+
const responseToolCallId = (_s = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _s : this.config.generateId();
|
|
2040
2042
|
content.push({
|
|
2041
2043
|
type: "tool-result",
|
|
2042
2044
|
toolCallId: responseToolCallId,
|
|
2043
2045
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2044
|
-
result: (
|
|
2046
|
+
result: (_t = part.toolResponse.response) != null ? _t : {},
|
|
2045
2047
|
providerMetadata: part.thoughtSignature ? {
|
|
2046
2048
|
[providerOptionsName]: {
|
|
2047
2049
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -2058,10 +2060,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2058
2060
|
lastServerToolCallId = void 0;
|
|
2059
2061
|
}
|
|
2060
2062
|
}
|
|
2061
|
-
const sources = (
|
|
2063
|
+
const sources = (_u = extractSources({
|
|
2062
2064
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2063
2065
|
generateId: this.config.generateId
|
|
2064
|
-
})) != null ?
|
|
2066
|
+
})) != null ? _u : [];
|
|
2065
2067
|
for (const source of sources) {
|
|
2066
2068
|
content.push(source);
|
|
2067
2069
|
}
|
|
@@ -2081,13 +2083,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2081
2083
|
warnings,
|
|
2082
2084
|
providerMetadata: {
|
|
2083
2085
|
[providerOptionsName]: {
|
|
2084
|
-
promptFeedback: (
|
|
2085
|
-
groundingMetadata: (
|
|
2086
|
-
|
|
2087
|
-
|
|
2086
|
+
promptFeedback: (_v = response.promptFeedback) != null ? _v : null,
|
|
2087
|
+
groundingMetadata: (_w = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _w : null,
|
|
2088
|
+
...groundingMetadataPerRequest.length > 1 ? { groundingMetadataPerRequest } : {},
|
|
2089
|
+
urlContextMetadata: (_x = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _x : null,
|
|
2090
|
+
safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
|
|
2088
2091
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2089
|
-
finishMessage: (
|
|
2090
|
-
serviceTier: (
|
|
2092
|
+
finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
|
|
2093
|
+
serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
|
|
2091
2094
|
...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
|
|
2092
2095
|
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
|
|
2093
2096
|
}
|
|
@@ -2095,7 +2098,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2095
2098
|
request: { body: args },
|
|
2096
2099
|
response: {
|
|
2097
2100
|
// TODO timestamp, model id
|
|
2098
|
-
id: (
|
|
2101
|
+
id: (_B = response.responseId) != null ? _B : void 0,
|
|
2099
2102
|
headers: responseHeaders,
|
|
2100
2103
|
body: rawResponse
|
|
2101
2104
|
}
|
|
@@ -2120,14 +2123,27 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2120
2123
|
fetch: this.config.fetch
|
|
2121
2124
|
});
|
|
2122
2125
|
const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
|
|
2126
|
+
const groundingMetadataPerRequest = [];
|
|
2127
|
+
let requestGroundingMetadata = null;
|
|
2123
2128
|
const response = continueGoogleStream({
|
|
2124
2129
|
stream: firstResponse,
|
|
2125
2130
|
getContinuationToken: (chunk) => {
|
|
2126
2131
|
var _a, _b;
|
|
2127
2132
|
const candidate = (_a = chunk.candidates) == null ? void 0 : _a[0];
|
|
2133
|
+
if ((candidate == null ? void 0 : candidate.groundingMetadata) != null) {
|
|
2134
|
+
requestGroundingMetadata = candidate.groundingMetadata;
|
|
2135
|
+
}
|
|
2128
2136
|
return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
|
|
2129
2137
|
},
|
|
2130
|
-
continueStream: async (continuationToken) =>
|
|
2138
|
+
continueStream: async (continuationToken) => {
|
|
2139
|
+
const { value } = await streamGenerateContent({
|
|
2140
|
+
...args,
|
|
2141
|
+
continuationToken
|
|
2142
|
+
});
|
|
2143
|
+
groundingMetadataPerRequest.push(requestGroundingMetadata);
|
|
2144
|
+
requestGroundingMetadata = null;
|
|
2145
|
+
return value;
|
|
2146
|
+
}
|
|
2131
2147
|
});
|
|
2132
2148
|
let finishReason = {
|
|
2133
2149
|
unified: "other",
|
|
@@ -2562,6 +2578,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2562
2578
|
[providerOptionsName]: {
|
|
2563
2579
|
promptFeedback,
|
|
2564
2580
|
groundingMetadata: lastGroundingMetadata,
|
|
2581
|
+
...groundingMetadataPerRequest.length > 0 ? {
|
|
2582
|
+
groundingMetadataPerRequest: [
|
|
2583
|
+
...groundingMetadataPerRequest,
|
|
2584
|
+
requestGroundingMetadata
|
|
2585
|
+
]
|
|
2586
|
+
} : {},
|
|
2565
2587
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2566
2588
|
safetyRatings: lastSafetyRatings,
|
|
2567
2589
|
usageMetadata: usage != null ? usage : null,
|