@ai-sdk/google 2.0.2 → 2.0.4

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
@@ -332,9 +332,20 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
332
332
  contents.push({
333
333
  role: "model",
334
334
  parts: content.map((part) => {
335
+ var _a2, _b, _c, _d, _e, _f;
335
336
  switch (part.type) {
336
337
  case "text": {
337
- return part.text.length === 0 ? void 0 : { text: part.text };
338
+ return part.text.length === 0 ? void 0 : {
339
+ text: part.text,
340
+ thoughtSignature: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.thoughtSignature
341
+ };
342
+ }
343
+ case "reasoning": {
344
+ return part.text.length === 0 ? void 0 : {
345
+ text: part.text,
346
+ thought: true,
347
+ thoughtSignature: (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.thoughtSignature
348
+ };
338
349
  }
339
350
  case "file": {
340
351
  if (part.mediaType !== "image/png") {
@@ -359,7 +370,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
359
370
  functionCall: {
360
371
  name: part.toolName,
361
372
  args: part.input
362
- }
373
+ },
374
+ thoughtSignature: (_f = (_e = part.providerOptions) == null ? void 0 : _e.google) == null ? void 0 : _f.thoughtSignature
363
375
  };
364
376
  }
365
377
  }
@@ -459,7 +471,13 @@ var googleGenerativeAIProviderOptions = z4.object({
459
471
  *
460
472
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
461
473
  */
462
- audioTimestamp: z4.boolean().optional()
474
+ audioTimestamp: z4.boolean().optional(),
475
+ /**
476
+ * Optional. Defines labels used in billing reports. Available on Vertex AI only.
477
+ *
478
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
479
+ */
480
+ labels: z4.record(z4.string(), z4.string()).optional()
463
481
  });
464
482
 
465
483
  // src/google-prepare-tools.ts
@@ -779,7 +797,8 @@ var GoogleGenerativeAILanguageModel = class {
779
797
  safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
780
798
  tools: googleTools2,
781
799
  toolConfig: googleToolConfig,
782
- cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
800
+ cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
801
+ labels: googleOptions == null ? void 0 : googleOptions.labels
783
802
  },
784
803
  warnings: [...warnings, ...toolWarnings]
785
804
  };
@@ -837,17 +856,18 @@ var GoogleGenerativeAILanguageModel = class {
837
856
  });
838
857
  lastCodeExecutionToolCallId = void 0;
839
858
  } else if ("text" in part && part.text != null && part.text.length > 0) {
840
- if (part.thought === true) {
841
- content.push({ type: "reasoning", text: part.text });
842
- } else {
843
- content.push({ type: "text", text: part.text });
844
- }
859
+ content.push({
860
+ type: part.thought === true ? "reasoning" : "text",
861
+ text: part.text,
862
+ providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
863
+ });
845
864
  } else if ("functionCall" in part) {
846
865
  content.push({
847
866
  type: "tool-call",
848
867
  toolCallId: this.config.generateId(),
849
868
  toolName: part.functionCall.name,
850
- input: JSON.stringify(part.functionCall.args)
869
+ input: JSON.stringify(part.functionCall.args),
870
+ providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
851
871
  });
852
872
  } else if ("inlineData" in part) {
853
873
  content.push({
@@ -1009,13 +1029,21 @@ var GoogleGenerativeAILanguageModel = class {
1009
1029
  currentReasoningBlockId = String(blockCounter++);
1010
1030
  controller.enqueue({
1011
1031
  type: "reasoning-start",
1012
- id: currentReasoningBlockId
1032
+ id: currentReasoningBlockId,
1033
+ providerMetadata: part.thoughtSignature ? {
1034
+ google: {
1035
+ thoughtSignature: part.thoughtSignature
1036
+ }
1037
+ } : void 0
1013
1038
  });
1014
1039
  }
1015
1040
  controller.enqueue({
1016
1041
  type: "reasoning-delta",
1017
1042
  id: currentReasoningBlockId,
1018
- delta: part.text
1043
+ delta: part.text,
1044
+ providerMetadata: part.thoughtSignature ? {
1045
+ google: { thoughtSignature: part.thoughtSignature }
1046
+ } : void 0
1019
1047
  });
1020
1048
  } else {
1021
1049
  if (currentReasoningBlockId !== null) {
@@ -1029,13 +1057,21 @@ var GoogleGenerativeAILanguageModel = class {
1029
1057
  currentTextBlockId = String(blockCounter++);
1030
1058
  controller.enqueue({
1031
1059
  type: "text-start",
1032
- id: currentTextBlockId
1060
+ id: currentTextBlockId,
1061
+ providerMetadata: part.thoughtSignature ? {
1062
+ google: {
1063
+ thoughtSignature: part.thoughtSignature
1064
+ }
1065
+ } : void 0
1033
1066
  });
1034
1067
  }
1035
1068
  controller.enqueue({
1036
1069
  type: "text-delta",
1037
1070
  id: currentTextBlockId,
1038
- delta: part.text
1071
+ delta: part.text,
1072
+ providerMetadata: part.thoughtSignature ? {
1073
+ google: { thoughtSignature: part.thoughtSignature }
1074
+ } : void 0
1039
1075
  });
1040
1076
  }
1041
1077
  }
@@ -1059,22 +1095,26 @@ var GoogleGenerativeAILanguageModel = class {
1059
1095
  controller.enqueue({
1060
1096
  type: "tool-input-start",
1061
1097
  id: toolCall.toolCallId,
1062
- toolName: toolCall.toolName
1098
+ toolName: toolCall.toolName,
1099
+ providerMetadata: toolCall.providerMetadata
1063
1100
  });
1064
1101
  controller.enqueue({
1065
1102
  type: "tool-input-delta",
1066
1103
  id: toolCall.toolCallId,
1067
- delta: toolCall.args
1104
+ delta: toolCall.args,
1105
+ providerMetadata: toolCall.providerMetadata
1068
1106
  });
1069
1107
  controller.enqueue({
1070
1108
  type: "tool-input-end",
1071
- id: toolCall.toolCallId
1109
+ id: toolCall.toolCallId,
1110
+ providerMetadata: toolCall.providerMetadata
1072
1111
  });
1073
1112
  controller.enqueue({
1074
1113
  type: "tool-call",
1075
1114
  toolCallId: toolCall.toolCallId,
1076
1115
  toolName: toolCall.toolName,
1077
- input: toolCall.args
1116
+ input: toolCall.args,
1117
+ providerMetadata: toolCall.providerMetadata
1078
1118
  });
1079
1119
  hasToolCalls = true;
1080
1120
  }
@@ -1135,7 +1175,8 @@ function getToolCallsFromParts({
1135
1175
  type: "tool-call",
1136
1176
  toolCallId: generateId3(),
1137
1177
  toolName: part.functionCall.name,
1138
- args: JSON.stringify(part.functionCall.args)
1178
+ args: JSON.stringify(part.functionCall.args),
1179
+ providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
1139
1180
  }));
1140
1181
  }
1141
1182
  function getInlineDataParts(parts) {
@@ -1166,7 +1207,8 @@ var contentSchema = z7.object({
1166
1207
  functionCall: z7.object({
1167
1208
  name: z7.string(),
1168
1209
  args: z7.unknown()
1169
- })
1210
+ }),
1211
+ thoughtSignature: z7.string().nullish()
1170
1212
  }),
1171
1213
  z7.object({
1172
1214
  inlineData: z7.object({
@@ -1184,7 +1226,8 @@ var contentSchema = z7.object({
1184
1226
  output: z7.string()
1185
1227
  }).nullish(),
1186
1228
  text: z7.string().nullish(),
1187
- thought: z7.boolean().nullish()
1229
+ thought: z7.boolean().nullish(),
1230
+ thoughtSignature: z7.string().nullish()
1188
1231
  })
1189
1232
  ])
1190
1233
  ).nullish()