@ai-sdk/google 4.0.0-beta.1 → 4.0.0-beta.11
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 +66 -0
- package/dist/index.d.mts +31 -14
- package/dist/index.d.ts +31 -14
- package/dist/index.js +97 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -28
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +11 -7
- package/dist/internal/index.d.ts +11 -7
- package/dist/internal/index.js +49 -18
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +46 -15
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +30 -3
- package/package.json +3 -3
- package/src/convert-google-generative-ai-usage.ts +2 -2
- package/src/convert-to-google-generative-ai-messages.ts +23 -2
- package/src/google-generative-ai-embedding-model.ts +42 -13
- package/src/google-generative-ai-embedding-options.ts +24 -0
- package/src/google-generative-ai-image-model.ts +14 -14
- package/src/google-generative-ai-language-model.ts +65 -44
- package/src/google-generative-ai-prompt.ts +9 -0
- package/src/google-generative-ai-video-model.ts +7 -7
- package/src/google-prepare-tools.ts +6 -6
- package/src/google-provider.ts +18 -18
- package/src/map-google-generative-ai-finish-reason.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f7d4f01: feat(provider): add support for `reasoning-file` type for files that are part of reasoning
|
|
8
|
+
- Updated dependencies [f7d4f01]
|
|
9
|
+
- @ai-sdk/provider-utils@5.0.0-beta.3
|
|
10
|
+
- @ai-sdk/provider@4.0.0-beta.2
|
|
11
|
+
|
|
12
|
+
## 4.0.0-beta.10
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [5c2a5a2]
|
|
17
|
+
- @ai-sdk/provider@4.0.0-beta.1
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.0-beta.2
|
|
19
|
+
|
|
20
|
+
## 4.0.0-beta.9
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- e59176c: chore(google): update v3 specs to v4
|
|
25
|
+
|
|
26
|
+
## 4.0.0-beta.8
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 4dac142: feat(google): add new finishMessage field in providerMetadata
|
|
31
|
+
|
|
32
|
+
## 4.0.0-beta.7
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 82288b0: feat(provider/google): add `gemini-embedding-2-preview` and fix multimodal embedding support with `embedMany`
|
|
37
|
+
|
|
38
|
+
## 4.0.0-beta.6
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- add4326: fix(provider/google): correct JSDoc for multimodal embedding content option
|
|
43
|
+
|
|
44
|
+
## 4.0.0-beta.5
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- ab43029: feat(provider/google): support multimodal content parts in embedding provider options
|
|
49
|
+
|
|
50
|
+
## 4.0.0-beta.4
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 2edd14e: fix(provider/google): correctly mark reasoning files as such and fix related multi-turn errors
|
|
55
|
+
|
|
56
|
+
## 4.0.0-beta.3
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- Updated dependencies [531251e]
|
|
61
|
+
- @ai-sdk/provider-utils@5.0.0-beta.1
|
|
62
|
+
|
|
63
|
+
## 4.0.0-beta.2
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- c9c4661: fix(provider/google): preserve groundingMetadata and urlContextMetadata when they arrive in a stream chunk before the finishReason chunk
|
|
68
|
+
|
|
3
69
|
## 4.0.0-beta.1
|
|
4
70
|
|
|
5
71
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
6
6
|
error: {
|
|
@@ -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?: {
|
|
@@ -72,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
72
73
|
})[] | null | undefined;
|
|
73
74
|
} | null | undefined;
|
|
74
75
|
finishReason?: string | null | undefined;
|
|
76
|
+
finishMessage?: string | null | undefined;
|
|
75
77
|
safetyRatings?: {
|
|
76
78
|
category?: string | null | undefined;
|
|
77
79
|
probability?: string | null | undefined;
|
|
@@ -157,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
157
159
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
158
160
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
159
161
|
type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
162
|
+
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
163
|
+
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
160
164
|
|
|
161
165
|
type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
162
166
|
type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
163
167
|
type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
168
|
+
type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
|
|
169
|
+
type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
|
|
164
170
|
interface GoogleGenerativeAIProviderMetadata {
|
|
171
|
+
promptFeedback: GoogleGenerativeAIPromptFeedback | null;
|
|
165
172
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
166
173
|
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
167
174
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
175
|
+
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
176
|
+
finishMessage: string | null;
|
|
168
177
|
}
|
|
169
178
|
|
|
170
179
|
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
|
@@ -181,10 +190,18 @@ declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
181
190
|
}>;
|
|
182
191
|
type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
|
|
183
192
|
|
|
184
|
-
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {});
|
|
193
|
+
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
|
|
185
194
|
declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
186
195
|
outputDimensionality?: number | undefined;
|
|
187
196
|
taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
|
|
197
|
+
content?: (({
|
|
198
|
+
text: string;
|
|
199
|
+
} | {
|
|
200
|
+
inlineData: {
|
|
201
|
+
mimeType: string;
|
|
202
|
+
data: string;
|
|
203
|
+
};
|
|
204
|
+
})[] | null)[] | undefined;
|
|
188
205
|
}>;
|
|
189
206
|
type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
|
|
190
207
|
|
|
@@ -285,42 +302,42 @@ declare const googleTools: {
|
|
|
285
302
|
}>;
|
|
286
303
|
};
|
|
287
304
|
|
|
288
|
-
interface GoogleGenerativeAIProvider extends
|
|
289
|
-
(modelId: GoogleGenerativeAIModelId):
|
|
290
|
-
languageModel(modelId: GoogleGenerativeAIModelId):
|
|
291
|
-
chat(modelId: GoogleGenerativeAIModelId):
|
|
305
|
+
interface GoogleGenerativeAIProvider extends ProviderV4 {
|
|
306
|
+
(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
307
|
+
languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
308
|
+
chat(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
292
309
|
/**
|
|
293
310
|
* Creates a model for image generation.
|
|
294
311
|
*/
|
|
295
|
-
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings):
|
|
312
|
+
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV4;
|
|
296
313
|
/**
|
|
297
314
|
* @deprecated Use `chat()` instead.
|
|
298
315
|
*/
|
|
299
|
-
generativeAI(modelId: GoogleGenerativeAIModelId):
|
|
316
|
+
generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
300
317
|
/**
|
|
301
318
|
* Creates a model for text embeddings.
|
|
302
319
|
*/
|
|
303
|
-
embedding(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
320
|
+
embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
304
321
|
/**
|
|
305
322
|
* Creates a model for text embeddings.
|
|
306
323
|
*/
|
|
307
|
-
embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
324
|
+
embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
308
325
|
/**
|
|
309
326
|
* @deprecated Use `embedding` instead.
|
|
310
327
|
*/
|
|
311
|
-
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
328
|
+
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
312
329
|
/**
|
|
313
330
|
* @deprecated Use `embeddingModel` instead.
|
|
314
331
|
*/
|
|
315
|
-
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
332
|
+
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
316
333
|
/**
|
|
317
334
|
* Creates a model for video generation.
|
|
318
335
|
*/
|
|
319
|
-
video(modelId: GoogleGenerativeAIVideoModelId):
|
|
336
|
+
video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
320
337
|
/**
|
|
321
338
|
* Creates a model for video generation.
|
|
322
339
|
*/
|
|
323
|
-
videoModel(modelId: GoogleGenerativeAIVideoModelId):
|
|
340
|
+
videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
324
341
|
tools: typeof googleTools;
|
|
325
342
|
}
|
|
326
343
|
interface GoogleGenerativeAIProviderSettings {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
6
6
|
error: {
|
|
@@ -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?: {
|
|
@@ -72,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
72
73
|
})[] | null | undefined;
|
|
73
74
|
} | null | undefined;
|
|
74
75
|
finishReason?: string | null | undefined;
|
|
76
|
+
finishMessage?: string | null | undefined;
|
|
75
77
|
safetyRatings?: {
|
|
76
78
|
category?: string | null | undefined;
|
|
77
79
|
probability?: string | null | undefined;
|
|
@@ -157,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
157
159
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
158
160
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
159
161
|
type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
162
|
+
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
163
|
+
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
160
164
|
|
|
161
165
|
type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
162
166
|
type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
163
167
|
type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
168
|
+
type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
|
|
169
|
+
type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
|
|
164
170
|
interface GoogleGenerativeAIProviderMetadata {
|
|
171
|
+
promptFeedback: GoogleGenerativeAIPromptFeedback | null;
|
|
165
172
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
166
173
|
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
167
174
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
175
|
+
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
176
|
+
finishMessage: string | null;
|
|
168
177
|
}
|
|
169
178
|
|
|
170
179
|
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
|
@@ -181,10 +190,18 @@ declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
181
190
|
}>;
|
|
182
191
|
type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
|
|
183
192
|
|
|
184
|
-
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {});
|
|
193
|
+
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
|
|
185
194
|
declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
186
195
|
outputDimensionality?: number | undefined;
|
|
187
196
|
taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
|
|
197
|
+
content?: (({
|
|
198
|
+
text: string;
|
|
199
|
+
} | {
|
|
200
|
+
inlineData: {
|
|
201
|
+
mimeType: string;
|
|
202
|
+
data: string;
|
|
203
|
+
};
|
|
204
|
+
})[] | null)[] | undefined;
|
|
188
205
|
}>;
|
|
189
206
|
type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
|
|
190
207
|
|
|
@@ -285,42 +302,42 @@ declare const googleTools: {
|
|
|
285
302
|
}>;
|
|
286
303
|
};
|
|
287
304
|
|
|
288
|
-
interface GoogleGenerativeAIProvider extends
|
|
289
|
-
(modelId: GoogleGenerativeAIModelId):
|
|
290
|
-
languageModel(modelId: GoogleGenerativeAIModelId):
|
|
291
|
-
chat(modelId: GoogleGenerativeAIModelId):
|
|
305
|
+
interface GoogleGenerativeAIProvider extends ProviderV4 {
|
|
306
|
+
(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
307
|
+
languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
308
|
+
chat(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
292
309
|
/**
|
|
293
310
|
* Creates a model for image generation.
|
|
294
311
|
*/
|
|
295
|
-
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings):
|
|
312
|
+
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV4;
|
|
296
313
|
/**
|
|
297
314
|
* @deprecated Use `chat()` instead.
|
|
298
315
|
*/
|
|
299
|
-
generativeAI(modelId: GoogleGenerativeAIModelId):
|
|
316
|
+
generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
300
317
|
/**
|
|
301
318
|
* Creates a model for text embeddings.
|
|
302
319
|
*/
|
|
303
|
-
embedding(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
320
|
+
embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
304
321
|
/**
|
|
305
322
|
* Creates a model for text embeddings.
|
|
306
323
|
*/
|
|
307
|
-
embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
324
|
+
embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
308
325
|
/**
|
|
309
326
|
* @deprecated Use `embedding` instead.
|
|
310
327
|
*/
|
|
311
|
-
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
328
|
+
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
312
329
|
/**
|
|
313
330
|
* @deprecated Use `embeddingModel` instead.
|
|
314
331
|
*/
|
|
315
|
-
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
332
|
+
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
316
333
|
/**
|
|
317
334
|
* Creates a model for video generation.
|
|
318
335
|
*/
|
|
319
|
-
video(modelId: GoogleGenerativeAIVideoModelId):
|
|
336
|
+
video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
320
337
|
/**
|
|
321
338
|
* Creates a model for video generation.
|
|
322
339
|
*/
|
|
323
|
-
videoModel(modelId: GoogleGenerativeAIVideoModelId):
|
|
340
|
+
videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
324
341
|
tools: typeof googleTools;
|
|
325
342
|
}
|
|
326
343
|
interface GoogleGenerativeAIProviderSettings {
|
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
|
|
22
|
-
__export(
|
|
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(
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-provider.ts
|
|
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.
|
|
33
|
+
var VERSION = true ? "4.0.0-beta.11" : "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,17 @@ 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. Per-value multimodal content parts for embedding non-text
|
|
103
|
+
* content (images, video, PDF, audio). Each entry corresponds to the
|
|
104
|
+
* embedding value at the same index and its parts are merged with the
|
|
105
|
+
* text value in the request. Use `null` for entries that are text-only.
|
|
106
|
+
*
|
|
107
|
+
* The array length must match the number of values being embedded. In
|
|
108
|
+
* the case of a single embedding, the array length must be 1.
|
|
109
|
+
*/
|
|
110
|
+
content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
|
|
92
111
|
})
|
|
93
112
|
)
|
|
94
113
|
);
|
|
@@ -96,7 +115,7 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
|
96
115
|
// src/google-generative-ai-embedding-model.ts
|
|
97
116
|
var GoogleGenerativeAIEmbeddingModel = class {
|
|
98
117
|
constructor(modelId, config) {
|
|
99
|
-
this.specificationVersion = "
|
|
118
|
+
this.specificationVersion = "v4";
|
|
100
119
|
this.maxEmbeddingsPerCall = 2048;
|
|
101
120
|
this.supportsParallelCalls = true;
|
|
102
121
|
this.modelId = modelId;
|
|
@@ -128,7 +147,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
128
147
|
await (0, import_provider_utils3.resolve)(this.config.headers),
|
|
129
148
|
headers
|
|
130
149
|
);
|
|
150
|
+
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
151
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
131
156
|
if (values.length === 1) {
|
|
157
|
+
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
158
|
+
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
159
|
+
const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
|
|
132
160
|
const {
|
|
133
161
|
responseHeaders: responseHeaders2,
|
|
134
162
|
value: response2,
|
|
@@ -139,7 +167,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
139
167
|
body: {
|
|
140
168
|
model: `models/${this.modelId}`,
|
|
141
169
|
content: {
|
|
142
|
-
parts
|
|
170
|
+
parts
|
|
143
171
|
},
|
|
144
172
|
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
|
145
173
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
@@ -166,12 +194,19 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
166
194
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
|
167
195
|
headers: mergedHeaders,
|
|
168
196
|
body: {
|
|
169
|
-
requests: values.map((value) =>
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
197
|
+
requests: values.map((value, index) => {
|
|
198
|
+
const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
|
|
199
|
+
const textPart = value ? [{ text: value }] : [];
|
|
200
|
+
return {
|
|
201
|
+
model: `models/${this.modelId}`,
|
|
202
|
+
content: {
|
|
203
|
+
role: "user",
|
|
204
|
+
parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
|
|
205
|
+
},
|
|
206
|
+
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
|
207
|
+
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
208
|
+
};
|
|
209
|
+
})
|
|
175
210
|
},
|
|
176
211
|
failedResponseHandler: googleFailedResponseHandler,
|
|
177
212
|
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
@@ -436,6 +471,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
436
471
|
thoughtSignature
|
|
437
472
|
};
|
|
438
473
|
}
|
|
474
|
+
case "reasoning-file": {
|
|
475
|
+
if (part.data instanceof URL) {
|
|
476
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
477
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
inlineData: {
|
|
482
|
+
mimeType: part.mediaType,
|
|
483
|
+
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
|
484
|
+
},
|
|
485
|
+
thought: true,
|
|
486
|
+
thoughtSignature
|
|
487
|
+
};
|
|
488
|
+
}
|
|
439
489
|
case "file": {
|
|
440
490
|
if (part.data instanceof URL) {
|
|
441
491
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
@@ -447,6 +497,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
447
497
|
mimeType: part.mediaType,
|
|
448
498
|
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
|
449
499
|
},
|
|
500
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
450
501
|
thoughtSignature
|
|
451
502
|
};
|
|
452
503
|
}
|
|
@@ -900,7 +951,7 @@ function mapGoogleGenerativeAIFinishReason({
|
|
|
900
951
|
// src/google-generative-ai-language-model.ts
|
|
901
952
|
var GoogleGenerativeAILanguageModel = class {
|
|
902
953
|
constructor(modelId, config) {
|
|
903
|
-
this.specificationVersion = "
|
|
954
|
+
this.specificationVersion = "v4";
|
|
904
955
|
var _a;
|
|
905
956
|
this.modelId = modelId;
|
|
906
957
|
this.config = config;
|
|
@@ -1012,7 +1063,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1012
1063
|
};
|
|
1013
1064
|
}
|
|
1014
1065
|
async doGenerate(options) {
|
|
1015
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1066
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1016
1067
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1017
1068
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
1018
1069
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1092,11 +1143,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1092
1143
|
} : void 0
|
|
1093
1144
|
});
|
|
1094
1145
|
} else if ("inlineData" in part) {
|
|
1146
|
+
const hasThought = part.thought === true;
|
|
1147
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1095
1148
|
content.push({
|
|
1096
|
-
type: "file",
|
|
1149
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1097
1150
|
data: part.inlineData.data,
|
|
1098
1151
|
mediaType: part.inlineData.mimeType,
|
|
1099
|
-
providerMetadata:
|
|
1152
|
+
providerMetadata: hasThoughtSignature ? {
|
|
1100
1153
|
[providerOptionsName]: {
|
|
1101
1154
|
thoughtSignature: part.thoughtSignature
|
|
1102
1155
|
}
|
|
@@ -1131,7 +1184,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1131
1184
|
groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
|
|
1132
1185
|
urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
|
|
1133
1186
|
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1134
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1187
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1188
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null
|
|
1135
1189
|
}
|
|
1136
1190
|
},
|
|
1137
1191
|
request: { body: args },
|
|
@@ -1165,6 +1219,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1165
1219
|
};
|
|
1166
1220
|
let usage = void 0;
|
|
1167
1221
|
let providerMetadata = void 0;
|
|
1222
|
+
let lastGroundingMetadata = null;
|
|
1223
|
+
let lastUrlContextMetadata = null;
|
|
1168
1224
|
const generateId3 = this.config.generateId;
|
|
1169
1225
|
let hasToolCalls = false;
|
|
1170
1226
|
let currentTextBlockId = null;
|
|
@@ -1179,7 +1235,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1179
1235
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1180
1236
|
},
|
|
1181
1237
|
transform(chunk, controller) {
|
|
1182
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
1238
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1183
1239
|
if (options.includeRawChunks) {
|
|
1184
1240
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1185
1241
|
}
|
|
@@ -1197,6 +1253,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1197
1253
|
return;
|
|
1198
1254
|
}
|
|
1199
1255
|
const content = candidate.content;
|
|
1256
|
+
if (candidate.groundingMetadata != null) {
|
|
1257
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
1258
|
+
}
|
|
1259
|
+
if (candidate.urlContextMetadata != null) {
|
|
1260
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
1261
|
+
}
|
|
1200
1262
|
const sources = extractSources({
|
|
1201
1263
|
groundingMetadata: candidate.groundingMetadata,
|
|
1202
1264
|
generateId: generateId3
|
|
@@ -1311,16 +1373,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1311
1373
|
});
|
|
1312
1374
|
currentReasoningBlockId = null;
|
|
1313
1375
|
}
|
|
1314
|
-
const
|
|
1376
|
+
const hasThought = part.thought === true;
|
|
1377
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1378
|
+
const fileMeta = hasThoughtSignature ? {
|
|
1315
1379
|
[providerOptionsName]: {
|
|
1316
1380
|
thoughtSignature: part.thoughtSignature
|
|
1317
1381
|
}
|
|
1318
1382
|
} : void 0;
|
|
1319
1383
|
controller.enqueue({
|
|
1320
|
-
type: "file",
|
|
1384
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1321
1385
|
mediaType: part.inlineData.mimeType,
|
|
1322
1386
|
data: part.inlineData.data,
|
|
1323
|
-
providerMetadata:
|
|
1387
|
+
providerMetadata: fileMeta
|
|
1324
1388
|
});
|
|
1325
1389
|
}
|
|
1326
1390
|
}
|
|
@@ -1370,14 +1434,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1370
1434
|
providerMetadata = {
|
|
1371
1435
|
[providerOptionsName]: {
|
|
1372
1436
|
promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
|
|
1373
|
-
groundingMetadata:
|
|
1374
|
-
urlContextMetadata:
|
|
1375
|
-
safetyRatings: (
|
|
1437
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1438
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1439
|
+
safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
|
|
1440
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1441
|
+
finishMessage: (_g = candidate.finishMessage) != null ? _g : null
|
|
1376
1442
|
}
|
|
1377
1443
|
};
|
|
1378
|
-
if (usageMetadata != null) {
|
|
1379
|
-
providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
|
|
1380
|
-
}
|
|
1381
1444
|
}
|
|
1382
1445
|
},
|
|
1383
1446
|
flush(controller) {
|
|
@@ -1586,6 +1649,7 @@ var getContentSchema = () => import_v45.z.object({
|
|
|
1586
1649
|
mimeType: import_v45.z.string(),
|
|
1587
1650
|
data: import_v45.z.string()
|
|
1588
1651
|
}),
|
|
1652
|
+
thought: import_v45.z.boolean().nullish(),
|
|
1589
1653
|
thoughtSignature: import_v45.z.string().nullish()
|
|
1590
1654
|
}),
|
|
1591
1655
|
import_v45.z.object({
|
|
@@ -1636,6 +1700,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1636
1700
|
import_v45.z.object({
|
|
1637
1701
|
content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
|
|
1638
1702
|
finishReason: import_v45.z.string().nullish(),
|
|
1703
|
+
finishMessage: import_v45.z.string().nullish(),
|
|
1639
1704
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
|
|
1640
1705
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1641
1706
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1656,6 +1721,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1656
1721
|
import_v45.z.object({
|
|
1657
1722
|
content: getContentSchema().nullish(),
|
|
1658
1723
|
finishReason: import_v45.z.string().nullish(),
|
|
1724
|
+
finishMessage: import_v45.z.string().nullish(),
|
|
1659
1725
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
|
|
1660
1726
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1661
1727
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1838,7 +1904,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1838
1904
|
this.modelId = modelId;
|
|
1839
1905
|
this.settings = settings;
|
|
1840
1906
|
this.config = config;
|
|
1841
|
-
this.specificationVersion = "
|
|
1907
|
+
this.specificationVersion = "v4";
|
|
1842
1908
|
}
|
|
1843
1909
|
get maxImagesPerCall() {
|
|
1844
1910
|
if (this.settings.maxImagesPerCall != null) {
|
|
@@ -2079,7 +2145,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2079
2145
|
constructor(modelId, config) {
|
|
2080
2146
|
this.modelId = modelId;
|
|
2081
2147
|
this.config = config;
|
|
2082
|
-
this.specificationVersion = "
|
|
2148
|
+
this.specificationVersion = "v4";
|
|
2083
2149
|
}
|
|
2084
2150
|
get provider() {
|
|
2085
2151
|
return this.config.provider;
|
|
@@ -2391,7 +2457,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2391
2457
|
}
|
|
2392
2458
|
return createChatModel(modelId);
|
|
2393
2459
|
};
|
|
2394
|
-
provider.specificationVersion = "
|
|
2460
|
+
provider.specificationVersion = "v4";
|
|
2395
2461
|
provider.languageModel = createChatModel;
|
|
2396
2462
|
provider.chat = createChatModel;
|
|
2397
2463
|
provider.generativeAI = createChatModel;
|