@ai-sdk/google 4.0.0-canary.69 → 4.0.0-canary.71
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 +18 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +57 -30
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +56 -29
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +12 -5
- package/package.json +1 -1
- package/src/convert-google-usage.ts +1 -0
- package/src/google-language-model-options.ts +23 -8
- package/src/google-language-model.ts +45 -19
package/dist/internal/index.d.ts
CHANGED
|
@@ -214,6 +214,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
214
214
|
candidatesTokenCount?: number | null | undefined;
|
|
215
215
|
totalTokenCount?: number | null | undefined;
|
|
216
216
|
trafficType?: string | null | undefined;
|
|
217
|
+
serviceTier?: string | null | undefined;
|
|
217
218
|
promptTokensDetails?: {
|
|
218
219
|
modality: string;
|
|
219
220
|
tokenCount: number;
|
|
@@ -234,7 +235,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
234
235
|
blocked?: boolean | null | undefined;
|
|
235
236
|
}[] | null | undefined;
|
|
236
237
|
} | null | undefined;
|
|
237
|
-
serviceTier?: string | null | undefined;
|
|
238
238
|
}>;
|
|
239
239
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
240
240
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
package/dist/internal/index.js
CHANGED
|
@@ -760,17 +760,32 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
760
760
|
*/
|
|
761
761
|
streamFunctionCallArguments: z2.boolean().optional(),
|
|
762
762
|
/**
|
|
763
|
-
* Optional. The service tier to use for the request.
|
|
763
|
+
* Optional. The service tier to use for the request. Sent as the
|
|
764
|
+
* `serviceTier` body field. Gemini API only.
|
|
764
765
|
*/
|
|
765
|
-
serviceTier: z2.enum(["standard", "flex", "priority"]).optional()
|
|
766
|
+
serviceTier: z2.enum(["standard", "flex", "priority"]).optional(),
|
|
767
|
+
/**
|
|
768
|
+
* Optional. Vertex AI only. Sent as the
|
|
769
|
+
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
770
|
+
* shared (PayGo) tier. With Provisioned Throughput allocated and
|
|
771
|
+
* `requestType` unset, the request falls back to this tier only if
|
|
772
|
+
* PT capacity is exhausted.
|
|
773
|
+
*
|
|
774
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
775
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
|
|
776
|
+
*/
|
|
777
|
+
sharedRequestType: z2.enum(["priority", "flex", "standard"]).optional(),
|
|
778
|
+
/**
|
|
779
|
+
* Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
|
|
780
|
+
* request header. Set to `'shared'` together with `sharedRequestType`
|
|
781
|
+
* to bypass Provisioned Throughput entirely.
|
|
782
|
+
*
|
|
783
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
784
|
+
*/
|
|
785
|
+
requestType: z2.enum(["shared"]).optional()
|
|
766
786
|
})
|
|
767
787
|
)
|
|
768
788
|
);
|
|
769
|
-
var VertexServiceTierMap = {
|
|
770
|
-
standard: "SERVICE_TIER_STANDARD",
|
|
771
|
-
flex: "SERVICE_TIER_FLEX",
|
|
772
|
-
priority: "SERVICE_TIER_PRIORITY"
|
|
773
|
-
};
|
|
774
789
|
|
|
775
790
|
// src/google-prepare-tools.ts
|
|
776
791
|
import {
|
|
@@ -1351,10 +1366,27 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1351
1366
|
message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
|
|
1352
1367
|
});
|
|
1353
1368
|
}
|
|
1354
|
-
let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1355
1369
|
if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
|
|
1356
|
-
|
|
1370
|
+
warnings.push({
|
|
1371
|
+
type: "other",
|
|
1372
|
+
message: "'serviceTier' is a Gemini API option and is not supported on Vertex AI. Use 'sharedRequestType' (and optionally 'requestType') instead. See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo"
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
|
|
1376
|
+
warnings.push({
|
|
1377
|
+
type: "other",
|
|
1378
|
+
message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
|
|
1379
|
+
});
|
|
1357
1380
|
}
|
|
1381
|
+
const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
|
|
1382
|
+
...googleOptions.sharedRequestType && {
|
|
1383
|
+
"X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
|
|
1384
|
+
},
|
|
1385
|
+
...googleOptions.requestType && {
|
|
1386
|
+
"X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
|
|
1387
|
+
}
|
|
1388
|
+
} : void 0;
|
|
1389
|
+
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1358
1390
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1359
1391
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1360
1392
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
@@ -1429,21 +1461,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1429
1461
|
toolConfig,
|
|
1430
1462
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1431
1463
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1432
|
-
serviceTier:
|
|
1464
|
+
serviceTier: bodyServiceTier
|
|
1433
1465
|
},
|
|
1434
1466
|
warnings: [...warnings, ...toolWarnings],
|
|
1435
|
-
providerOptionsNames
|
|
1467
|
+
providerOptionsNames,
|
|
1468
|
+
extraHeaders: vertexPaygoHeaders
|
|
1436
1469
|
};
|
|
1437
1470
|
}
|
|
1438
1471
|
async doGenerate(options) {
|
|
1439
1472
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1440
|
-
const { args, warnings, providerOptionsNames } = await this.getArgs(options);
|
|
1473
|
+
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
|
|
1441
1474
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1442
1475
|
providerOptionsNames.map((name) => [name, payload])
|
|
1443
1476
|
);
|
|
1444
1477
|
const mergedHeaders = combineHeaders(
|
|
1445
1478
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
1446
|
-
options.headers
|
|
1479
|
+
options.headers,
|
|
1480
|
+
extraHeaders
|
|
1447
1481
|
);
|
|
1448
1482
|
const {
|
|
1449
1483
|
responseHeaders,
|
|
@@ -1592,7 +1626,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1592
1626
|
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1593
1627
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1594
1628
|
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1595
|
-
serviceTier: (_r =
|
|
1629
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
1596
1630
|
}),
|
|
1597
1631
|
request: { body: args },
|
|
1598
1632
|
response: {
|
|
@@ -1603,16 +1637,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1603
1637
|
};
|
|
1604
1638
|
}
|
|
1605
1639
|
async doStream(options) {
|
|
1606
|
-
const { args, warnings, providerOptionsNames } = await this.getArgs(
|
|
1607
|
-
options,
|
|
1608
|
-
{ isStreaming: true }
|
|
1609
|
-
);
|
|
1640
|
+
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
1610
1641
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1611
1642
|
providerOptionsNames.map((name) => [name, payload])
|
|
1612
1643
|
);
|
|
1613
1644
|
const headers = combineHeaders(
|
|
1614
1645
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
1615
|
-
options.headers
|
|
1646
|
+
options.headers,
|
|
1647
|
+
extraHeaders
|
|
1616
1648
|
);
|
|
1617
1649
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1618
1650
|
url: `${this.config.baseURL}/${getModelPath(
|
|
@@ -1633,7 +1665,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1633
1665
|
let providerMetadata = void 0;
|
|
1634
1666
|
let lastGroundingMetadata = null;
|
|
1635
1667
|
let lastUrlContextMetadata = null;
|
|
1636
|
-
let serviceTier = null;
|
|
1637
1668
|
const generateId2 = this.config.generateId;
|
|
1638
1669
|
let hasToolCalls = false;
|
|
1639
1670
|
let currentTextBlockId = null;
|
|
@@ -1678,7 +1709,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1678
1709
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1679
1710
|
},
|
|
1680
1711
|
transform(chunk, controller) {
|
|
1681
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1712
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1682
1713
|
if (options.includeRawChunks) {
|
|
1683
1714
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1684
1715
|
}
|
|
@@ -1691,9 +1722,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1691
1722
|
if (usageMetadata != null) {
|
|
1692
1723
|
usage = usageMetadata;
|
|
1693
1724
|
}
|
|
1694
|
-
if (value.serviceTier != null) {
|
|
1695
|
-
serviceTier = value.serviceTier;
|
|
1696
|
-
}
|
|
1697
1725
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1698
1726
|
if (candidate == null) {
|
|
1699
1727
|
return;
|
|
@@ -1989,7 +2017,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1989
2017
|
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1990
2018
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1991
2019
|
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1992
|
-
serviceTier
|
|
2020
|
+
serviceTier: (_p = usage == null ? void 0 : usage.serviceTier) != null ? _p : null
|
|
1993
2021
|
});
|
|
1994
2022
|
}
|
|
1995
2023
|
},
|
|
@@ -2316,6 +2344,7 @@ var usageSchema = z3.object({
|
|
|
2316
2344
|
totalTokenCount: z3.number().nullish(),
|
|
2317
2345
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2318
2346
|
trafficType: z3.string().nullish(),
|
|
2347
|
+
serviceTier: z3.string().nullish(),
|
|
2319
2348
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2320
2349
|
promptTokensDetails: tokenDetailsSchema,
|
|
2321
2350
|
candidatesTokensDetails: tokenDetailsSchema
|
|
@@ -2345,8 +2374,7 @@ var responseSchema = lazySchema3(
|
|
|
2345
2374
|
promptFeedback: z3.object({
|
|
2346
2375
|
blockReason: z3.string().nullish(),
|
|
2347
2376
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
2348
|
-
}).nullish()
|
|
2349
|
-
serviceTier: z3.string().nullish()
|
|
2377
|
+
}).nullish()
|
|
2350
2378
|
})
|
|
2351
2379
|
)
|
|
2352
2380
|
);
|
|
@@ -2367,8 +2395,7 @@ var chunkSchema = lazySchema3(
|
|
|
2367
2395
|
promptFeedback: z3.object({
|
|
2368
2396
|
blockReason: z3.string().nullish(),
|
|
2369
2397
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
2370
|
-
}).nullish()
|
|
2371
|
-
serviceTier: z3.string().nullish()
|
|
2398
|
+
}).nullish()
|
|
2372
2399
|
})
|
|
2373
2400
|
)
|
|
2374
2401
|
);
|