@ai-sdk/google 3.0.22 → 3.0.24

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/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.22" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.24" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -1010,7 +1010,7 @@ var GoogleGenerativeAILanguageModel = class {
1010
1010
  };
1011
1011
  }
1012
1012
  async doGenerate(options) {
1013
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1013
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1014
1014
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1015
1015
  const mergedHeaders = combineHeaders2(
1016
1016
  await resolve2(this.config.headers),
@@ -1055,20 +1055,28 @@ var GoogleGenerativeAILanguageModel = class {
1055
1055
  toolName: "code_execution",
1056
1056
  result: {
1057
1057
  outcome: part.codeExecutionResult.outcome,
1058
- output: part.codeExecutionResult.output
1058
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
1059
1059
  }
1060
1060
  });
1061
1061
  lastCodeExecutionToolCallId = void 0;
1062
- } else if ("text" in part && part.text != null && part.text.length > 0) {
1063
- content.push({
1064
- type: part.thought === true ? "reasoning" : "text",
1065
- text: part.text,
1066
- providerMetadata: part.thoughtSignature ? {
1067
- [providerOptionsName]: {
1068
- thoughtSignature: part.thoughtSignature
1069
- }
1070
- } : void 0
1071
- });
1062
+ } else if ("text" in part && part.text != null) {
1063
+ const thoughtSignatureMetadata = part.thoughtSignature ? {
1064
+ [providerOptionsName]: {
1065
+ thoughtSignature: part.thoughtSignature
1066
+ }
1067
+ } : void 0;
1068
+ if (part.text.length === 0) {
1069
+ if (thoughtSignatureMetadata != null && content.length > 0) {
1070
+ const lastContent = content[content.length - 1];
1071
+ lastContent.providerMetadata = thoughtSignatureMetadata;
1072
+ }
1073
+ } else {
1074
+ content.push({
1075
+ type: part.thought === true ? "reasoning" : "text",
1076
+ text: part.text,
1077
+ providerMetadata: thoughtSignatureMetadata
1078
+ });
1079
+ }
1072
1080
  } else if ("functionCall" in part) {
1073
1081
  content.push({
1074
1082
  type: "tool-call",
@@ -1094,10 +1102,10 @@ var GoogleGenerativeAILanguageModel = class {
1094
1102
  });
1095
1103
  }
1096
1104
  }
1097
- const sources = (_d = extractSources({
1105
+ const sources = (_e = extractSources({
1098
1106
  groundingMetadata: candidate.groundingMetadata,
1099
1107
  generateId: this.config.generateId
1100
- })) != null ? _d : [];
1108
+ })) != null ? _e : [];
1101
1109
  for (const source of sources) {
1102
1110
  content.push(source);
1103
1111
  }
@@ -1111,16 +1119,16 @@ var GoogleGenerativeAILanguageModel = class {
1111
1119
  (part) => part.type === "tool-call" && !part.providerExecuted
1112
1120
  )
1113
1121
  }),
1114
- raw: (_e = candidate.finishReason) != null ? _e : void 0
1122
+ raw: (_f = candidate.finishReason) != null ? _f : void 0
1115
1123
  },
1116
1124
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
1117
1125
  warnings,
1118
1126
  providerMetadata: {
1119
1127
  [providerOptionsName]: {
1120
- promptFeedback: (_f = response.promptFeedback) != null ? _f : null,
1121
- groundingMetadata: (_g = candidate.groundingMetadata) != null ? _g : null,
1122
- urlContextMetadata: (_h = candidate.urlContextMetadata) != null ? _h : null,
1123
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
1128
+ promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
1129
+ groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
1130
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
1131
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1124
1132
  usageMetadata: usageMetadata != null ? usageMetadata : null
1125
1133
  }
1126
1134
  },
@@ -1169,7 +1177,7 @@ var GoogleGenerativeAILanguageModel = class {
1169
1177
  controller.enqueue({ type: "stream-start", warnings });
1170
1178
  },
1171
1179
  transform(chunk, controller) {
1172
- var _a, _b, _c, _d, _e, _f, _g;
1180
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1173
1181
  if (options.includeRawChunks) {
1174
1182
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1175
1183
  }
@@ -1221,13 +1229,27 @@ var GoogleGenerativeAILanguageModel = class {
1221
1229
  toolName: "code_execution",
1222
1230
  result: {
1223
1231
  outcome: part.codeExecutionResult.outcome,
1224
- output: part.codeExecutionResult.output
1232
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
1225
1233
  }
1226
1234
  });
