@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.143
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 93f4a18: Bound Google JSON Schema conversion work, output size, and depth to prevent excessive resource use when inlining repeated local references. Input inspection and conversion each have a separate budget of 10,000 visited JSON values and a conservative 1,000,000-character serialized-size allowance, with a depth limit of 100. Schemas exceeding these limits now fail with a controlled error, including large schemas that were previously accepted. String-size accounting reserves six characters per UTF-16 code unit for JSON escaping.
|
|
8
|
+
- 2a57dab: Pass `providerOptions.google.labels` through to Google and Vertex AI Interactions requests, including streaming, so callers can attach request metadata such as `safety_identifier`.
|
|
9
|
+
- f3c2cb3: skip streamed tool-call array indexes that leave a gap so a small response can't build a huge sparse array
|
|
10
|
+
- Updated dependencies [f0dee4b]
|
|
11
|
+
- @ai-sdk/provider-utils@4.0.65
|
|
12
|
+
|
|
3
13
|
## 3.0.142
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -350,6 +350,7 @@ type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'ge
|
|
|
350
350
|
* All fields are `.nullish()` per the existing google provider convention.
|
|
351
351
|
*/
|
|
352
352
|
declare const googleInteractionsLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
353
|
+
labels?: Record<string, string> | null | undefined;
|
|
353
354
|
previousInteractionId?: string | null | undefined;
|
|
354
355
|
store?: boolean | null | undefined;
|
|
355
356
|
agent?: string | null | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -350,6 +350,7 @@ type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'ge
|
|
|
350
350
|
* All fields are `.nullish()` per the existing google provider convention.
|
|
351
351
|
*/
|
|
352
352
|
declare const googleInteractionsLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
353
|
+
labels?: Record<string, string> | null | undefined;
|
|
353
354
|
previousInteractionId?: string | null | undefined;
|
|
354
355
|
store?: boolean | null | undefined;
|
|
355
356
|
agent?: string | null | undefined;
|
package/dist/index.js
CHANGED
|
@@ -278,7 +278,7 @@ var googleInteractionsTranscriptionResponseSchema = (0, import_provider_utils3.l
|
|
|
278
278
|
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
279
279
|
|
|
280
280
|
// src/version.ts
|
|
281
|
-
var VERSION = true ? "3.0.
|
|
281
|
+
var VERSION = true ? "3.0.143" : "0.0.0-test";
|
|
282
282
|
|
|
283
283
|
// src/google-generative-ai-embedding-model.ts
|
|
284
284
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -649,25 +649,54 @@ function addTokenDetails(a, b) {
|
|
|
649
649
|
|
|
650
650
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
651
651
|
var import_provider3 = require("@ai-sdk/provider");
|
|
652
|
+
var maxSchemaDepth = 100;
|
|
653
|
+
var maxSchemaNodes = 1e4;
|
|
654
|
+
var maxSchemaSize = 1e6;
|
|
652
655
|
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
653
656
|
function isRecursiveJSONSchemaReferenceError(error) {
|
|
654
657
|
return import_provider3.UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
655
658
|
}
|
|
656
659
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
660
|
+
consumeSchemaBudget(jsonSchema, {
|
|
661
|
+
nodes: maxSchemaNodes,
|
|
662
|
+
size: maxSchemaSize
|
|
663
|
+
});
|
|
657
664
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
658
665
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
659
666
|
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
660
667
|
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
661
|
-
resolvingReferences: /* @__PURE__ */ new Set()
|
|
668
|
+
resolvingReferences: /* @__PURE__ */ new Set(),
|
|
669
|
+
budget: { nodes: maxSchemaNodes, size: maxSchemaSize },
|
|
670
|
+
depth: 0
|
|
662
671
|
});
|
|
663
672
|
}
|
|
664
673
|
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
665
674
|
if (jsonSchema == null) {
|
|
666
675
|
return void 0;
|
|
667
676
|
}
|
|
677
|
+
referenceContext.budget.nodes--;
|
|
678
|
+
referenceContext.budget.size -= 128;
|
|
679
|
+
checkSchemaBudget(referenceContext.budget, referenceContext.depth);
|
|
680
|
+
referenceContext = {
|
|
681
|
+
...referenceContext,
|
|
682
|
+
depth: referenceContext.depth + 1
|
|
683
|
+
};
|
|
668
684
|
if (typeof jsonSchema === "boolean") {
|
|
669
685
|
return { type: "boolean", properties: {} };
|
|
670
686
|
}
|
|
687
|
+
consumeSchemaBudget(
|
|
688
|
+
[
|
|
689
|
+
jsonSchema.$ref,
|
|
690
|
+
jsonSchema.type,
|
|
691
|
+
jsonSchema.description,
|
|
692
|
+
jsonSchema.required,
|
|
693
|
+
jsonSchema.format,
|
|
694
|
+
jsonSchema.const,
|
|
695
|
+
jsonSchema.enum,
|
|
696
|
+
jsonSchema.minLength
|
|
697
|
+
],
|
|
698
|
+
referenceContext.budget
|
|
699
|
+
);
|
|
671
700
|
if (jsonSchema.$ref != null) {
|
|
672
701
|
return convertJSONSchemaReference({
|
|
673
702
|
jsonSchema,
|
|
@@ -731,6 +760,7 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
731
760
|
if (properties != null) {
|
|
732
761
|
result.properties = Object.entries(properties).reduce(
|
|
733
762
|
(acc, [key, value]) => {
|
|
763
|
+
consumeSchemaBudget(key, referenceContext.budget);
|
|
734
764
|
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
735
765
|
return acc;
|
|
736
766
|
},
|
|
@@ -786,6 +816,38 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
786
816
|
}
|
|
787
817
|
return result;
|
|
788
818
|
}
|
|
819
|
+
function checkSchemaBudget(budget, depth) {
|
|
820
|
+
if (budget.nodes < 0 || budget.size < 0 || depth > maxSchemaDepth) {
|
|
821
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
822
|
+
functionality: "JSON Schema conversion exceeding resource limits",
|
|
823
|
+
message: "Google schema conversion exceeded its node, size, or depth limit."
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function consumeSchemaBudget(value, budget, depth = 0) {
|
|
828
|
+
if (value === void 0) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
budget.nodes--;
|
|
832
|
+
budget.size -= typeof value === "string" ? value.length * 6 + 2 : 32;
|
|
833
|
+
checkSchemaBudget(budget, depth);
|
|
834
|
+
if (Array.isArray(value)) {
|
|
835
|
+
for (const item of value) {
|
|
836
|
+
consumeSchemaBudget(item, budget, depth + 1);
|
|
837
|
+
}
|
|
838
|
+
} else if (value !== null && typeof value === "object") {
|
|
839
|
+
for (const key in value) {
|
|
840
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
841
|
+
consumeSchemaBudget(key, budget, depth + 1);
|
|
842
|
+
consumeSchemaBudget(
|
|
843
|
+
value[key],
|
|
844
|
+
budget,
|
|
845
|
+
depth + 1
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
789
851
|
function addEnumToSchema({
|
|
790
852
|
values,
|
|
791
853
|
type,
|
|
@@ -1939,6 +2001,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1939
2001
|
const rawPath = jsonPath.replace(/^\$\./, "");
|
|
1940
2002
|
if (!rawPath || rawPath === "$") continue;
|
|
1941
2003
|
const segments = parsePath(rawPath);
|
|
2004
|
+
if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
|
|
1942
2005
|
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1943
2006
|
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1944
2007
|
if (isStringContinuation) {
|
|
@@ -2159,6 +2222,17 @@ function getNestedValue(obj, segments) {
|
|
|
2159
2222
|
}
|
|
2160
2223
|
return current;
|
|
2161
2224
|
}
|
|
2225
|
+
function hasContiguousIndexes(obj, segments) {
|
|
2226
|
+
let current = obj;
|
|
2227
|
+
for (const pathSegment of segments) {
|
|
2228
|
+
if (typeof pathSegment === "number") {
|
|
2229
|
+
const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
|
|
2230
|
+
if (length !== void 0 && pathSegment > length) return false;
|
|
2231
|
+
}
|
|
2232
|
+
current = current != null && typeof current === "object" && hasOwnProperty(current, pathSegment) ? current[pathSegment] : void 0;
|
|
2233
|
+
}
|
|
2234
|
+
return true;
|
|
2235
|
+
}
|
|
2162
2236
|
function setNestedValue(obj, segments, value) {
|
|
2163
2237
|
let current = obj;
|
|
2164
2238
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
@@ -5731,6 +5805,8 @@ var import_v419 = require("zod/v4");
|
|
|
5731
5805
|
var googleInteractionsLanguageModelOptions = (0, import_provider_utils21.lazySchema)(
|
|
5732
5806
|
() => (0, import_provider_utils21.zodSchema)(
|
|
5733
5807
|
import_v419.z.object({
|
|
5808
|
+
/** User-defined request metadata, including `safety_identifier`. */
|
|
5809
|
+
labels: import_v419.z.record(import_v419.z.string(), import_v419.z.string()).nullish(),
|
|
5734
5810
|
previousInteractionId: import_v419.z.string().nullish(),
|
|
5735
5811
|
store: import_v419.z.boolean().nullish(),
|
|
5736
5812
|
agent: import_v419.z.string().nullish(),
|
|
@@ -6681,7 +6757,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6681
6757
|
};
|
|
6682
6758
|
}
|
|
6683
6759
|
async getArgs(options) {
|
|
6684
|
-
var _a2, _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;
|
|
6760
|
+
var _a2, _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;
|
|
6685
6761
|
const warnings = [];
|
|
6686
6762
|
const opts = await (0, import_provider_utils25.parseProviderOptions)({
|
|
6687
6763
|
provider: "google",
|
|
@@ -6916,24 +6992,25 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6916
6992
|
const args = pruneUndefined({
|
|
6917
6993
|
...isAgent ? { agent: this.agent } : { model: this.modelId },
|
|
6918
6994
|
input,
|
|
6995
|
+
labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
|
|
6919
6996
|
system_instruction: systemInstruction,
|
|
6920
6997
|
tools: toolsForBody,
|
|
6921
6998
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
6922
6999
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
6923
|
-
previous_interaction_id: (
|
|
6924
|
-
service_tier: (
|
|
6925
|
-
store: (
|
|
7000
|
+
previous_interaction_id: (_C = opts == null ? void 0 : opts.previousInteractionId) != null ? _C : void 0,
|
|
7001
|
+
service_tier: (_D = opts == null ? void 0 : opts.serviceTier) != null ? _D : void 0,
|
|
7002
|
+
store: (_E = opts == null ? void 0 : opts.store) != null ? _E : void 0,
|
|
6926
7003
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
6927
7004
|
agent_config: agentConfig,
|
|
6928
7005
|
environment,
|
|
6929
|
-
background: (
|
|
7006
|
+
background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
|
|
6930
7007
|
});
|
|
6931
7008
|
return {
|
|
6932
7009
|
args,
|
|
6933
7010
|
warnings,
|
|
6934
7011
|
isAgent,
|
|
6935
7012
|
isBackground: (opts == null ? void 0 : opts.background) === true,
|
|
6936
|
-
pollingTimeoutMs: (
|
|
7013
|
+
pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
|
|
6937
7014
|
};
|
|
6938
7015
|
}
|
|
6939
7016
|
async doGenerate(options) {
|