@ai-sdk/google 2.0.62 → 2.0.64

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.64
4
+
5
+ ### Patch Changes
6
+
7
+ - fd3f1d3: feat(provider/google): add support for service tier parameter
8
+
9
+ ## 2.0.63
10
+
11
+ ### Patch Changes
12
+
13
+ - 7655bcf: feat(provider/google): Add multimodal tool-result support for Google function responses.
14
+
15
+ Tool results with `output.type = 'content'` now map media parts into
16
+ `functionResponse.parts` for Google models, including `image-data`,
17
+ `file-data`, and base64 `data:` URLs in URL-style content parts.
18
+ Remote HTTP(S) URLs in URL-style tool-result parts are not supported.
19
+
3
20
  ## 2.0.62
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -39,6 +39,7 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
39
39
  longitude: number;
40
40
  } | undefined;
41
41
  } | undefined;
42
+ serviceTier?: "SERVICE_TIER_STANDARD" | "SERVICE_TIER_FLEX" | "SERVICE_TIER_PRIORITY" | undefined;
42
43
  }>;
43
44
  type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
44
45
 
@@ -152,6 +153,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
152
153
  blocked?: boolean | null | undefined;
153
154
  }[] | null | undefined;
154
155
  } | null | undefined;
156
+ serviceTier?: string | null | undefined;
155
157
  }>;
156
158
  type GroundingMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
157
159
  type UrlContextMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
@@ -164,6 +166,7 @@ interface GoogleGenerativeAIProviderMetadata {
164
166
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
165
167
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
166
168
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
169
+ serviceTier: string | null;
167
170
  }
168
171
 
169
172
  type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | (string & {});
package/dist/index.d.ts CHANGED
@@ -39,6 +39,7 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
39
39
  longitude: number;
40
40
  } | undefined;
41
41
  } | undefined;
42
+ serviceTier?: "SERVICE_TIER_STANDARD" | "SERVICE_TIER_FLEX" | "SERVICE_TIER_PRIORITY" | undefined;
42
43
  }>;
43
44
  type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
44
45
 
@@ -152,6 +153,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
152
153
  blocked?: boolean | null | undefined;
153
154
  }[] | null | undefined;
154
155
  } | null | undefined;
156
+ serviceTier?: string | null | undefined;
155
157
  }>;
156
158
  type GroundingMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
157
159
  type UrlContextMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
@@ -164,6 +166,7 @@ interface GoogleGenerativeAIProviderMetadata {
164
166
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
165
167
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
166
168
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
169
+ serviceTier: string | null;
167
170
  }
168
171
 
169
172
  type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | (string & {});
package/dist/index.js CHANGED
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  VERSION: () => VERSION,
24
24
  createGoogleGenerativeAI: () => createGoogleGenerativeAI,
25
25
  google: () => google
26
26
  });
