@ai-sdk/google 2.0.90 → 2.0.94
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 +29 -0
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +160 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -49
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -5
- package/dist/internal/index.d.ts +6 -5
- package/dist/internal/index.js +159 -48
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +159 -48
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -82,7 +82,7 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
|
|
|
82
82
|
}, z.core.$strip>>;
|
|
83
83
|
}, z.core.$strip>;
|
|
84
84
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
85
|
-
candidates
|
|
85
|
+
candidates?: {
|
|
86
86
|
content?: Record<string, never> | {
|
|
87
87
|
parts?: ({
|
|
88
88
|
functionCall: {
|
|
@@ -172,7 +172,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
172
172
|
urlRetrievalStatus: string;
|
|
173
173
|
}[];
|
|
174
174
|
} | null | undefined;
|
|
175
|
-
}[];
|
|
175
|
+
}[] | null | undefined;
|
|
176
176
|
usageMetadata?: {
|
|
177
177
|
cachedContentTokenCount?: number | null | undefined;
|
|
178
178
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -202,9 +202,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
202
202
|
} | null | undefined;
|
|
203
203
|
serviceTier?: string | null | undefined;
|
|
204
204
|
}>;
|
|
205
|
-
type
|
|
206
|
-
type
|
|
207
|
-
type
|
|
205
|
+
type CandidateSchema = NonNullable<InferValidator<typeof responseSchema>['candidates']>[number];
|
|
206
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
207
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
208
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
208
209
|
|
|
209
210
|
declare const googleTools: {
|
|
210
211
|
/**
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
|
|
|
82
82
|
}, z.core.$strip>>;
|
|
83
83
|
}, z.core.$strip>;
|
|
84
84
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
85
|
-
candidates
|
|
85
|
+
candidates?: {
|
|
86
86
|
content?: Record<string, never> | {
|
|
87
87
|
parts?: ({
|
|
88
88
|
functionCall: {
|
|
@@ -172,7 +172,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
172
172
|
urlRetrievalStatus: string;
|
|
173
173
|
}[];
|
|
174
174
|
} | null | undefined;
|
|
175
|
-
}[];
|
|
175
|
+
}[] | null | undefined;
|
|
176
176
|
usageMetadata?: {
|
|
177
177
|
cachedContentTokenCount?: number | null | undefined;
|
|
178
178
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -202,9 +202,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
202
202
|
} | null | undefined;
|
|
203
203
|
serviceTier?: string | null | undefined;
|
|
204
204
|
}>;
|
|
205
|
-
type
|
|
206
|
-
type
|
|
207
|
-
type
|
|
205
|
+
type CandidateSchema = NonNullable<InferValidator<typeof responseSchema>['candidates']>[number];
|
|
206
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
207
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
208
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
208
209
|
|
|
209
210
|
declare const googleTools: {
|
|
210
211
|
/**
|
package/dist/internal/index.js
CHANGED
|
@@ -33,6 +33,10 @@ var import_v43 = require("zod/v4");
|
|
|
33
33
|
|
|
34
34
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
35
35
|
var import_provider = require("@ai-sdk/provider");
|
|
36
|
+
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
37
|
+
function isRecursiveJSONSchemaReferenceError(error) {
|
|
38
|
+
return import_provider.UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
39
|
+
}
|
|
36
40
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
37
41
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
38
42
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
@@ -83,9 +87,6 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
83
87
|
if (description) result.description = description;
|
|
84
88
|
if (required) result.required = required;
|
|
85
89
|
if (format) result.format = format;
|
|
86
|
-
if (constValue !== void 0) {
|
|
87
|
-
result.enum = [constValue];
|
|
88
|
-
}
|
|
89
90
|
if (type) {
|
|
90
91
|
if (Array.isArray(type)) {
|
|
91
92
|
const hasNull = type.includes("null");
|
|
@@ -102,8 +103,9 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
102
103
|
result.type = type;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
107
|
+
if (values !== void 0) {
|
|
108
|
+
addEnumToSchema({ values, type, result });
|
|
107
109
|
}
|
|
108
110
|
if (properties != null) {
|
|
109
111
|
result.properties = Object.entries(properties).reduce(
|
|
@@ -163,6 +165,68 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
163
165
|
}
|
|
164
166
|
return result;
|
|
165
167
|
}
|
|
168
|
+
function addEnumToSchema({
|
|
169
|
+
values,
|
|
170
|
+
type,
|
|
171
|
+
result
|
|
172
|
+
}) {
|
|
173
|
+
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
174
|
+
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
175
|
+
if (values.length > 0 && values.every((value) => value === null)) {
|
|
176
|
+
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
177
|
+
if (typeAllowsNull) {
|
|
178
|
+
result.type = "null";
|
|
179
|
+
if (Array.isArray(type)) {
|
|
180
|
+
delete result.anyOf;
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const enumType = getEnumType({ values: enumValues, type });
|
|
186
|
+
if (enumType === void 0) {
|
|
187
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
188
|
+
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
189
|
+
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
result.type = enumType;
|
|
193
|
+
if (Array.isArray(type)) {
|
|
194
|
+
delete result.anyOf;
|
|
195
|
+
}
|
|
196
|
+
if (nullable) {
|
|
197
|
+
result.nullable = true;
|
|
198
|
+
}
|
|
199
|
+
if (enumType === "string") {
|
|
200
|
+
result.enum = enumValues;
|
|
201
|
+
} else {
|
|
202
|
+
result.format = "enum";
|
|
203
|
+
result.enum = enumValues.map(String);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function getEnumType({
|
|
207
|
+
values,
|
|
208
|
+
type
|
|
209
|
+
}) {
|
|
210
|
+
if (values.length === 0) {
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
214
|
+
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
215
|
+
return "string";
|
|
216
|
+
}
|
|
217
|
+
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
218
|
+
if (typeAllows("number")) {
|
|
219
|
+
return "number";
|
|
220
|
+
}
|
|
221
|
+
if (values.every((value) => Number.isInteger(value))) {
|
|
222
|
+
return "integer";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
226
|
+
return "boolean";
|
|
227
|
+
}
|
|
228
|
+
return void 0;
|
|
229
|
+
}
|
|
166
230
|
function convertJSONSchemaReference({
|
|
167
231
|
jsonSchema,
|
|
168
232
|
reference,
|
|
@@ -175,7 +239,7 @@ function convertJSONSchemaReference({
|
|
|
175
239
|
);
|
|
176
240
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
177
241
|
throw new import_provider.UnsupportedFunctionalityError({
|
|
178
|
-
functionality:
|
|
242
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
179
243
|
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
180
244
|
});
|
|
181
245
|
}
|
|
@@ -681,7 +745,6 @@ function prepareTools({
|
|
|
681
745
|
modelId,
|
|
682
746
|
isVertexProvider = false
|
|
683
747
|
}) {
|
|
684
|
-
var _a, _b;
|
|
685
748
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
686
749
|
const toolWarnings = [];
|
|
687
750
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
@@ -802,11 +865,7 @@ function prepareTools({
|
|
|
802
865
|
const functionDeclarations2 = [];
|
|
803
866
|
for (const tool of tools) {
|
|
804
867
|
if (tool.type === "function") {
|
|
805
|
-
functionDeclarations2.push(
|
|
806
|
-
name: tool.name,
|
|
807
|
-
description: (_a = tool.description) != null ? _a : "",
|
|
808
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
809
|
-
});
|
|
868
|
+
functionDeclarations2.push(prepareFunctionDeclaration(tool));
|
|
810
869
|
}
|
|
811
870
|
}
|
|
812
871
|
const combinedToolConfig = {
|
|
@@ -850,11 +909,7 @@ function prepareTools({
|
|
|
850
909
|
for (const tool of tools) {
|
|
851
910
|
switch (tool.type) {
|
|
852
911
|
case "function":
|
|
853
|
-
functionDeclarations.push(
|
|
854
|
-
name: tool.name,
|
|
855
|
-
description: (_b = tool.description) != null ? _b : "",
|
|
856
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
857
|
-
});
|
|
912
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
858
913
|
if (tool.strict === true) {
|
|
859
914
|
hasStrictTools = true;
|
|
860
915
|
}
|
|
@@ -918,6 +973,27 @@ function prepareTools({
|
|
|
918
973
|
}
|
|
919
974
|
}
|
|
920
975
|
}
|
|
976
|
+
function prepareFunctionDeclaration(tool) {
|
|
977
|
+
var _a;
|
|
978
|
+
const declaration = {
|
|
979
|
+
name: tool.name,
|
|
980
|
+
description: (_a = tool.description) != null ? _a : ""
|
|
981
|
+
};
|
|
982
|
+
try {
|
|
983
|
+
return {
|
|
984
|
+
...declaration,
|
|
985
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
986
|
+
};
|
|
987
|
+
} catch (error) {
|
|
988
|
+
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
989
|
+
throw error;
|
|
990
|
+
}
|
|
991
|
+
return {
|
|
992
|
+
...declaration,
|
|
993
|
+
parametersJsonSchema: tool.inputSchema
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
}
|
|
921
997
|
|
|
922
998
|
// src/map-google-generative-ai-finish-reason.ts
|
|
923
999
|
function mapGoogleGenerativeAIFinishReason({
|
|
@@ -953,6 +1029,7 @@ var configurableSafetySettingCategories = [
|
|
|
953
1029
|
"HARM_CATEGORY_HARASSMENT",
|
|
954
1030
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
955
1031
|
];
|
|
1032
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
956
1033
|
var GoogleGenerativeAILanguageModel = class {
|
|
957
1034
|
constructor(modelId, config) {
|
|
958
1035
|
this.specificationVersion = "v2";
|
|
@@ -1030,6 +1107,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1030
1107
|
threshold: safetyThreshold
|
|
1031
1108
|
})) : void 0;
|
|
1032
1109
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1110
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1111
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1112
|
+
warnings.push({
|
|
1113
|
+
type: "unsupported-setting",
|
|
1114
|
+
setting: "frequencyPenalty"
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1118
|
+
warnings.push({
|
|
1119
|
+
type: "unsupported-setting",
|
|
1120
|
+
setting: "presencePenalty"
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1033
1123
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1034
1124
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1035
1125
|
prompt,
|
|
@@ -1057,8 +1147,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1057
1147
|
temperature,
|
|
1058
1148
|
topK,
|
|
1059
1149
|
topP,
|
|
1060
|
-
frequencyPenalty,
|
|
1061
|
-
presencePenalty,
|
|
1150
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1151
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1062
1152
|
stopSequences,
|
|
1063
1153
|
seed,
|
|
1064
1154
|
// response format:
|
|
@@ -1094,7 +1184,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1094
1184
|
};
|
|
1095
1185
|
}
|
|
1096
1186
|
async doGenerate(options) {
|
|
1097
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1187
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1098
1188
|
const { args, warnings } = await this.getArgs(options);
|
|
1099
1189
|
const body = JSON.stringify(args);
|
|
1100
1190
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
@@ -1116,13 +1206,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1116
1206
|
abortSignal: options.abortSignal,
|
|
1117
1207
|
fetch: this.config.fetch
|
|
1118
1208
|
});
|
|
1119
|
-
const candidate = response.candidates[0];
|
|
1209
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1210
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1211
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1120
1212
|
const content = [];
|
|
1121
|
-
const parts = (
|
|
1213
|
+
const parts = (_d = (_c = candidate == null ? void 0 : candidate.content) == null ? void 0 : _c.parts) != null ? _d : [];
|
|
1122
1214
|
const usageMetadata = response.usageMetadata;
|
|
1123
1215
|
let lastCodeExecutionToolCallId;
|
|
1124
1216
|
for (const part of parts) {
|
|
1125
|
-
if ("executableCode" in part && ((
|
|
1217
|
+
if ("executableCode" in part && ((_e = part.executableCode) == null ? void 0 : _e.code)) {
|
|
1126
1218
|
const toolCallId = this.config.generateId();
|
|
1127
1219
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1128
1220
|
content.push({
|
|
@@ -1163,7 +1255,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1163
1255
|
} else if ("functionCall" in part) {
|
|
1164
1256
|
content.push({
|
|
1165
1257
|
type: "tool-call",
|
|
1166
|
-
toolCallId: (
|
|
1258
|
+
toolCallId: (_f = part.functionCall.id) != null ? _f : this.config.generateId(),
|
|
1167
1259
|
toolName: part.functionCall.name,
|
|
1168
1260
|
input: JSON.stringify(part.functionCall.args),
|
|
1169
1261
|
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
@@ -1176,34 +1268,34 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1176
1268
|
});
|
|
1177
1269
|
}
|
|
1178
1270
|
}
|
|
1179
|
-
const sources = (
|
|
1180
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1271
|
+
const sources = (_g = extractSources({
|
|
1272
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1181
1273
|
generateId: this.config.generateId
|
|
1182
|
-
})) != null ?
|
|
1274
|
+
})) != null ? _g : [];
|
|
1183
1275
|
for (const source of sources) {
|
|
1184
1276
|
content.push(source);
|
|
1185
1277
|
}
|
|
1186
1278
|
return {
|
|
1187
1279
|
content,
|
|
1188
|
-
finishReason: mapGoogleGenerativeAIFinishReason({
|
|
1189
|
-
finishReason: candidate.finishReason,
|
|
1280
|
+
finishReason: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1281
|
+
finishReason: candidate == null ? void 0 : candidate.finishReason,
|
|
1190
1282
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
1191
1283
|
}),
|
|
1192
1284
|
usage: {
|
|
1193
|
-
inputTokens: (
|
|
1194
|
-
outputTokens: (
|
|
1195
|
-
totalTokens: (
|
|
1196
|
-
reasoningTokens: (
|
|
1197
|
-
cachedInputTokens: (
|
|
1285
|
+
inputTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _h : void 0,
|
|
1286
|
+
outputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _i : void 0,
|
|
1287
|
+
totalTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _j : void 0,
|
|
1288
|
+
reasoningTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _k : void 0,
|
|
1289
|
+
cachedInputTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _l : void 0
|
|
1198
1290
|
},
|
|
1199
1291
|
warnings,
|
|
1200
1292
|
providerMetadata: {
|
|
1201
1293
|
google: {
|
|
1202
|
-
promptFeedback: (
|
|
1203
|
-
groundingMetadata: (
|
|
1204
|
-
urlContextMetadata: (
|
|
1205
|
-
safetyRatings: (
|
|
1206
|
-
serviceTier: (
|
|
1294
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1295
|
+
groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
|
|
1296
|
+
urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
|
|
1297
|
+
safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
|
|
1298
|
+
serviceTier: (_q = response.serviceTier) != null ? _q : null,
|
|
1207
1299
|
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1208
1300
|
}
|
|
1209
1301
|
},
|
|
@@ -1257,7 +1349,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1257
1349
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1258
1350
|
},
|
|
1259
1351
|
transform(chunk, controller) {
|
|
1260
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1352
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1261
1353
|
if (options.includeRawChunks) {
|
|
1262
1354
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1263
1355
|
}
|
|
@@ -1279,6 +1371,22 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1279
1371
|
}
|
|
1280
1372
|
const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
|
|
1281
1373
|
if (candidate == null) {
|
|
1374
|
+
const promptBlockReason2 = (_g = value.promptFeedback) == null ? void 0 : _g.blockReason;
|
|
1375
|
+
if (promptBlockReason2 != null) {
|
|
1376
|
+
finishReason = "content-filter";
|
|
1377
|
+
providerMetadata = {
|
|
1378
|
+
google: {
|
|
1379
|
+
promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
|
|
1380
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1381
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1382
|
+
safetyRatings: null,
|
|
1383
|
+
serviceTier
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
if (usageMetadata != null) {
|
|
1387
|
+
providerMetadata.google.usageMetadata = usageMetadata;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1282
1390
|
return;
|
|
1283
1391
|
}
|
|
1284
1392
|
const content = candidate.content;
|
|
@@ -1301,9 +1409,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1301
1409
|
}
|
|
1302
1410
|
}
|
|
1303
1411
|
if (content != null) {
|
|
1304
|
-
const parts = (
|
|
1412
|
+
const parts = (_i = content.parts) != null ? _i : [];
|
|
1305
1413
|
for (const part of parts) {
|
|
1306
|
-
if ("executableCode" in part && ((
|
|
1414
|
+
if ("executableCode" in part && ((_j = part.executableCode) == null ? void 0 : _j.code)) {
|
|
1307
1415
|
const toolCallId = generateId2();
|
|
1308
1416
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1309
1417
|
controller.enqueue({
|
|
@@ -1430,17 +1538,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1430
1538
|
}
|
|
1431
1539
|
}
|
|
1432
1540
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1541
|
+
const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
|
|
1542
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
1543
|
+
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
1544
|
+
if (rawFinishReason != null) {
|
|
1545
|
+
finishReason = isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1546
|
+
finishReason: rawFinishReason,
|
|
1436
1547
|
hasToolCalls
|
|
1437
1548
|
});
|
|
1438
1549
|
providerMetadata = {
|
|
1439
1550
|
google: {
|
|
1440
|
-
promptFeedback: (
|
|
1551
|
+
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
1441
1552
|
groundingMetadata: lastGroundingMetadata,
|
|
1442
1553
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1443
|
-
safetyRatings: (
|
|
1554
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
1444
1555
|
serviceTier
|
|
1445
1556
|
}
|
|
1446
1557
|
};
|
|
@@ -1716,7 +1827,7 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1716
1827
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1717
1828
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
1718
1829
|
})
|
|
1719
|
-
),
|
|
1830
|
+
).nullish(),
|
|
1720
1831
|
usageMetadata: usageSchema.nullish(),
|
|
1721
1832
|
promptFeedback: import_v43.z.object({
|
|
1722
1833
|
blockReason: import_v43.z.string().nullish(),
|