@ai-sdk/google 4.0.0-beta.2 → 4.0.0-beta.20
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 +133 -4
- package/dist/index.d.mts +56 -22
- package/dist/index.d.ts +56 -22
- package/dist/index.js +500 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +500 -77
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +34 -15
- package/dist/internal/index.d.ts +34 -15
- package/dist/internal/index.js +452 -67
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +452 -64
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +36 -3
- package/package.json +3 -5
- package/src/convert-google-generative-ai-usage.ts +2 -2
- package/src/convert-to-google-generative-ai-messages.ts +273 -34
- 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 +305 -44
- package/src/google-generative-ai-options.ts +11 -1
- package/src/google-generative-ai-prompt.ts +39 -3
- package/src/google-generative-ai-video-model.ts +7 -7
- package/src/google-prepare-tools.ts +63 -8
- package/src/google-provider.ts +18 -18
- package/src/map-google-generative-ai-finish-reason.ts +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult } from '@ai-sdk/provider';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
|
|
6
|
-
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-
|
|
6
|
+
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
7
7
|
|
|
8
8
|
type GoogleGenerativeAIConfig = {
|
|
9
9
|
provider: string;
|
|
@@ -14,10 +14,10 @@ type GoogleGenerativeAIConfig = {
|
|
|
14
14
|
/**
|
|
15
15
|
* The supported URLs for the model.
|
|
16
16
|
*/
|
|
17
|
-
supportedUrls?: () =>
|
|
17
|
+
supportedUrls?: () => LanguageModelV4['supportedUrls'];
|
|
18
18
|
};
|
|
19
|
-
declare class GoogleGenerativeAILanguageModel implements
|
|
20
|
-
readonly specificationVersion = "
|
|
19
|
+
declare class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
20
|
+
readonly specificationVersion = "v4";
|
|
21
21
|
readonly modelId: GoogleGenerativeAIModelId;
|
|
22
22
|
private readonly config;
|
|
23
23
|
private readonly generateId;
|
|
@@ -25,8 +25,8 @@ declare class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
25
25
|
get provider(): string;
|
|
26
26
|
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
27
27
|
private getArgs;
|
|
28
|
-
doGenerate(options:
|
|
29
|
-
doStream(options:
|
|
28
|
+
doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
|
|
29
|
+
doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
|
|
30
30
|
}
|
|
31
31
|
declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
32
32
|
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
@@ -95,6 +95,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
95
95
|
mimeType: string;
|
|
96
96
|
data: string;
|
|
97
97
|
};
|
|
98
|
+
thought?: boolean | null | undefined;
|
|
99
|
+
thoughtSignature?: string | null | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
toolCall: {
|
|
102
|
+
toolType: string;
|
|
103
|
+
id: string;
|
|
104
|
+
args?: unknown;
|
|
105
|
+
};
|
|
106
|
+
thoughtSignature?: string | null | undefined;
|
|
107
|
+
} | {
|
|
108
|
+
toolResponse: {
|
|
109
|
+
toolType: string;
|
|
110
|
+
id: string;
|
|
111
|
+
response?: unknown;
|
|
112
|
+
};
|
|
98
113
|
thoughtSignature?: string | null | undefined;
|
|
99
114
|
} | {
|
|
100
115
|
executableCode?: {
|
|
@@ -111,6 +126,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
111
126
|
})[] | null | undefined;
|
|
112
127
|
} | null | undefined;
|
|
113
128
|
finishReason?: string | null | undefined;
|
|
129
|
+
finishMessage?: string | null | undefined;
|
|
114
130
|
safetyRatings?: {
|
|
115
131
|
category?: string | null | undefined;
|
|
116
132
|
probability?: string | null | undefined;
|
|
@@ -192,10 +208,13 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
192
208
|
blocked?: boolean | null | undefined;
|
|
193
209
|
}[] | null | undefined;
|
|
194
210
|
} | null | undefined;
|
|
211
|
+
serviceTier?: string | null | undefined;
|
|
195
212
|
}>;
|
|
196
213
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
197
214
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
198
215
|
type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
216
|
+
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
217
|
+
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
199
218
|
|
|
200
219
|
declare const googleTools: {
|
|
201
220
|
/**
|
|
@@ -212,7 +231,7 @@ declare const googleTools: {
|
|
|
212
231
|
startTime: string;
|
|
213
232
|
endTime: string;
|
|
214
233
|
} | undefined;
|
|
215
|
-
}>;
|
|
234
|
+
}, {}>;
|
|
216
235
|
/**
|
|
217
236
|
* Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
|
|
218
237
|
* Designed for highly-regulated industries (finance, healthcare, public sector).
|
|
@@ -223,7 +242,7 @@ declare const googleTools: {
|
|
|
223
242
|
*
|
|
224
243
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
|
|
225
244
|
*/
|
|
226
|
-
enterpriseWebSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
|
|
245
|
+
enterpriseWebSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}, {}>;
|
|
227
246
|
/**
|
|
228
247
|
* Creates a Google Maps grounding tool that gives the model access to Google Maps data.
|
|
229
248
|
* Must have name "google_maps".
|
|
@@ -231,12 +250,12 @@ declare const googleTools: {
|
|
|
231
250
|
* @see https://ai.google.dev/gemini-api/docs/maps-grounding
|
|
232
251
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
233
252
|
*/
|
|
234
|
-
googleMaps: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
|
|
253
|
+
googleMaps: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}, {}>;
|
|
235
254
|
/**
|
|
236
255
|
* Creates a URL context tool that gives Google direct access to real-time web content.
|
|
237
256
|
* Must have name "url_context".
|
|
238
257
|
*/
|
|
239
|
-
urlContext: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
|
|
258
|
+
urlContext: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}, {}>;
|
|
240
259
|
/**
|
|
241
260
|
* Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
|
|
242
261
|
* Must have name "file_search".
|
|
@@ -252,7 +271,7 @@ declare const googleTools: {
|
|
|
252
271
|
fileSearchStoreNames: string[];
|
|
253
272
|
topK?: number | undefined;
|
|
254
273
|
metadataFilter?: string | undefined;
|
|
255
|
-
}>;
|
|
274
|
+
}, {}>;
|
|
256
275
|
/**
|
|
257
276
|
* A tool that enables the model to generate and run Python code.
|
|
258
277
|
* Must have name "code_execution".
|
|
@@ -269,7 +288,7 @@ declare const googleTools: {
|
|
|
269
288
|
}, {
|
|
270
289
|
outcome: string;
|
|
271
290
|
output: string;
|
|
272
|
-
}, {}>;
|
|
291
|
+
}, {}, {}>;
|
|
273
292
|
/**
|
|
274
293
|
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
275
294
|
* Must have name "vertex_rag_store".
|
|
@@ -277,7 +296,7 @@ declare const googleTools: {
|
|
|
277
296
|
vertexRagStore: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
|
|
278
297
|
ragCorpus: string;
|
|
279
298
|
topK?: number;
|
|
280
|
-
}>;
|
|
299
|
+
}, {}>;
|
|
281
300
|
};
|
|
282
301
|
|
|
283
|
-
export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
|
|
302
|
+
export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult } from '@ai-sdk/provider';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
|
|
6
|
-
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-
|
|
6
|
+
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
7
7
|
|
|
8
8
|
type GoogleGenerativeAIConfig = {
|
|
9
9
|
provider: string;
|
|
@@ -14,10 +14,10 @@ type GoogleGenerativeAIConfig = {
|
|
|
14
14
|
/**
|
|
15
15
|
* The supported URLs for the model.
|
|
16
16
|
*/
|
|
17
|
-
supportedUrls?: () =>
|
|
17
|
+
supportedUrls?: () => LanguageModelV4['supportedUrls'];
|
|
18
18
|
};
|
|
19
|
-
declare class GoogleGenerativeAILanguageModel implements
|
|
20
|
-
readonly specificationVersion = "
|
|
19
|
+
declare class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
20
|
+
readonly specificationVersion = "v4";
|
|
21
21
|
readonly modelId: GoogleGenerativeAIModelId;
|
|
22
22
|
private readonly config;
|
|
23
23
|
private readonly generateId;
|
|
@@ -25,8 +25,8 @@ declare class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
25
25
|
get provider(): string;
|
|
26
26
|
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
27
27
|
private getArgs;
|
|
28
|
-
doGenerate(options:
|
|
29
|
-
doStream(options:
|
|
28
|
+
doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
|
|
29
|
+
doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
|
|
30
30
|
}
|
|
31
31
|
declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
32
32
|
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
@@ -95,6 +95,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
95
95
|
mimeType: string;
|
|
96
96
|
data: string;
|
|
97
97
|
};
|
|
98
|
+
thought?: boolean | null | undefined;
|
|
99
|
+
thoughtSignature?: string | null | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
toolCall: {
|
|
102
|
+
toolType: string;
|
|
103
|
+
id: string;
|
|
104
|
+
args?: unknown;
|
|
105
|
+
};
|
|
106
|
+
thoughtSignature?: string | null | undefined;
|
|
107
|
+
} | {
|
|
108
|
+
toolResponse: {
|
|
109
|
+
toolType: string;
|
|
110
|
+
id: string;
|
|
111
|
+
response?: unknown;
|
|
112
|
+
};
|
|
98
113
|
thoughtSignature?: string | null | undefined;
|
|
99
114
|
} | {
|
|
100
115
|
executableCode?: {
|
|
@@ -111,6 +126,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
111
126
|
})[] | null | undefined;
|
|
112
127
|
} | null | undefined;
|
|
113
128
|
finishReason?: string | null | undefined;
|
|
129
|
+
finishMessage?: string | null | undefined;
|
|
114
130
|
safetyRatings?: {
|
|
115
131
|
category?: string | null | undefined;
|
|
116
132
|
probability?: string | null | undefined;
|
|
@@ -192,10 +208,13 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
192
208
|
blocked?: boolean | null | undefined;
|
|
193
209
|
}[] | null | undefined;
|
|
194
210
|
} | null | undefined;
|
|
211
|
+
serviceTier?: string | null | undefined;
|
|
195
212
|
}>;
|
|
196
213
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
197
214
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
198
215
|
type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
216
|
+
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
217
|
+
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
199
218
|
|
|
200
219
|
declare const googleTools: {
|
|
201
220
|
/**
|
|
@@ -212,7 +231,7 @@ declare const googleTools: {
|
|
|
212
231
|
startTime: string;
|
|
213
232
|
endTime: string;
|
|
214
233
|
} | undefined;
|
|
215
|
-
}>;
|
|
234
|
+
}, {}>;
|
|
216
235
|
/**
|
|
217
236
|
* Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
|
|
218
237
|
* Designed for highly-regulated industries (finance, healthcare, public sector).
|
|
@@ -223,7 +242,7 @@ declare const googleTools: {
|
|
|
223
242
|
*
|
|
224
243
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
|
|
225
244
|
*/
|
|
226
|
-
enterpriseWebSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
|
|
245
|
+
enterpriseWebSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}, {}>;
|
|
227
246
|
/**
|
|
228
247
|
* Creates a Google Maps grounding tool that gives the model access to Google Maps data.
|
|
229
248
|
* Must have name "google_maps".
|
|
@@ -231,12 +250,12 @@ declare const googleTools: {
|
|
|
231
250
|
* @see https://ai.google.dev/gemini-api/docs/maps-grounding
|
|
232
251
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
233
252
|
*/
|
|
234
|
-
googleMaps: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
|
|
253
|
+
googleMaps: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}, {}>;
|
|
235
254
|
/**
|
|
236
255
|
* Creates a URL context tool that gives Google direct access to real-time web content.
|
|
237
256
|
* Must have name "url_context".
|
|
238
257
|
*/
|
|
239
|
-
urlContext: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
|
|
258
|
+
urlContext: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}, {}>;
|
|
240
259
|
/**
|
|
241
260
|
* Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
|
|
242
261
|
* Must have name "file_search".
|
|
@@ -252,7 +271,7 @@ declare const googleTools: {
|
|
|
252
271
|
fileSearchStoreNames: string[];
|
|
253
272
|
topK?: number | undefined;
|
|
254
273
|
metadataFilter?: string | undefined;
|
|
255
|
-
}>;
|
|
274
|
+
}, {}>;
|
|
256
275
|
/**
|
|
257
276
|
* A tool that enables the model to generate and run Python code.
|
|
258
277
|
* Must have name "code_execution".
|
|
@@ -269,7 +288,7 @@ declare const googleTools: {
|
|
|
269
288
|
}, {
|
|
270
289
|
outcome: string;
|
|
271
290
|
output: string;
|
|
272
|
-
}, {}>;
|
|
291
|
+
}, {}, {}>;
|
|
273
292
|
/**
|
|
274
293
|
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
275
294
|
* Must have name "vertex_rag_store".
|
|
@@ -277,7 +296,7 @@ declare const googleTools: {
|
|
|
277
296
|
vertexRagStore: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
|
|
278
297
|
ragCorpus: string;
|
|
279
298
|
topK?: number;
|
|
280
|
-
}>;
|
|
299
|
+
}, {}>;
|
|
281
300
|
};
|
|
282
301
|
|
|
283
|
-
export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
|
|
302
|
+
export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
|