@ai-sdk/google 3.0.113 → 3.0.114
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 +6 -0
- package/dist/index.js +29 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -13
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +28 -12
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +28 -12
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/convert-json-schema-to-openapi-schema.ts +13 -1
- package/src/google-prepare-tools.ts +45 -21
package/package.json
CHANGED
|
@@ -14,6 +14,18 @@ type ReferenceContext = {
|
|
|
14
14
|
resolvingReferences: ReadonlySet<string>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
const recursiveReferenceFunctionalityPrefix =
|
|
18
|
+
'recursive JSON Schema reference:';
|
|
19
|
+
|
|
20
|
+
export function isRecursiveJSONSchemaReferenceError(
|
|
21
|
+
error: unknown,
|
|
22
|
+
): error is UnsupportedFunctionalityError {
|
|
23
|
+
return (
|
|
24
|
+
UnsupportedFunctionalityError.isInstance(error) &&
|
|
25
|
+
error.functionality.startsWith(recursiveReferenceFunctionalityPrefix)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
/**
|
|
18
30
|
* Converts JSON Schema 7 to OpenAPI Schema 3.0
|
|
19
31
|
*/
|
|
@@ -207,7 +219,7 @@ function convertJSONSchemaReference({
|
|
|
207
219
|
|
|
208
220
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
209
221
|
throw new UnsupportedFunctionalityError({
|
|
210
|
-
functionality:
|
|
222
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
211
223
|
message:
|
|
212
224
|
'Google schema conversion does not support recursive JSON Schema references.',
|
|
213
225
|
});
|
|
@@ -3,10 +3,25 @@ import {
|
|
|
3
3
|
type LanguageModelV3CallOptions,
|
|
4
4
|
type SharedV3Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
convertJSONSchemaToOpenAPISchema,
|
|
8
|
+
isRecursiveJSONSchemaReferenceError,
|
|
9
|
+
} from './convert-json-schema-to-openapi-schema';
|
|
7
10
|
import type { GoogleGenerativeAIModelId } from './google-generative-ai-options';
|
|
8
11
|
import { getGoogleModelCapabilities } from './google-model-capabilities';
|
|
9
12
|
|
|
13
|
+
type FunctionTool = Extract<
|
|
14
|
+
NonNullable<LanguageModelV3CallOptions['tools']>[number],
|
|
15
|
+
{ type: 'function' }
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
type GoogleFunctionDeclaration = {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
parameters?: unknown;
|
|
22
|
+
parametersJsonSchema?: unknown;
|
|
23
|
+
};
|
|
24
|
+
|
|
10
25
|
export function prepareTools({
|
|
11
26
|
tools,
|
|
12
27
|
toolChoice,
|
|
@@ -21,11 +36,7 @@ export function prepareTools({
|
|
|
21
36
|
tools:
|
|
22
37
|
| Array<
|
|
23
38
|
| {
|
|
24
|
-
functionDeclarations:
|
|
25
|
-
name: string;
|
|
26
|
-
description: string;
|
|
27
|
-
parameters: unknown;
|
|
28
|
-
}>;
|
|
39
|
+
functionDeclarations: GoogleFunctionDeclaration[];
|
|
29
40
|
}
|
|
30
41
|
| Record<string, any>
|
|
31
42
|
>
|
|
@@ -172,18 +183,10 @@ export function prepareTools({
|
|
|
172
183
|
});
|
|
173
184
|
|
|
174
185
|
if (hasFunctionTools && usesGemini3Features && googleTools.length > 0) {
|
|
175
|
-
const functionDeclarations:
|
|
176
|
-
name: string;
|
|
177
|
-
description: string;
|
|
178
|
-
parameters: unknown;
|
|
179
|
-
}> = [];
|
|
186
|
+
const functionDeclarations: GoogleFunctionDeclaration[] = [];
|
|
180
187
|
for (const tool of tools) {
|
|
181
188
|
if (tool.type === 'function') {
|
|
182
|
-
functionDeclarations.push(
|
|
183
|
-
name: tool.name,
|
|
184
|
-
description: tool.description ?? '',
|
|
185
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
|
|
186
|
-
});
|
|
189
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
187
190
|
}
|
|
188
191
|
}
|
|
189
192
|
|
|
@@ -238,11 +241,7 @@ export function prepareTools({
|
|
|
238
241
|
for (const tool of tools) {
|
|
239
242
|
switch (tool.type) {
|
|
240
243
|
case 'function':
|
|
241
|
-
functionDeclarations.push(
|
|
242
|
-
name: tool.name,
|
|
243
|
-
description: tool.description ?? '',
|
|
244
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
|
|
245
|
-
});
|
|
244
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
246
245
|
if (tool.strict === true) {
|
|
247
246
|
hasStrictTools = true;
|
|
248
247
|
}
|
|
@@ -314,3 +313,28 @@ export function prepareTools({
|
|
|
314
313
|
}
|
|
315
314
|
}
|
|
316
315
|
}
|
|
316
|
+
|
|
317
|
+
function prepareFunctionDeclaration(
|
|
318
|
+
tool: FunctionTool,
|
|
319
|
+
): GoogleFunctionDeclaration {
|
|
320
|
+
const declaration = {
|
|
321
|
+
name: tool.name,
|
|
322
|
+
description: tool.description ?? '',
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
return {
|
|
327
|
+
...declaration,
|
|
328
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
|
|
329
|
+
};
|
|
330
|
+
} catch (error) {
|
|
331
|
+
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
...declaration,
|
|
337
|
+
parametersJsonSchema: tool.inputSchema,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|