@ai-sdk/google 3.0.141 → 3.0.143
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 +16 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +88 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +87 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +87 -7
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +18 -0
- package/package.json +2 -2
- package/src/convert-json-schema-to-openapi-schema.ts +85 -0
- package/src/google-json-accumulator.ts +34 -0
- package/src/google-prepare-tools.ts +7 -0
- package/src/interactions/google-interactions-language-model-options.ts +2 -0
- package/src/interactions/google-interactions-language-model.ts +1 -0
- package/src/interactions/google-interactions-prompt.ts +1 -0
package/dist/internal/index.js
CHANGED
|
@@ -178,25 +178,54 @@ function addTokenDetails(a, b) {
|
|
|
178
178
|
|
|
179
179
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
180
180
|
var import_provider = require("@ai-sdk/provider");
|
|
181
|
+
var maxSchemaDepth = 100;
|
|
182
|
+
var maxSchemaNodes = 1e4;
|
|
183
|
+
var maxSchemaSize = 1e6;
|
|
181
184
|
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
182
185
|
function isRecursiveJSONSchemaReferenceError(error) {
|
|
183
186
|
return import_provider.UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
184
187
|
}
|
|
185
188
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
189
|
+
consumeSchemaBudget(jsonSchema, {
|
|
190
|
+
nodes: maxSchemaNodes,
|
|
191
|
+
size: maxSchemaSize
|
|
192
|
+
});
|
|
186
193
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
187
194
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
188
195
|
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
189
196
|
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
190
|
-
resolvingReferences: /* @__PURE__ */ new Set()
|
|
197
|
+
resolvingReferences: /* @__PURE__ */ new Set(),
|
|
198
|
+
budget: { nodes: maxSchemaNodes, size: maxSchemaSize },
|
|
199
|
+
depth: 0
|
|
191
200
|
});
|
|
192
201
|
}
|
|
193
202
|
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
194
203
|
if (jsonSchema == null) {
|
|
195
204
|
return void 0;
|
|
196
205
|
}
|
|
206
|
+
referenceContext.budget.nodes--;
|
|
207
|
+
referenceContext.budget.size -= 128;
|
|
208
|
+
checkSchemaBudget(referenceContext.budget, referenceContext.depth);
|
|
209
|
+
referenceContext = {
|
|
210
|
+
...referenceContext,
|
|
211
|
+
depth: referenceContext.depth + 1
|
|
212
|
+
};
|
|
197
213
|
if (typeof jsonSchema === "boolean") {
|
|
198
214
|
return { type: "boolean", properties: {} };
|
|
199
215
|
}
|
|
216
|
+
consumeSchemaBudget(
|
|
217
|
+
[
|
|
218
|
+
jsonSchema.$ref,
|
|
219
|
+
jsonSchema.type,
|
|
220
|
+
jsonSchema.description,
|
|
221
|
+
jsonSchema.required,
|
|
222
|
+
jsonSchema.format,
|
|
223
|
+
jsonSchema.const,
|
|
224
|
+
jsonSchema.enum,
|
|
225
|
+
jsonSchema.minLength
|
|
226
|
+
],
|
|
227
|
+
referenceContext.budget
|
|
228
|
+
);
|
|
200
229
|
if (jsonSchema.$ref != null) {
|
|
201
230
|
return convertJSONSchemaReference({
|
|
202
231
|
jsonSchema,
|
|
@@ -260,6 +289,7 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
260
289
|
if (properties != null) {
|
|
261
290
|
result.properties = Object.entries(properties).reduce(
|
|
262
291
|
(acc, [key, value]) => {
|
|
292
|
+
consumeSchemaBudget(key, referenceContext.budget);
|
|
263
293
|
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
264
294
|
return acc;
|
|
265
295
|
},
|
|
@@ -315,6 +345,38 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
315
345
|
}
|
|
316
346
|
return result;
|
|
317
347
|
}
|
|
348
|
+
function checkSchemaBudget(budget, depth) {
|
|
349
|
+
if (budget.nodes < 0 || budget.size < 0 || depth > maxSchemaDepth) {
|
|
350
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
351
|
+
functionality: "JSON Schema conversion exceeding resource limits",
|
|
352
|
+
message: "Google schema conversion exceeded its node, size, or depth limit."
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function consumeSchemaBudget(value, budget, depth = 0) {
|
|
357
|
+
if (value === void 0) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
budget.nodes--;
|
|
361
|
+
budget.size -= typeof value === "string" ? value.length * 6 + 2 : 32;
|
|
362
|
+
checkSchemaBudget(budget, depth);
|
|
363
|
+
if (Array.isArray(value)) {
|
|
364
|
+
for (const item of value) {
|
|
365
|
+
consumeSchemaBudget(item, budget, depth + 1);
|
|
366
|
+
}
|
|
367
|
+
} else if (value !== null && typeof value === "object") {
|
|
368
|
+
for (const key in value) {
|
|
369
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
370
|
+
consumeSchemaBudget(key, budget, depth + 1);
|
|
371
|
+
consumeSchemaBudget(
|
|
372
|
+
value[key],
|
|
373
|
+
budget,
|
|
374
|
+
depth + 1
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
318
380
|
function addEnumToSchema({
|
|
319
381
|
values,
|
|
320
382
|
type,
|
|
@@ -1241,6 +1303,9 @@ function prepareTools({
|
|
|
1241
1303
|
modelId,
|
|
1242
1304
|
isVertexProvider = false
|
|
1243
1305
|
}) {
|
|
1306
|
+
if ((toolChoice == null ? void 0 : toolChoice.type) === "none") {
|
|
1307
|
+
tools = tools == null ? void 0 : tools.filter((tool) => tool.type === "function");
|
|
1308
|
+
}
|
|
1244
1309
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1245
1310
|
const toolWarnings = [];
|
|
1246
1311
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
@@ -1519,6 +1584,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1519
1584
|
const rawPath = jsonPath.replace(/^\$\./, "");
|
|
1520
1585
|
if (!rawPath || rawPath === "$") continue;
|
|
1521
1586
|
const segments = parsePath(rawPath);
|
|
1587
|
+
if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
|
|
1522
1588
|
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1523
1589
|
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1524
1590
|
if (isStringContinuation) {
|
|
@@ -1739,6 +1805,17 @@ function getNestedValue(obj, segments) {
|
|
|
1739
1805
|
}
|
|
1740
1806
|
return current;
|
|
1741
1807
|
}
|
|
1808
|
+
function hasContiguousIndexes(obj, segments) {
|
|
1809
|
+
let current = obj;
|
|
1810
|
+
for (const pathSegment of segments) {
|
|
1811
|
+
if (typeof pathSegment === "number") {
|
|
1812
|
+
const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
|
|
1813
|
+
if (length !== void 0 && pathSegment > length) return false;
|
|
1814
|
+
}
|
|
1815
|
+
current = current != null && typeof current === "object" && hasOwnProperty(current, pathSegment) ? current[pathSegment] : void 0;
|
|
1816
|
+
}
|
|
1817
|
+
return true;
|
|
1818
|
+
}
|
|
1742
1819
|
function setNestedValue(obj, segments, value) {
|
|
1743
1820
|
let current = obj;
|
|
1744
1821
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
@@ -4715,6 +4792,8 @@ var import_v413 = require("zod/v4");
|
|
|
4715
4792
|
var googleInteractionsLanguageModelOptions = (0, import_provider_utils15.lazySchema)(
|
|
4716
4793
|
() => (0, import_provider_utils15.zodSchema)(
|
|
4717
4794
|
import_v413.z.object({
|
|
4795
|
+
/** User-defined request metadata, including `safety_identifier`. */
|
|
4796
|
+
labels: import_v413.z.record(import_v413.z.string(), import_v413.z.string()).nullish(),
|
|
4718
4797
|
previousInteractionId: import_v413.z.string().nullish(),
|
|
4719
4798
|
store: import_v413.z.boolean().nullish(),
|
|
4720
4799
|
agent: import_v413.z.string().nullish(),
|
|
@@ -5665,7 +5744,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5665
5744
|
};
|
|
5666
5745
|
}
|
|
5667
5746
|
async getArgs(options) {
|
|
5668
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
5747
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
|
|
5669
5748
|
const warnings = [];
|
|
5670
5749
|
const opts = await (0, import_provider_utils19.parseProviderOptions)({
|
|
5671
5750
|
provider: "google",
|
|
@@ -5900,24 +5979,25 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5900
5979
|
const args = pruneUndefined({
|
|
5901
5980
|
...isAgent ? { agent: this.agent } : { model: this.modelId },
|
|
5902
5981
|
input,
|
|
5982
|
+
labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
|
|
5903
5983
|
system_instruction: systemInstruction,
|
|
5904
5984
|
tools: toolsForBody,
|
|
5905
5985
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
5906
5986
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
5907
|
-
previous_interaction_id: (
|
|
5908
|
-
service_tier: (
|
|
5909
|
-
store: (
|
|
5987
|
+
previous_interaction_id: (_C = opts == null ? void 0 : opts.previousInteractionId) != null ? _C : void 0,
|
|
5988
|
+
service_tier: (_D = opts == null ? void 0 : opts.serviceTier) != null ? _D : void 0,
|
|
5989
|
+
store: (_E = opts == null ? void 0 : opts.store) != null ? _E : void 0,
|
|
5910
5990
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
5911
5991
|
agent_config: agentConfig,
|
|
5912
5992
|
environment,
|
|
5913
|
-
background: (
|
|
5993
|
+
background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
|
|
5914
5994
|
});
|
|
5915
5995
|
return {
|
|
5916
5996
|
args,
|
|
5917
5997
|
warnings,
|
|
5918
5998
|
isAgent,
|
|
5919
5999
|
isBackground: (opts == null ? void 0 : opts.background) === true,
|
|
5920
|
-
pollingTimeoutMs: (
|
|
6000
|
+
pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
|
|
5921
6001
|
};
|
|
5922
6002
|
}
|
|
5923
6003
|
async doGenerate(options) {
|