@ai-sdk/google 4.0.0-beta.3 → 4.0.0-beta.5

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,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.0-beta.5
4
+
5
+ ### Patch Changes
6
+
7
+ - ab43029: feat(provider/google): support multimodal content parts in embedding provider options
8
+
9
+ ## 4.0.0-beta.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 2edd14e: fix(provider/google): correctly mark reasoning files as such and fix related multi-turn errors
14
+
3
15
  ## 4.0.0-beta.3
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -56,6 +56,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
56
56
  mimeType: string;
57
57
  data: string;
58
58
  };
59
+ thought?: boolean | null | undefined;
59
60
  thoughtSignature?: string | null | undefined;
60
61
  } | {
61
62
  executableCode?: {
@@ -185,6 +186,14 @@ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {})
185
186
  declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
186
187
  outputDimensionality?: number | undefined;
187
188
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
189
+ content?: ({
190
+ text: string;
191
+ } | {
192
+ inlineData: {
193
+ mimeType: string;
194
+ data: string;
195
+ };
196
+ })[] | undefined;
188
197
  }>;
189
198
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
190
199
 
package/dist/index.d.ts CHANGED
@@ -56,6 +56,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
56
56
  mimeType: string;
57
57
  data: string;
58
58
  };
59
+ thought?: boolean | null | undefined;
59
60
  thoughtSignature?: string | null | undefined;
60
61
  } | {
61
62
  executableCode?: {
@@ -185,6 +186,14 @@ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {})
185
186
  declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
186
187
  outputDimensionality?: number | undefined;
187
188
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
189
+ content?: ({
190
+ text: string;
191
+ } | {
192
+ inlineData: {
193
+ mimeType: string;
194
+ data: string;
195
+ };
196
+ })[] | undefined;
188
197
  }>;
189
198
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
190
199
 
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
30
30
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "4.0.0-beta.3" : "0.0.0-test";
33
+ var VERSION = true ? "4.0.0-beta.5" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -59,6 +59,15 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
59
59
  // src/google-generative-ai-embedding-options.ts
60
60
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
61
61
  var import_v42 = require("zod/v4");
62
+ var googleEmbeddingContentPartSchema = import_v42.z.union([
63
+ import_v42.z.object({ text: import_v42.z.string() }),
64
+ import_v42.z.object({
65
+ inlineData: import_v42.z.object({
66
+ mimeType: import_v42.z.string(),
67
+ data: import_v42.z.string()
68
+ })
69
+ })
70
+ ]);
62
71
  var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
63
72
  () => (0, import_provider_utils2.zodSchema)(
64
73
  import_v42.z.object({
@@ -88,7 +97,13 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
88
97
  "QUESTION_ANSWERING",
89
98
  "FACT_VERIFICATION",
90
99
  "CODE_RETRIEVAL_QUERY"
91
- ]).optional()
100
+ ]).optional(),
101
+ /**
102
+ * Optional. Multimodal content parts for embedding non-text content
103
+ * (images, video, PDF, audio). When provided, these parts are used
104
+ * instead of the text values in the embedding request.
105
+ */
106
+ content: import_v42.z.array(googleEmbeddingContentPartSchema).min(1).optional()
92
107
  })
93
108
  )
94
109
  );
@@ -111,6 +126,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
111
126
  abortSignal,
112
127
  providerOptions
113
128
  }) {
129
+ var _a;
114
130
  const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
115
131
  provider: "google",
116
132
  providerOptions,
@@ -128,7 +144,10 @@ var GoogleGenerativeAIEmbeddingModel = class {
128
144
  await (0, import_provider_utils3.resolve)(this.config.headers),
129
145
  headers
130
146
  );
147
+ const multimodalContent = (_a = googleOptions == null ? void 0 : googleOptions.content) != null ? _a : [];
131
148
  if (values.length === 1) {
149
+ const textPart = values[0] ? [{ text: values[0] }] : [];
150
+ const parts = multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: values[0] }];
132
151
  const {
133
152
  responseHeaders: responseHeaders2,
134
153
  value: response2,
@@ -139,7 +158,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
139
158
  body: {
140
159
  model: `models/${this.modelId}`,
141
160
  content: {
142
- parts: [{ text: values[0] }]
161
+ parts
143
162
  },
144
163
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
145
164
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -166,12 +185,18 @@ var GoogleGenerativeAIEmbeddingModel = class {
166
185
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
167
186
  headers: mergedHeaders,
168
187
  body: {
169
- requests: values.map((value) => ({
170
- model: `models/${this.modelId}`,
171
- content: { role: "user", parts: [{ text: value }] },
172
- outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
173
- taskType: googleOptions == null ? void 0 : googleOptions.taskType
174
- }))
188
+ requests: values.map((value) => {
189
+ const textPart = value ? [{ text: value }] : [];
190
+ return {
191
+ model: `models/${this.modelId}`,
192
+ content: {
193
+ role: "user",
194
+ parts: multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: value }]
195
+ },
196
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
197
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
198
+ };
199
+ })
175
200
  },
176
201
  failedResponseHandler: googleFailedResponseHandler,
177
202
  successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
@@ -447,6 +472,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
447
472
  mimeType: part.mediaType,
448
473
  data: (0, import_provider_utils4.convertToBase64)(part.data)
449
474
  },
475
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
450
476
  thoughtSignature
451
477
  };
452
478
  }
@@ -1092,13 +1118,16 @@ var GoogleGenerativeAILanguageModel = class {
1092
1118
  } : void 0
1093
1119
  });
1094
1120
  } else if ("inlineData" in part) {
1121
+ const hasThought = part.thought === true;
1122
+ const hasThoughtSignature = !!part.thoughtSignature;
1095
1123
  content.push({
1096
1124
  type: "file",
1097
1125
  data: part.inlineData.data,
1098
1126
  mediaType: part.inlineData.mimeType,
1099
- providerMetadata: part.thoughtSignature ? {
1127
+ providerMetadata: hasThought || hasThoughtSignature ? {
1100
1128
  [providerOptionsName]: {
1101
- thoughtSignature: part.thoughtSignature
1129
+ ...hasThought ? { thought: true } : {},
1130
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1102
1131
  }
1103
1132
  } : void 0
1104
1133
  });
@@ -1319,16 +1348,19 @@ var GoogleGenerativeAILanguageModel = class {
1319
1348
  });
1320
1349
  currentReasoningBlockId = null;
1321
1350
  }
1322
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1351
+ const hasThought = part.thought === true;
1352
+ const hasThoughtSignature = !!part.thoughtSignature;
1353
+ const fileMeta = hasThought || hasThoughtSignature ? {
1323
1354
  [providerOptionsName]: {
1324
- thoughtSignature: part.thoughtSignature
1355
+ ...hasThought ? { thought: true } : {},
1356
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1325
1357
  }
1326
1358
  } : void 0;
1327
1359
  controller.enqueue({
1328
1360
  type: "file",
1329
1361
  mediaType: part.inlineData.mimeType,
1330
1362
  data: part.inlineData.data,
1331
- providerMetadata: thoughtSignatureMetadata
1363
+ providerMetadata: fileMeta
1332
1364
  });
1333
1365
  }
1334
1366
  }
@@ -1594,6 +1626,7 @@ var getContentSchema = () => import_v45.z.object({
1594
1626
  mimeType: import_v45.z.string(),
1595
1627
  data: import_v45.z.string()
1596
1628
  }),
1629
+ thought: import_v45.z.boolean().nullish(),
1597
1630
  thoughtSignature: import_v45.z.string().nullish()
1598
1631
  }),
1599
1632
  import_v45.z.object({