@depup/ai-sdk__google 3.0.43-depup.0

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +2531 -0
  2. package/LICENSE +13 -0
  3. package/README.md +25 -0
  4. package/changes.json +5 -0
  5. package/dist/index.d.mts +367 -0
  6. package/dist/index.d.ts +367 -0
  7. package/dist/index.js +2404 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +2454 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/dist/internal/index.d.mts +283 -0
  12. package/dist/internal/index.d.ts +283 -0
  13. package/dist/internal/index.js +1670 -0
  14. package/dist/internal/index.js.map +1 -0
  15. package/dist/internal/index.mjs +1678 -0
  16. package/dist/internal/index.mjs.map +1 -0
  17. package/docs/15-google-generative-ai.mdx +1298 -0
  18. package/internal.d.ts +1 -0
  19. package/package.json +96 -0
  20. package/src/convert-google-generative-ai-usage.ts +51 -0
  21. package/src/convert-json-schema-to-openapi-schema.ts +158 -0
  22. package/src/convert-to-google-generative-ai-messages.ts +236 -0
  23. package/src/get-model-path.ts +3 -0
  24. package/src/google-error.ts +26 -0
  25. package/src/google-generative-ai-embedding-model.ts +159 -0
  26. package/src/google-generative-ai-embedding-options.ts +51 -0
  27. package/src/google-generative-ai-image-model.ts +359 -0
  28. package/src/google-generative-ai-image-settings.ts +17 -0
  29. package/src/google-generative-ai-language-model.ts +1056 -0
  30. package/src/google-generative-ai-options.ts +198 -0
  31. package/src/google-generative-ai-prompt.ts +38 -0
  32. package/src/google-generative-ai-video-model.ts +374 -0
  33. package/src/google-generative-ai-video-settings.ts +8 -0
  34. package/src/google-prepare-tools.ts +254 -0
  35. package/src/google-provider.ts +227 -0
  36. package/src/google-supported-file-url.ts +20 -0
  37. package/src/google-tools.ts +71 -0
  38. package/src/index.ts +29 -0
  39. package/src/internal/index.ts +3 -0
  40. package/src/map-google-generative-ai-finish-reason.ts +29 -0
  41. package/src/tool/code-execution.ts +35 -0
  42. package/src/tool/enterprise-web-search.ts +18 -0
  43. package/src/tool/file-search.ts +51 -0
  44. package/src/tool/google-maps.ts +14 -0
  45. package/src/tool/google-search.ts +43 -0
  46. package/src/tool/url-context.ts +16 -0
  47. package/src/tool/vertex-rag-store.ts +31 -0
  48. package/src/version.ts +6 -0
