@ai-sdk/google 3.0.142 → 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 +10 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +85 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +84 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +84 -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/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,
|
|
@@ -1522,6 +1584,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1522
1584
|
const rawPath = jsonPath.replace(/^\$\./, "");
|
|
1523
1585
|
if (!rawPath || rawPath === "$") continue;
|
|
1524
1586
|
const segments = parsePath(rawPath);
|
|
1587
|
+
if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
|
|
1525
1588
|
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1526
1589
|
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1527
1590
|
if (isStringContinuation) {
|
|
@@ -1742,6 +1805,17 @@ function getNestedValue(obj, segments) {
|
|
|
1742
1805
|
}
|
|
1743
1806
|
return current;
|
|
1744
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
|
+
}
|
|
1745
1819
|
function setNestedValue(obj, segments, value) {
|
|
1746
1820
|
let current = obj;
|
|
1747
1821
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
@@ -4718,6 +4792,8 @@ var import_v413 = require("zod/v4");
|
|
|
4718
4792
|
var googleInteractionsLanguageModelOptions = (0, import_provider_utils15.lazySchema)(
|
|
4719
4793
|
() => (0, import_provider_utils15.zodSchema)(
|
|
4720
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(),
|
|
4721
4797
|
previousInteractionId: import_v413.z.string().nullish(),
|
|
4722
4798
|
store: import_v413.z.boolean().nullish(),
|
|
4723
4799
|
agent: import_v413.z.string().nullish(),
|
|
@@ -5668,7 +5744,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5668
5744
|
};
|
|
5669
5745
|
}
|
|
5670
5746
|
async getArgs(options) {
|
|
5671
|
-
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;
|
|
5672
5748
|
const warnings = [];
|
|
5673
5749
|
const opts = await (0, import_provider_utils19.parseProviderOptions)({
|
|
5674
5750
|
provider: "google",
|
|
@@ -5903,24 +5979,25 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5903
5979
|
const args = pruneUndefined({
|
|
5904
5980
|
...isAgent ? { agent: this.agent } : { model: this.modelId },
|
|
5905
5981
|
input,
|
|
5982
|
+
labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
|
|
5906
5983
|
system_instruction: systemInstruction,
|
|
5907
5984
|
tools: toolsForBody,
|
|
5908
5985
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
5909
5986
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
5910
|
-
previous_interaction_id: (
|
|
5911
|
-
service_tier: (
|
|
5912
|
-
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,
|
|
5913
5990
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
5914
5991
|
agent_config: agentConfig,
|
|
5915
5992
|
environment,
|
|
5916
|
-
background: (
|
|
5993
|
+
background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
|
|
5917
5994
|
});
|
|
5918
5995
|
return {
|
|
5919
5996
|
args,
|
|
5920
5997
|
warnings,
|
|
5921
5998
|
isAgent,
|
|
5922
5999
|
isBackground: (opts == null ? void 0 : opts.background) === true,
|
|
5923
|
-
pollingTimeoutMs: (
|
|
6000
|
+
pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
|
|
5924
6001
|
};
|
|
5925
6002
|
}
|
|
5926
6003
|
async doGenerate(options) {
|