@ai-sdk/google 3.0.75 → 3.0.78
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 +25 -0
- package/dist/index.d.mts +40 -12
- package/dist/index.d.ts +40 -12
- package/dist/index.js +214 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +214 -69
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +96 -59
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +96 -59
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +1 -0
- package/package.json +1 -1
- package/src/convert-google-generative-ai-usage.ts +1 -0
- package/src/google-generative-ai-language-model.ts +104 -57
- package/src/google-generative-ai-options.ts +24 -8
- package/src/google-provider.ts +9 -4
- package/src/interactions/google-interactions-agent.ts +6 -7
- package/src/interactions/google-interactions-language-model-options.ts +65 -0
- package/src/interactions/google-interactions-language-model.ts +73 -22
- package/src/interactions/google-interactions-prompt.ts +50 -0
- package/src/interactions/stream-google-interactions.ts +1 -1
|
@@ -3,7 +3,7 @@ import { Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
|
3
3
|
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
|
|
6
|
-
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
6
|
+
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
7
7
|
|
|
8
8
|
type GoogleGenerativeAIConfig = {
|
|
9
9
|
provider: string;
|
|
@@ -206,6 +206,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
206
206
|
candidatesTokenCount?: number | null | undefined;
|
|
207
207
|
totalTokenCount?: number | null | undefined;
|
|
208
208
|
trafficType?: string | null | undefined;
|
|
209
|
+
serviceTier?: string | null | undefined;
|
|
209
210
|
promptTokensDetails?: {
|
|
210
211
|
modality: string;
|
|
211
212
|
tokenCount: number;
|
|
@@ -226,7 +227,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
226
227
|
blocked?: boolean | null | undefined;
|
|
227
228
|
}[] | null | undefined;
|
|
228
229
|
} | null | undefined;
|
|
229
|
-
serviceTier?: string | null | undefined;
|
|
230
230
|
}>;
|
|
231
231
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
232
232
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
|
3
3
|
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
|
|
6
|
-
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
6
|
+
type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
7
7
|
|
|
8
8
|
type GoogleGenerativeAIConfig = {
|
|
9
9
|
provider: string;
|
|
@@ -206,6 +206,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
206
206
|
candidatesTokenCount?: number | null | undefined;
|
|
207
207
|
totalTokenCount?: number | null | undefined;
|
|
208
208
|
trafficType?: string | null | undefined;
|
|
209
|
+
serviceTier?: string | null | undefined;
|
|
209
210
|
promptTokensDetails?: {
|
|
210
211
|
modality: string;
|
|
211
212
|
tokenCount: number;
|
|
@@ -226,7 +227,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
226
227
|
blocked?: boolean | null | undefined;
|
|
227
228
|
}[] | null | undefined;
|
|
228
229
|
} | null | undefined;
|
|
229
|
-
serviceTier?: string | null | undefined;
|
|
230
230
|
}>;
|
|
231
231
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
232
232
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
package/dist/internal/index.js
CHANGED
|
@@ -653,17 +653,32 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
653
653
|
*/
|
|
654
654
|
streamFunctionCallArguments: import_v42.z.boolean().optional(),
|
|
655
655
|
/**
|
|
656
|
-
* Optional. The service tier to use for the request.
|
|
656
|
+
* Optional. The service tier to use for the request. Sent as the
|
|
657
|
+
* `serviceTier` body field. Gemini API only.
|
|
657
658
|
*/
|
|
658
|
-
serviceTier: import_v42.z.enum(["standard", "flex", "priority"]).optional()
|
|
659
|
+
serviceTier: import_v42.z.enum(["standard", "flex", "priority"]).optional(),
|
|
660
|
+
/**
|
|
661
|
+
* Optional. Vertex AI only. Sent as the
|
|
662
|
+
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
663
|
+
* shared (PayGo) tier. With Provisioned Throughput allocated and
|
|
664
|
+
* `requestType` unset, the request falls back to this tier only if
|
|
665
|
+
* PT capacity is exhausted.
|
|
666
|
+
*
|
|
667
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
668
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
|
|
669
|
+
*/
|
|
670
|
+
sharedRequestType: import_v42.z.enum(["priority", "flex", "standard"]).optional(),
|
|
671
|
+
/**
|
|
672
|
+
* Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
|
|
673
|
+
* request header. Set to `'shared'` together with `sharedRequestType`
|
|
674
|
+
* to bypass Provisioned Throughput entirely.
|
|
675
|
+
*
|
|
676
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
677
|
+
*/
|
|
678
|
+
requestType: import_v42.z.enum(["shared"]).optional()
|
|
659
679
|
})
|
|
660
680
|
)
|
|
661
681
|
);
|
|
662
|
-
var VertexServiceTierMap = {
|
|
663
|
-
standard: "SERVICE_TIER_STANDARD",
|
|
664
|
-
flex: "SERVICE_TIER_FLEX",
|
|
665
|
-
priority: "SERVICE_TIER_PRIORITY"
|
|
666
|
-
};
|
|
667
682
|
|
|
668
683
|
// src/google-prepare-tools.ts
|
|
669
684
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -1228,10 +1243,27 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1228
1243
|
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`
|
|
1229
1244
|
});
|
|
1230
1245
|
}
|
|
1231
|
-
let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1232
1246
|
if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
|
|
1233
|
-
|
|
1247
|
+
warnings.push({
|
|
1248
|
+
type: "other",
|
|
1249
|
+
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"
|
|
1250
|
+
});
|
|
1234
1251
|
}
|
|
1252
|
+
if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
|
|
1253
|
+
warnings.push({
|
|
1254
|
+
type: "other",
|
|
1255
|
+
message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
|
|
1259
|
+
...googleOptions.sharedRequestType && {
|
|
1260
|
+
"X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
|
|
1261
|
+
},
|
|
1262
|
+
...googleOptions.requestType && {
|
|
1263
|
+
"X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
|
|
1264
|
+
}
|
|
1265
|
+
} : void 0;
|
|
1266
|
+
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1235
1267
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1236
1268
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1237
1269
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
@@ -1303,18 +1335,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1303
1335
|
toolConfig,
|
|
1304
1336
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1305
1337
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1306
|
-
serviceTier:
|
|
1338
|
+
serviceTier: bodyServiceTier
|
|
1307
1339
|
},
|
|
1308
1340
|
warnings: [...warnings, ...toolWarnings],
|
|
1309
|
-
providerOptionsName
|
|
1341
|
+
providerOptionsName,
|
|
1342
|
+
extraHeaders: vertexPaygoHeaders
|
|
1310
1343
|
};
|
|
1311
1344
|
}
|
|
1312
1345
|
async doGenerate(options) {
|
|
1313
1346
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1314
|
-
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1347
|
+
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
1315
1348
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
1316
1349
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
1317
|
-
options.headers
|
|
1350
|
+
options.headers,
|
|
1351
|
+
extraHeaders
|
|
1318
1352
|
);
|
|
1319
1353
|
const {
|
|
1320
1354
|
responseHeaders,
|
|
@@ -1479,7 +1513,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1479
1513
|
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1480
1514
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1481
1515
|
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1482
|
-
serviceTier: (_r =
|
|
1516
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
1483
1517
|
}
|
|
1484
1518
|
},
|
|
1485
1519
|
request: { body: args },
|
|
@@ -1491,13 +1525,11 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1491
1525
|
};
|
|
1492
1526
|
}
|
|
1493
1527
|
async doStream(options) {
|
|
1494
|
-
const { args, warnings, providerOptionsName } = await this.getArgs(
|
|
1495
|
-
options,
|
|
1496
|
-
{ isStreaming: true }
|
|
1497
|
-
);
|
|
1528
|
+
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
1498
1529
|
const headers = (0, import_provider_utils4.combineHeaders)(
|
|
1499
1530
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
1500
|
-
options.headers
|
|
1531
|
+
options.headers,
|
|
1532
|
+
extraHeaders
|
|
1501
1533
|
);
|
|
1502
1534
|
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1503
1535
|
url: `${this.config.baseURL}/${getModelPath(
|
|
@@ -1518,7 +1550,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1518
1550
|
let providerMetadata = void 0;
|
|
1519
1551
|
let lastGroundingMetadata = null;
|
|
1520
1552
|
let lastUrlContextMetadata = null;
|
|
1521
|
-
let serviceTier = null;
|
|
1522
1553
|
const generateId2 = this.config.generateId;
|
|
1523
1554
|
let hasToolCalls = false;
|
|
1524
1555
|
let currentTextBlockId = null;
|
|
@@ -1528,6 +1559,34 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1528
1559
|
let lastCodeExecutionToolCallId;
|
|
1529
1560
|
let lastServerToolCallId;
|
|
1530
1561
|
const activeStreamingToolCalls = [];
|
|
1562
|
+
const finishActiveStreamingToolCall = (controller) => {
|
|
1563
|
+
const active = activeStreamingToolCalls.pop();
|
|
1564
|
+
if (active == null) {
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1568
|
+
if (closingDelta.length > 0) {
|
|
1569
|
+
controller.enqueue({
|
|
1570
|
+
type: "tool-input-delta",
|
|
1571
|
+
id: active.toolCallId,
|
|
1572
|
+
delta: closingDelta,
|
|
1573
|
+
providerMetadata: active.providerMetadata
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
controller.enqueue({
|
|
1577
|
+
type: "tool-input-end",
|
|
1578
|
+
id: active.toolCallId,
|
|
1579
|
+
providerMetadata: active.providerMetadata
|
|
1580
|
+
});
|
|
1581
|
+
controller.enqueue({
|
|
1582
|
+
type: "tool-call",
|
|
1583
|
+
toolCallId: active.toolCallId,
|
|
1584
|
+
toolName: active.toolName,
|
|
1585
|
+
input: finalJSON,
|
|
1586
|
+
providerMetadata: active.providerMetadata
|
|
1587
|
+
});
|
|
1588
|
+
hasToolCalls = true;
|
|
1589
|
+
};
|
|
1531
1590
|
return {
|
|
1532
1591
|
stream: response.pipeThrough(
|
|
1533
1592
|
new TransformStream({
|
|
@@ -1535,7 +1594,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1535
1594
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1536
1595
|
},
|
|
1537
1596
|
transform(chunk, controller) {
|
|
1538
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1597
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1539
1598
|
if (options.includeRawChunks) {
|
|
1540
1599
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1541
1600
|
}
|
|
@@ -1548,9 +1607,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1548
1607
|
if (usageMetadata != null) {
|
|
1549
1608
|
usage = usageMetadata;
|
|
1550
1609
|
}
|
|
1551
|
-
if (value.serviceTier != null) {
|
|
1552
|
-
serviceTier = value.serviceTier;
|
|
1553
|
-
}
|
|
1554
1610
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1555
1611
|
if (candidate == null) {
|
|
1556
1612
|
return;
|
|
@@ -1740,7 +1796,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1740
1796
|
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1741
1797
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1742
1798
|
if (isStreamingChunk) {
|
|
1743
|
-
if (part.functionCall.name != null
|
|
1799
|
+
if (part.functionCall.name != null) {
|
|
1744
1800
|
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
|
|
1745
1801
|
const accumulator = new GoogleJSONAccumulator();
|
|
1746
1802
|
activeStreamingToolCalls.push({
|
|
@@ -1756,9 +1812,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1756
1812
|
providerMetadata: providerMeta
|
|
1757
1813
|
});
|
|
1758
1814
|
if (part.functionCall.partialArgs != null) {
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
);
|
|
1815
|
+
const partialArgs = part.functionCall.partialArgs;
|
|
1816
|
+
const { textDelta } = accumulator.processPartialArgs(partialArgs);
|
|
1762
1817
|
if (textDelta.length > 0) {
|
|
1763
1818
|
controller.enqueue({
|
|
1764
1819
|
type: "tool-input-delta",
|
|
@@ -1767,12 +1822,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1767
1822
|
providerMetadata: providerMeta
|
|
1768
1823
|
});
|
|
1769
1824
|
}
|
|
1825
|
+
if (part.functionCall.willContinue !== true && partialArgs.every((arg) => arg.willContinue !== true)) {
|
|
1826
|
+
finishActiveStreamingToolCall(controller);
|
|
1827
|
+
}
|
|
1770
1828
|
}
|
|
1771
1829
|
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
1772
1830
|
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1775
|
-
);
|
|
1831
|
+
const partialArgs = part.functionCall.partialArgs;
|
|
1832
|
+
const { textDelta } = active.accumulator.processPartialArgs(partialArgs);
|
|
1776
1833
|
if (textDelta.length > 0) {
|
|
1777
1834
|
controller.enqueue({
|
|
1778
1835
|
type: "tool-input-delta",
|
|
@@ -1781,31 +1838,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1781
1838
|
providerMetadata: providerMeta
|
|
1782
1839
|
});
|
|
1783
1840
|
}
|
|
1841
|
+
if (part.functionCall.willContinue !== true && partialArgs.every((arg) => arg.willContinue !== true)) {
|
|
1842
|
+
finishActiveStreamingToolCall(controller);
|
|
1843
|
+
}
|
|
1784
1844
|
}
|
|
1785
1845
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
1786
|
-
|
|
1787
|
-
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1788
|
-
if (closingDelta.length > 0) {
|
|
1789
|
-
controller.enqueue({
|
|
1790
|
-
type: "tool-input-delta",
|
|
1791
|
-
id: active.toolCallId,
|
|
1792
|
-
delta: closingDelta,
|
|
1793
|
-
providerMetadata: active.providerMetadata
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
controller.enqueue({
|
|
1797
|
-
type: "tool-input-end",
|
|
1798
|
-
id: active.toolCallId,
|
|
1799
|
-
providerMetadata: active.providerMetadata
|
|
1800
|
-
});
|
|
1801
|
-
controller.enqueue({
|
|
1802
|
-
type: "tool-call",
|
|
1803
|
-
toolCallId: active.toolCallId,
|
|
1804
|
-
toolName: active.toolName,
|
|
1805
|
-
input: finalJSON,
|
|
1806
|
-
providerMetadata: active.providerMetadata
|
|
1807
|
-
});
|
|
1808
|
-
hasToolCalls = true;
|
|
1846
|
+
finishActiveStreamingToolCall(controller);
|
|
1809
1847
|
} else if (isCompleteCall) {
|
|
1810
1848
|
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
|
|
1811
1849
|
const toolName = part.functionCall.name;
|
|
@@ -1876,7 +1914,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1876
1914
|
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1877
1915
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1878
1916
|
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1879
|
-
serviceTier
|
|
1917
|
+
serviceTier: (_p = usage == null ? void 0 : usage.serviceTier) != null ? _p : null
|
|
1880
1918
|
}
|
|
1881
1919
|
};
|
|
1882
1920
|
}
|
|
@@ -2135,6 +2173,7 @@ var usageSchema = import_v43.z.object({
|
|
|
2135
2173
|
totalTokenCount: import_v43.z.number().nullish(),
|
|
2136
2174
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2137
2175
|
trafficType: import_v43.z.string().nullish(),
|
|
2176
|
+
serviceTier: import_v43.z.string().nullish(),
|
|
2138
2177
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2139
2178
|
promptTokensDetails: tokenDetailsSchema,
|
|
2140
2179
|
candidatesTokensDetails: tokenDetailsSchema
|
|
@@ -2164,8 +2203,7 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
2164
2203
|
promptFeedback: import_v43.z.object({
|
|
2165
2204
|
blockReason: import_v43.z.string().nullish(),
|
|
2166
2205
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
|
|
2167
|
-
}).nullish()
|
|
2168
|
-
serviceTier: import_v43.z.string().nullish()
|
|
2206
|
+
}).nullish()
|
|
2169
2207
|
})
|
|
2170
2208
|
)
|
|
2171
2209
|
);
|
|
@@ -2186,8 +2224,7 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
2186
2224
|
promptFeedback: import_v43.z.object({
|
|
2187
2225
|
blockReason: import_v43.z.string().nullish(),
|
|
2188
2226
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
|
|
2189
|
-
}).nullish()
|
|
2190
|
-
serviceTier: import_v43.z.string().nullish()
|
|
2227
|
+
}).nullish()
|
|
2191
2228
|
})
|
|
2192
2229
|
)
|
|
2193
2230
|
);
|