@ai-sdk/google 3.0.122 → 3.0.123
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 +6 -0
- package/dist/index.js +58 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -55
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +57 -54
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +57 -54
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/google-generative-ai-language-model.ts +63 -51
package/dist/internal/index.mjs
CHANGED
|
@@ -1874,9 +1874,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1874
1874
|
raw: void 0
|
|
1875
1875
|
};
|
|
1876
1876
|
let usage = void 0;
|
|
1877
|
-
let
|
|
1877
|
+
let promptFeedback = null;
|
|
1878
1878
|
let lastGroundingMetadata = null;
|
|
1879
1879
|
let lastUrlContextMetadata = null;
|
|
1880
|
+
let lastSafetyRatings = null;
|
|
1881
|
+
let lastFinishMessage = null;
|
|
1882
|
+
let confirmedPromptBlockReason;
|
|
1880
1883
|
const generateId2 = this.config.generateId;
|
|
1881
1884
|
let hasToolCalls = false;
|
|
1882
1885
|
let hasEmittedResponseMetadata = false;
|
|
@@ -1922,7 +1925,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1922
1925
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1923
1926
|
},
|
|
1924
1927
|
transform(chunk, controller) {
|
|
1925
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
1928
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1926
1929
|
if (options.includeRawChunks) {
|
|
1927
1930
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1928
1931
|
}
|
|
@@ -1942,35 +1945,35 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1942
1945
|
if (usageMetadata != null) {
|
|
1943
1946
|
usage = usageMetadata;
|
|
1944
1947
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1948
|
+
if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
|
|
1949
|
+
promptFeedback = value.promptFeedback;
|
|
1950
|
+
if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
|
|
1951
|
+
confirmedPromptBlockReason = value.promptFeedback.blockReason;
|
|
1949
1952
|
finishReason = {
|
|
1950
1953
|
unified: "content-filter",
|
|
1951
|
-
raw:
|
|
1952
|
-
};
|
|
1953
|
-
providerMetadata = {
|
|
1954
|
-
[providerOptionsName]: {
|
|
1955
|
-
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
1956
|
-
groundingMetadata: lastGroundingMetadata,
|
|
1957
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
1958
|
-
safetyRatings: null,
|
|
1959
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1960
|
-
finishMessage: null,
|
|
1961
|
-
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
1962
|
-
}
|
|
1954
|
+
raw: confirmedPromptBlockReason
|
|
1963
1955
|
};
|
|
1964
1956
|
}
|
|
1965
|
-
return;
|
|
1966
1957
|
}
|
|
1967
|
-
const
|
|
1968
|
-
if (candidate
|
|
1969
|
-
|
|
1958
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1959
|
+
if (candidate != null) {
|
|
1960
|
+
if (candidate.groundingMetadata != null) {
|
|
1961
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
1962
|
+
}
|
|
1963
|
+
if (candidate.urlContextMetadata != null) {
|
|
1964
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
1965
|
+
}
|
|
1966
|
+
if (candidate.safetyRatings != null) {
|
|
1967
|
+
lastSafetyRatings = candidate.safetyRatings;
|
|
1968
|
+
}
|
|
1969
|
+
if (candidate.finishMessage != null) {
|
|
1970
|
+
lastFinishMessage = candidate.finishMessage;
|
|
1971
|
+
}
|
|
1970
1972
|
}
|
|
1971
|
-
if (
|
|
1972
|
-
|
|
1973
|
+
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
1974
|
+
return;
|
|
1973
1975
|
}
|
|
1976
|
+
const content = candidate.content;
|
|
1974
1977
|
const sources = extractSources({
|
|
1975
1978
|
groundingMetadata: candidate.groundingMetadata,
|
|
1976
1979
|
generateId: generateId2
|
|
@@ -1984,9 +1987,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1984
1987
|
}
|
|
1985
1988
|
}
|
|
1986
1989
|
if (content != null) {
|
|
1987
|
-
const parts = (
|
|
1990
|
+
const parts = (_b = content.parts) != null ? _b : [];
|
|
1988
1991
|
for (const part of parts) {
|
|
1989
|
-
if ("executableCode" in part && ((
|
|
1992
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
1990
1993
|
const toolCallId = generateId2();
|
|
1991
1994
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1992
1995
|
controller.enqueue({
|
|
@@ -2005,7 +2008,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2005
2008
|
toolName: "code_execution",
|
|
2006
2009
|
result: {
|
|
2007
2010
|
outcome: part.codeExecutionResult.outcome,
|
|
2008
|
-
output: (
|
|
2011
|
+
output: (_d = part.codeExecutionResult.output) != null ? _d : ""
|
|
2009
2012
|
}
|
|
2010
2013
|
});
|
|
2011
2014
|
}
|
|
@@ -2099,7 +2102,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2099
2102
|
providerMetadata: fileMeta
|
|
2100
2103
|
});
|
|
2101
2104
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2102
|
-
const toolCallId = (
|
|
2105
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
2103
2106
|
lastServerToolCallId = toolCallId;
|
|
2104
2107
|
const serverMeta = {
|
|
2105
2108
|
[providerOptionsName]: {
|
|
@@ -2112,13 +2115,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2112
2115
|
type: "tool-call",
|
|
2113
2116
|
toolCallId,
|
|
2114
2117
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2115
|
-
input: JSON.stringify((
|
|
2118
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
2116
2119
|
providerExecuted: true,
|
|
2117
2120
|
dynamic: true,
|
|
2118
2121
|
providerMetadata: serverMeta
|
|
2119
2122
|
});
|
|
2120
2123
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2121
|
-
const responseToolCallId = (
|
|
2124
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
2122
2125
|
const serverMeta = {
|
|
2123
2126
|
[providerOptionsName]: {
|
|
2124
2127
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2130,7 +2133,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2130
2133
|
type: "tool-result",
|
|
2131
2134
|
toolCallId: responseToolCallId,
|
|
2132
2135
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2133
|
-
result: (
|
|
2136
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
2134
2137
|
providerMetadata: serverMeta
|
|
2135
2138
|
});
|
|
2136
2139
|
lastServerToolCallId = void 0;
|
|
@@ -2149,7 +2152,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2149
2152
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2150
2153
|
if (isStreamingChunk) {
|
|
2151
2154
|
if (part.functionCall.name != null) {
|
|
2152
|
-
const toolCallId = (
|
|
2155
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
|
|
2153
2156
|
const accumulator = new GoogleJSONAccumulator();
|
|
2154
2157
|
activeStreamingToolCalls.push({
|
|
2155
2158
|
toolCallId,
|
|
@@ -2197,9 +2200,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2197
2200
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2198
2201
|
finishActiveStreamingToolCall(controller);
|
|
2199
2202
|
} else if (isCompleteCall) {
|
|
2200
|
-
const toolCallId = (
|
|
2203
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
|
|
2201
2204
|
const toolName = part.functionCall.name;
|
|
2202
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2205
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2203
2206
|
controller.enqueue({
|
|
2204
2207
|
type: "tool-input-start",
|
|
2205
2208
|
id: toolCallId,
|
|
@@ -2226,7 +2229,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2226
2229
|
});
|
|
2227
2230
|
hasToolCalls = true;
|
|
2228
2231
|
} else if (isNoArgsCompleteCall) {
|
|
2229
|
-
const toolCallId = (
|
|
2232
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
2230
2233
|
const toolName = part.functionCall.name;
|
|
2231
2234
|
controller.enqueue({
|
|
2232
2235
|
type: "tool-input-start",
|
|
@@ -2250,31 +2253,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2250
2253
|
}
|
|
2251
2254
|
}
|
|
2252
2255
|
}
|
|
2253
|
-
|
|
2254
|
-
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2255
|
-
const rawFinishReason = (_r = (_q = candidate.finishReason) != null ? _q : promptBlockReason) != null ? _r : void 0;
|
|
2256
|
-
if (rawFinishReason != null) {
|
|
2256
|
+
if (candidate.finishReason != null) {
|
|
2257
2257
|
finishReason = {
|
|
2258
|
-
unified:
|
|
2259
|
-
finishReason:
|
|
2258
|
+
unified: mapGoogleGenerativeAIFinishReason({
|
|
2259
|
+
finishReason: candidate.finishReason,
|
|
2260
2260
|
hasToolCalls
|
|
2261
2261
|
}),
|
|
2262
|
-
raw:
|
|
2263
|
-
};
|
|
2264
|
-
providerMetadata = {
|
|
2265
|
-
[providerOptionsName]: {
|
|
2266
|
-
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2267
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2268
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2269
|
-
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2270
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2271
|
-
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2272
|
-
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2273
|
-
}
|
|
2262
|
+
raw: candidate.finishReason
|
|
2274
2263
|
};
|
|
2275
2264
|
}
|
|
2276
2265
|
},
|
|
2277
2266
|
flush(controller) {
|
|
2267
|
+
var _a;
|
|
2278
2268
|
if (currentTextBlockId !== null) {
|
|
2279
2269
|
controller.enqueue({
|
|
2280
2270
|
type: "text-end",
|
|
@@ -2291,7 +2281,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2291
2281
|
type: "finish",
|
|
2292
2282
|
finishReason,
|
|
2293
2283
|
usage: convertGoogleGenerativeAIUsage(usage),
|
|
2294
|
-
providerMetadata
|
|
2284
|
+
providerMetadata: {
|
|
2285
|
+
[providerOptionsName]: {
|
|
2286
|
+
promptFeedback,
|
|
2287
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2288
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2289
|
+
safetyRatings: lastSafetyRatings,
|
|
2290
|
+
usageMetadata: usage != null ? usage : null,
|
|
2291
|
+
finishMessage: lastFinishMessage,
|
|
2292
|
+
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
2295
|
});
|
|
2296
2296
|
}
|
|
2297
2297
|
})
|
|
@@ -2588,6 +2588,9 @@ var chunkSchema = lazySchema3(
|
|
|
2588
2588
|
})
|
|
2589
2589
|
)
|
|
2590
2590
|
);
|
|
2591
|
+
function isConfirmedPromptBlockReason(blockReason) {
|
|
2592
|
+
return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
|
|
2593
|
+
}
|
|
2591
2594
|
|
|
2592
2595
|
// src/tool/code-execution.ts
|
|
2593
2596
|
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|