@ai-sdk/google 4.0.51 → 4.0.53
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 +21 -0
- package/dist/index.js +67 -78
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -3
- package/dist/internal/index.js +43 -17
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +28 -16
- package/package.json +2 -2
- package/src/convert-json-schema-to-openapi-schema.ts +13 -1
- package/src/google-batch.ts +9 -78
- package/src/google-files.ts +27 -2
- package/src/google-prepare-tools.ts +45 -21
- package/src/interactions/build-google-interactions-stream-transform.ts +13 -5
package/dist/internal/index.d.ts
CHANGED
|
@@ -137,11 +137,12 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
137
137
|
threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF";
|
|
138
138
|
}[] | undefined;
|
|
139
139
|
tools: ({
|
|
140
|
-
functionDeclarations:
|
|
140
|
+
functionDeclarations: {
|
|
141
141
|
name: string;
|
|
142
142
|
description: string;
|
|
143
|
-
parameters
|
|
144
|
-
|
|
143
|
+
parameters?: unknown;
|
|
144
|
+
parametersJsonSchema?: unknown;
|
|
145
|
+
}[];
|
|
145
146
|
} | Record<string, any>)[] | undefined;
|
|
146
147
|
toolConfig: {
|
|
147
148
|
retrievalConfig?: {
|
package/dist/internal/index.js
CHANGED
|
@@ -49,6 +49,10 @@ function convertGoogleUsage(usage) {
|
|
|
49
49
|
import {
|
|
50
50
|
UnsupportedFunctionalityError
|
|
51
51
|
} from "@ai-sdk/provider";
|
|
52
|
+
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
53
|
+
function isRecursiveJSONSchemaReferenceError(error) {
|
|
54
|
+
return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
55
|
+
}
|
|
52
56
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
53
57
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
54
58
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
@@ -189,7 +193,7 @@ function convertJSONSchemaReference({
|
|
|
189
193
|
);
|
|
190
194
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
191
195
|
throw new UnsupportedFunctionalityError({
|
|
192
|
-
functionality:
|
|
196
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
193
197
|
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
194
198
|
});
|
|
195
199
|
}
|
|
@@ -1025,7 +1029,6 @@ function prepareTools({
|
|
|
1025
1029
|
modelId,
|
|
1026
1030
|
isVertexProvider = false
|
|
1027
1031
|
}) {
|
|
1028
|
-
var _a, _b;
|
|
1029
1032
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1030
1033
|
const toolWarnings = [];
|
|
1031
1034
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
@@ -1143,11 +1146,7 @@ function prepareTools({
|
|
|
1143
1146
|
const functionDeclarations2 = [];
|
|
1144
1147
|
for (const tool of tools) {
|
|
1145
1148
|
if (tool.type === "function") {
|
|
1146
|
-
functionDeclarations2.push(
|
|
1147
|
-
name: tool.name,
|
|
1148
|
-
description: (_a = tool.description) != null ? _a : "",
|
|
1149
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1150
|
-
});
|
|
1149
|
+
functionDeclarations2.push(prepareFunctionDeclaration(tool));
|
|
1151
1150
|
}
|
|
1152
1151
|
}
|
|
1153
1152
|
const combinedToolConfig = {
|
|
@@ -1191,11 +1190,7 @@ function prepareTools({
|
|
|
1191
1190
|
for (const tool of tools) {
|
|
1192
1191
|
switch (tool.type) {
|
|
1193
1192
|
case "function":
|
|
1194
|
-
functionDeclarations.push(
|
|
1195
|
-
name: tool.name,
|
|
1196
|
-
description: (_b = tool.description) != null ? _b : "",
|
|
1197
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1198
|
-
});
|
|
1193
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
1199
1194
|
if (tool.strict === true) {
|
|
1200
1195
|
hasStrictTools = true;
|
|
1201
1196
|
}
|
|
@@ -1262,6 +1257,27 @@ function prepareTools({
|
|
|
1262
1257
|
}
|
|
1263
1258
|
}
|
|
1264
1259
|
}
|
|
1260
|
+
function prepareFunctionDeclaration(tool) {
|
|
1261
|
+
var _a;
|
|
1262
|
+
const declaration = {
|
|
1263
|
+
name: tool.name,
|
|
1264
|
+
description: (_a = tool.description) != null ? _a : ""
|
|
1265
|
+
};
|
|
1266
|
+
try {
|
|
1267
|
+
return {
|
|
1268
|
+
...declaration,
|
|
1269
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1270
|
+
};
|
|
1271
|
+
} catch (error) {
|
|
1272
|
+
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
1273
|
+
throw error;
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
...declaration,
|
|
1277
|
+
parametersJsonSchema: tool.inputSchema
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1265
1281
|
|
|
1266
1282
|
// src/google-json-accumulator.ts
|
|
1267
1283
|
var GoogleJSONAccumulator = class {
|
|
@@ -3179,6 +3195,11 @@ import {
|
|
|
3179
3195
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
3180
3196
|
} from "@ai-sdk/provider-utils";
|
|
3181
3197
|
|
|
3198
|
+
// src/interactions/build-google-interactions-stream-transform.ts
|
|
3199
|
+
import {
|
|
3200
|
+
createProviderStreamError
|
|
3201
|
+
} from "@ai-sdk/provider-utils";
|
|
3202
|
+
|
|
3182
3203
|
// src/interactions/convert-google-interactions-usage.ts
|
|
3183
3204
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
3184
3205
|
function convertGoogleInteractionsUsage(usage) {
|
|
@@ -3473,7 +3494,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3473
3494
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3474
3495
|
},
|
|
3475
3496
|
transform(chunk, controller) {
|
|
3476
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
3497
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
3477
3498
|
if (includeRawChunks) {
|
|
3478
3499
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3479
3500
|
}
|
|
@@ -3884,10 +3905,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3884
3905
|
case "error": {
|
|
3885
3906
|
const event = value;
|
|
3886
3907
|
finishStatus = "failed";
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3908
|
+
controller.enqueue({
|
|
3909
|
+
type: "error",
|
|
3910
|
+
error: createProviderStreamError({
|
|
3911
|
+
message: (_r = (_q = event.error) == null ? void 0 : _q.message) != null ? _r : "Unknown interaction error",
|
|
3912
|
+
type: event.event_type,
|
|
3913
|
+
code: (_t = (_s = event.error) == null ? void 0 : _s.code) != null ? _t : void 0,
|
|
3914
|
+
data: event
|
|
3915
|
+
})
|
|
3916
|
+
});
|
|
3891
3917
|
break;
|
|
3892
3918
|
}
|
|
3893
3919
|
default:
|