1227
1235
  lastCodeExecutionToolCallId = void 0;
1228
1236
  }
1229
- } else if ("text" in part && part.text != null && part.text.length > 0) {
1230
- if (part.thought === true) {
1237
+ } else if ("text" in part && part.text != null) {
1238
+ const thoughtSignatureMetadata = part.thoughtSignature ? {
1239
+ [providerOptionsName]: {
1240
+ thoughtSignature: part.thoughtSignature
1241
+ }
1242
+ } : void 0;
1243
+ if (part.text.length === 0) {
1244
+ if (thoughtSignatureMetadata != null && currentTextBlockId !== null) {
1245
+ controller.enqueue({
1246
+ type: "text-delta",
1247
+ id: currentTextBlockId,
1248
+ delta: "",
1249
+ providerMetadata: thoughtSignatureMetadata
1250
+ });
1251
+ }
1252
+ } else if (part.thought === true) {
1231
1253
  if (currentTextBlockId !== null) {
1232
1254
  controller.enqueue({
1233
1255
  type: "text-end",
@@ -1240,22 +1262,14 @@ var GoogleGenerativeAILanguageModel = class {
1240
1262
  controller.enqueue({
1241
1263
  type: "reasoning-start",
1242
1264
  id: currentReasoningBlockId,
1243
- providerMetadata: part.thoughtSignature ? {
1244
- [providerOptionsName]: {
1245
- thoughtSignature: part.thoughtSignature
1246
- }
1247
- } : void 0
1265
+ providerMetadata: thoughtSignatureMetadata
1248
1266
  });
1249
1267
  }
1250
1268
  controller.enqueue({
1251
1269
  type: "reasoning-delta",
1252
1270
  id: currentReasoningBlockId,
1253
1271
  delta: part.text,
1254
- providerMetadata: part.thoughtSignature ? {
1255
- [providerOptionsName]: {
1256
- thoughtSignature: part.thoughtSignature
1257
- }
1258
- } : void 0
1272
+ providerMetadata: thoughtSignatureMetadata
1259
1273
  });
1260
1274
  } else {
1261
1275
  if (currentReasoningBlockId !== null) {
@@ -1270,22 +1284,14 @@ var GoogleGenerativeAILanguageModel = class {
1270
1284
  controller.enqueue({
1271
1285
  type: "text-start",
1272
1286
  id: currentTextBlockId,
1273
- providerMetadata: part.thoughtSignature ? {
1274
- [providerOptionsName]: {
1275
- thoughtSignature: part.thoughtSignature
1276
- }
1277
- } : void 0
1287
+ providerMetadata: thoughtSignatureMetadata
1278
1288
  });
1279
1289
  }
1280
1290
  controller.enqueue({
1281
1291
  type: "text-delta",
1282
1292
  id: currentTextBlockId,
1283
1293
  delta: part.text,
1284
- providerMetadata: part.thoughtSignature ? {
1285
- [providerOptionsName]: {
1286
- thoughtSignature: part.thoughtSignature
1287
- }
1288
- } : void 0
1294
+ providerMetadata: thoughtSignatureMetadata
1289
1295
  });
1290
1296
  }
1291
1297
  } else if ("inlineData" in part) {
@@ -1341,10 +1347,10 @@ var GoogleGenerativeAILanguageModel = class {
1341
1347
  };
1342
1348
  providerMetadata = {
1343
1349
  [providerOptionsName]: {
1344
- promptFeedback: (_d = value.promptFeedback) != null ? _d : null,
1345
- groundingMetadata: (_e = candidate.groundingMetadata) != null ? _e : null,
1346
- urlContextMetadata: (_f = candidate.urlContextMetadata) != null ? _f : null,
1347
- safetyRatings: (_g = candidate.safetyRatings) != null ? _g : null
1350
+ promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1351
+ groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1352
+ urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1353
+ safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1348
1354
  }
1349
1355
  };
1350
1356
  if (usageMetadata != null) {
@@ -1550,7 +1556,7 @@ var getContentSchema = () => z5.object({
1550
1556
  }).nullish(),
1551
1557
  codeExecutionResult: z5.object({
1552
1558
  outcome: z5.string(),
1553
- output: z5.string()
1559
+ output: z5.string().nullish()
1554
1560
  }).nullish(),
1555
1561
  text: z5.string().nullish(),
1556
1562
  thought: z5.boolean().nullish(),