cloudassist-ai-provider 0.0.1
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 +1901 -0
- package/README.md +35 -0
- package/dist/convert-json-schema-to-openapi-schema.d.ts +6 -0
- package/dist/convert-json-schema-to-openapi-schema.d.ts.map +1 -0
- package/dist/convert-json-schema-to-openapi-schema.js +108 -0
- package/dist/convert-json-schema-to-openapi-schema.test.d.ts +2 -0
- package/dist/convert-json-schema-to-openapi-schema.test.d.ts.map +1 -0
- package/dist/convert-json-schema-to-openapi-schema.test.js +630 -0
- package/dist/convert-to-google-generative-ai-messages.d.ts +7 -0
- package/dist/convert-to-google-generative-ai-messages.d.ts.map +1 -0
- package/dist/convert-to-google-generative-ai-messages.js +195 -0
- package/dist/convert-to-google-generative-ai-messages.test.d.ts +2 -0
- package/dist/convert-to-google-generative-ai-messages.test.d.ts.map +1 -0
- package/dist/convert-to-google-generative-ai-messages.test.js +456 -0
- package/dist/get-model-path.d.ts +2 -0
- package/dist/get-model-path.d.ts.map +1 -0
- package/dist/get-model-path.js +3 -0
- package/dist/get-model-path.test.d.ts +2 -0
- package/dist/get-model-path.test.d.ts.map +1 -0
- package/dist/get-model-path.test.js +11 -0
- package/dist/google-error.d.ts +12 -0
- package/dist/google-error.d.ts.map +1 -0
- package/dist/google-error.js +13 -0
- package/dist/google-generative-ai-embedding-model.d.ts +21 -0
- package/dist/google-generative-ai-embedding-model.d.ts.map +1 -0
- package/dist/google-generative-ai-embedding-model.js +88 -0
- package/dist/google-generative-ai-embedding-model.test.d.ts +2 -0
- package/dist/google-generative-ai-embedding-model.test.d.ts.map +1 -0
- package/dist/google-generative-ai-embedding-model.test.js +148 -0
- package/dist/google-generative-ai-embedding-options.d.ts +8 -0
- package/dist/google-generative-ai-embedding-options.d.ts.map +1 -0
- package/dist/google-generative-ai-embedding-options.js +33 -0
- package/dist/google-generative-ai-image-model.d.ts +31 -0
- package/dist/google-generative-ai-image-model.d.ts.map +1 -0
- package/dist/google-generative-ai-image-model.js +96 -0
- package/dist/google-generative-ai-image-model.test.d.ts +2 -0
- package/dist/google-generative-ai-image-model.test.d.ts.map +1 -0
- package/dist/google-generative-ai-image-model.test.js +252 -0
- package/dist/google-generative-ai-image-settings.d.ts +8 -0
- package/dist/google-generative-ai-image-settings.d.ts.map +1 -0
- package/dist/google-generative-ai-image-settings.js +1 -0
- package/dist/google-generative-ai-language-model.d.ts +183 -0
- package/dist/google-generative-ai-language-model.d.ts.map +1 -0
- package/dist/google-generative-ai-language-model.js +1001 -0
- package/dist/google-generative-ai-language-model.test.d.ts +2 -0
- package/dist/google-generative-ai-language-model.test.d.ts.map +1 -0
- package/dist/google-generative-ai-language-model.test.js +3463 -0
- package/dist/google-generative-ai-options.d.ts +37 -0
- package/dist/google-generative-ai-options.d.ts.map +1 -0
- package/dist/google-generative-ai-options.js +149 -0
- package/dist/google-generative-ai-prompt.d.ts +52 -0
- package/dist/google-generative-ai-prompt.d.ts.map +1 -0
- package/dist/google-generative-ai-prompt.js +1 -0
- package/dist/google-prepare-tools.d.ts +27 -0
- package/dist/google-prepare-tools.d.ts.map +1 -0
- package/dist/google-prepare-tools.js +219 -0
- package/dist/google-prepare-tools.test.d.ts +2 -0
- package/dist/google-prepare-tools.test.d.ts.map +1 -0
- package/dist/google-prepare-tools.test.js +447 -0
- package/dist/google-provider.d.ts +65 -0
- package/dist/google-provider.d.ts.map +1 -0
- package/dist/google-provider.js +74 -0
- package/dist/google-provider.test.d.ts +2 -0
- package/dist/google-provider.test.d.ts.map +1 -0
- package/dist/google-provider.test.js +234 -0
- package/dist/google-supported-file-url.d.ts +2 -0
- package/dist/google-supported-file-url.d.ts.map +1 -0
- package/dist/google-supported-file-url.js +13 -0
- package/dist/google-supported-file-url.test.d.ts +2 -0
- package/dist/google-supported-file-url.test.d.ts.map +1 -0
- package/dist/google-supported-file-url.test.js +45 -0
- package/dist/google-tools.d.ts +76 -0
- package/dist/google-tools.d.ts.map +1 -0
- package/dist/google-tools.js +65 -0
- package/dist/index.d.mts +326 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2172 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.d.mts +262 -0
- package/dist/internal/index.d.ts +4 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +2 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/index.mjs +1810 -0
- package/dist/internal/index.mjs.map +1 -0
- package/dist/map-google-generative-ai-finish-reason.d.ts +6 -0
- package/dist/map-google-generative-ai-finish-reason.d.ts.map +1 -0
- package/dist/map-google-generative-ai-finish-reason.js +22 -0
- package/dist/tool/code-execution.d.ts +17 -0
- package/dist/tool/code-execution.d.ts.map +1 -0
- package/dist/tool/code-execution.js +25 -0
- package/dist/tool/enterprise-web-search.d.ts +2 -0
- package/dist/tool/enterprise-web-search.d.ts.map +1 -0
- package/dist/tool/enterprise-web-search.js +8 -0
- package/dist/tool/file-search.d.ts +16 -0
- package/dist/tool/file-search.d.ts.map +1 -0
- package/dist/tool/file-search.js +33 -0
- package/dist/tool/google-maps.d.ts +2 -0
- package/dist/tool/google-maps.d.ts.map +1 -0
- package/dist/tool/google-maps.js +9 -0
- package/dist/tool/google-search.d.ts +14 -0
- package/dist/tool/google-search.d.ts.map +1 -0
- package/dist/tool/google-search.js +15 -0
- package/dist/tool/url-context.d.ts +2 -0
- package/dist/tool/url-context.d.ts.map +1 -0
- package/dist/tool/url-context.js +7 -0
- package/dist/tool/vertex-rag-store.d.ts +16 -0
- package/dist/tool/vertex-rag-store.d.ts.map +1 -0
- package/dist/tool/vertex-rag-store.js +17 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/internal.d.ts +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type InferValidator } from '@ai-sdk/provider-utils';
|
|
2
|
+
export type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
3
|
+
export declare const googleGenerativeAIProviderOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
4
|
+
responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
|
|
5
|
+
thinkingConfig?: {
|
|
6
|
+
thinkingBudget?: number | undefined;
|
|
7
|
+
includeThoughts?: boolean | undefined;
|
|
8
|
+
thinkingLevel?: "minimal" | "low" | "medium" | "high" | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
cachedContent?: string | undefined;
|
|
11
|
+
structuredOutputs?: boolean | undefined;
|
|
12
|
+
safetySettings?: {
|
|
13
|
+
category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
14
|
+
threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF";
|
|
15
|
+
}[] | undefined;
|
|
16
|
+
threshold?: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF" | undefined;
|
|
17
|
+
audioTimestamp?: boolean | undefined;
|
|
18
|
+
labels?: Record<string, string> | undefined;
|
|
19
|
+
mediaResolution?: "MEDIA_RESOLUTION_UNSPECIFIED" | "MEDIA_RESOLUTION_LOW" | "MEDIA_RESOLUTION_MEDIUM" | "MEDIA_RESOLUTION_HIGH" | undefined;
|
|
20
|
+
imageConfig?: {
|
|
21
|
+
aspectRatio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9" | undefined;
|
|
22
|
+
imageSize?: "1K" | "2K" | "4K" | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
retrievalConfig?: {
|
|
25
|
+
latLng?: {
|
|
26
|
+
latitude: number;
|
|
27
|
+
longitude: number;
|
|
28
|
+
} | undefined;
|
|
29
|
+
} | undefined;
|
|
30
|
+
projectId?: string | undefined;
|
|
31
|
+
sessionId?: string | undefined;
|
|
32
|
+
requestType?: string | undefined;
|
|
33
|
+
userAgent?: string | undefined;
|
|
34
|
+
requestId?: string | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
export type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
|
|
37
|
+
//# sourceMappingURL=google-generative-ai-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-generative-ai-options.d.ts","sourceRoot":"","sources":["../src/google-generative-ai-options.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,yBAAyB,GAGjC,kBAAkB,GAClB,yBAAyB,GACzB,sBAAsB,GACtB,sBAAsB,GACtB,qBAAqB,GACrB,4BAA4B,GAC5B,yBAAyB,GACzB,gBAAgB,GAChB,uBAAuB,GACvB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,sBAAsB,GACtB,2BAA2B,GAC3B,uBAAuB,GACvB,0BAA0B,GAC1B,qCAAqC,GACrC,sBAAsB,GACtB,gBAAgB,GAChB,kBAAkB,GAClB,gCAAgC,GAChC,uBAAuB,GACvB,uCAAuC,GACvC,gCAAgC,GAChC,kCAAkC,GAClC,sBAAsB,GACtB,4BAA4B,GAC5B,wBAAwB,GAGxB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAG1B,0BAA0B,GAC1B,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwK7C,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,cAAc,CAC5D,OAAO,iCAAiC,CACzC,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { lazySchema, zodSchema, } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
export const googleGenerativeAIProviderOptions = lazySchema(() => zodSchema(z.object({
|
|
4
|
+
responseModalities: z.array(z.enum(['TEXT', 'IMAGE'])).optional(),
|
|
5
|
+
thinkingConfig: z
|
|
6
|
+
.object({
|
|
7
|
+
thinkingBudget: z.number().optional(),
|
|
8
|
+
includeThoughts: z.boolean().optional(),
|
|
9
|
+
// https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
|
|
10
|
+
thinkingLevel: z
|
|
11
|
+
.enum(['minimal', 'low', 'medium', 'high'])
|
|
12
|
+
.optional(),
|
|
13
|
+
})
|
|
14
|
+
.optional(),
|
|
15
|
+
/**
|
|
16
|
+
* Optional.
|
|
17
|
+
* The name of the cached content used as context to serve the prediction.
|
|
18
|
+
* Format: cachedContents/{cachedContent}
|
|
19
|
+
*/
|
|
20
|
+
cachedContent: z.string().optional(),
|
|
21
|
+
/**
|
|
22
|
+
* Optional. Enable structured output. Default is true.
|
|
23
|
+
*
|
|
24
|
+
* This is useful when the JSON Schema contains elements that are
|
|
25
|
+
* not supported by the OpenAPI schema version that
|
|
26
|
+
* Google Generative AI uses. You can use this to disable
|
|
27
|
+
* structured outputs if you need to.
|
|
28
|
+
*/
|
|
29
|
+
structuredOutputs: z.boolean().optional(),
|
|
30
|
+
/**
|
|
31
|
+
* Optional. A list of unique safety settings for blocking unsafe content.
|
|
32
|
+
*/
|
|
33
|
+
safetySettings: z
|
|
34
|
+
.array(z.object({
|
|
35
|
+
category: z.enum([
|
|
36
|
+
'HARM_CATEGORY_UNSPECIFIED',
|
|
37
|
+
'HARM_CATEGORY_HATE_SPEECH',
|
|
38
|
+
'HARM_CATEGORY_DANGEROUS_CONTENT',
|
|
39
|
+
'HARM_CATEGORY_HARASSMENT',
|
|
40
|
+
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
|
41
|
+
'HARM_CATEGORY_CIVIC_INTEGRITY',
|
|
42
|
+
]),
|
|
43
|
+
threshold: z.enum([
|
|
44
|
+
'HARM_BLOCK_THRESHOLD_UNSPECIFIED',
|
|
45
|
+
'BLOCK_LOW_AND_ABOVE',
|
|
46
|
+
'BLOCK_MEDIUM_AND_ABOVE',
|
|
47
|
+
'BLOCK_ONLY_HIGH',
|
|
48
|
+
'BLOCK_NONE',
|
|
49
|
+
'OFF',
|
|
50
|
+
]),
|
|
51
|
+
}))
|
|
52
|
+
.optional(),
|
|
53
|
+
threshold: z
|
|
54
|
+
.enum([
|
|
55
|
+
'HARM_BLOCK_THRESHOLD_UNSPECIFIED',
|
|
56
|
+
'BLOCK_LOW_AND_ABOVE',
|
|
57
|
+
'BLOCK_MEDIUM_AND_ABOVE',
|
|
58
|
+
'BLOCK_ONLY_HIGH',
|
|
59
|
+
'BLOCK_NONE',
|
|
60
|
+
'OFF',
|
|
61
|
+
])
|
|
62
|
+
.optional(),
|
|
63
|
+
/**
|
|
64
|
+
* Optional. Enables timestamp understanding for audio-only files.
|
|
65
|
+
*
|
|
66
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
|
67
|
+
*/
|
|
68
|
+
audioTimestamp: z.boolean().optional(),
|
|
69
|
+
/**
|
|
70
|
+
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
71
|
+
*
|
|
72
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
|
73
|
+
*/
|
|
74
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
75
|
+
/**
|
|
76
|
+
* Optional. If specified, the media resolution specified will be used.
|
|
77
|
+
*
|
|
78
|
+
* https://ai.google.dev/api/generate-content#MediaResolution
|
|
79
|
+
*/
|
|
80
|
+
mediaResolution: z
|
|
81
|
+
.enum([
|
|
82
|
+
'MEDIA_RESOLUTION_UNSPECIFIED',
|
|
83
|
+
'MEDIA_RESOLUTION_LOW',
|
|
84
|
+
'MEDIA_RESOLUTION_MEDIUM',
|
|
85
|
+
'MEDIA_RESOLUTION_HIGH',
|
|
86
|
+
])
|
|
87
|
+
.optional(),
|
|
88
|
+
/**
|
|
89
|
+
* Optional. Configures the image generation aspect ratio for Gemini models.
|
|
90
|
+
*
|
|
91
|
+
* https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
|
|
92
|
+
*/
|
|
93
|
+
imageConfig: z
|
|
94
|
+
.object({
|
|
95
|
+
aspectRatio: z
|
|
96
|
+
.enum([
|
|
97
|
+
'1:1',
|
|
98
|
+
'2:3',
|
|
99
|
+
'3:2',
|
|
100
|
+
'3:4',
|
|
101
|
+
'4:3',
|
|
102
|
+
'4:5',
|
|
103
|
+
'5:4',
|
|
104
|
+
'9:16',
|
|
105
|
+
'16:9',
|
|
106
|
+
'21:9',
|
|
107
|
+
])
|
|
108
|
+
.optional(),
|
|
109
|
+
imageSize: z.enum(['1K', '2K', '4K']).optional(),
|
|
110
|
+
})
|
|
111
|
+
.optional(),
|
|
112
|
+
/**
|
|
113
|
+
* Optional. Configuration for grounding retrieval.
|
|
114
|
+
* Used to provide location context for Google Maps and Google Search grounding.
|
|
115
|
+
*
|
|
116
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
117
|
+
*/
|
|
118
|
+
retrievalConfig: z
|
|
119
|
+
.object({
|
|
120
|
+
latLng: z
|
|
121
|
+
.object({
|
|
122
|
+
latitude: z.number(),
|
|
123
|
+
longitude: z.number(),
|
|
124
|
+
})
|
|
125
|
+
.optional(),
|
|
126
|
+
})
|
|
127
|
+
.optional(),
|
|
128
|
+
// Cloud Assist specific options
|
|
129
|
+
/**
|
|
130
|
+
* Required for Cloud Assist. The Google Cloud project ID.
|
|
131
|
+
*/
|
|
132
|
+
projectId: z.string().optional(),
|
|
133
|
+
/**
|
|
134
|
+
* Optional. Session ID for conversation continuity.
|
|
135
|
+
*/
|
|
136
|
+
sessionId: z.string().optional(),
|
|
137
|
+
/**
|
|
138
|
+
* Optional. Request type (e.g., "agent").
|
|
139
|
+
*/
|
|
140
|
+
requestType: z.string().optional(),
|
|
141
|
+
/**
|
|
142
|
+
* Required for Cloud Assist. User agent identifier.
|
|
143
|
+
*/
|
|
144
|
+
userAgent: z.string().optional(),
|
|
145
|
+
/**
|
|
146
|
+
* Optional. Custom request ID. If not provided, one will be generated.
|
|
147
|
+
*/
|
|
148
|
+
requestId: z.string().optional(),
|
|
149
|
+
})));
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GroundingMetadataSchema, UrlContextMetadataSchema } from './google-generative-ai-language-model';
|
|
2
|
+
import { type SafetyRatingSchema } from './google-generative-ai-language-model';
|
|
3
|
+
export type GoogleGenerativeAIPrompt = {
|
|
4
|
+
systemInstruction?: GoogleGenerativeAISystemInstruction;
|
|
5
|
+
contents: Array<GoogleGenerativeAIContent>;
|
|
6
|
+
};
|
|
7
|
+
export type GoogleGenerativeAISystemInstruction = {
|
|
8
|
+
parts: Array<{
|
|
9
|
+
text: string;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
export type GoogleGenerativeAIContent = {
|
|
13
|
+
role: 'user' | 'model';
|
|
14
|
+
parts: Array<GoogleGenerativeAIContentPart>;
|
|
15
|
+
};
|
|
16
|
+
export type GoogleGenerativeAIContentPart = {
|
|
17
|
+
text: string;
|
|
18
|
+
thought?: boolean;
|
|
19
|
+
thoughtSignature?: string;
|
|
20
|
+
} | {
|
|
21
|
+
inlineData: {
|
|
22
|
+
mimeType: string;
|
|
23
|
+
data: string;
|
|
24
|
+
};
|
|
25
|
+
} | {
|
|
26
|
+
functionCall: {
|
|
27
|
+
name: string;
|
|
28
|
+
args: unknown;
|
|
29
|
+
id?: string;
|
|
30
|
+
};
|
|
31
|
+
thoughtSignature?: string;
|
|
32
|
+
} | {
|
|
33
|
+
functionResponse: {
|
|
34
|
+
name: string;
|
|
35
|
+
response: unknown;
|
|
36
|
+
id?: string;
|
|
37
|
+
};
|
|
38
|
+
} | {
|
|
39
|
+
fileData: {
|
|
40
|
+
mimeType: string;
|
|
41
|
+
fileUri: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
45
|
+
export type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
46
|
+
export type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
47
|
+
export interface GoogleGenerativeAIProviderMetadata {
|
|
48
|
+
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
49
|
+
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
50
|
+
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=google-generative-ai-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-generative-ai-prompt.d.ts","sourceRoot":"","sources":["../src/google-generative-ai-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,iBAAiB,CAAC,EAAE,mCAAmC,CAAC;IACxD,QAAQ,EAAE,KAAK,CAAC,yBAAyB,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,6BAA6B,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,UAAU,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAClD;IACE,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3D,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GACD;IAAE,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACtE;IAAE,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAExD,MAAM,MAAM,mCAAmC,GAAG,uBAAuB,CAAC;AAE1E,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CAAC;AAE5E,MAAM,MAAM,8BAA8B,GAAG,kBAAkB,CAAC;AAEhE,MAAM,WAAW,kCAAkC;IACjD,iBAAiB,EAAE,mCAAmC,GAAG,IAAI,CAAC;IAC9D,kBAAkB,EAAE,oCAAoC,GAAG,IAAI,CAAC;IAChE,aAAa,EAAE,8BAA8B,EAAE,GAAG,IAAI,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LanguageModelV2CallOptions, LanguageModelV2CallWarning } from '@ai-sdk/provider';
|
|
2
|
+
import { GoogleGenerativeAIModelId } from './google-generative-ai-options';
|
|
3
|
+
/**
|
|
4
|
+
* Check if the model is a Claude model (requires special handling for tool calls).
|
|
5
|
+
*/
|
|
6
|
+
export declare function isClaudeModel(modelId: string): boolean;
|
|
7
|
+
export declare function prepareTools({ tools, toolChoice, modelId, }: {
|
|
8
|
+
tools: LanguageModelV2CallOptions['tools'];
|
|
9
|
+
toolChoice?: LanguageModelV2CallOptions['toolChoice'];
|
|
10
|
+
modelId: GoogleGenerativeAIModelId;
|
|
11
|
+
}): {
|
|
12
|
+
tools: Array<{
|
|
13
|
+
functionDeclarations: Array<{
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
parameters: unknown;
|
|
17
|
+
}>;
|
|
18
|
+
} | Record<string, any>> | undefined;
|
|
19
|
+
toolConfig: undefined | {
|
|
20
|
+
functionCallingConfig: {
|
|
21
|
+
mode: 'AUTO' | 'NONE' | 'ANY';
|
|
22
|
+
allowedFunctionNames?: string[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
toolWarnings: LanguageModelV2CallWarning[];
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=google-prepare-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-prepare-tools.d.ts","sourceRoot":"","sources":["../src/google-prepare-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,UAAU,EACV,OAAO,GACR,EAAE;IACD,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;IACtD,OAAO,EAAE,yBAAyB,CAAC;CACpC,GAAG;IACF,KAAK,EACD,KAAK,CACD;QACE,oBAAoB,EAAE,KAAK,CAAC;YAC1B,IAAI,EAAE,MAAM,CAAC;YACb,WAAW,EAAE,MAAM,CAAC;YACpB,UAAU,EAAE,OAAO,CAAC;SACrB,CAAC,CAAC;KACJ,GACD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACtB,GACD,SAAS,CAAC;IACd,UAAU,EACN,SAAS,GACT;QACE,qBAAqB,EAAE;YACrB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;YAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;SACjC,CAAC;KACH,CAAC;IACN,YAAY,EAAE,0BAA0B,EAAE,CAAC;CAC5C,CAyOA"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { UnsupportedFunctionalityError, } from '@ai-sdk/provider';
|
|
2
|
+
import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
|
|
3
|
+
/**
|
|
4
|
+
* Check if the model is a Claude model (requires special handling for tool calls).
|
|
5
|
+
*/
|
|
6
|
+
export function isClaudeModel(modelId) {
|
|
7
|
+
return modelId.toLowerCase().startsWith('claude-');
|
|
8
|
+
}
|
|
9
|
+
export function prepareTools({ tools, toolChoice, modelId, }) {
|
|
10
|
+
var _a;
|
|
11
|
+
// when the tools array is empty, change it to undefined to prevent errors:
|
|
12
|
+
tools = (tools === null || tools === void 0 ? void 0 : tools.length) ? tools : undefined;
|
|
13
|
+
const toolWarnings = [];
|
|
14
|
+
const isLatest = [
|
|
15
|
+
'gemini-flash-latest',
|
|
16
|
+
'gemini-flash-lite-latest',
|
|
17
|
+
'gemini-pro-latest',
|
|
18
|
+
].some(id => id === modelId);
|
|
19
|
+
const isGemini2orNewer = modelId.includes('gemini-2') || modelId.includes('gemini-3') || isLatest;
|
|
20
|
+
const supportsDynamicRetrieval = modelId.includes('gemini-1.5-flash') && !modelId.includes('-8b');
|
|
21
|
+
const supportsFileSearch = modelId.includes('gemini-2.5');
|
|
22
|
+
if (tools == null) {
|
|
23
|
+
return { tools: undefined, toolConfig: undefined, toolWarnings };
|
|
24
|
+
}
|
|
25
|
+
// Check for mixed tool types and add warnings
|
|
26
|
+
const hasFunctionTools = tools.some(tool => tool.type === 'function');
|
|
27
|
+
const hasProviderDefinedTools = tools.some(tool => tool.type === 'provider-defined');
|
|
28
|
+
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
29
|
+
const functionTools = tools.filter(tool => tool.type === 'function');
|
|
30
|
+
toolWarnings.push({
|
|
31
|
+
type: 'unsupported-tool',
|
|
32
|
+
tool: tools.find(tool => tool.type === 'function'),
|
|
33
|
+
details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map(t => t.name).join(', ')}. Please use either function tools or provider-defined tools, but not both.`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (hasProviderDefinedTools) {
|
|
37
|
+
const googleTools = [];
|
|
38
|
+
const providerDefinedTools = tools.filter(tool => tool.type === 'provider-defined');
|
|
39
|
+
providerDefinedTools.forEach(tool => {
|
|
40
|
+
switch (tool.id) {
|
|
41
|
+
case 'google.google_search':
|
|
42
|
+
if (isGemini2orNewer) {
|
|
43
|
+
googleTools.push({ googleSearch: {} });
|
|
44
|
+
}
|
|
45
|
+
else if (supportsDynamicRetrieval) {
|
|
46
|
+
// For non-Gemini-2 models that don't support dynamic retrieval, use basic googleSearchRetrieval
|
|
47
|
+
googleTools.push({
|
|
48
|
+
googleSearchRetrieval: {
|
|
49
|
+
dynamicRetrievalConfig: {
|
|
50
|
+
mode: tool.args.mode,
|
|
51
|
+
dynamicThreshold: tool.args.dynamicThreshold,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
googleTools.push({ googleSearchRetrieval: {} });
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case 'google.enterprise_web_search':
|
|
61
|
+
if (isGemini2orNewer) {
|
|
62
|
+
googleTools.push({ enterpriseWebSearch: {} });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
toolWarnings.push({
|
|
66
|
+
type: 'unsupported-tool',
|
|
67
|
+
tool,
|
|
68
|
+
details: 'Enterprise Web Search requires Gemini 2.0 or newer.',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case 'google.url_context':
|
|
73
|
+
if (isGemini2orNewer) {
|
|
74
|
+
googleTools.push({ urlContext: {} });
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
toolWarnings.push({
|
|
78
|
+
type: 'unsupported-tool',
|
|
79
|
+
tool,
|
|
80
|
+
details: 'The URL context tool is not supported with other Gemini models than Gemini 2.',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case 'google.code_execution':
|
|
85
|
+
if (isGemini2orNewer) {
|
|
86
|
+
googleTools.push({ codeExecution: {} });
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
toolWarnings.push({
|
|
90
|
+
type: 'unsupported-tool',
|
|
91
|
+
tool,
|
|
92
|
+
details: 'The code execution tools is not supported with other Gemini models than Gemini 2.',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case 'google.file_search':
|
|
97
|
+
if (supportsFileSearch) {
|
|
98
|
+
googleTools.push({ fileSearch: { ...tool.args } });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
toolWarnings.push({
|
|
102
|
+
type: 'unsupported-tool',
|
|
103
|
+
tool,
|
|
104
|
+
details: 'The file search tool is only supported with Gemini 2.5 models.',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case 'google.vertex_rag_store':
|
|
109
|
+
if (isGemini2orNewer) {
|
|
110
|
+
googleTools.push({
|
|
111
|
+
retrieval: {
|
|
112
|
+
vertex_rag_store: {
|
|
113
|
+
rag_resources: {
|
|
114
|
+
rag_corpus: tool.args.ragCorpus,
|
|
115
|
+
},
|
|
116
|
+
similarity_top_k: tool.args.topK,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
toolWarnings.push({
|
|
123
|
+
type: 'unsupported-tool',
|
|
124
|
+
tool,
|
|
125
|
+
details: 'The RAG store tool is not supported with other Gemini models than Gemini 2.',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case 'google.google_maps':
|
|
130
|
+
if (isGemini2orNewer) {
|
|
131
|
+
googleTools.push({ googleMaps: {} });
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
toolWarnings.push({
|
|
135
|
+
type: 'unsupported-tool',
|
|
136
|
+
tool,
|
|
137
|
+
details: 'The Google Maps grounding tool is not supported with Gemini models other than Gemini 2 or newer.',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
toolWarnings.push({ type: 'unsupported-tool', tool });
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
tools: googleTools.length > 0 ? googleTools : undefined,
|
|
148
|
+
toolConfig: undefined,
|
|
149
|
+
toolWarnings,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const functionDeclarations = [];
|
|
153
|
+
for (const tool of tools) {
|
|
154
|
+
switch (tool.type) {
|
|
155
|
+
case 'function': {
|
|
156
|
+
let parameters = convertJSONSchemaToOpenAPISchema(tool.inputSchema);
|
|
157
|
+
// Claude models require empty parameters to be explicitly defined
|
|
158
|
+
// as { type: "object", properties: {} } instead of undefined/null
|
|
159
|
+
if (isClaudeModel(modelId) && !parameters) {
|
|
160
|
+
parameters = { type: 'object', properties: {} };
|
|
161
|
+
}
|
|
162
|
+
functionDeclarations.push({
|
|
163
|
+
name: tool.name,
|
|
164
|
+
description: (_a = tool.description) !== null && _a !== void 0 ? _a : '',
|
|
165
|
+
parameters,
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
default:
|
|
170
|
+
toolWarnings.push({ type: 'unsupported-tool', tool });
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (toolChoice == null) {
|
|
175
|
+
return {
|
|
176
|
+
tools: [{ functionDeclarations }],
|
|
177
|
+
toolConfig: undefined,
|
|
178
|
+
toolWarnings,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const type = toolChoice.type;
|
|
182
|
+
switch (type) {
|
|
183
|
+
case 'auto':
|
|
184
|
+
return {
|
|
185
|
+
tools: [{ functionDeclarations }],
|
|
186
|
+
toolConfig: { functionCallingConfig: { mode: 'AUTO' } },
|
|
187
|
+
toolWarnings,
|
|
188
|
+
};
|
|
189
|
+
case 'none':
|
|
190
|
+
return {
|
|
191
|
+
tools: [{ functionDeclarations }],
|
|
192
|
+
toolConfig: { functionCallingConfig: { mode: 'NONE' } },
|
|
193
|
+
toolWarnings,
|
|
194
|
+
};
|
|
195
|
+
case 'required':
|
|
196
|
+
return {
|
|
197
|
+
tools: [{ functionDeclarations }],
|
|
198
|
+
toolConfig: { functionCallingConfig: { mode: 'ANY' } },
|
|
199
|
+
toolWarnings,
|
|
200
|
+
};
|
|
201
|
+
case 'tool':
|
|
202
|
+
return {
|
|
203
|
+
tools: [{ functionDeclarations }],
|
|
204
|
+
toolConfig: {
|
|
205
|
+
functionCallingConfig: {
|
|
206
|
+
mode: 'ANY',
|
|
207
|
+
allowedFunctionNames: [toolChoice.toolName],
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
toolWarnings,
|
|
211
|
+
};
|
|
212
|
+
default: {
|
|
213
|
+
const _exhaustiveCheck = type;
|
|
214
|
+
throw new UnsupportedFunctionalityError({
|
|
215
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-prepare-tools.test.d.ts","sourceRoot":"","sources":["../src/google-prepare-tools.test.ts"],"names":[],"mappings":""}
|