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,447 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { prepareTools } from './google-prepare-tools';
|
|
3
|
+
it('should return undefined tools and tool_choice when tools are null', () => {
|
|
4
|
+
const result = prepareTools({
|
|
5
|
+
tools: undefined,
|
|
6
|
+
modelId: 'gemini-2.5-flash',
|
|
7
|
+
});
|
|
8
|
+
expect(result).toEqual({
|
|
9
|
+
tools: undefined,
|
|
10
|
+
tool_choice: undefined,
|
|
11
|
+
toolWarnings: [],
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it('should return undefined tools and tool_choice when tools are empty', () => {
|
|
15
|
+
const result = prepareTools({ tools: [], modelId: 'gemini-2.5-flash' });
|
|
16
|
+
expect(result).toEqual({
|
|
17
|
+
tools: undefined,
|
|
18
|
+
tool_choice: undefined,
|
|
19
|
+
toolWarnings: [],
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it('should correctly prepare function tools', () => {
|
|
23
|
+
const result = prepareTools({
|
|
24
|
+
tools: [
|
|
25
|
+
{
|
|
26
|
+
type: 'function',
|
|
27
|
+
name: 'testFunction',
|
|
28
|
+
description: 'A test function',
|
|
29
|
+
inputSchema: { type: 'object', properties: {} },
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
modelId: 'gemini-2.5-flash',
|
|
33
|
+
});
|
|
34
|
+
expect(result.tools).toEqual([
|
|
35
|
+
{
|
|
36
|
+
functionDeclarations: [
|
|
37
|
+
{
|
|
38
|
+
name: 'testFunction',
|
|
39
|
+
description: 'A test function',
|
|
40
|
+
parameters: undefined,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
45
|
+
expect(result.toolConfig).toBeUndefined();
|
|
46
|
+
expect(result.toolWarnings).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
it('should correctly prepare provider-defined tools as array', () => {
|
|
49
|
+
const result = prepareTools({
|
|
50
|
+
tools: [
|
|
51
|
+
{
|
|
52
|
+
type: 'provider-defined',
|
|
53
|
+
id: 'google.google_search',
|
|
54
|
+
name: 'google_search',
|
|
55
|
+
args: {},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: 'provider-defined',
|
|
59
|
+
id: 'google.url_context',
|
|
60
|
+
name: 'url_context',
|
|
61
|
+
args: {},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'provider-defined',
|
|
65
|
+
id: 'google.file_search',
|
|
66
|
+
name: 'file_search',
|
|
67
|
+
args: { fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'] },
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
modelId: 'gemini-2.5-flash',
|
|
71
|
+
});
|
|
72
|
+
expect(result.tools).toEqual([
|
|
73
|
+
{ googleSearch: {} },
|
|
74
|
+
{ urlContext: {} },
|
|
75
|
+
{
|
|
76
|
+
fileSearch: {
|
|
77
|
+
fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
expect(result.toolConfig).toBeUndefined();
|
|
82
|
+
expect(result.toolWarnings).toEqual([]);
|
|
83
|
+
});
|
|
84
|
+
it('should correctly prepare single provider-defined tool', () => {
|
|
85
|
+
const result = prepareTools({
|
|
86
|
+
tools: [
|
|
87
|
+
{
|
|
88
|
+
type: 'provider-defined',
|
|
89
|
+
id: 'google.google_search',
|
|
90
|
+
name: 'google_search',
|
|
91
|
+
args: {},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
modelId: 'gemini-2.5-flash',
|
|
95
|
+
});
|
|
96
|
+
expect(result.tools).toEqual([{ googleSearch: {} }]);
|
|
97
|
+
expect(result.toolConfig).toBeUndefined();
|
|
98
|
+
expect(result.toolWarnings).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
it('should add warnings for unsupported tools', () => {
|
|
101
|
+
const result = prepareTools({
|
|
102
|
+
tools: [
|
|
103
|
+
{
|
|
104
|
+
type: 'provider-defined',
|
|
105
|
+
id: 'unsupported.tool',
|
|
106
|
+
name: 'unsupported_tool',
|
|
107
|
+
args: {},
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
modelId: 'gemini-2.5-flash',
|
|
111
|
+
});
|
|
112
|
+
expect(result.tools).toBeUndefined();
|
|
113
|
+
expect(result.toolConfig).toBeUndefined();
|
|
114
|
+
expect(result.toolWarnings).toMatchInlineSnapshot(`
|
|
115
|
+
[
|
|
116
|
+
{
|
|
117
|
+
"tool": {
|
|
118
|
+
"args": {},
|
|
119
|
+
"id": "unsupported.tool",
|
|
120
|
+
"name": "unsupported_tool",
|
|
121
|
+
"type": "provider-defined",
|
|
122
|
+
},
|
|
123
|
+
"type": "unsupported-tool",
|
|
124
|
+
},
|
|
125
|
+
]
|
|
126
|
+
`);
|
|
127
|
+
});
|
|
128
|
+
it('should add warnings for file search on unsupported models', () => {
|
|
129
|
+
const tool = {
|
|
130
|
+
type: 'provider-defined',
|
|
131
|
+
id: 'google.file_search',
|
|
132
|
+
name: 'file_search',
|
|
133
|
+
args: { fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'] },
|
|
134
|
+
};
|
|
135
|
+
const result = prepareTools({
|
|
136
|
+
tools: [tool],
|
|
137
|
+
modelId: 'gemini-1.5-flash-8b',
|
|
138
|
+
});
|
|
139
|
+
expect(result.tools).toBeUndefined();
|
|
140
|
+
expect(result.toolWarnings).toMatchInlineSnapshot(`
|
|
141
|
+
[
|
|
142
|
+
{
|
|
143
|
+
"details": "The file search tool is only supported with Gemini 2.5 models.",
|
|
144
|
+
"tool": {
|
|
145
|
+
"args": {
|
|
146
|
+
"fileSearchStoreNames": [
|
|
147
|
+
"projects/foo/fileSearchStores/bar",
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
"id": "google.file_search",
|
|
151
|
+
"name": "file_search",
|
|
152
|
+
"type": "provider-defined",
|
|
153
|
+
},
|
|
154
|
+
"type": "unsupported-tool",
|
|
155
|
+
},
|
|
156
|
+
]
|
|
157
|
+
`);
|
|
158
|
+
});
|
|
159
|
+
it('should correctly prepare file search tool', () => {
|
|
160
|
+
const result = prepareTools({
|
|
161
|
+
tools: [
|
|
162
|
+
{
|
|
163
|
+
type: 'provider-defined',
|
|
164
|
+
id: 'google.file_search',
|
|
165
|
+
name: 'file_search',
|
|
166
|
+
args: {
|
|
167
|
+
fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'],
|
|
168
|
+
metadataFilter: 'author=Robert Graves',
|
|
169
|
+
topK: 5,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
modelId: 'gemini-2.5-pro',
|
|
174
|
+
});
|
|
175
|
+
expect(result.tools).toEqual([
|
|
176
|
+
{
|
|
177
|
+
fileSearch: {
|
|
178
|
+
fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'],
|
|
179
|
+
metadataFilter: 'author=Robert Graves',
|
|
180
|
+
topK: 5,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
expect(result.toolWarnings).toEqual([]);
|
|
185
|
+
});
|
|
186
|
+
it('should handle tool choice "auto"', () => {
|
|
187
|
+
const result = prepareTools({
|
|
188
|
+
tools: [
|
|
189
|
+
{
|
|
190
|
+
type: 'function',
|
|
191
|
+
name: 'testFunction',
|
|
192
|
+
description: 'Test',
|
|
193
|
+
inputSchema: {},
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
toolChoice: { type: 'auto' },
|
|
197
|
+
modelId: 'gemini-2.5-flash',
|
|
198
|
+
});
|
|
199
|
+
expect(result.toolConfig).toEqual({
|
|
200
|
+
functionCallingConfig: { mode: 'AUTO' },
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
it('should handle tool choice "required"', () => {
|
|
204
|
+
const result = prepareTools({
|
|
205
|
+
tools: [
|
|
206
|
+
{
|
|
207
|
+
type: 'function',
|
|
208
|
+
name: 'testFunction',
|
|
209
|
+
description: 'Test',
|
|
210
|
+
inputSchema: {},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
toolChoice: { type: 'required' },
|
|
214
|
+
modelId: 'gemini-2.5-flash',
|
|
215
|
+
});
|
|
216
|
+
expect(result.toolConfig).toEqual({
|
|
217
|
+
functionCallingConfig: { mode: 'ANY' },
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
it('should handle tool choice "none"', () => {
|
|
221
|
+
const result = prepareTools({
|
|
222
|
+
tools: [
|
|
223
|
+
{
|
|
224
|
+
type: 'function',
|
|
225
|
+
name: 'testFunction',
|
|
226
|
+
description: 'Test',
|
|
227
|
+
inputSchema: {},
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
toolChoice: { type: 'none' },
|
|
231
|
+
modelId: 'gemini-2.5-flash',
|
|
232
|
+
});
|
|
233
|
+
expect(result.tools).toEqual([
|
|
234
|
+
{
|
|
235
|
+
functionDeclarations: [
|
|
236
|
+
{
|
|
237
|
+
name: 'testFunction',
|
|
238
|
+
description: 'Test',
|
|
239
|
+
parameters: {},
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
]);
|
|
244
|
+
expect(result.toolConfig).toEqual({
|
|
245
|
+
functionCallingConfig: { mode: 'NONE' },
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
it('should handle tool choice "tool"', () => {
|
|
249
|
+
const result = prepareTools({
|
|
250
|
+
tools: [
|
|
251
|
+
{
|
|
252
|
+
type: 'function',
|
|
253
|
+
name: 'testFunction',
|
|
254
|
+
description: 'Test',
|
|
255
|
+
inputSchema: {},
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
toolChoice: { type: 'tool', toolName: 'testFunction' },
|
|
259
|
+
modelId: 'gemini-2.5-flash',
|
|
260
|
+
});
|
|
261
|
+
expect(result.toolConfig).toEqual({
|
|
262
|
+
functionCallingConfig: {
|
|
263
|
+
mode: 'ANY',
|
|
264
|
+
allowedFunctionNames: ['testFunction'],
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
it('should warn when mixing function and provider-defined tools', () => {
|
|
269
|
+
const result = prepareTools({
|
|
270
|
+
tools: [
|
|
271
|
+
{
|
|
272
|
+
type: 'function',
|
|
273
|
+
name: 'testFunction',
|
|
274
|
+
description: 'A test function',
|
|
275
|
+
inputSchema: { type: 'object', properties: {} },
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
type: 'provider-defined',
|
|
279
|
+
id: 'google.google_search',
|
|
280
|
+
name: 'google_search',
|
|
281
|
+
args: {},
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
modelId: 'gemini-2.5-flash',
|
|
285
|
+
});
|
|
286
|
+
// Should only include provider-defined tools as array
|
|
287
|
+
expect(result.tools).toEqual([{ googleSearch: {} }]);
|
|
288
|
+
// Should have warning about mixed tool types
|
|
289
|
+
expect(result.toolWarnings).toEqual([
|
|
290
|
+
{
|
|
291
|
+
type: 'unsupported-tool',
|
|
292
|
+
tool: {
|
|
293
|
+
type: 'function',
|
|
294
|
+
name: 'testFunction',
|
|
295
|
+
description: 'A test function',
|
|
296
|
+
inputSchema: { type: 'object', properties: {} },
|
|
297
|
+
},
|
|
298
|
+
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: testFunction. Please use either function tools or provider-defined tools, but not both.',
|
|
299
|
+
},
|
|
300
|
+
]);
|
|
301
|
+
expect(result.toolConfig).toBeUndefined();
|
|
302
|
+
});
|
|
303
|
+
it('should handle tool choice with mixed tools (provider-defined tools only)', () => {
|
|
304
|
+
const result = prepareTools({
|
|
305
|
+
tools: [
|
|
306
|
+
{
|
|
307
|
+
type: 'function',
|
|
308
|
+
name: 'testFunction',
|
|
309
|
+
description: 'A test function',
|
|
310
|
+
inputSchema: { type: 'object', properties: {} },
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
type: 'provider-defined',
|
|
314
|
+
id: 'google.google_search',
|
|
315
|
+
name: 'google_search',
|
|
316
|
+
args: {},
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
toolChoice: { type: 'auto' },
|
|
320
|
+
modelId: 'gemini-2.5-flash',
|
|
321
|
+
});
|
|
322
|
+
// Should only include provider-defined tools as array
|
|
323
|
+
expect(result.tools).toEqual([{ googleSearch: {} }]);
|
|
324
|
+
// Should apply tool choice to provider-defined tools
|
|
325
|
+
expect(result.toolConfig).toEqual(undefined);
|
|
326
|
+
// Should have warning about mixed tool types
|
|
327
|
+
expect(result.toolWarnings).toEqual([
|
|
328
|
+
{
|
|
329
|
+
type: 'unsupported-tool',
|
|
330
|
+
tool: {
|
|
331
|
+
type: 'function',
|
|
332
|
+
name: 'testFunction',
|
|
333
|
+
description: 'A test function',
|
|
334
|
+
inputSchema: { type: 'object', properties: {} },
|
|
335
|
+
},
|
|
336
|
+
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: testFunction. Please use either function tools or provider-defined tools, but not both.',
|
|
337
|
+
},
|
|
338
|
+
]);
|
|
339
|
+
});
|
|
340
|
+
it('should handle latest modelId for provider-defined tools correctly', () => {
|
|
341
|
+
const result = prepareTools({
|
|
342
|
+
tools: [
|
|
343
|
+
{
|
|
344
|
+
type: 'provider-defined',
|
|
345
|
+
id: 'google.google_search',
|
|
346
|
+
name: 'google_search',
|
|
347
|
+
args: {},
|
|
348
|
+
},
|
|
349
|
+
],
|
|
350
|
+
modelId: 'gemini-flash-latest',
|
|
351
|
+
});
|
|
352
|
+
expect(result.tools).toEqual([{ googleSearch: {} }]);
|
|
353
|
+
expect(result.toolConfig).toBeUndefined();
|
|
354
|
+
expect(result.toolWarnings).toEqual([]);
|
|
355
|
+
});
|
|
356
|
+
it('should handle gemini-3 modelId for provider-defined tools correctly', () => {
|
|
357
|
+
const result = prepareTools({
|
|
358
|
+
tools: [
|
|
359
|
+
{
|
|
360
|
+
type: 'provider-defined',
|
|
361
|
+
id: 'google.google_search',
|
|
362
|
+
name: 'google_search',
|
|
363
|
+
args: {},
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
modelId: 'gemini-3-pro-preview',
|
|
367
|
+
});
|
|
368
|
+
expect(result.tools).toEqual([{ googleSearch: {} }]);
|
|
369
|
+
expect(result.toolConfig).toBeUndefined();
|
|
370
|
+
expect(result.toolWarnings).toEqual([]);
|
|
371
|
+
});
|
|
372
|
+
it('should handle code execution tool', () => {
|
|
373
|
+
const result = prepareTools({
|
|
374
|
+
tools: [
|
|
375
|
+
{
|
|
376
|
+
type: 'provider-defined',
|
|
377
|
+
id: 'google.code_execution',
|
|
378
|
+
name: 'code_execution',
|
|
379
|
+
args: {},
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
modelId: 'gemini-2.5-flash',
|
|
383
|
+
});
|
|
384
|
+
expect(result.tools).toEqual([{ codeExecution: {} }]);
|
|
385
|
+
expect(result.toolConfig).toBeUndefined();
|
|
386
|
+
expect(result.toolWarnings).toEqual([]);
|
|
387
|
+
});
|
|
388
|
+
it('should handle url context tool alone', () => {
|
|
389
|
+
const result = prepareTools({
|
|
390
|
+
tools: [
|
|
391
|
+
{
|
|
392
|
+
type: 'provider-defined',
|
|
393
|
+
id: 'google.url_context',
|
|
394
|
+
name: 'url_context',
|
|
395
|
+
args: {},
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
modelId: 'gemini-2.5-flash',
|
|
399
|
+
});
|
|
400
|
+
expect(result.tools).toEqual([{ urlContext: {} }]);
|
|
401
|
+
expect(result.toolConfig).toBeUndefined();
|
|
402
|
+
expect(result.toolWarnings).toEqual([]);
|
|
403
|
+
});
|
|
404
|
+
it('should handle google maps tool', () => {
|
|
405
|
+
const result = prepareTools({
|
|
406
|
+
tools: [
|
|
407
|
+
{
|
|
408
|
+
type: 'provider-defined',
|
|
409
|
+
id: 'google.google_maps',
|
|
410
|
+
name: 'google_maps',
|
|
411
|
+
args: {},
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
modelId: 'gemini-2.5-flash',
|
|
415
|
+
});
|
|
416
|
+
expect(result.tools).toEqual([{ googleMaps: {} }]);
|
|
417
|
+
expect(result.toolConfig).toBeUndefined();
|
|
418
|
+
expect(result.toolWarnings).toEqual([]);
|
|
419
|
+
});
|
|
420
|
+
it('should add warnings for google maps on unsupported models', () => {
|
|
421
|
+
const result = prepareTools({
|
|
422
|
+
tools: [
|
|
423
|
+
{
|
|
424
|
+
type: 'provider-defined',
|
|
425
|
+
id: 'google.google_maps',
|
|
426
|
+
name: 'google_maps',
|
|
427
|
+
args: {},
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
modelId: 'gemini-1.5-flash',
|
|
431
|
+
});
|
|
432
|
+
expect(result.tools).toBeUndefined();
|
|
433
|
+
expect(result.toolWarnings).toMatchInlineSnapshot(`
|
|
434
|
+
[
|
|
435
|
+
{
|
|
436
|
+
"details": "The Google Maps grounding tool is not supported with Gemini models other than Gemini 2 or newer.",
|
|
437
|
+
"tool": {
|
|
438
|
+
"args": {},
|
|
439
|
+
"id": "google.google_maps",
|
|
440
|
+
"name": "google_maps",
|
|
441
|
+
"type": "provider-defined",
|
|
442
|
+
},
|
|
443
|
+
"type": "unsupported-tool",
|
|
444
|
+
},
|
|
445
|
+
]
|
|
446
|
+
`);
|
|
447
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { EmbeddingModelV2, LanguageModelV2, ProviderV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { GoogleGenerativeAIEmbeddingModelId } from './google-generative-ai-embedding-options';
|
|
4
|
+
import { GoogleGenerativeAIModelId } from './google-generative-ai-options';
|
|
5
|
+
import { googleTools } from './google-tools';
|
|
6
|
+
import { GoogleGenerativeAIImageSettings, GoogleGenerativeAIImageModelId } from './google-generative-ai-image-settings';
|
|
7
|
+
export interface GoogleGenerativeAIProvider extends ProviderV2 {
|
|
8
|
+
(modelId: GoogleGenerativeAIModelId): LanguageModelV2;
|
|
9
|
+
languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV2;
|
|
10
|
+
chat(modelId: GoogleGenerativeAIModelId): LanguageModelV2;
|
|
11
|
+
/**
|
|
12
|
+
Creates a model for image generation.
|
|
13
|
+
*/
|
|
14
|
+
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV2;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `chat()` instead.
|
|
17
|
+
*/
|
|
18
|
+
generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV2;
|
|
19
|
+
/**
|
|
20
|
+
@deprecated Use `textEmbedding()` instead.
|
|
21
|
+
*/
|
|
22
|
+
embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
|
23
|
+
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
|
24
|
+
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
|
25
|
+
tools: typeof googleTools;
|
|
26
|
+
}
|
|
27
|
+
export interface GoogleGenerativeAIProviderSettings {
|
|
28
|
+
/**
|
|
29
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
30
|
+
The default prefix is `https://cloudcode-pa.googleapis.com`.
|
|
31
|
+
*/
|
|
32
|
+
baseURL?: string;
|
|
33
|
+
/**
|
|
34
|
+
Google Cloud access token used for Bearer authentication.
|
|
35
|
+
It defaults to the `GOOGLE_CLOUD_ACCESS_TOKEN` environment variable.
|
|
36
|
+
*/
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
Custom headers to include in the requests.
|
|
40
|
+
*/
|
|
41
|
+
headers?: Record<string, string | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
44
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
45
|
+
*/
|
|
46
|
+
fetch?: FetchFunction;
|
|
47
|
+
/**
|
|
48
|
+
Optional function to generate a unique ID for each request.
|
|
49
|
+
*/
|
|
50
|
+
generateId?: () => string;
|
|
51
|
+
/**
|
|
52
|
+
* Custom provider name
|
|
53
|
+
* Defaults to 'google.generative-ai'.
|
|
54
|
+
*/
|
|
55
|
+
name?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
Create a Google Generative AI provider instance.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createGoogleGenerativeAI(options?: GoogleGenerativeAIProviderSettings): GoogleGenerativeAIProvider;
|
|
61
|
+
/**
|
|
62
|
+
Default Google Generative AI provider instance.
|
|
63
|
+
*/
|
|
64
|
+
export declare const google: GoogleGenerativeAIProvider;
|
|
65
|
+
//# sourceMappingURL=google-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-provider.d.ts","sourceRoot":"","sources":["../src/google-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EAKd,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,kCAAkC,EAAE,MAAM,0CAA0C,CAAC;AAE9F,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,EAC/B,MAAM,uCAAuC,CAAC;AAG/C,MAAM,WAAW,0BAA2B,SAAQ,UAAU;IAC5D,CAAC,OAAO,EAAE,yBAAyB,GAAG,eAAe,CAAC;IAEtD,aAAa,CAAC,OAAO,EAAE,yBAAyB,GAAG,eAAe,CAAC;IAEnE,IAAI,CAAC,OAAO,EAAE,yBAAyB,GAAG,eAAe,CAAC;IAE1D;;KAEC;IACD,KAAK,CACH,OAAO,EAAE,8BAA8B,EACvC,QAAQ,CAAC,EAAE,+BAA+B,GACzC,YAAY,CAAC;IAEhB;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,eAAe,CAAC;IAElE;;OAEG;IACH,SAAS,CACP,OAAO,EAAE,kCAAkC,GAC1C,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE5B,aAAa,CACX,OAAO,EAAE,kCAAkC,GAC1C,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE5B,kBAAkB,CAChB,OAAO,EAAE,kCAAkC,GAC1C,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE5B,KAAK,EAAE,OAAO,WAAW,CAAC;CAC3B;AAED,MAAM,WAAW,kCAAkC;IACjD;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;SAEK;IACL,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAE7C;;;QAGI;IACJ,KAAK,CAAC,EAAE,aAAa,CAAC;IAEtB;;SAEK;IACL,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC;IAE1B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,kCAAuC,GAC/C,0BAA0B,CAgF5B;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,4BAA6B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { generateId, loadApiKey, withoutTrailingSlash, withUserAgentSuffix, } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { VERSION } from './version';
|
|
3
|
+
import { GoogleGenerativeAIEmbeddingModel } from './google-generative-ai-embedding-model';
|
|
4
|
+
import { GoogleGenerativeAILanguageModel } from './google-generative-ai-language-model';
|
|
5
|
+
import { googleTools } from './google-tools';
|
|
6
|
+
import { GoogleGenerativeAIImageModel } from './google-generative-ai-image-model';
|
|
7
|
+
/**
|
|
8
|
+
Create a Google Generative AI provider instance.
|
|
9
|
+
*/
|
|
10
|
+
export function createGoogleGenerativeAI(options = {}) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) !== null && _a !== void 0 ? _a : 'https://cloudcode-pa.googleapis.com';
|
|
13
|
+
const providerName = (_b = options.name) !== null && _b !== void 0 ? _b : 'google.generative-ai';
|
|
14
|
+
const getHeaders = () => withUserAgentSuffix({
|
|
15
|
+
Authorization: `Bearer ${loadApiKey({
|
|
16
|
+
apiKey: options.apiKey,
|
|
17
|
+
environmentVariableName: 'GOOGLE_CLOUD_ACCESS_TOKEN',
|
|
18
|
+
description: 'Google Cloud Access Token',
|
|
19
|
+
})}`,
|
|
20
|
+
...options.headers,
|
|
21
|
+
}, `ai-sdk/google-cloudassist/${VERSION}`);
|
|
22
|
+
const createChatModel = (modelId) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return new GoogleGenerativeAILanguageModel(modelId, {
|
|
25
|
+
provider: providerName,
|
|
26
|
+
baseURL,
|
|
27
|
+
headers: getHeaders,
|
|
28
|
+
generateId: (_a = options.generateId) !== null && _a !== void 0 ? _a : generateId,
|
|
29
|
+
supportedUrls: () => ({
|
|
30
|
+
'*': [
|
|
31
|
+
// Google Generative Language "files" endpoint
|
|
32
|
+
// e.g. https://generativelanguage.googleapis.com/v1beta/files/...
|
|
33
|
+
new RegExp(`^${baseURL}/files/.*$`),
|
|
34
|
+
// YouTube URLs (public or unlisted videos)
|
|
35
|
+
new RegExp(`^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`),
|
|
36
|
+
new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`),
|
|
37
|
+
],
|
|
38
|
+
}),
|
|
39
|
+
fetch: options.fetch,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
|
|
43
|
+
provider: providerName,
|
|
44
|
+
baseURL,
|
|
45
|
+
headers: getHeaders,
|
|
46
|
+
fetch: options.fetch,
|
|
47
|
+
});
|
|
48
|
+
const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
|
|
49
|
+
provider: providerName,
|
|
50
|
+
baseURL,
|
|
51
|
+
headers: getHeaders,
|
|
52
|
+
fetch: options.fetch,
|
|
53
|
+
});
|
|
54
|
+
const provider = function (modelId) {
|
|
55
|
+
if (new.target) {
|
|
56
|
+
throw new Error('The Google Generative AI model function cannot be called with the new keyword.');
|
|
57
|
+
}
|
|
58
|
+
return createChatModel(modelId);
|
|
59
|
+
};
|
|
60
|
+
provider.languageModel = createChatModel;
|
|
61
|
+
provider.chat = createChatModel;
|
|
62
|
+
provider.generativeAI = createChatModel;
|
|
63
|
+
provider.embedding = createEmbeddingModel;
|
|
64
|
+
provider.textEmbedding = createEmbeddingModel;
|
|
65
|
+
provider.textEmbeddingModel = createEmbeddingModel;
|
|
66
|
+
provider.image = createImageModel;
|
|
67
|
+
provider.imageModel = createImageModel;
|
|
68
|
+
provider.tools = googleTools;
|
|
69
|
+
return provider;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
Default Google Generative AI provider instance.
|
|
73
|
+
*/
|
|
74
|
+
export const google = createGoogleGenerativeAI();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-provider.test.d.ts","sourceRoot":"","sources":["../src/google-provider.test.ts"],"names":[],"mappings":""}
|