@ai-sdk/google 2.0.61 → 2.0.63

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 ? "2.0.61" : "0.0.0-test";
10
+ var VERSION = true ? "2.0.63" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -93,11 +93,15 @@ var googleGenerativeAIEmbeddingProviderOptions = lazySchema2(
93
93
  "CODE_RETRIEVAL_QUERY"
94
94
  ]).optional(),
95
95
  /**
96
- * Optional. Multimodal content parts for embedding non-text content
97
- * (images, video, PDF, audio). When provided, these parts are merged
98
- * with the text values in the embedding request.
96
+ * Optional. Per-value multimodal content parts for embedding non-text
97
+ * content (images, video, PDF, audio). Each entry corresponds to the
98
+ * embedding value at the same index and its parts are merged with the
99
+ * text value in the request. Use `null` for entries that are text-only.
100
+ *
101
+ * The array length must match the number of values being embedded. In
102
+ * the case of a single embedding, the array length must be 1.
99
103
  */
100
- content: z2.array(googleEmbeddingContentPartSchema).min(1).optional()
104
+ content: z2.array(z2.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
101
105
  })
102
106
  )
103
107
  );
@@ -120,7 +124,6 @@ var GoogleGenerativeAIEmbeddingModel = class {
120
124
  abortSignal,
121
125
  providerOptions
122
126
  }) {
123
- var _a;
124
127
  const googleOptions = await parseProviderOptions({
125
128
  provider: "google",
126
129
  providerOptions,
@@ -138,10 +141,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
138
141
  await resolve(this.config.headers),
139
142
  headers
140
143
  );
141
- const multimodalContent = (_a = googleOptions == null ? void 0 : googleOptions.content) != null ? _a : [];
144
+ const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
145
+ if (multimodalContent != null && multimodalContent.length !== values.length) {
146
+ throw new Error(
147
+ `The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
148
+ );
149
+ }
142
150
  if (values.length === 1) {
151
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
143
152
  const textPart = values[0] ? [{ text: values[0] }] : [];
144
- const parts = multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: values[0] }];
153
+ const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
145
154
  const {
146
155
  responseHeaders: responseHeaders2,
147
156
  value: response2,
@@ -178,13 +187,14 @@ var GoogleGenerativeAIEmbeddingModel = class {
178
187
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
179
188
  headers: mergedHeaders,
180
189
  body: {
181
- requests: values.map((value) => {
190
+ requests: values.map((value, index) => {
191
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
182
192
  const textPart = value ? [{ text: value }] : [];
183
193
  return {
184
194
  model: `models/${this.modelId}`,
185
195
  content: {
186
196
  role: "user",
187
- parts: multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: value }]
197
+ parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
188
198
  },
189
199
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
190
200
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -356,11 +366,12 @@ import {
356
366
  } from "@ai-sdk/provider";
357
367
  import { convertToBase64 } from "@ai-sdk/provider-utils";
358
368
  function convertToGoogleGenerativeAIMessages(prompt, options) {
359
- var _a;
369
+ var _a, _b;
360
370
  const systemInstructionParts = [];
361
371
  const contents = [];
362
372
  let systemMessagesAllowed = true;
363
373
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
374
+ const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
364
375
  for (const { role, content } of prompt) {
365
376
  switch (role) {
366
377
  case "system": {
@@ -408,8 +419,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
408
419
  contents.push({
409
420
  role: "model",
410
421
  parts: content.map((part) => {
411
- var _a2, _b, _c;
412
- 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;
422
+ var _a2, _b2, _c;
423
+ 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;
413
424
  switch (part.type) {
414
425
  case "text": {
415
426
  return part.text.length === 0 ? void 0 : {
@@ -462,36 +473,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
462
473
  for (const part of content) {
463
474
  const output = part.output;
464
475
  if (output.type === "content") {
465
- for (const contentPart of output.value) {
466
- switch (contentPart.type) {
467
- case "text":
468
- parts.push({
469
- functionResponse: {
470
- name: part.toolName,
471
- response: {
472
- name: part.toolName,
473
- content: contentPart.text
474
- }
475
- }
476
- });
477
- break;
478
- case "media":
479
- parts.push(
480
- {
481
- inlineData: {
482
- mimeType: contentPart.mediaType,
483
- data: contentPart.data
484
- }
485
- },
486
- {
487
- text: "Tool executed successfully and returned this image as a response"
488
- }
489
- );
490
- break;
491
- default:
492
- parts.push({ text: JSON.stringify(contentPart) });
493
- break;
494
- }
476
+ if (supportsFunctionResponseParts) {
477
+ appendToolResultParts({ parts, part, output });
478
+ } else {
479
+ appendLegacyToolResultParts({ parts, part, output });
495
480
  }
496
481
  } else {
497
482
  parts.push({
@@ -522,6 +507,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
522
507
  contents
523
508
  };
524
509
  }
510
+ function appendToolResultParts({
511
+ parts,
512
+ part,
513
+ output
514
+ }) {
515
+ const responseTextParts = [];
516
+ const functionResponseParts = [];
517
+ for (const contentPart of output.value) {
518
+ switch (contentPart.type) {
519
+ case "text":
520
+ responseTextParts.push(contentPart.text);
521
+ break;
522
+ case "media":
523
+ functionResponseParts.push({
524
+ inlineData: {
525
+ mimeType: contentPart.mediaType,
526
+ data: contentPart.data
527
+ }
528
+ });
529
+ break;
530
+ }
531
+ }
532
+ const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
533
+ parts.push({
534
+ functionResponse: {
535
+ name: part.toolName,
536
+ response: {
537
+ name: part.toolName,
538
+ content: responseText
539
+ },
540
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
541
+ }
542
+ });
543
+ }
544
+ function appendLegacyToolResultParts({
545
+ parts,
546
+ part,
547
+ output
548
+ }) {
549
+ for (const contentPart of output.value) {
550
+ switch (contentPart.type) {
551
+ case "text":
552
+ parts.push({
553
+ functionResponse: {
554
+ name: part.toolName,
555
+ response: {
556
+ name: part.toolName,
557
+ content: contentPart.text
558
+ }
559
+ }
560
+ });
561
+ break;
562
+ case "media":
563
+ parts.push(
564
+ {
565
+ inlineData: {
566
+ mimeType: contentPart.mediaType,
567
+ data: contentPart.data
568
+ }
569
+ },
570
+ {
571
+ text: "Tool executed successfully and returned this image as a response"
572
+ }
573
+ );
574
+ break;
575
+ default:
576
+ parts.push({ text: JSON.stringify(contentPart) });
577
+ break;
578
+ }
579
+ }
580
+ }
525
581
 
526
582
  // src/get-model-path.ts
527
583
  function getModelPath(modelId) {
@@ -927,9 +983,10 @@ var GoogleGenerativeAILanguageModel = class {
927
983
  });
928
984
  }
929
985
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
986
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
930
987
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
931
988
  prompt,
932
- { isGemmaModel }
989
+ { isGemmaModel, supportsFunctionResponseParts }
933
990
  );
934
991
  const {
935
992
  tools: googleTools2,