@ai-sdk/google 3.0.143 → 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 +9 -0
- package/dist/index.js +17 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +16 -8
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +16 -8
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/google-generative-ai-language-model.ts +8 -2
- package/src/google-json-accumulator.ts +21 -6
package/dist/internal/index.mjs
CHANGED
|
@@ -1588,7 +1588,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1588
1588
|
const rawPath = jsonPath.replace(/^\$\./, "");
|
|
1589
1589
|
if (!rawPath || rawPath === "$") continue;
|
|
1590
1590
|
const segments = parsePath(rawPath);
|
|
1591
|
-
if (!
|
|
1591
|
+
if (!normalizeAndCheckIndexes(this.accumulatedArgs, segments)) continue;
|
|
1592
1592
|
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1593
1593
|
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1594
1594
|
if (isStringContinuation) {
|
|
@@ -1809,9 +1809,17 @@ function getNestedValue(obj, segments) {
|
|
|
1809
1809
|
}
|
|
1810
1810
|
return current;
|
|
1811
1811
|
}
|
|
1812
|
-
function
|
|
1812
|
+
function normalizeAndCheckIndexes(obj, segments) {
|
|
1813
1813
|
let current = obj;
|
|
1814
|
-
for (
|
|
1814
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1815
|
+
let pathSegment = segments[i];
|
|
1816
|
+
if (Array.isArray(current) && typeof pathSegment === "string") {
|
|
1817
|
+
const index = Number(pathSegment);
|
|
1818
|
+
if (Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === pathSegment) {
|
|
1819
|
+
pathSegment = index;
|
|
1820
|
+
segments[i] = index;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1815
1823
|
if (typeof pathSegment === "number") {
|
|
1816
1824
|
const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
|
|
1817
1825
|
if (length !== void 0 && pathSegment > length) return false;
|
|
@@ -2094,7 +2102,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2094
2102
|
};
|
|
2095
2103
|
}
|
|
2096
2104
|
async doGenerate(options) {
|
|
2097
|
-
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;
|
|
2105
|
+
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;
|
|
2098
2106
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2099
2107
|
const mergedHeaders = combineHeaders(
|
|
2100
2108
|
await resolve(this.config.headers),
|
|
@@ -2296,7 +2304,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2296
2304
|
safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
|
|
2297
2305
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2298
2306
|
finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
|
|
2299
|
-
serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
|
|
2307
|
+
serviceTier: (_B = (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _B : null,
|
|
2300
2308
|
...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
|
|
2301
2309
|
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
|
|
2302
2310
|
}
|
|
@@ -2304,7 +2312,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2304
2312
|
request: { body: args },
|
|
2305
2313
|
response: {
|
|
2306
2314
|
// TODO timestamp, model id
|
|
2307
|
-
id: (
|
|
2315
|
+
id: (_C = response.responseId) != null ? _C : void 0,
|
|
2308
2316
|
headers: responseHeaders,
|
|
2309
2317
|
body: rawResponse
|
|
2310
2318
|
}
|
|
@@ -2780,7 +2788,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2780
2788
|
}
|
|
2781
2789
|
},
|
|
2782
2790
|
flush(controller) {
|
|
2783
|
-
var _a;
|
|
2791
|
+
var _a, _b;
|
|
2784
2792
|
usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
|
|
2785
2793
|
if (currentTextBlockId !== null) {
|
|
2786
2794
|
controller.enqueue({
|
|
@@ -2812,7 +2820,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2812
2820
|
safetyRatings: lastSafetyRatings,
|
|
2813
2821
|
usageMetadata: usage != null ? usage : null,
|
|
2814
2822
|
finishMessage: lastFinishMessage,
|
|
2815
|
-
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null,
|
|
2823
|
+
serviceTier: (_b = (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _b : null,
|
|
2816
2824
|
// Only surface the token when the response stopped early
|
|
2817
2825
|
// (budget used up, or continuing failed), not for the
|
|
2818
2826
|
// checkpoint tokens of a stream that finished normally.
|