27
- module.exports = __toCommonJS(src_exports);
27
+ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/google-provider.ts
30
30
  var import_provider_utils15 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.62" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.64" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -360,11 +360,12 @@ function isEmptyObjectSchema(jsonSchema) {
360
360
  var import_provider2 = require("@ai-sdk/provider");
361
361
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
362
362
  function convertToGoogleGenerativeAIMessages(prompt, options) {
363
- var _a;
363
+ var _a, _b;
364
364
  const systemInstructionParts = [];
365
365
  const contents = [];
366
366
  let systemMessagesAllowed = true;
367
367
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
368
+ const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
368
369
  for (const { role, content } of prompt) {
369
370
  switch (role) {
370
371
  case "system": {
@@ -412,8 +413,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
412
413
  contents.push({
413
414
  role: "model",
414
415
  parts: content.map((part) => {
415
- var _a2, _b, _c;
416
- const thoughtSignature = ((_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
416
+ var _a2, _b2, _c;
417
+ const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
417
418
  switch (part.type) {
418
419
  case "text": {
419
420
  return part.text.length === 0 ? void 0 : {
@@ -466,36 +467,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
466
467
  for (const part of content) {
467
468
  const output = part.output;
468
469
  if (output.type === "content") {
469
- for (const contentPart of output.value) {
470
- switch (contentPart.type) {
471
- case "text":
472
- parts.push({
473
- functionResponse: {
474
- name: part.toolName,
475
- response: {
476
- name: part.toolName,
477
- content: contentPart.text
478
- }
479
- }
480
- });
481
- break;
482
- case "media":
483
- parts.push(
484
- {
485
- inlineData: {
486
- mimeType: contentPart.mediaType,
487
- data: contentPart.data
488
- }
489
- },
490
- {
491
- text: "Tool executed successfully and returned this image as a response"
492
- }
493
- );
494
- break;
495
- default:
496
- parts.push({ text: JSON.stringify(contentPart) });
497
- break;
498
- }
470
+ if (supportsFunctionResponseParts) {
471
+ appendToolResultParts({ parts, part, output });
472
+ } else {
473
+ appendLegacyToolResultParts({ parts, part, output });
499
474
  }
500
475
  } else {
501
476
  parts.push({
@@ -526,6 +501,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
526
501
  contents
527
502
  };
528
503
  }
504
+ function appendToolResultParts({
505
+ parts,
506
+ part,
507
+ output
508
+ }) {
509
+ const responseTextParts = [];
510
+ const functionResponseParts = [];
511
+ for (const contentPart of output.value) {
512
+ switch (contentPart.type) {
513
+ case "text":
514
+ responseTextParts.push(contentPart.text);
515
+ break;
516
+ case "media":
517
+ functionResponseParts.push({
518
+ inlineData: {
519
+ mimeType: contentPart.mediaType,
520
+ data: contentPart.data
521
+ }
522
+ });
523
+ break;
524
+ }
525
+ }
526
+ const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
527
+ parts.push({
528
+ functionResponse: {
529
+ name: part.toolName,
530
+ response: {
531
+ name: part.toolName,
532
+ content: responseText
533
+ },
534
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
535
+ }
536
+ });
537
+ }
538
+ function appendLegacyToolResultParts({
539
+ parts,
540
+ part,
541
+ output
542
+ }) {
543
+ for (const contentPart of output.value) {
544
+ switch (contentPart.type) {
545
+ case "text":
546
+ parts.push({
547
+ functionResponse: {
548
+ name: part.toolName,
549
+ response: {
550
+ name: part.toolName,
551
+ content: contentPart.text
552
+ }
553
+ }
554
+ });
555
+ break;
556
+ case "media":
557
+ parts.push(
558
+ {
559
+ inlineData: {
560
+ mimeType: contentPart.mediaType,
561
+ data: contentPart.data
562
+ }
563
+ },
564
+ {
565
+ text: "Tool executed successfully and returned this image as a response"
566
+ }
567
+ );
568
+ break;
569
+ default:
570
+ parts.push({ text: JSON.stringify(contentPart) });
571
+ break;
572
+ }
573
+ }
574
+ }
529
575
 
530
576
  // src/get-model-path.ts
531
577
  function getModelPath(modelId) {
@@ -649,7 +695,15 @@ var googleGenerativeAIProviderOptions = (0, import_provider_utils5.lazySchema)(
649
695
  latitude: import_v44.z.number(),
650
696
  longitude: import_v44.z.number()
651
697
  }).optional()
652
- }).optional()
698
+ }).optional(),
699
+ /**
700
+ * Optional. The service tier to use for the request.
701
+ */
702
+ serviceTier: import_v44.z.enum([
703
+ "SERVICE_TIER_STANDARD",
704
+ "SERVICE_TIER_FLEX",
705
+ "SERVICE_TIER_PRIORITY"
706
+ ]).optional()
653
707
  })
654
708
  )
655
709
  );
@@ -926,9 +980,10 @@ var GoogleGenerativeAILanguageModel = class {
926
980
  });
927
981
  }
928
982
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
983
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
929
984
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
930
985
  prompt,
931
- { isGemmaModel }
986
+ { isGemmaModel, supportsFunctionResponseParts }
932
987
  );
933
988
  const {
934
989
  tools: googleTools2,
@@ -979,13 +1034,14 @@ var GoogleGenerativeAILanguageModel = class {
979
1034
  retrievalConfig: googleOptions.retrievalConfig
980
1035
  } : googleToolConfig,
981
1036
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
982
- labels: googleOptions == null ? void 0 : googleOptions.labels
1037
+ labels: googleOptions == null ? void 0 : googleOptions.labels,
1038
+ serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
983
1039
  },
984
1040
  warnings: [...warnings, ...toolWarnings]
985
1041
  };
986
1042
  }
987
1043
  async doGenerate(options) {
988
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1044
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
989
1045
  const { args, warnings } = await this.getArgs(options);
990
1046
  const body = JSON.stringify(args);
991
1047
  const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
@@ -1095,7 +1151,7 @@ var GoogleGenerativeAILanguageModel = class {
1095
1151
  groundingMetadata: (_k = candidate.groundingMetadata) != null ? _k : null,
1096
1152
  urlContextMetadata: (_l = candidate.urlContextMetadata) != null ? _l : null,
1097
1153
  safetyRatings: (_m = candidate.safetyRatings) != null ? _m : null,
1098
- usageMetadata: usageMetadata != null ? usageMetadata : null
1154
+ serviceTier: (_n = response.serviceTier) != null ? _n : null
1099
1155
  }
1100
1156
  },
1101
1157
  request: { body },
@@ -1133,6 +1189,7 @@ var GoogleGenerativeAILanguageModel = class {
1133
1189
  let providerMetadata = void 0;
1134
1190
  let lastGroundingMetadata = null;
1135
1191
  let lastUrlContextMetadata = null;
1192
+ let serviceTier = null;
1136
1193
  const generateId3 = this.config.generateId;
1137
1194
  let hasToolCalls = false;
1138
1195
  let currentTextBlockId = null;
@@ -1164,6 +1221,9 @@ var GoogleGenerativeAILanguageModel = class {
1164
1221
  usage.reasoningTokens = (_d = usageMetadata.thoughtsTokenCount) != null ? _d : void 0;
1165
1222
  usage.cachedInputTokens = (_e = usageMetadata.cachedContentTokenCount) != null ? _e : void 0;
1166
1223
  }
1224
+ if (value.serviceTier != null) {
1225
+ serviceTier = value.serviceTier;
1226
+ }
1167
1227
  const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
1168
1228
  if (candidate == null) {
1169
1229
  return;
@@ -1328,7 +1388,8 @@ var GoogleGenerativeAILanguageModel = class {
1328
1388
  promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
1329
1389
  groundingMetadata: lastGroundingMetadata,
1330
1390
  urlContextMetadata: lastUrlContextMetadata,
1331
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
1391
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1392
+ serviceTier
1332
1393
  }
1333
1394
  };
1334
1395
  if (usageMetadata != null) {
@@ -1595,7 +1656,8 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
1595
1656
  promptFeedback: import_v45.z.object({
1596
1657
  blockReason: import_v45.z.string().nullish(),
1597
1658
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
1598
- }).nullish()
1659
+ }).nullish(),
1660
+ serviceTier: import_v45.z.string().nullish()
1599
1661
  })
1600
1662
  )
1601
1663
  );
@@ -1615,7 +1677,8 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
1615
1677
  promptFeedback: import_v45.z.object({
1616
1678
  blockReason: import_v45.z.string().nullish(),
1617
1679
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
1618
- }).nullish()
1680
+ }).nullish(),
1681
+ serviceTier: import_v45.z.string().nullish()
1619
1682
  })
1620
1683
  )
1621
1684
  );