@@ -0,0 +1,254 @@
1
+ import {
2
+ LanguageModelV3CallOptions,
3
+ SharedV3Warning,
4
+ UnsupportedFunctionalityError,
5
+ } from '@ai-sdk/provider';
6
+ import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
7
+ import { GoogleGenerativeAIModelId } from './google-generative-ai-options';
8
+
9
+ export function prepareTools({
10
+ tools,
11
+ toolChoice,
12
+ modelId,
13
+ }: {
14
+ tools: LanguageModelV3CallOptions['tools'];
15
+ toolChoice?: LanguageModelV3CallOptions['toolChoice'];
16
+ modelId: GoogleGenerativeAIModelId;
17
+ }): {
18
+ tools:
19
+ | Array<
20
+ | {
21
+ functionDeclarations: Array<{
22
+ name: string;
23
+ description: string;
24
+ parameters: unknown;
25
+ }>;
26
+ }
27
+ | Record<string, any>
28
+ >
29
+ | undefined;
30
+ toolConfig:
31
+ | undefined
32
+ | {
33
+ functionCallingConfig: {
34
+ mode: 'AUTO' | 'NONE' | 'ANY';
35
+ allowedFunctionNames?: string[];
36
+ };
37
+ };
38
+ toolWarnings: SharedV3Warning[];
39
+ } {
40
+ // when the tools array is empty, change it to undefined to prevent errors:
41
+ tools = tools?.length ? tools : undefined;
42
+
43
+ const toolWarnings: SharedV3Warning[] = [];
44
+
45
+ const isLatest = (
46
+ [
47
+ 'gemini-flash-latest',
48
+ 'gemini-flash-lite-latest',
49
+ 'gemini-pro-latest',
50
+ ] as const satisfies GoogleGenerativeAIModelId[]
51
+ ).some(id => id === modelId);
52
+ const isGemini2orNewer =
53
+ modelId.includes('gemini-2') ||
54
+ modelId.includes('gemini-3') ||
55
+ modelId.includes('nano-banana') ||
56
+ isLatest;
57
+ const supportsFileSearch =
58
+ modelId.includes('gemini-2.5') || modelId.includes('gemini-3');
59
+
60
+ if (tools == null) {
61
+ return { tools: undefined, toolConfig: undefined, toolWarnings };
62
+ }
63
+
64
+ // Check for mixed tool types and add warnings
65
+ const hasFunctionTools = tools.some(tool => tool.type === 'function');
66
+ const hasProviderTools = tools.some(tool => tool.type === 'provider');
67
+
68
+ if (hasFunctionTools && hasProviderTools) {
69
+ toolWarnings.push({
70
+ type: 'unsupported',
71
+ feature: `combination of function and provider-defined tools`,
72
+ });
73
+ }
74
+
75
+ if (hasProviderTools) {
76
+ const googleTools: any[] = [];
77
+
78
+ const ProviderTools = tools.filter(tool => tool.type === 'provider');
79
+ ProviderTools.forEach(tool => {
80
+ switch (tool.id) {
81
+ case 'google.google_search':
82
+ if (isGemini2orNewer) {
83
+ googleTools.push({ googleSearch: { ...tool.args } });
84
+ } else {
85
+ toolWarnings.push({
86
+ type: 'unsupported',
87
+ feature: `provider-defined tool ${tool.id}`,
88
+ details: 'Google Search requires Gemini 2.0 or newer.',
89
+ });
90
+ }
91
+ break;
92
+ case 'google.enterprise_web_search':
93
+ if (isGemini2orNewer) {
94
+ googleTools.push({ enterpriseWebSearch: {} });
95
+ } else {
96
+ toolWarnings.push({
97
+ type: 'unsupported',
98
+ feature: `provider-defined tool ${tool.id}`,
99
+ details: 'Enterprise Web Search requires Gemini 2.0 or newer.',
100
+ });
101
+ }
102
+ break;
103
+ case 'google.url_context':
104
+ if (isGemini2orNewer) {
105
+ googleTools.push({ urlContext: {} });
106
+ } else {
107
+ toolWarnings.push({
108
+ type: 'unsupported',
109
+ feature: `provider-defined tool ${tool.id}`,
110
+ details:
111
+ 'The URL context tool is not supported with other Gemini models than Gemini 2.',
112
+ });
113
+ }
114
+ break;
115
+ case 'google.code_execution':
116
+ if (isGemini2orNewer) {
117
+ googleTools.push({ codeExecution: {} });
118
+ } else {
119
+ toolWarnings.push({
120
+ type: 'unsupported',
121
+ feature: `provider-defined tool ${tool.id}`,
122
+ details:
123
+ 'The code execution tools is not supported with other Gemini models than Gemini 2.',
124
+ });
125
+ }
126
+ break;
127
+ case 'google.file_search':
128
+ if (supportsFileSearch) {
129
+ googleTools.push({ fileSearch: { ...tool.args } });
130
+ } else {
131
+ toolWarnings.push({
132
+ type: 'unsupported',
133
+ feature: `provider-defined tool ${tool.id}`,
134
+ details:
135
+ 'The file search tool is only supported with Gemini 2.5 models and Gemini 3 models.',
136
+ });
137
+ }
138
+ break;
139
+ case 'google.vertex_rag_store':
140
+ if (isGemini2orNewer) {
141
+ googleTools.push({
142
+ retrieval: {
143
+ vertex_rag_store: {
144
+ rag_resources: {
145
+ rag_corpus: tool.args.ragCorpus,
146
+ },
147
+ similarity_top_k: tool.args.topK as number | undefined,
148
+ },
149
+ },
150
+ });
151
+ } else {
152
+ toolWarnings.push({
153
+ type: 'unsupported',
154
+ feature: `provider-defined tool ${tool.id}`,
155
+ details:
156
+ 'The RAG store tool is not supported with other Gemini models than Gemini 2.',
157
+ });
158
+ }
159
+ break;
160
+ case 'google.google_maps':
161
+ if (isGemini2orNewer) {
162
+ googleTools.push({ googleMaps: {} });
163
+ } else {
164
+ toolWarnings.push({
165
+ type: 'unsupported',
166
+ feature: `provider-defined tool ${tool.id}`,
167
+ details:
168
+ 'The Google Maps grounding tool is not supported with Gemini models other than Gemini 2 or newer.',
169
+ });
170
+ }
171
+ break;
172
+ default:
173
+ toolWarnings.push({
174
+ type: 'unsupported',
175
+ feature: `provider-defined tool ${tool.id}`,
176
+ });
177
+ break;
178
+ }
179
+ });
180
+
181
+ return {
182
+ tools: googleTools.length > 0 ? googleTools : undefined,
183
+ toolConfig: undefined,
184
+ toolWarnings,
185
+ };
186
+ }
187
+
188
+ const functionDeclarations = [];
189
+ for (const tool of tools) {
190
+ switch (tool.type) {
191
+ case 'function':
192
+ functionDeclarations.push({
193
+ name: tool.name,
194
+ description: tool.description ?? '',
195
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
196
+ });
197
+ break;
198
+ default:
199
+ toolWarnings.push({
200
+ type: 'unsupported',
201
+ feature: `function tool ${tool.name}`,
202
+ });
203
+ break;
204
+ }
205
+ }
206
+
207
+ if (toolChoice == null) {
208
+ return {
209
+ tools: [{ functionDeclarations }],
210
+ toolConfig: undefined,
211
+ toolWarnings,
212
+ };
213
+ }
214
+
215
+ const type = toolChoice.type;
216
+
217
+ switch (type) {
218
+ case 'auto':
219
+ return {
220
+ tools: [{ functionDeclarations }],
221
+ toolConfig: { functionCallingConfig: { mode: 'AUTO' } },
222
+ toolWarnings,
223
+ };
224
+ case 'none':
225
+ return {
226
+ tools: [{ functionDeclarations }],
227
+ toolConfig: { functionCallingConfig: { mode: 'NONE' } },
228
+ toolWarnings,
229
+ };
230
+ case 'required':
231
+ return {
232
+ tools: [{ functionDeclarations }],
233
+ toolConfig: { functionCallingConfig: { mode: 'ANY' } },
234
+ toolWarnings,
235
+ };
236
+ case 'tool':
237
+ return {
238
+ tools: [{ functionDeclarations }],
239
+ toolConfig: {
240
+ functionCallingConfig: {
241
+ mode: 'ANY',
242
+ allowedFunctionNames: [toolChoice.toolName],
243
+ },
244
+ },
245
+ toolWarnings,
246
+ };
247
+ default: {
248
+ const _exhaustiveCheck: never = type;
249
+ throw new UnsupportedFunctionalityError({
250
+ functionality: `tool choice type: ${_exhaustiveCheck}`,
251
+ });
252
+ }
253
+ }
254
+ }
@@ -0,0 +1,227 @@
1
+ import {
2
+ EmbeddingModelV3,
3
+ Experimental_VideoModelV3,
4
+ ImageModelV3,
5
+ LanguageModelV3,
6
+ ProviderV3,
7
+ } from '@ai-sdk/provider';
8
+ import {
9
+ FetchFunction,
10
+ generateId,
11
+ loadApiKey,
12
+ withoutTrailingSlash,
13
+ withUserAgentSuffix,
14
+ } from '@ai-sdk/provider-utils';
15
+ import { VERSION } from './version';
16
+ import { GoogleGenerativeAIEmbeddingModel } from './google-generative-ai-embedding-model';
17
+ import { GoogleGenerativeAIEmbeddingModelId } from './google-generative-ai-embedding-options';
18
+ import { GoogleGenerativeAILanguageModel } from './google-generative-ai-language-model';
19
+ import { GoogleGenerativeAIModelId } from './google-generative-ai-options';
20
+ import { googleTools } from './google-tools';
21
+
22
+ import {
23
+ GoogleGenerativeAIImageSettings,
24
+ GoogleGenerativeAIImageModelId,
25
+ } from './google-generative-ai-image-settings';
26
+ import { GoogleGenerativeAIImageModel } from './google-generative-ai-image-model';
27
+ import { GoogleGenerativeAIVideoModel } from './google-generative-ai-video-model';
28
+ import { GoogleGenerativeAIVideoModelId } from './google-generative-ai-video-settings';
29
+
30
+ export interface GoogleGenerativeAIProvider extends ProviderV3 {
31
+ (modelId: GoogleGenerativeAIModelId): LanguageModelV3;
32
+
33
+ languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
34
+
35
+ chat(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
36
+
37
+ /**
38
+ * Creates a model for image generation.
39
+ */
40
+ image(
41
+ modelId: GoogleGenerativeAIImageModelId,
42
+ settings?: GoogleGenerativeAIImageSettings,
43
+ ): ImageModelV3;
44
+
45
+ /**
46
+ * @deprecated Use `chat()` instead.
47
+ */
48
+ generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
49
+
50
+ /**
51
+ * Creates a model for text embeddings.
52
+ */
53
+ embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
54
+
55
+ /**
56
+ * Creates a model for text embeddings.
57
+ */
58
+ embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
59
+
60
+ /**
61
+ * @deprecated Use `embedding` instead.
62
+ */
63
+ textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
64
+
65
+ /**
66
+ * @deprecated Use `embeddingModel` instead.
67
+ */
68
+ textEmbeddingModel(
69
+ modelId: GoogleGenerativeAIEmbeddingModelId,
70
+ ): EmbeddingModelV3;
71
+
72
+ /**
73
+ * Creates a model for video generation.
74
+ */
75
+ video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
76
+
77
+ /**
78
+ * Creates a model for video generation.
79
+ */
80
+ videoModel(
81
+ modelId: GoogleGenerativeAIVideoModelId,
82
+ ): Experimental_VideoModelV3;
83
+
84
+ tools: typeof googleTools;
85
+ }
86
+
87
+ export interface GoogleGenerativeAIProviderSettings {
88
+ /**
89
+ * Use a different URL prefix for API calls, e.g. to use proxy servers.
90
+ * The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
91
+ */
92
+ baseURL?: string;
93
+
94
+ /**
95
+ * API key that is being send using the `x-goog-api-key` header.
96
+ * It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
97
+ */
98
+ apiKey?: string;
99
+
100
+ /**
101
+ * Custom headers to include in the requests.
102
+ */
103
+ headers?: Record<string, string | undefined>;
104
+
105
+ /**
106
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
107
+ * or to provide a custom fetch implementation for e.g. testing.
108
+ */
109
+ fetch?: FetchFunction;
110
+
111
+ /**
112
+ * Optional function to generate a unique ID for each request.
113
+ */
114
+ generateId?: () => string;
115
+
116
+ /**
117
+ * Custom provider name
118
+ * Defaults to 'google.generative-ai'.
119
+ */
120
+ name?: string;
121
+ }
122
+
123
+ /**
124
+ * Create a Google Generative AI provider instance.
125
+ */
126
+ export function createGoogleGenerativeAI(
127
+ options: GoogleGenerativeAIProviderSettings = {},
128
+ ): GoogleGenerativeAIProvider {
129
+ const baseURL =
130
+ withoutTrailingSlash(options.baseURL) ??
131
+ 'https://generativelanguage.googleapis.com/v1beta';
132
+
133
+ const providerName = options.name ?? 'google.generative-ai';
134
+
135
+ const getHeaders = () =>
136
+ withUserAgentSuffix(
137
+ {
138
+ 'x-goog-api-key': loadApiKey({
139
+ apiKey: options.apiKey,
140
+ environmentVariableName: 'GOOGLE_GENERATIVE_AI_API_KEY',
141
+ description: 'Google Generative AI',
142
+ }),
143
+ ...options.headers,
144
+ },
145
+ `ai-sdk/google/${VERSION}`,
146
+ );
147
+
148
+ const createChatModel = (modelId: GoogleGenerativeAIModelId) =>
149
+ new GoogleGenerativeAILanguageModel(modelId, {
150
+ provider: providerName,
151
+ baseURL,
152
+ headers: getHeaders,
153
+ generateId: options.generateId ?? generateId,
154
+ supportedUrls: () => ({
155
+ '*': [
156
+ // Google Generative Language "files" endpoint
157
+ // e.g. https://generativelanguage.googleapis.com/v1beta/files/...
158
+ new RegExp(`^${baseURL}/files/.*$`),
159
+ // YouTube URLs (public or unlisted videos)
160
+ new RegExp(
161
+ `^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`,
162
+ ),
163
+ new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`),
164
+ ],
165
+ }),
166
+ fetch: options.fetch,
167
+ });
168
+
169
+ const createEmbeddingModel = (modelId: GoogleGenerativeAIEmbeddingModelId) =>
170
+ new GoogleGenerativeAIEmbeddingModel(modelId, {
171
+ provider: providerName,
172
+ baseURL,
173
+ headers: getHeaders,
174
+ fetch: options.fetch,
175
+ });
176
+
177
+ const createImageModel = (
178
+ modelId: GoogleGenerativeAIImageModelId,
179
+ settings: GoogleGenerativeAIImageSettings = {},
180
+ ) =>
181
+ new GoogleGenerativeAIImageModel(modelId, settings, {
182
+ provider: providerName,
183
+ baseURL,
184
+ headers: getHeaders,
185
+ fetch: options.fetch,
186
+ });
187
+
188
+ const createVideoModel = (modelId: GoogleGenerativeAIVideoModelId) =>
189
+ new GoogleGenerativeAIVideoModel(modelId, {
190
+ provider: providerName,
191
+ baseURL,
192
+ headers: getHeaders,
193
+ fetch: options.fetch,
194
+ generateId: options.generateId ?? generateId,
195
+ });
196
+
197
+ const provider = function (modelId: GoogleGenerativeAIModelId) {
198
+ if (new.target) {
199
+ throw new Error(
200
+ 'The Google Generative AI model function cannot be called with the new keyword.',
201
+ );
202
+ }
203
+
204
+ return createChatModel(modelId);
205
+ };
206
+
207
+ provider.specificationVersion = 'v3' as const;
208
+ provider.languageModel = createChatModel;
209
+ provider.chat = createChatModel;
210
+ provider.generativeAI = createChatModel;
211
+ provider.embedding = createEmbeddingModel;
212
+ provider.embeddingModel = createEmbeddingModel;
213
+ provider.textEmbedding = createEmbeddingModel;
214
+ provider.textEmbeddingModel = createEmbeddingModel;
215
+ provider.image = createImageModel;
216
+ provider.imageModel = createImageModel;
217
+ provider.video = createVideoModel;
218
+ provider.videoModel = createVideoModel;
219
+ provider.tools = googleTools;
220
+
221
+ return provider as GoogleGenerativeAIProvider;
222
+ }
223
+
224
+ /**
225
+ * Default Google Generative AI provider instance.
226
+ */
227
+ export const google = createGoogleGenerativeAI();
@@ -0,0 +1,20 @@
1
+ export function isSupportedFileUrl(url: URL): boolean {
2
+ const urlString = url.toString();
3
+
4
+ // Google Generative Language files API
5
+ if (
6
+ urlString.startsWith(
7
+ 'https://generativelanguage.googleapis.com/v1beta/files/',
8
+ )
9
+ ) {
10
+ return true;
11
+ }
12
+
13
+ // YouTube URLs (public or unlisted videos)
14
+ const youtubeRegexes = [
15
+ /^https:\/\/(?:www\.)?youtube\.com\/watch\?v=[\w-]+(?:&[\w=&.-]*)?$/,
16
+ /^https:\/\/youtu\.be\/[\w-]+(?:\?[\w=&.-]*)?$/,
17
+ ];
18
+
19
+ return youtubeRegexes.some(regex => regex.test(urlString));
20
+ }
@@ -0,0 +1,71 @@
1
+ import { codeExecution } from './tool/code-execution';
2
+ import { enterpriseWebSearch } from './tool/enterprise-web-search';
3
+ import { fileSearch } from './tool/file-search';
4
+ import { googleMaps } from './tool/google-maps';
5
+ import { googleSearch } from './tool/google-search';
6
+ import { urlContext } from './tool/url-context';
7
+ import { vertexRagStore } from './tool/vertex-rag-store';
8
+
9
+ export const googleTools = {
10
+ /**
11
+ * Creates a Google search tool that gives Google direct access to real-time web content.
12
+ * Must have name "google_search".
13
+ */
14
+ googleSearch,
15
+
16
+ /**
17
+ * Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
18
+ * Designed for highly-regulated industries (finance, healthcare, public sector).
19
+ * Does not log customer data and supports VPC service controls.
20
+ * Must have name "enterprise_web_search".
21
+ *
22
+ * @note Only available on Vertex AI. Requires Gemini 2.0 or newer.
23
+ *
24
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
25
+ */
26
+ enterpriseWebSearch,
27
+
28
+ /**
29
+ * Creates a Google Maps grounding tool that gives the model access to Google Maps data.
30
+ * Must have name "google_maps".
31
+ *
32
+ * @see https://ai.google.dev/gemini-api/docs/maps-grounding
33
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
34
+ */
35
+ googleMaps,
36
+
37
+ /**
38
+ * Creates a URL context tool that gives Google direct access to real-time web content.
39
+ * Must have name "url_context".
40
+ */
41
+ urlContext,
42
+
43
+ /**
44
+ * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
45
+ * Must have name "file_search".
46
+ *
47
+ * @param fileSearchStoreNames - Fully-qualified File Search store resource names.
48
+ * @param metadataFilter - Optional filter expression to restrict the files that can be retrieved.
49
+ * @param topK - Optional result limit for the number of chunks returned from File Search.
50
+ *
51
+ * @see https://ai.google.dev/gemini-api/docs/file-search
52
+ */
53
+ fileSearch,
54
+ /**
55
+ * A tool that enables the model to generate and run Python code.
56
+ * Must have name "code_execution".
57
+ *
58
+ * @note Ensure the selected model supports Code Execution.
59
+ * Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
60
+ *
61
+ * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
62
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
63
+ */
64
+ codeExecution,
65
+
66
+ /**
67
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
68
+ * Must have name "vertex_rag_store".
69
+ */
70
+ vertexRagStore,
71
+ };
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ export type { GoogleErrorData } from './google-error';
2
+ export type {
3
+ GoogleLanguageModelOptions,
4
+ /** @deprecated Use `GoogleLanguageModelOptions` instead. */
5
+ GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions,
6
+ } from './google-generative-ai-options';
7
+ export type { GoogleGenerativeAIProviderMetadata } from './google-generative-ai-prompt';
8
+ export type {
9
+ GoogleImageModelOptions,
10
+ /** @deprecated Use `GoogleImageModelOptions` instead. */
11
+ GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions,
12
+ } from './google-generative-ai-image-model';
13
+ export type {
14
+ GoogleEmbeddingModelOptions,
15
+ /** @deprecated Use `GoogleEmbeddingModelOptions` instead. */
16
+ GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions,
17
+ } from './google-generative-ai-embedding-options';
18
+ export type {
19
+ GoogleVideoModelOptions,
20
+ /** @deprecated Use `GoogleVideoModelOptions` instead. */
21
+ GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions,
22
+ } from './google-generative-ai-video-model';
23
+ export type { GoogleGenerativeAIVideoModelId } from './google-generative-ai-video-settings';
24
+ export { createGoogleGenerativeAI, google } from './google-provider';
25
+ export type {
26
+ GoogleGenerativeAIProvider,
27
+ GoogleGenerativeAIProviderSettings,
28
+ } from './google-provider';
29
+ export { VERSION } from './version';
@@ -0,0 +1,3 @@
1
+ export * from '../google-generative-ai-language-model';
2
+ export { googleTools } from '../google-tools';
3
+ export type { GoogleGenerativeAIModelId } from '../google-generative-ai-options';
@@ -0,0 +1,29 @@
1
+ import { LanguageModelV3FinishReason } from '@ai-sdk/provider';
2
+
3
+ export function mapGoogleGenerativeAIFinishReason({
4
+ finishReason,
5
+ hasToolCalls,
6
+ }: {
7
+ finishReason: string | null | undefined;
8
+ hasToolCalls: boolean;
9
+ }): LanguageModelV3FinishReason['unified'] {
10
+ switch (finishReason) {
11
+ case 'STOP':
12
+ return hasToolCalls ? 'tool-calls' : 'stop';
13
+ case 'MAX_TOKENS':
14
+ return 'length';
15
+ case 'IMAGE_SAFETY':
16
+ case 'RECITATION':
17
+ case 'SAFETY':
18
+ case 'BLOCKLIST':
19
+ case 'PROHIBITED_CONTENT':
20
+ case 'SPII':
21
+ return 'content-filter';
22
+ case 'MALFORMED_FUNCTION_CALL':
23
+ return 'error';
24
+ case 'FINISH_REASON_UNSPECIFIED':
25
+ case 'OTHER':
26
+ default:
27
+ return 'other';
28
+ }
29
+ }
@@ -0,0 +1,35 @@
1
+ import { createProviderToolFactoryWithOutputSchema } from '@ai-sdk/provider-utils';
2
+ import { z } from 'zod/v4';
3
+
4
+ /**
5
+ * A tool that enables the model to generate and run Python code.
6
+ *
7
+ * @note Ensure the selected model supports Code Execution.
8
+ * Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
9
+ *
10
+ * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
11
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
12
+ */
13
+ export const codeExecution = createProviderToolFactoryWithOutputSchema<
14
+ {
15
+ language: string;
16
+ code: string;
17
+ },
18
+ {
19
+ outcome: string;
20
+ output: string;
21
+ },
22
+ {}
23
+ >({
24
+ id: 'google.code_execution',
25
+ inputSchema: z.object({
26
+ language: z.string().describe('The programming language of the code.'),
27
+ code: z.string().describe('The code to be executed.'),
28
+ }),
29
+ outputSchema: z.object({
30
+ outcome: z
31
+ .string()
32
+ .describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
33
+ output: z.string().describe('The output from the code execution.'),
34
+ }),
35
+ });
@@ -0,0 +1,18 @@
1
+ import {
2
+ createProviderToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ // https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
9
+
10
+ export const enterpriseWebSearch = createProviderToolFactory<
11
+ {
12
+ // Enterprise Web Search does not have any input schema
13
+ },
14
+ {}
15
+ >({
16
+ id: 'google.enterprise_web_search',
17
+ inputSchema: lazySchema(() => zodSchema(z.object({}))),
18
+ });