@ai-sdk/google 4.0.0-beta.8 → 4.0.0-canary.50
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 +351 -4
- package/README.md +6 -4
- package/dist/index.d.ts +97 -54
- package/dist/index.js +1644 -580
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +66 -26
- package/dist/internal/index.js +1258 -450
- package/dist/internal/index.js.map +1 -1
- package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +46 -40
- package/package.json +13 -14
- package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +12 -5
- package/src/convert-json-schema-to-openapi-schema.ts +1 -1
- package/src/convert-to-google-messages.ts +577 -0
- package/src/{google-generative-ai-embedding-options.ts → google-embedding-model-options.ts} +2 -2
- package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +31 -18
- package/src/google-error.ts +1 -1
- package/src/google-files.ts +225 -0
- package/src/google-image-model-options.ts +23 -0
- package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +74 -62
- package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
- package/src/google-json-accumulator.ts +336 -0
- package/src/{google-generative-ai-options.ts → google-language-model-options.ts} +32 -5
- package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +609 -214
- package/src/google-prepare-tools.ts +72 -12
- package/src/google-prompt.ts +82 -0
- package/src/google-provider.ts +63 -54
- package/src/google-video-model-options.ts +43 -0
- package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +17 -56
- package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +2 -1
- package/src/index.ts +28 -9
- package/src/internal/index.ts +2 -2
- package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +3 -3
- package/src/tool/code-execution.ts +2 -2
- package/src/tool/enterprise-web-search.ts +9 -3
- package/src/tool/file-search.ts +5 -7
- package/src/tool/google-maps.ts +3 -2
- package/src/tool/google-search.ts +10 -11
- package/src/tool/url-context.ts +4 -2
- package/src/tool/vertex-rag-store.ts +9 -6
- package/dist/index.d.mts +0 -384
- package/dist/index.mjs +0 -2519
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -287
- package/dist/internal/index.mjs +0 -1708
- package/dist/internal/index.mjs.map +0 -1
- package/src/convert-to-google-generative-ai-messages.ts +0 -239
- package/src/google-generative-ai-prompt.ts +0 -47
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV3CallOptions,
|
|
3
|
-
SharedV3Warning,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV4CallOptions,
|
|
4
|
+
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
|
|
7
|
-
import {
|
|
7
|
+
import type { GoogleModelId } from './google-language-model-options';
|
|
8
8
|
|
|
9
9
|
export function prepareTools({
|
|
10
10
|
tools,
|
|
11
11
|
toolChoice,
|
|
12
12
|
modelId,
|
|
13
|
+
isVertexProvider = false,
|
|
13
14
|
}: {
|
|
14
|
-
tools:
|
|
15
|
-
toolChoice?:
|
|
16
|
-
modelId:
|
|
15
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
16
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
17
|
+
modelId: GoogleModelId;
|
|
18
|
+
isVertexProvider?: boolean;
|
|
17
19
|
}): {
|
|
18
20
|
tools:
|
|
19
21
|
| Array<
|
|
@@ -30,30 +32,33 @@ export function prepareTools({
|
|
|
30
32
|
toolConfig:
|
|
31
33
|
| undefined
|
|
32
34
|
| {
|
|
33
|
-
functionCallingConfig
|
|
35
|
+
functionCallingConfig?: {
|
|
34
36
|
mode: 'AUTO' | 'NONE' | 'ANY' | 'VALIDATED';
|
|
35
37
|
allowedFunctionNames?: string[];
|
|
38
|
+
streamFunctionCallArguments?: boolean;
|
|
36
39
|
};
|
|
40
|
+
includeServerSideToolInvocations?: boolean;
|
|
37
41
|
};
|
|
38
|
-
toolWarnings:
|
|
42
|
+
toolWarnings: SharedV4Warning[];
|
|
39
43
|
} {
|
|
40
44
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
41
45
|
tools = tools?.length ? tools : undefined;
|
|
42
46
|
|
|
43
|
-
const toolWarnings:
|
|
47
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
44
48
|
|
|
45
49
|
const isLatest = (
|
|
46
50
|
[
|
|
47
51
|
'gemini-flash-latest',
|
|
48
52
|
'gemini-flash-lite-latest',
|
|
49
53
|
'gemini-pro-latest',
|
|
50
|
-
] as const satisfies
|
|
54
|
+
] as const satisfies GoogleModelId[]
|
|
51
55
|
).some(id => id === modelId);
|
|
52
56
|
const isGemini2orNewer =
|
|
53
57
|
modelId.includes('gemini-2') ||
|
|
54
58
|
modelId.includes('gemini-3') ||
|
|
55
59
|
modelId.includes('nano-banana') ||
|
|
56
60
|
isLatest;
|
|
61
|
+
const isGemini3orNewer = modelId.includes('gemini-3');
|
|
57
62
|
const supportsFileSearch =
|
|
58
63
|
modelId.includes('gemini-2.5') || modelId.includes('gemini-3');
|
|
59
64
|
|
|
@@ -65,7 +70,7 @@ export function prepareTools({
|
|
|
65
70
|
const hasFunctionTools = tools.some(tool => tool.type === 'function');
|
|
66
71
|
const hasProviderTools = tools.some(tool => tool.type === 'provider');
|
|
67
72
|
|
|
68
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
73
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
69
74
|
toolWarnings.push({
|
|
70
75
|
type: 'unsupported',
|
|
71
76
|
feature: `combination of function and provider-defined tools`,
|
|
@@ -120,7 +125,7 @@ export function prepareTools({
|
|
|
120
125
|
type: 'unsupported',
|
|
121
126
|
feature: `provider-defined tool ${tool.id}`,
|
|
122
127
|
details:
|
|
123
|
-
'The code execution
|
|
128
|
+
'The code execution tool is not supported with other Gemini models than Gemini 2.',
|
|
124
129
|
});
|
|
125
130
|
}
|
|
126
131
|
break;
|
|
@@ -178,6 +183,61 @@ export function prepareTools({
|
|
|
178
183
|
}
|
|
179
184
|
});
|
|
180
185
|
|
|
186
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools.length > 0) {
|
|
187
|
+
const functionDeclarations: Array<{
|
|
188
|
+
name: string;
|
|
189
|
+
description: string;
|
|
190
|
+
parameters: unknown;
|
|
191
|
+
}> = [];
|
|
192
|
+
for (const tool of tools) {
|
|
193
|
+
if (tool.type === 'function') {
|
|
194
|
+
functionDeclarations.push({
|
|
195
|
+
name: tool.name,
|
|
196
|
+
description: tool.description ?? '',
|
|
197
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const combinedToolConfig: {
|
|
203
|
+
functionCallingConfig: {
|
|
204
|
+
mode: 'VALIDATED' | 'ANY' | 'NONE';
|
|
205
|
+
allowedFunctionNames?: string[];
|
|
206
|
+
};
|
|
207
|
+
includeServerSideToolInvocations?: true;
|
|
208
|
+
} = {
|
|
209
|
+
functionCallingConfig: { mode: 'VALIDATED' },
|
|
210
|
+
...(!isVertexProvider && {
|
|
211
|
+
includeServerSideToolInvocations: true,
|
|
212
|
+
}),
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
if (toolChoice != null) {
|
|
216
|
+
switch (toolChoice.type) {
|
|
217
|
+
case 'auto':
|
|
218
|
+
break;
|
|
219
|
+
case 'none':
|
|
220
|
+
combinedToolConfig.functionCallingConfig = { mode: 'NONE' };
|
|
221
|
+
break;
|
|
222
|
+
case 'required':
|
|
223
|
+
combinedToolConfig.functionCallingConfig = { mode: 'ANY' };
|
|
224
|
+
break;
|
|
225
|
+
case 'tool':
|
|
226
|
+
combinedToolConfig.functionCallingConfig = {
|
|
227
|
+
mode: 'ANY',
|
|
228
|
+
allowedFunctionNames: [toolChoice.toolName],
|
|
229
|
+
};
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
tools: [...googleTools, { functionDeclarations }],
|
|
236
|
+
toolConfig: combinedToolConfig,
|
|
237
|
+
toolWarnings,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
181
241
|
return {
|
|
182
242
|
tools: googleTools.length > 0 ? googleTools : undefined,
|
|
183
243
|
toolConfig: undefined,
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GroundingMetadataSchema,
|
|
3
|
+
PromptFeedbackSchema,
|
|
4
|
+
SafetyRatingSchema,
|
|
5
|
+
UrlContextMetadataSchema,
|
|
6
|
+
UsageMetadataSchema,
|
|
7
|
+
} from './google-language-model';
|
|
8
|
+
|
|
9
|
+
export type GooglePrompt = {
|
|
10
|
+
systemInstruction?: GoogleSystemInstruction;
|
|
11
|
+
contents: Array<GoogleContent>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type GoogleSystemInstruction = {
|
|
15
|
+
parts: Array<{ text: string }>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type GoogleContent = {
|
|
19
|
+
role: 'user' | 'model';
|
|
20
|
+
parts: Array<GoogleContentPart>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type GoogleContentPart =
|
|
24
|
+
| { text: string; thought?: boolean; thoughtSignature?: string }
|
|
25
|
+
| {
|
|
26
|
+
inlineData: { mimeType: string; data: string };
|
|
27
|
+
thought?: boolean;
|
|
28
|
+
thoughtSignature?: string;
|
|
29
|
+
}
|
|
30
|
+
| { functionCall: { name: string; args: unknown }; thoughtSignature?: string }
|
|
31
|
+
| {
|
|
32
|
+
functionResponse: {
|
|
33
|
+
name: string;
|
|
34
|
+
response: unknown;
|
|
35
|
+
parts?: Array<GoogleFunctionResponsePart>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
fileData: { mimeType: string; fileUri: string };
|
|
40
|
+
thought?: boolean;
|
|
41
|
+
thoughtSignature?: string;
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
toolCall: {
|
|
45
|
+
toolType: string;
|
|
46
|
+
args?: unknown;
|
|
47
|
+
id: string;
|
|
48
|
+
};
|
|
49
|
+
thoughtSignature?: string;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
toolResponse: {
|
|
53
|
+
toolType: string;
|
|
54
|
+
response?: unknown;
|
|
55
|
+
id: string;
|
|
56
|
+
};
|
|
57
|
+
thoughtSignature?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type GoogleFunctionResponsePart = {
|
|
61
|
+
inlineData: { mimeType: string; data: string };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type GoogleGroundingMetadata = GroundingMetadataSchema;
|
|
65
|
+
|
|
66
|
+
export type GoogleUrlContextMetadata = UrlContextMetadataSchema;
|
|
67
|
+
|
|
68
|
+
export type GoogleSafetyRating = SafetyRatingSchema;
|
|
69
|
+
|
|
70
|
+
export type GooglePromptFeedback = PromptFeedbackSchema;
|
|
71
|
+
|
|
72
|
+
export type GoogleUsageMetadata = UsageMetadataSchema;
|
|
73
|
+
|
|
74
|
+
export interface GoogleProviderMetadata {
|
|
75
|
+
promptFeedback: GooglePromptFeedback | null;
|
|
76
|
+
groundingMetadata: GoogleGroundingMetadata | null;
|
|
77
|
+
urlContextMetadata: GoogleUrlContextMetadata | null;
|
|
78
|
+
safetyRatings: GoogleSafetyRating[] | null;
|
|
79
|
+
usageMetadata: GoogleUsageMetadata | null;
|
|
80
|
+
finishMessage: string | null;
|
|
81
|
+
serviceTier: string | null;
|
|
82
|
+
}
|
package/src/google-provider.ts
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
EmbeddingModelV4,
|
|
3
|
+
Experimental_VideoModelV4,
|
|
4
|
+
FilesV4,
|
|
5
|
+
ImageModelV4,
|
|
6
|
+
LanguageModelV4,
|
|
7
|
+
ProviderV4,
|
|
7
8
|
} from '@ai-sdk/provider';
|
|
8
9
|
import {
|
|
9
|
-
FetchFunction,
|
|
10
10
|
generateId,
|
|
11
11
|
loadApiKey,
|
|
12
12
|
withoutTrailingSlash,
|
|
13
13
|
withUserAgentSuffix,
|
|
14
|
+
type FetchFunction,
|
|
14
15
|
} from '@ai-sdk/provider-utils';
|
|
15
16
|
import { VERSION } from './version';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
17
|
+
import { GoogleEmbeddingModel } from './google-embedding-model';
|
|
18
|
+
import type { GoogleEmbeddingModelId } from './google-embedding-model-options';
|
|
19
|
+
import { GoogleLanguageModel } from './google-language-model';
|
|
20
|
+
import type { GoogleModelId } from './google-language-model-options';
|
|
20
21
|
import { googleTools } from './google-tools';
|
|
21
22
|
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} from './google-
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
23
|
+
import type {
|
|
24
|
+
GoogleImageSettings,
|
|
25
|
+
GoogleImageModelId,
|
|
26
|
+
} from './google-image-settings';
|
|
27
|
+
import { GoogleImageModel } from './google-image-model';
|
|
28
|
+
import { GoogleFiles } from './google-files';
|
|
29
|
+
import { GoogleVideoModel } from './google-video-model';
|
|
30
|
+
import type { GoogleVideoModelId } from './google-video-settings';
|
|
29
31
|
|
|
30
|
-
export interface
|
|
31
|
-
(modelId:
|
|
32
|
+
export interface GoogleProvider extends ProviderV4 {
|
|
33
|
+
(modelId: GoogleModelId): LanguageModelV4;
|
|
32
34
|
|
|
33
|
-
languageModel(modelId:
|
|
35
|
+
languageModel(modelId: GoogleModelId): LanguageModelV4;
|
|
34
36
|
|
|
35
|
-
chat(modelId:
|
|
37
|
+
chat(modelId: GoogleModelId): LanguageModelV4;
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Creates a model for image generation.
|
|
39
41
|
*/
|
|
40
42
|
image(
|
|
41
|
-
modelId:
|
|
42
|
-
settings?:
|
|
43
|
-
):
|
|
43
|
+
modelId: GoogleImageModelId,
|
|
44
|
+
settings?: GoogleImageSettings,
|
|
45
|
+
): ImageModelV4;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* @deprecated Use `chat()` instead.
|
|
47
49
|
*/
|
|
48
|
-
generativeAI(modelId:
|
|
50
|
+
generativeAI(modelId: GoogleModelId): LanguageModelV4;
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* Creates a model for text embeddings.
|
|
52
54
|
*/
|
|
53
|
-
embedding(modelId:
|
|
55
|
+
embedding(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* Creates a model for text embeddings.
|
|
57
59
|
*/
|
|
58
|
-
embeddingModel(modelId:
|
|
60
|
+
embeddingModel(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* @deprecated Use `embedding` instead.
|
|
62
64
|
*/
|
|
63
|
-
textEmbedding(modelId:
|
|
65
|
+
textEmbedding(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
64
66
|
|
|
65
67
|
/**
|
|
66
68
|
* @deprecated Use `embeddingModel` instead.
|
|
67
69
|
*/
|
|
68
|
-
textEmbeddingModel(
|
|
69
|
-
modelId: GoogleGenerativeAIEmbeddingModelId,
|
|
70
|
-
): EmbeddingModelV3;
|
|
70
|
+
textEmbeddingModel(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Creates a model for video generation.
|
|
74
74
|
*/
|
|
75
|
-
video(modelId:
|
|
75
|
+
video(modelId: GoogleVideoModelId): Experimental_VideoModelV4;
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Creates a model for video generation.
|
|
79
79
|
*/
|
|
80
|
-
videoModel(
|
|
81
|
-
|
|
82
|
-
):
|
|
80
|
+
videoModel(modelId: GoogleVideoModelId): Experimental_VideoModelV4;
|
|
81
|
+
|
|
82
|
+
files(): FilesV4;
|
|
83
83
|
|
|
84
84
|
tools: typeof googleTools;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
export interface
|
|
87
|
+
export interface GoogleProviderSettings {
|
|
88
88
|
/**
|
|
89
89
|
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
90
90
|
* The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
|
@@ -121,11 +121,11 @@ export interface GoogleGenerativeAIProviderSettings {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* Create a Google
|
|
124
|
+
* Create a Google provider instance.
|
|
125
125
|
*/
|
|
126
|
-
export function
|
|
127
|
-
options:
|
|
128
|
-
):
|
|
126
|
+
export function createGoogle(
|
|
127
|
+
options: GoogleProviderSettings = {},
|
|
128
|
+
): GoogleProvider {
|
|
129
129
|
const baseURL =
|
|
130
130
|
withoutTrailingSlash(options.baseURL) ??
|
|
131
131
|
'https://generativelanguage.googleapis.com/v1beta';
|
|
@@ -145,8 +145,8 @@ export function createGoogleGenerativeAI(
|
|
|
145
145
|
`ai-sdk/google/${VERSION}`,
|
|
146
146
|
);
|
|
147
147
|
|
|
148
|
-
const createChatModel = (modelId:
|
|
149
|
-
new
|
|
148
|
+
const createChatModel = (modelId: GoogleModelId) =>
|
|
149
|
+
new GoogleLanguageModel(modelId, {
|
|
150
150
|
provider: providerName,
|
|
151
151
|
baseURL,
|
|
152
152
|
headers: getHeaders,
|
|
@@ -166,8 +166,8 @@ export function createGoogleGenerativeAI(
|
|
|
166
166
|
fetch: options.fetch,
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
const createEmbeddingModel = (modelId:
|
|
170
|
-
new
|
|
169
|
+
const createEmbeddingModel = (modelId: GoogleEmbeddingModelId) =>
|
|
170
|
+
new GoogleEmbeddingModel(modelId, {
|
|
171
171
|
provider: providerName,
|
|
172
172
|
baseURL,
|
|
173
173
|
headers: getHeaders,
|
|
@@ -175,18 +175,26 @@ export function createGoogleGenerativeAI(
|
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
const createImageModel = (
|
|
178
|
-
modelId:
|
|
179
|
-
settings:
|
|
178
|
+
modelId: GoogleImageModelId,
|
|
179
|
+
settings: GoogleImageSettings = {},
|
|
180
180
|
) =>
|
|
181
|
-
new
|
|
181
|
+
new GoogleImageModel(modelId, settings, {
|
|
182
|
+
provider: providerName,
|
|
183
|
+
baseURL,
|
|
184
|
+
headers: getHeaders,
|
|
185
|
+
fetch: options.fetch,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const createFiles = () =>
|
|
189
|
+
new GoogleFiles({
|
|
182
190
|
provider: providerName,
|
|
183
191
|
baseURL,
|
|
184
192
|
headers: getHeaders,
|
|
185
193
|
fetch: options.fetch,
|
|
186
194
|
});
|
|
187
195
|
|
|
188
|
-
const createVideoModel = (modelId:
|
|
189
|
-
new
|
|
196
|
+
const createVideoModel = (modelId: GoogleVideoModelId) =>
|
|
197
|
+
new GoogleVideoModel(modelId, {
|
|
190
198
|
provider: providerName,
|
|
191
199
|
baseURL,
|
|
192
200
|
headers: getHeaders,
|
|
@@ -194,7 +202,7 @@ export function createGoogleGenerativeAI(
|
|
|
194
202
|
generateId: options.generateId ?? generateId,
|
|
195
203
|
});
|
|
196
204
|
|
|
197
|
-
const provider = function (modelId:
|
|
205
|
+
const provider = function (modelId: GoogleModelId) {
|
|
198
206
|
if (new.target) {
|
|
199
207
|
throw new Error(
|
|
200
208
|
'The Google Generative AI model function cannot be called with the new keyword.',
|
|
@@ -204,7 +212,7 @@ export function createGoogleGenerativeAI(
|
|
|
204
212
|
return createChatModel(modelId);
|
|
205
213
|
};
|
|
206
214
|
|
|
207
|
-
provider.specificationVersion = '
|
|
215
|
+
provider.specificationVersion = 'v4' as const;
|
|
208
216
|
provider.languageModel = createChatModel;
|
|
209
217
|
provider.chat = createChatModel;
|
|
210
218
|
provider.generativeAI = createChatModel;
|
|
@@ -216,12 +224,13 @@ export function createGoogleGenerativeAI(
|
|
|
216
224
|
provider.imageModel = createImageModel;
|
|
217
225
|
provider.video = createVideoModel;
|
|
218
226
|
provider.videoModel = createVideoModel;
|
|
227
|
+
provider.files = createFiles;
|
|
219
228
|
provider.tools = googleTools;
|
|
220
229
|
|
|
221
|
-
return provider as
|
|
230
|
+
return provider as GoogleProvider;
|
|
222
231
|
}
|
|
223
232
|
|
|
224
233
|
/**
|
|
225
234
|
* Default Google Generative AI provider instance.
|
|
226
235
|
*/
|
|
227
|
-
export const google =
|
|
236
|
+
export const google = createGoogle();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
export type GoogleVideoModelOptions = {
|
|
5
|
+
// Polling configuration
|
|
6
|
+
pollIntervalMs?: number | null;
|
|
7
|
+
pollTimeoutMs?: number | null;
|
|
8
|
+
|
|
9
|
+
// Video generation options
|
|
10
|
+
personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all' | null;
|
|
11
|
+
negativePrompt?: string | null;
|
|
12
|
+
|
|
13
|
+
// Reference images (for style/asset reference)
|
|
14
|
+
referenceImages?: Array<{
|
|
15
|
+
bytesBase64Encoded?: string;
|
|
16
|
+
gcsUri?: string;
|
|
17
|
+
}> | null;
|
|
18
|
+
|
|
19
|
+
[key: string]: unknown; // For passthrough
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const googleVideoModelOptionsSchema = lazySchema(() =>
|
|
23
|
+
zodSchema(
|
|
24
|
+
z
|
|
25
|
+
.object({
|
|
26
|
+
pollIntervalMs: z.number().positive().nullish(),
|
|
27
|
+
pollTimeoutMs: z.number().positive().nullish(),
|
|
28
|
+
personGeneration: z
|
|
29
|
+
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
30
|
+
.nullish(),
|
|
31
|
+
negativePrompt: z.string().nullish(),
|
|
32
|
+
referenceImages: z
|
|
33
|
+
.array(
|
|
34
|
+
z.object({
|
|
35
|
+
bytesBase64Encoded: z.string().nullish(),
|
|
36
|
+
gcsUri: z.string().nullish(),
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
.nullish(),
|
|
40
|
+
})
|
|
41
|
+
.passthrough(),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AISDKError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type Experimental_VideoModelV4,
|
|
4
|
+
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
8
8
|
convertUint8ArrayToBase64,
|
|
9
9
|
createJsonResponseHandler,
|
|
10
10
|
delay,
|
|
11
|
-
type FetchFunction,
|
|
12
11
|
getFromApi,
|
|
13
|
-
lazySchema,
|
|
14
12
|
parseProviderOptions,
|
|
15
13
|
postJsonToApi,
|
|
16
|
-
type Resolvable,
|
|
17
14
|
resolve,
|
|
18
|
-
|
|
15
|
+
type FetchFunction,
|
|
16
|
+
type Resolvable,
|
|
19
17
|
} from '@ai-sdk/provider-utils';
|
|
20
18
|
import { z } from 'zod/v4';
|
|
21
19
|
import { googleFailedResponseHandler } from './google-error';
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pollTimeoutMs?: number | null;
|
|
28
|
-
|
|
29
|
-
// Video generation options
|
|
30
|
-
personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all' | null;
|
|
31
|
-
negativePrompt?: string | null;
|
|
32
|
-
|
|
33
|
-
// Reference images (for style/asset reference)
|
|
34
|
-
referenceImages?: Array<{
|
|
35
|
-
bytesBase64Encoded?: string;
|
|
36
|
-
gcsUri?: string;
|
|
37
|
-
}> | null;
|
|
38
|
-
|
|
39
|
-
[key: string]: unknown; // For passthrough
|
|
40
|
-
};
|
|
20
|
+
import {
|
|
21
|
+
googleVideoModelOptionsSchema,
|
|
22
|
+
type GoogleVideoModelOptions,
|
|
23
|
+
} from './google-video-model-options';
|
|
24
|
+
import type { GoogleVideoModelId } from './google-video-settings';
|
|
41
25
|
|
|
42
|
-
interface
|
|
26
|
+
interface GoogleVideoModelConfig {
|
|
43
27
|
provider: string;
|
|
44
28
|
baseURL: string;
|
|
45
29
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
@@ -50,8 +34,8 @@ interface GoogleGenerativeAIVideoModelConfig {
|
|
|
50
34
|
};
|
|
51
35
|
}
|
|
52
36
|
|
|
53
|
-
export class
|
|
54
|
-
readonly specificationVersion = '
|
|
37
|
+
export class GoogleVideoModel implements Experimental_VideoModelV4 {
|
|
38
|
+
readonly specificationVersion = 'v4';
|
|
55
39
|
|
|
56
40
|
get provider(): string {
|
|
57
41
|
return this.config.provider;
|
|
@@ -63,15 +47,15 @@ export class GoogleGenerativeAIVideoModel implements Experimental_VideoModelV3 {
|
|
|
63
47
|
}
|
|
64
48
|
|
|
65
49
|
constructor(
|
|
66
|
-
readonly modelId:
|
|
67
|
-
private readonly config:
|
|
50
|
+
readonly modelId: GoogleVideoModelId,
|
|
51
|
+
private readonly config: GoogleVideoModelConfig,
|
|
68
52
|
) {}
|
|
69
53
|
|
|
70
54
|
async doGenerate(
|
|
71
|
-
options: Parameters<
|
|
72
|
-
): Promise<Awaited<ReturnType<
|
|
55
|
+
options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
|
|
56
|
+
): Promise<Awaited<ReturnType<Experimental_VideoModelV4['doGenerate']>>> {
|
|
73
57
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
74
|
-
const warnings:
|
|
58
|
+
const warnings: SharedV4Warning[] = [];
|
|
75
59
|
|
|
76
60
|
const googleOptions = (await parseProviderOptions({
|
|
77
61
|
provider: 'google',
|
|
@@ -349,26 +333,3 @@ const googleOperationSchema = z.object({
|
|
|
349
333
|
})
|
|
350
334
|
.nullish(),
|
|
351
335
|
});
|
|
352
|
-
|
|
353
|
-
const googleVideoModelOptionsSchema = lazySchema(() =>
|
|
354
|
-
zodSchema(
|
|
355
|
-
z
|
|
356
|
-
.object({
|
|
357
|
-
pollIntervalMs: z.number().positive().nullish(),
|
|
358
|
-
pollTimeoutMs: z.number().positive().nullish(),
|
|
359
|
-
personGeneration: z
|
|
360
|
-
.enum(['dont_allow', 'allow_adult', 'allow_all'])
|
|
361
|
-
.nullish(),
|
|
362
|
-
negativePrompt: z.string().nullish(),
|
|
363
|
-
referenceImages: z
|
|
364
|
-
.array(
|
|
365
|
-
z.object({
|
|
366
|
-
bytesBase64Encoded: z.string().nullish(),
|
|
367
|
-
gcsUri: z.string().nullish(),
|
|
368
|
-
}),
|
|
369
|
-
)
|
|
370
|
-
.nullish(),
|
|
371
|
-
})
|
|
372
|
-
.passthrough(),
|
|
373
|
-
),
|
|
374
|
-
);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type GoogleVideoModelId =
|
|
2
2
|
| 'veo-3.1-fast-generate-preview'
|
|
3
3
|
| 'veo-3.1-generate-preview'
|
|
4
4
|
| 'veo-3.1-generate'
|
|
5
|
+
| 'veo-3.1-lite-generate-preview'
|
|
5
6
|
| 'veo-3.0-generate-001'
|
|
6
7
|
| 'veo-3.0-fast-generate-001'
|
|
7
8
|
| 'veo-2.0-generate-001'
|
package/src/index.ts
CHANGED
|
@@ -3,27 +3,46 @@ export type {
|
|
|
3
3
|
GoogleLanguageModelOptions,
|
|
4
4
|
/** @deprecated Use `GoogleLanguageModelOptions` instead. */
|
|
5
5
|
GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions,
|
|
6
|
-
} from './google-
|
|
7
|
-
export type {
|
|
6
|
+
} from './google-language-model-options';
|
|
7
|
+
export type {
|
|
8
|
+
GoogleProviderMetadata,
|
|
9
|
+
/** @deprecated Use `GoogleProviderMetadata` instead. */
|
|
10
|
+
GoogleProviderMetadata as GoogleGenerativeAIProviderMetadata,
|
|
11
|
+
} from './google-prompt';
|
|
8
12
|
export type {
|
|
9
13
|
GoogleImageModelOptions,
|
|
10
14
|
/** @deprecated Use `GoogleImageModelOptions` instead. */
|
|
11
15
|
GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions,
|
|
12
|
-
} from './google-
|
|
16
|
+
} from './google-image-model-options';
|
|
13
17
|
export type {
|
|
14
18
|
GoogleEmbeddingModelOptions,
|
|
15
19
|
/** @deprecated Use `GoogleEmbeddingModelOptions` instead. */
|
|
16
20
|
GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions,
|
|
17
|
-
} from './google-
|
|
21
|
+
} from './google-embedding-model-options';
|
|
18
22
|
export type {
|
|
19
23
|
GoogleVideoModelOptions,
|
|
20
24
|
/** @deprecated Use `GoogleVideoModelOptions` instead. */
|
|
21
25
|
GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions,
|
|
22
|
-
} from './google-
|
|
23
|
-
export type {
|
|
24
|
-
|
|
26
|
+
} from './google-video-model-options';
|
|
27
|
+
export type {
|
|
28
|
+
GoogleVideoModelId,
|
|
29
|
+
/** @deprecated Use `GoogleVideoModelId` instead. */
|
|
30
|
+
GoogleVideoModelId as GoogleGenerativeAIVideoModelId,
|
|
31
|
+
} from './google-video-settings';
|
|
32
|
+
export type { GoogleFilesUploadOptions } from './google-files';
|
|
33
|
+
export {
|
|
34
|
+
createGoogle,
|
|
35
|
+
google,
|
|
36
|
+
/** @deprecated Use `createGoogle` instead. */
|
|
37
|
+
createGoogle as createGoogleGenerativeAI,
|
|
38
|
+
} from './google-provider';
|
|
25
39
|
export type {
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
GoogleProvider,
|
|
41
|
+
GoogleProviderSettings,
|
|
42
|
+
/** @deprecated Use `GoogleProvider` instead. */
|
|
43
|
+
GoogleProvider as GoogleGenerativeAIProvider,
|
|
44
|
+
/** @deprecated Use `GoogleProviderSettings` instead. */
|
|
45
|
+
GoogleProviderSettings as GoogleGenerativeAIProviderSettings,
|
|
28
46
|
} from './google-provider';
|
|
47
|
+
|
|
29
48
|
export { VERSION } from './version';
|