@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
package/internal.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/internal';
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@depup/ai-sdk__google",
3
+ "version": "3.0.43-depup.0",
4
+ "license": "Apache-2.0",
5
+ "sideEffects": false,
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist/**/*",
11
+ "docs/**/*",
12
+ "src",
13
+ "!src/**/*.test.ts",
14
+ "!src/**/*.test-d.ts",
15
+ "!src/**/__snapshots__",
16
+ "!src/**/__fixtures__",
17
+ "CHANGELOG.md",
18
+ "README.md",
19
+ "internal.d.ts",
20
+ "changes.json"
21
+ ],
22
+ "directories": {
23
+ "doc": "./docs"
24
+ },
25
+ "exports": {
26
+ "./package.json": "./package.json",
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.mjs",
30
+ "require": "./dist/index.js"
31
+ },
32
+ "./internal": {
33
+ "types": "./dist/internal/index.d.ts",
34
+ "import": "./dist/internal/index.mjs",
35
+ "module": "./dist/internal/index.mjs",
36
+ "require": "./dist/internal/index.js"
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "@ai-sdk/provider": "3.0.8",
41
+ "@ai-sdk/provider-utils": "4.0.19"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "20.17.24",
45
+ "tsup": "^8",
46
+ "typescript": "5.8.3",
47
+ "zod": "3.25.76",
48
+ "@ai-sdk/test-server": "1.0.3",
49
+ "@vercel/ai-tsconfig": "0.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "zod": "^3.25.76 || ^4.1.8"
53
+ },
54
+ "engines": {
55
+ "node": ">=18"
56
+ },
57
+ "homepage": "https://ai-sdk.dev/docs",
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/vercel/ai.git"
61
+ },
62
+ "bugs": {
63
+ "url": "https://github.com/vercel/ai/issues"
64
+ },
65
+ "keywords": [
66
+ "@ai-sdk/google",
67
+ "depup",
68
+ "updated-dependencies",
69
+ "security",
70
+ "latest",
71
+ "patched",
72
+ "ai"
73
+ ],
74
+ "scripts": {
75
+ "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
76
+ "build:watch": "pnpm clean && tsup --watch",
77
+ "clean": "del-cli dist docs *.tsbuildinfo",
78
+ "lint": "eslint \"./**/*.ts*\"",
79
+ "type-check": "tsc --build",
80
+ "prettier-check": "prettier --check \"./**/*.ts*\"",
81
+ "test": "pnpm test:node && pnpm test:edge",
82
+ "test:update": "pnpm test:node -u",
83
+ "test:watch": "vitest --config vitest.node.config.js",
84
+ "test:edge": "vitest --config vitest.edge.config.js --run",
85
+ "test:node": "vitest --config vitest.node.config.js --run"
86
+ },
87
+ "description": "@ai-sdk/google with all dependencies updated to latest",
88
+ "depup": {
89
+ "changes": {},
90
+ "depsUpdated": 0,
91
+ "originalPackage": "@ai-sdk/google",
92
+ "originalVersion": "3.0.43",
93
+ "processedAt": "2026-03-18T23:32:40.401Z",
94
+ "smokeTest": "failed"
95
+ }
96
+ }
@@ -0,0 +1,51 @@
1
+ import { LanguageModelV3Usage } from '@ai-sdk/provider';
2
+
3
+ export type GoogleGenerativeAIUsageMetadata = {
4
+ promptTokenCount?: number | null;
5
+ candidatesTokenCount?: number | null;
6
+ totalTokenCount?: number | null;
7
+ cachedContentTokenCount?: number | null;
8
+ thoughtsTokenCount?: number | null;
9
+ trafficType?: string | null;
10
+ };
11
+
12
+ export function convertGoogleGenerativeAIUsage(
13
+ usage: GoogleGenerativeAIUsageMetadata | undefined | null,
14
+ ): LanguageModelV3Usage {
15
+ if (usage == null) {
16
+ return {
17
+ inputTokens: {
18
+ total: undefined,
19
+ noCache: undefined,
20
+ cacheRead: undefined,
21
+ cacheWrite: undefined,
22
+ },
23
+ outputTokens: {
24
+ total: undefined,
25
+ text: undefined,
26
+ reasoning: undefined,
27
+ },
28
+ raw: undefined,
29
+ };
30
+ }
31
+
32
+ const promptTokens = usage.promptTokenCount ?? 0;
33
+ const candidatesTokens = usage.candidatesTokenCount ?? 0;
34
+ const cachedContentTokens = usage.cachedContentTokenCount ?? 0;
35
+ const thoughtsTokens = usage.thoughtsTokenCount ?? 0;
36
+
37
+ return {
38
+ inputTokens: {
39
+ total: promptTokens,
40
+ noCache: promptTokens - cachedContentTokens,
41
+ cacheRead: cachedContentTokens,
42
+ cacheWrite: undefined,
43
+ },
44
+ outputTokens: {
45
+ total: candidatesTokens + thoughtsTokens,
46
+ text: candidatesTokens,
47
+ reasoning: thoughtsTokens,
48
+ },
49
+ raw: usage,
50
+ };
51
+ }
@@ -0,0 +1,158 @@
1
+ import { JSONSchema7Definition } from '@ai-sdk/provider';
2
+
3
+ /**
4
+ * Converts JSON Schema 7 to OpenAPI Schema 3.0
5
+ */
6
+ export function convertJSONSchemaToOpenAPISchema(
7
+ jsonSchema: JSONSchema7Definition | undefined,
8
+ isRoot = true,
9
+ ): unknown {
10
+ // Handle empty object schemas: undefined at root, preserved when nested
11
+ if (jsonSchema == null) {
12
+ return undefined;
13
+ }
14
+
15
+ if (isEmptyObjectSchema(jsonSchema)) {
16
+ if (isRoot) {
17
+ return undefined;
18
+ }
19
+
20
+ if (typeof jsonSchema === 'object' && jsonSchema.description) {
21
+ return { type: 'object', description: jsonSchema.description };
22
+ }
23
+ return { type: 'object' };
24
+ }
25
+
26
+ if (typeof jsonSchema === 'boolean') {
27
+ return { type: 'boolean', properties: {} };
28
+ }
29
+
30
+ const {
31
+ type,
32
+ description,
33
+ required,
34
+ properties,
35
+ items,
36
+ allOf,
37
+ anyOf,
38
+ oneOf,
39
+ format,
40
+ const: constValue,
41
+ minLength,
42
+ enum: enumValues,
43
+ } = jsonSchema;
44
+
45
+ const result: Record<string, unknown> = {};
46
+
47
+ if (description) result.description = description;
48
+ if (required) result.required = required;
49
+ if (format) result.format = format;
50
+
51
+ if (constValue !== undefined) {
52
+ result.enum = [constValue];
53
+ }
54
+
55
+ // Handle type
56
+ if (type) {
57
+ if (Array.isArray(type)) {
58
+ const hasNull = type.includes('null');
59
+ const nonNullTypes = type.filter(t => t !== 'null');
60
+
61
+ if (nonNullTypes.length === 0) {
62
+ // Only null type
63
+ result.type = 'null';
64
+ } else {
65
+ // One or more non-null types: always use anyOf
66
+ result.anyOf = nonNullTypes.map(t => ({ type: t }));
67
+ if (hasNull) {
68
+ result.nullable = true;
69
+ }
70
+ }
71
+ } else {
72
+ result.type = type;
73
+ }
74
+ }
75
+
76
+ // Handle enum
77
+ if (enumValues !== undefined) {
78
+ result.enum = enumValues;
79
+ }
80
+
81
+ if (properties != null) {
82
+ result.properties = Object.entries(properties).reduce(
83
+ (acc, [key, value]) => {
84
+ acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
85
+ return acc;
86
+ },
87
+ {} as Record<string, unknown>,
88
+ );
89
+ }
90
+
91
+ if (items) {
92
+ result.items = Array.isArray(items)
93
+ ? items.map(item => convertJSONSchemaToOpenAPISchema(item, false))
94
+ : convertJSONSchemaToOpenAPISchema(items, false);
95
+ }
96
+
97
+ if (allOf) {
98
+ result.allOf = allOf.map(item =>
99
+ convertJSONSchemaToOpenAPISchema(item, false),
100
+ );
101
+ }
102
+ if (anyOf) {
103
+ // Handle cases where anyOf includes a null type
104
+ if (
105
+ anyOf.some(
106
+ schema => typeof schema === 'object' && schema?.type === 'null',
107
+ )
108
+ ) {
109
+ const nonNullSchemas = anyOf.filter(
110
+ schema => !(typeof schema === 'object' && schema?.type === 'null'),
111
+ );
112
+
113
+ if (nonNullSchemas.length === 1) {
114
+ // If there's only one non-null schema, convert it and make it nullable
115
+ const converted = convertJSONSchemaToOpenAPISchema(
116
+ nonNullSchemas[0],
117
+ false,
118
+ );
119
+ if (typeof converted === 'object') {
120
+ result.nullable = true;
121
+ Object.assign(result, converted);
122
+ }
123
+ } else {
124
+ // If there are multiple non-null schemas, keep them in anyOf
125
+ result.anyOf = nonNullSchemas.map(item =>
126
+ convertJSONSchemaToOpenAPISchema(item, false),
127
+ );
128
+ result.nullable = true;
129
+ }
130
+ } else {
131
+ result.anyOf = anyOf.map(item =>
132
+ convertJSONSchemaToOpenAPISchema(item, false),
133
+ );
134
+ }
135
+ }
136
+ if (oneOf) {
137
+ result.oneOf = oneOf.map(item =>
138
+ convertJSONSchemaToOpenAPISchema(item, false),
139
+ );
140
+ }
141
+
142
+ if (minLength !== undefined) {
143
+ result.minLength = minLength;
144
+ }
145
+
146
+ return result;
147
+ }
148
+
149
+ function isEmptyObjectSchema(jsonSchema: JSONSchema7Definition): boolean {
150
+ return (
151
+ jsonSchema != null &&
152
+ typeof jsonSchema === 'object' &&
153
+ jsonSchema.type === 'object' &&
154
+ (jsonSchema.properties == null ||
155
+ Object.keys(jsonSchema.properties).length === 0) &&
156
+ !jsonSchema.additionalProperties
157
+ );
158
+ }
@@ -0,0 +1,236 @@
1
+ import {
2
+ LanguageModelV3Prompt,
3
+ UnsupportedFunctionalityError,
4
+ } from '@ai-sdk/provider';
5
+ import {
6
+ GoogleGenerativeAIContent,
7
+ GoogleGenerativeAIContentPart,
8
+ GoogleGenerativeAIPrompt,
9
+ } from './google-generative-ai-prompt';
10
+ import { convertToBase64 } from '@ai-sdk/provider-utils';
11
+
12
+ export function convertToGoogleGenerativeAIMessages(
13
+ prompt: LanguageModelV3Prompt,
14
+ options?: { isGemmaModel?: boolean; providerOptionsName?: string },
15
+ ): GoogleGenerativeAIPrompt {
16
+ const systemInstructionParts: Array<{ text: string }> = [];
17
+ const contents: Array<GoogleGenerativeAIContent> = [];
18
+ let systemMessagesAllowed = true;
19
+ const isGemmaModel = options?.isGemmaModel ?? false;
20
+ const providerOptionsName = options?.providerOptionsName ?? 'google';
21
+
22
+ for (const { role, content } of prompt) {
23
+ switch (role) {
24
+ case 'system': {
25
+ if (!systemMessagesAllowed) {
26
+ throw new UnsupportedFunctionalityError({
27
+ functionality:
28
+ 'system messages are only supported at the beginning of the conversation',
29
+ });
30
+ }
31
+
32
+ systemInstructionParts.push({ text: content });
33
+ break;
34
+ }
35
+
36
+ case 'user': {
37
+ systemMessagesAllowed = false;
38
+
39
+ const parts: GoogleGenerativeAIContentPart[] = [];
40
+
41
+ for (const part of content) {
42
+ switch (part.type) {
43
+ case 'text': {
44
+ parts.push({ text: part.text });
45
+ break;
46
+ }
47
+
48
+ case 'file': {
49
+ // default to image/jpeg for unknown image/* types
50
+ const mediaType =
51
+ part.mediaType === 'image/*' ? 'image/jpeg' : part.mediaType;
52
+
53
+ parts.push(
54
+ part.data instanceof URL
55
+ ? {
56
+ fileData: {
57
+ mimeType: mediaType,
58
+ fileUri: part.data.toString(),
59
+ },
60
+ }
61
+ : {
62
+ inlineData: {
63
+ mimeType: mediaType,
64
+ data: convertToBase64(part.data),
65
+ },
66
+ },
67
+ );
68
+
69
+ break;
70
+ }
71
+ }
72
+ }
73
+
74
+ contents.push({ role: 'user', parts });
75
+ break;
76
+ }
77
+
78
+ case 'assistant': {
79
+ systemMessagesAllowed = false;
80
+
81
+ contents.push({
82
+ role: 'model',
83
+ parts: content
84
+ .map(part => {
85
+ const providerOpts =
86
+ part.providerOptions?.[providerOptionsName] ??
87
+ (providerOptionsName !== 'google'
88
+ ? part.providerOptions?.google
89
+ : part.providerOptions?.vertex);
90
+ const thoughtSignature =
91
+ providerOpts?.thoughtSignature != null
92
+ ? String(providerOpts.thoughtSignature)
93
+ : undefined;
94
+
95
+ switch (part.type) {
96
+ case 'text': {
97
+ return part.text.length === 0
98
+ ? undefined
99
+ : {
100
+ text: part.text,
101
+ thoughtSignature,
102
+ };
103
+ }
104
+
105
+ case 'reasoning': {
106
+ return part.text.length === 0
107
+ ? undefined
108
+ : {
109
+ text: part.text,
110
+ thought: true,
111
+ thoughtSignature,
112
+ };
113
+ }
114
+
115
+ case 'file': {
116
+ if (part.data instanceof URL) {
117
+ throw new UnsupportedFunctionalityError({
118
+ functionality:
119
+ 'File data URLs in assistant messages are not supported',
120
+ });
121
+ }
122
+
123
+ return {
124
+ inlineData: {
125
+ mimeType: part.mediaType,
126
+ data: convertToBase64(part.data),
127
+ },
128
+ thoughtSignature,
129
+ };
130
+ }
131
+
132
+ case 'tool-call': {
133
+ return {
134
+ functionCall: {
135
+ name: part.toolName,
136
+ args: part.input,
137
+ },
138
+ thoughtSignature,
139
+ };
140
+ }
141
+ }
142
+ })
143
+ .filter(part => part !== undefined),
144
+ });
145
+ break;
146
+ }
147
+
148
+ case 'tool': {
149
+ systemMessagesAllowed = false;
150
+
151
+ const parts: GoogleGenerativeAIContentPart[] = [];
152
+
153
+ for (const part of content) {
154
+ if (part.type === 'tool-approval-response') {
155
+ continue;
156
+ }
157
+ const output = part.output;
158
+
159
+ if (output.type === 'content') {
160
+ for (const contentPart of output.value) {
161
+ switch (contentPart.type) {
162
+ case 'text':
163
+ parts.push({
164
+ functionResponse: {
165
+ name: part.toolName,
166
+ response: {
167
+ name: part.toolName,
168
+ content: contentPart.text,
169
+ },
170
+ },
171
+ });
172
+ break;
173
+ case 'image-data':
174
+ parts.push(
175
+ {
176
+ inlineData: {
177
+ mimeType: contentPart.mediaType,
178
+ data: contentPart.data,
179
+ },
180
+ },
181
+ {
182
+ text: 'Tool executed successfully and returned this image as a response',
183
+ },
184
+ );
185
+ break;
186
+ default:
187
+ parts.push({ text: JSON.stringify(contentPart) });
188
+ break;
189
+ }
190
+ }
191
+ } else {
192
+ parts.push({
193
+ functionResponse: {
194
+ name: part.toolName,
195
+ response: {
196
+ name: part.toolName,
197
+ content:
198
+ output.type === 'execution-denied'
199
+ ? (output.reason ?? 'Tool execution denied.')
200
+ : output.value,
201
+ },
202
+ },
203
+ });
204
+ }
205
+ }
206
+
207
+ contents.push({
208
+ role: 'user',
209
+ parts,
210
+ });
211
+ break;
212
+ }
213
+ }
214
+ }
215
+
216
+ if (
217
+ isGemmaModel &&
218
+ systemInstructionParts.length > 0 &&
219
+ contents.length > 0 &&
220
+ contents[0].role === 'user'
221
+ ) {
222
+ const systemText = systemInstructionParts
223
+ .map(part => part.text)
224
+ .join('\n\n');
225
+
226
+ contents[0].parts.unshift({ text: systemText + '\n\n' });
227
+ }
228
+
229
+ return {
230
+ systemInstruction:
231
+ systemInstructionParts.length > 0 && !isGemmaModel
232
+ ? { parts: systemInstructionParts }
233
+ : undefined,
234
+ contents,
235
+ };
236
+ }
@@ -0,0 +1,3 @@
1
+ export function getModelPath(modelId: string): string {
2
+ return modelId.includes('/') ? modelId : `models/${modelId}`;
3
+ }
@@ -0,0 +1,26 @@
1
+ import {
2
+ createJsonErrorResponseHandler,
3
+ type InferSchema,
4
+ lazySchema,
5
+ zodSchema,
6
+ } from '@ai-sdk/provider-utils';
7
+ import { z } from 'zod/v4';
8
+
9
+ const googleErrorDataSchema = lazySchema(() =>
10
+ zodSchema(
11
+ z.object({
12
+ error: z.object({
13
+ code: z.number().nullable(),
14
+ message: z.string(),
15
+ status: z.string(),
16
+ }),
17
+ }),
18
+ ),
19
+ );
20
+
21
+ export type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
22
+
23
+ export const googleFailedResponseHandler = createJsonErrorResponseHandler({
24
+ errorSchema: googleErrorDataSchema,
25
+ errorToMessage: data => data.error.message,
26
+ });