@ai-sdk/google 3.0.142 → 3.0.144
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 +19 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +98 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -13
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +97 -12
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +97 -12
- 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-generative-ai-language-model.ts +8 -2
- package/src/google-json-accumulator.ts +49 -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/index.mjs
CHANGED
|
@@ -272,7 +272,7 @@ import {
|
|
|
272
272
|
} from "@ai-sdk/provider-utils";
|
|
273
273
|
|
|
274
274
|
// src/version.ts
|
|
275
|
-
var VERSION = true ? "3.0.
|
|
275
|
+
var VERSION = true ? "3.0.144" : "0.0.0-test";
|
|
276
276
|
|
|
277
277
|
// src/google-generative-ai-embedding-model.ts
|
|
278
278
|
import {
|
|
@@ -671,25 +671,54 @@ function addTokenDetails(a, b) {
|
|
|
671
671
|
import {
|
|
672
672
|
UnsupportedFunctionalityError
|
|
673
673
|
} from "@ai-sdk/provider";
|
|
674
|
+
var maxSchemaDepth = 100;
|
|
675
|
+
var maxSchemaNodes = 1e4;
|
|
676
|
+
var maxSchemaSize = 1e6;
|
|
674
677
|
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
675
678
|
function isRecursiveJSONSchemaReferenceError(error) {
|
|
676
679
|
return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
677
680
|
}
|
|
678
681
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
682
|
+
consumeSchemaBudget(jsonSchema, {
|
|
683
|
+
nodes: maxSchemaNodes,
|
|
684
|
+
size: maxSchemaSize
|
|
685
|
+
});
|
|
679
686
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
680
687
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
681
688
|
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
682
689
|
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
683
|
-
resolvingReferences: /* @__PURE__ */ new Set()
|
|
690
|
+
resolvingReferences: /* @__PURE__ */ new Set(),
|
|
691
|
+
budget: { nodes: maxSchemaNodes, size: maxSchemaSize },
|
|
692
|
+
depth: 0
|
|
684
693
|
});
|
|
685
694
|
}
|
|
686
695
|
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
687
696
|
if (jsonSchema == null) {
|
|
688
697
|
return void 0;
|
|
689
698
|
}
|
|
699
|
+
referenceContext.budget.nodes--;
|
|
700
|
+
referenceContext.budget.size -= 128;
|
|
701
|
+
checkSchemaBudget(referenceContext.budget, referenceContext.depth);
|
|
702
|
+
referenceContext = {
|
|
703
|
+
...referenceContext,
|
|
704
|
+
depth: referenceContext.depth + 1
|
|
705
|
+
};
|
|
690
706
|
if (typeof jsonSchema === "boolean") {
|
|
691
707
|
return { type: "boolean", properties: {} };
|
|
692
708
|
}
|
|
709
|
+
consumeSchemaBudget(
|
|
710
|
+
[
|
|
711
|
+
jsonSchema.$ref,
|
|
712
|
+
jsonSchema.type,
|
|
713
|
+
jsonSchema.description,
|
|
714
|
+
jsonSchema.required,
|
|
715
|
+
jsonSchema.format,
|
|
716
|
+
jsonSchema.const,
|
|
717
|
+
jsonSchema.enum,
|
|
718
|
+
jsonSchema.minLength
|
|
719
|
+
],
|
|
720
|
+
referenceContext.budget
|
|
721
|
+
);
|
|
693
722
|
if (jsonSchema.$ref != null) {
|
|
694
723
|
return convertJSONSchemaReference({
|
|
695
724
|
jsonSchema,
|
|
@@ -753,6 +782,7 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
753
782
|
if (properties != null) {
|
|
754
783
|
result.properties = Object.entries(properties).reduce(
|
|
755
784
|
(acc, [key, value]) => {
|
|
785
|
+
consumeSchemaBudget(key, referenceContext.budget);
|
|
756
786
|
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
757
787
|
return acc;
|
|
758
788
|
},
|
|
@@ -808,6 +838,38 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
808
838
|
}
|
|
809
839
|
return result;
|
|
810
840
|
}
|
|
841
|
+
function checkSchemaBudget(budget, depth) {
|
|
842
|
+
if (budget.nodes < 0 || budget.size < 0 || depth > maxSchemaDepth) {
|
|
843
|
+
throw new UnsupportedFunctionalityError({
|
|
844
|
+
functionality: "JSON Schema conversion exceeding resource limits",
|
|
845
|
+
message: "Google schema conversion exceeded its node, size, or depth limit."
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function consumeSchemaBudget(value, budget, depth = 0) {
|
|
850
|
+
if (value === void 0) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
budget.nodes--;
|
|
854
|
+
budget.size -= typeof value === "string" ? value.length * 6 + 2 : 32;
|
|
855
|
+
checkSchemaBudget(budget, depth);
|
|
856
|
+
if (Array.isArray(value)) {
|
|
857
|
+
for (const item of value) {
|
|
858
|
+
consumeSchemaBudget(item, budget, depth + 1);
|
|
859
|
+
}
|
|
860
|
+
} else if (value !== null && typeof value === "object") {
|
|
861
|
+
for (const key in value) {
|
|
862
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
863
|
+
consumeSchemaBudget(key, budget, depth + 1);
|
|
864
|
+
consumeSchemaBudget(
|
|
865
|
+
value[key],
|
|
866
|
+
budget,
|
|
867
|
+
depth + 1
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
811
873
|
function addEnumToSchema({
|
|
812
874
|
values,
|
|
813
875
|
type,
|
|
@@ -1977,6 +2039,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1977
2039
|
const rawPath = jsonPath.replace(/^\$\./, "");
|
|
1978
2040
|
if (!rawPath || rawPath === "$") continue;
|
|
1979
2041
|
const segments = parsePath(rawPath);
|
|
2042
|
+
if (!normalizeAndCheckIndexes(this.accumulatedArgs, segments)) continue;
|
|
1980
2043
|
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1981
2044
|
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1982
2045
|
if (isStringContinuation) {
|
|
@@ -2197,6 +2260,25 @@ function getNestedValue(obj, segments) {
|
|
|
2197
2260
|
}
|
|
2198
2261
|
return current;
|
|
2199
2262
|
}
|
|
2263
|
+
function normalizeAndCheckIndexes(obj, segments) {
|
|
2264
|
+
let current = obj;
|
|
2265
|
+
for (let i = 0; i < segments.length; i++) {
|
|
2266
|
+
let pathSegment = segments[i];
|
|
2267
|
+
if (Array.isArray(current) && typeof pathSegment === "string") {
|
|
2268
|
+
const index = Number(pathSegment);
|
|
2269
|
+
if (Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === pathSegment) {
|
|
2270
|
+
pathSegment = index;
|
|
2271
|
+
segments[i] = index;
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
if (typeof pathSegment === "number") {
|
|
2275
|
+
const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
|
|
2276
|
+
if (length !== void 0 && pathSegment > length) return false;
|
|
2277
|
+
}
|
|
2278
|
+
current = current != null && typeof current === "object" && hasOwnProperty(current, pathSegment) ? current[pathSegment] : void 0;
|
|
2279
|
+
}
|
|
2280
|
+
return true;
|
|
2281
|
+
}
|
|
2200
2282
|
function setNestedValue(obj, segments, value) {
|
|
2201
2283
|
let current = obj;
|
|
2202
2284
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
@@ -2471,7 +2553,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2471
2553
|
};
|
|
2472
2554
|
}
|
|
2473
2555
|
async doGenerate(options) {
|
|
2474
|
-
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;
|
|
2556
|
+
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;
|
|
2475
2557
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2476
2558
|
const mergedHeaders = combineHeaders3(
|
|
2477
2559
|
await resolve3(this.config.headers),
|
|
@@ -2673,7 +2755,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2673
2755
|
safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
|
|
2674
2756
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2675
2757
|
finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
|
|
2676
|
-
serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
|
|
2758
|
+
serviceTier: (_B = (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _B : null,
|
|
2677
2759
|
...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
|
|
2678
2760
|
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
|
|
2679
2761
|
}
|
|
@@ -2681,7 +2763,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2681
2763
|
request: { body: args },
|
|
2682
2764
|
response: {
|
|
2683
2765
|
// TODO timestamp, model id
|
|
2684
|
-
id: (
|
|
2766
|
+
id: (_C = response.responseId) != null ? _C : void 0,
|
|
2685
2767
|
headers: responseHeaders,
|
|
2686
2768
|
body: rawResponse
|
|
2687
2769
|
}
|
|
@@ -3157,7 +3239,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
3157
3239
|
}
|
|
3158
3240
|
},
|
|
3159
3241
|
flush(controller) {
|
|
3160
|
-
var _a2;
|
|
3242
|
+
var _a2, _b;
|
|
3161
3243
|
usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
|
|
3162
3244
|
if (currentTextBlockId !== null) {
|
|
3163
3245
|
controller.enqueue({
|
|
@@ -3189,7 +3271,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
3189
3271
|
safetyRatings: lastSafetyRatings,
|
|
3190
3272
|
usageMetadata: usage != null ? usage : null,
|
|
3191
3273
|
finishMessage: lastFinishMessage,
|
|
3192
|
-
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null,
|
|
3274
|
+
serviceTier: (_b = (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _b : null,
|
|
3193
3275
|
// Only surface the token when the response stopped early
|
|
3194
3276
|
// (budget used up, or continuing failed), not for the
|
|
3195
3277
|
// checkpoint tokens of a stream that finished normally.
|
|
@@ -5827,6 +5909,8 @@ import { z as z19 } from "zod/v4";
|
|
|
5827
5909
|
var googleInteractionsLanguageModelOptions = lazySchema16(
|
|
5828
5910
|
() => zodSchema16(
|
|
5829
5911
|
z19.object({
|
|
5912
|
+
/** User-defined request metadata, including `safety_identifier`. */
|
|
5913
|
+
labels: z19.record(z19.string(), z19.string()).nullish(),
|
|
5830
5914
|
previousInteractionId: z19.string().nullish(),
|
|
5831
5915
|
store: z19.boolean().nullish(),
|
|
5832
5916
|
agent: z19.string().nullish(),
|
|
@@ -6791,7 +6875,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6791
6875
|
};
|
|
6792
6876
|
}
|
|
6793
6877
|
async getArgs(options) {
|
|
6794
|
-
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;
|
|
6878
|
+
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;
|
|
6795
6879
|
const warnings = [];
|
|
6796
6880
|
const opts = await parseProviderOptions6({
|
|
6797
6881
|
provider: "google",
|
|
@@ -7026,24 +7110,25 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
7026
7110
|
const args = pruneUndefined({
|
|
7027
7111
|
...isAgent ? { agent: this.agent } : { model: this.modelId },
|
|
7028
7112
|
input,
|
|
7113
|
+
labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
|
|
7029
7114
|
system_instruction: systemInstruction,
|
|
7030
7115
|
tools: toolsForBody,
|
|
7031
7116
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
7032
7117
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
7033
|
-
previous_interaction_id: (
|
|
7034
|
-
service_tier: (
|
|
7035
|
-
store: (
|
|
7118
|
+
previous_interaction_id: (_C = opts == null ? void 0 : opts.previousInteractionId) != null ? _C : void 0,
|
|
7119
|
+
service_tier: (_D = opts == null ? void 0 : opts.serviceTier) != null ? _D : void 0,
|
|
7120
|
+
store: (_E = opts == null ? void 0 : opts.store) != null ? _E : void 0,
|
|
7036
7121
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
7037
7122
|
agent_config: agentConfig,
|
|
7038
7123
|
environment,
|
|
7039
|
-
background: (
|
|
7124
|
+
background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
|
|
7040
7125
|
});
|
|
7041
7126
|
return {
|
|
7042
7127
|
args,
|
|
7043
7128
|
warnings,
|
|
7044
7129
|
isAgent,
|
|
7045
7130
|
isBackground: (opts == null ? void 0 : opts.background) === true,
|
|
7046
|
-
pollingTimeoutMs: (
|
|
7131
|
+
pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
|
|
7047
7132
|
};
|
|
7048
7133
|
}
|
|
7049
7134
|
async doGenerate(options) {
|