@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.js
CHANGED
|
@@ -1881,9 +1881,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1881
1881
|
raw: void 0
|
|
1882
1882
|
};
|
|
1883
1883
|
let usage = void 0;
|
|
1884
|
-
let
|
|
1884
|
+
let promptFeedback = null;
|
|
1885
1885
|
let lastGroundingMetadata = null;
|
|
1886
1886
|
let lastUrlContextMetadata = null;
|
|
1887
|
+
let lastSafetyRatings = null;
|
|
1888
|
+
let lastFinishMessage = null;
|
|
1889
|
+
let confirmedPromptBlockReason;
|
|
1887
1890
|
const generateId2 = this.config.generateId;
|
|
1888
1891
|
let hasToolCalls = false;
|
|
1889
1892
|
let hasEmittedResponseMetadata = false;
|
|
@@ -1929,7 +1932,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1929
1932
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1930
1933
|
},
|
|
1931
1934
|
transform(chunk, controller) {
|
|
1932
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
1935
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1933
1936
|
if (options.includeRawChunks) {
|
|
1934
1937
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1935
1938
|
}
|
|
@@ -1949,35 +1952,35 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1949
1952
|
if (usageMetadata != null) {
|
|
1950
1953
|
usage = usageMetadata;
|
|
1951
1954
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1955
|
+
if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
|
|
1956
|
+
promptFeedback = value.promptFeedback;
|
|
1957
|
+
if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
|
|
1958
|
+
confirmedPromptBlockReason = value.promptFeedback.blockReason;
|
|
1956
1959
|
finishReason = {
|
|
1957
1960
|
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
|
-
}
|
|
1961
|
+
raw: confirmedPromptBlockReason
|
|
1970
1962
|
};
|
|
1971
1963
|
}
|
|
1972
|
-
return;
|
|
1973
1964
|
}
|
|
1974
|
-
const
|
|
1975
|
-
if (candidate
|
|
1976
|
-
|
|
1965
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1966
|
+
if (candidate != null) {
|
|
1967
|
+
if (candidate.groundingMetadata != null) {
|
|
1968
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
1969
|
+
}
|
|
1970
|
+
if (candidate.urlContextMetadata != null) {
|
|
1971
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
1972
|
+
}
|
|
1973
|
+
if (candidate.safetyRatings != null) {
|
|
1974
|
+
lastSafetyRatings = candidate.safetyRatings;
|
|
1975
|
+
}
|
|
1976
|
+
if (candidate.finishMessage != null) {
|
|
1977
|
+
lastFinishMessage = candidate.finishMessage;
|
|
1978
|
+
}
|
|
1977
1979
|
}
|
|
1978
|
-
if (
|
|
1979
|
-
|
|
1980
|
+
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
1981
|
+
return;
|
|
1980
1982
|
}
|
|
1983
|
+
const content = candidate.content;
|
|
1981
1984
|
const sources = extractSources({
|
|
1982
1985
|
groundingMetadata: candidate.groundingMetadata,
|
|
1983
1986
|
generateId: generateId2
|
|
@@ -1991,9 +1994,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1991
1994
|
}
|
|
1992
1995
|
}
|
|
1993
1996
|
if (content != null) {
|
|
1994
|
-
const parts = (
|
|
1997
|
+
const parts = (_b = content.parts) != null ? _b : [];
|
|
1995
1998
|
for (const part of parts) {
|
|
1996
|
-
if ("executableCode" in part && ((
|
|
1999
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
1997
2000
|
const toolCallId = generateId2();
|
|
1998
2001
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1999
2002
|
controller.enqueue({
|
|
@@ -2012,7 +2015,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2012
2015
|
toolName: "code_execution",
|
|
2013
2016
|
result: {
|
|
2014
2017
|
outcome: part.codeExecutionResult.outcome,
|
|
2015
|
-
output: (
|
|
2018
|
+
output: (_d = part.codeExecutionResult.output) != null ? _d : ""
|
|
2016
2019
|
}
|
|
2017
2020
|
});
|
|
2018
2021
|
}
|
|
@@ -2106,7 +2109,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2106
2109
|
providerMetadata: fileMeta
|
|
2107
2110
|
});
|
|
2108
2111
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2109
|
-
const toolCallId = (
|
|
2112
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
2110
2113
|
lastServerToolCallId = toolCallId;
|
|
2111
2114
|
const serverMeta = {
|
|
2112
2115
|
[providerOptionsName]: {
|
|
@@ -2119,13 +2122,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2119
2122
|
type: "tool-call",
|
|
2120
2123
|
toolCallId,
|
|
2121
2124
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2122
|
-
input: JSON.stringify((
|
|
2125
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
2123
2126
|
providerExecuted: true,
|
|
2124
2127
|
dynamic: true,
|
|
2125
2128
|
providerMetadata: serverMeta
|
|
2126
2129
|
});
|
|
2127
2130
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2128
|
-
const responseToolCallId = (
|
|
2131
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
2129
2132
|
const serverMeta = {
|
|
2130
2133
|
[providerOptionsName]: {
|
|
2131
2134
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2137,7 +2140,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2137
2140
|
type: "tool-result",
|
|
2138
2141
|
toolCallId: responseToolCallId,
|
|
2139
2142
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2140
|
-
result: (
|
|
2143
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
2141
2144
|
providerMetadata: serverMeta
|
|
2142
2145
|
});
|
|
2143
2146
|
lastServerToolCallId = void 0;
|
|
@@ -2156,7 +2159,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2156
2159
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2157
2160
|
if (isStreamingChunk) {
|
|
2158
2161
|
if (part.functionCall.name != null) {
|
|
2159
|
-
const toolCallId = (
|
|
2162
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
|
|
2160
2163
|
const accumulator = new GoogleJSONAccumulator();
|
|
2161
2164
|
activeStreamingToolCalls.push({
|
|
2162
2165
|
toolCallId,
|
|
@@ -2204,9 +2207,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2204
2207
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2205
2208
|
finishActiveStreamingToolCall(controller);
|
|
2206
2209
|
} else if (isCompleteCall) {
|
|
2207
|
-
const toolCallId = (
|
|
2210
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
|
|
2208
2211
|
const toolName = part.functionCall.name;
|
|
2209
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2212
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2210
2213
|
controller.enqueue({
|
|
2211
2214
|
type: "tool-input-start",
|
|
2212
2215
|
id: toolCallId,
|
|
@@ -2233,7 +2236,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2233
2236
|
});
|
|
2234
2237
|
hasToolCalls = true;
|
|
2235
2238
|
} else if (isNoArgsCompleteCall) {
|
|
2236
|
-
const toolCallId = (
|
|
2239
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
2237
2240
|
const toolName = part.functionCall.name;
|
|
2238
2241
|
controller.enqueue({
|
|
2239
2242
|
type: "tool-input-start",
|
|
@@ -2257,31 +2260,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2257
2260
|
}
|
|
2258
2261
|
}
|
|
2259
2262
|
}
|
|
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) {
|
|
2263
|
+
if (candidate.finishReason != null) {
|
|
2264
2264
|
finishReason = {
|
|
2265
|
-
unified:
|
|
2266
|
-
finishReason:
|
|
2265
|
+
unified: mapGoogleGenerativeAIFinishReason({
|
|
2266
|
+
finishReason: candidate.finishReason,
|
|
2267
2267
|
hasToolCalls
|
|
2268
2268
|
}),
|
|
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
|
-
}
|
|
2269
|
+
raw: candidate.finishReason
|
|
2281
2270
|
};
|
|
2282
2271
|
}
|
|
2283
2272
|
},
|
|
2284
2273
|
flush(controller) {
|
|
2274
|
+
var _a;
|
|
2285
2275
|
if (currentTextBlockId !== null) {
|
|
2286
2276
|
controller.enqueue({
|
|
2287
2277
|
type: "text-end",
|
|
@@ -2298,7 +2288,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2298
2288
|
type: "finish",
|
|
2299
2289
|
finishReason,
|
|
2300
2290
|
usage: convertGoogleGenerativeAIUsage(usage),
|
|
2301
|
-
providerMetadata
|
|
2291
|
+
providerMetadata: {
|
|
2292
|
+
[providerOptionsName]: {
|
|
2293
|
+
promptFeedback,
|
|
2294
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2295
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2296
|
+
safetyRatings: lastSafetyRatings,
|
|
2297
|
+
usageMetadata: usage != null ? usage : null,
|
|
2298
|
+
finishMessage: lastFinishMessage,
|
|
2299
|
+
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
2302
|
});
|
|
2303
2303
|
}
|
|
2304
2304
|
})
|
|
@@ -2595,6 +2595,9 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
2595
2595
|
})
|
|
2596
2596
|
)
|
|
2597
2597
|
);
|
|
2598
|
+
function isConfirmedPromptBlockReason(blockReason) {
|
|
2599
|
+
return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
|
|
2600
|
+
}
|
|
2598
2601
|
|
|
2599
2602
|
// src/tool/code-execution.ts
|
|
2600
2603
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|