@ai-sdk/google 4.0.80 → 4.0.82
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 +17 -0
- package/dist/index.js +479 -519
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -0
- package/dist/internal/index.js +342 -342
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +3 -3
- package/package.json +3 -3
- package/src/convert-to-google-messages.ts +30 -9
- package/src/download-tool-result-files.ts +20 -2
- package/src/google-language-model.ts +16 -0
- package/src/google-prompt.ts +7 -3
- package/src/interactions/convert-to-google-interactions-input.ts +2 -2
- package/src/interactions/google-interactions-prompt.ts +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -22,15 +22,14 @@ import { z as z4 } from "zod/v4";
|
|
|
22
22
|
// src/convert-google-usage.ts
|
|
23
23
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
24
24
|
function convertGoogleUsage(usage) {
|
|
25
|
-
var _a, _b, _c, _d, _e;
|
|
26
25
|
if (usage == null) {
|
|
27
26
|
return createNullLanguageModelUsage();
|
|
28
27
|
}
|
|
29
|
-
const promptTokens =
|
|
30
|
-
const candidatesTokens =
|
|
31
|
-
const toolUsePromptTokens =
|
|
32
|
-
const cachedContentTokens =
|
|
33
|
-
const thoughtsTokens =
|
|
28
|
+
const promptTokens = usage.promptTokenCount ?? 0;
|
|
29
|
+
const candidatesTokens = usage.candidatesTokenCount ?? 0;
|
|
30
|
+
const toolUsePromptTokens = usage.toolUsePromptTokenCount ?? 0;
|
|
31
|
+
const cachedContentTokens = usage.cachedContentTokenCount ?? 0;
|
|
32
|
+
const thoughtsTokens = usage.thoughtsTokenCount ?? 0;
|
|
34
33
|
const inputTokens = promptTokens + toolUsePromptTokens;
|
|
35
34
|
return {
|
|
36
35
|
inputTokens: {
|
|
@@ -56,6 +55,7 @@ import {
|
|
|
56
55
|
convertToBase64,
|
|
57
56
|
getTopLevelMediaType,
|
|
58
57
|
isFullMediaType,
|
|
58
|
+
isUrlSupported,
|
|
59
59
|
resolveFullMediaType,
|
|
60
60
|
resolveProviderReference,
|
|
61
61
|
secureJsonParse
|
|
@@ -117,7 +117,7 @@ function containsJSONSchemaReference(value) {
|
|
|
117
117
|
function serializeFunctionResponseContent(value) {
|
|
118
118
|
return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
|
|
119
119
|
}
|
|
120
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
120
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedUrls = {}) {
|
|
121
121
|
const functionResponseParts = [];
|
|
122
122
|
const responseTextParts = [];
|
|
123
123
|
for (const contentPart of outputValue) {
|
|
@@ -135,11 +135,22 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
|
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
} else if (contentPart.data.type === "url") {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
functionResponseParts.push(
|
|
138
|
+
const url = contentPart.data.url.toString();
|
|
139
|
+
const convertedUrlPart = convertUrlToolResultPart(url);
|
|
140
|
+
const supportedUrl = contentPart.data.url.protocol === "gs:" && contentPart.data.originalUrl != null ? contentPart.data.originalUrl : url;
|
|
141
|
+
if (convertedUrlPart != null) {
|
|
142
|
+
functionResponseParts.push(convertedUrlPart);
|
|
143
|
+
} else if (isFullMediaType(contentPart.mediaType) && isUrlSupported({
|
|
144
|
+
url: supportedUrl,
|
|
145
|
+
mediaType: contentPart.mediaType,
|
|
146
|
+
supportedUrls
|
|
147
|
+
})) {
|
|
148
|
+
functionResponseParts.push({
|
|
149
|
+
fileData: {
|
|
150
|
+
mimeType: contentPart.mediaType,
|
|
151
|
+
fileUri: supportedUrl
|
|
152
|
+
}
|
|
153
|
+
});
|
|
143
154
|
} else {
|
|
144
155
|
responseTextParts.push(JSON.stringify(contentPart));
|
|
145
156
|
}
|
|
@@ -207,17 +218,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
function convertToGoogleMessages(prompt, options) {
|
|
210
|
-
var _a, _b, _c, _d, _e, _f;
|
|
211
221
|
const systemInstructionParts = [];
|
|
212
222
|
const contents = [];
|
|
213
223
|
let systemMessagesAllowed = true;
|
|
214
|
-
const isGemmaModel =
|
|
215
|
-
const isGemini3Model =
|
|
216
|
-
const onWarning = options
|
|
217
|
-
const providerOptionsNames =
|
|
224
|
+
const isGemmaModel = options?.isGemmaModel ?? false;
|
|
225
|
+
const isGemini3Model = options?.isGemini3Model ?? false;
|
|
226
|
+
const onWarning = options?.onWarning;
|
|
227
|
+
const providerOptionsNames = options?.providerOptionsNames ?? ["google"];
|
|
218
228
|
const isVertexLike = !providerOptionsNames.includes("google");
|
|
219
|
-
const supportsFunctionResponseParts =
|
|
220
|
-
const includeFunctionCallIds =
|
|
229
|
+
const supportsFunctionResponseParts = options?.supportsFunctionResponseParts ?? true;
|
|
230
|
+
const includeFunctionCallIds = options?.includeFunctionCallIds ?? true;
|
|
231
|
+
const supportedFunctionResponseUrls = options?.supportedFunctionResponseUrls ?? {};
|
|
221
232
|
let sentinelInjected = false;
|
|
222
233
|
const missingSignatureToolNames = [];
|
|
223
234
|
const injectSkipSignature = (toolName) => {
|
|
@@ -226,15 +237,14 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
226
237
|
return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
227
238
|
};
|
|
228
239
|
const readProviderOpts = (part) => {
|
|
229
|
-
var _a2, _b2, _c2, _d2, _e2;
|
|
230
240
|
for (const name of providerOptionsNames) {
|
|
231
|
-
const v =
|
|
241
|
+
const v = part.providerOptions?.[name];
|
|
232
242
|
if (v != null) return v;
|
|
233
243
|
}
|
|
234
244
|
if (isVertexLike) {
|
|
235
|
-
return
|
|
245
|
+
return part.providerOptions?.google;
|
|
236
246
|
}
|
|
237
|
-
return
|
|
247
|
+
return part.providerOptions?.googleVertex ?? part.providerOptions?.vertex;
|
|
238
248
|
};
|
|
239
249
|
for (const { role, content } of prompt) {
|
|
240
250
|
switch (role) {
|
|
@@ -319,7 +329,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
319
329
|
role: "model",
|
|
320
330
|
parts: content.map((part) => {
|
|
321
331
|
const providerOpts = readProviderOpts(part);
|
|
322
|
-
const thoughtSignature =
|
|
332
|
+
const thoughtSignature = providerOpts?.thoughtSignature != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
323
333
|
switch (part.type) {
|
|
324
334
|
case "text": {
|
|
325
335
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -375,7 +385,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
375
385
|
provider: "google"
|
|
376
386
|
})
|
|
377
387
|
},
|
|
378
|
-
...
|
|
388
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
379
389
|
thoughtSignature
|
|
380
390
|
};
|
|
381
391
|
}
|
|
@@ -387,7 +397,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
387
397
|
new TextEncoder().encode(part.data.text)
|
|
388
398
|
)
|
|
389
399
|
},
|
|
390
|
-
...
|
|
400
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
391
401
|
thoughtSignature
|
|
392
402
|
};
|
|
393
403
|
}
|
|
@@ -397,7 +407,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
397
407
|
mimeType: part.mediaType,
|
|
398
408
|
data: convertToBase64(part.data.data)
|
|
399
409
|
},
|
|
400
|
-
...
|
|
410
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
401
411
|
thoughtSignature
|
|
402
412
|
};
|
|
403
413
|
}
|
|
@@ -412,8 +422,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
412
422
|
)
|
|
413
423
|
};
|
|
414
424
|
}
|
|
415
|
-
const serverToolCallId =
|
|
416
|
-
const serverToolType =
|
|
425
|
+
const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
426
|
+
const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
|
|
417
427
|
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
418
428
|
const shouldSkipMissingSignatureMitigation = (
|
|
419
429
|
// Gemini 3 returns a single signature for a parallel
|
|
@@ -422,7 +432,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
422
432
|
// model response legitimately have no signature.
|
|
423
433
|
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
424
434
|
);
|
|
425
|
-
const effectiveThoughtSignature = thoughtSignature
|
|
435
|
+
const effectiveThoughtSignature = thoughtSignature ?? (isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0);
|
|
426
436
|
if (!isServerToolCall && thoughtSignature != null) {
|
|
427
437
|
modelResponseHasSignedFunctionCall = true;
|
|
428
438
|
}
|
|
@@ -453,8 +463,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
453
463
|
)
|
|
454
464
|
};
|
|
455
465
|
}
|
|
456
|
-
const serverToolCallId =
|
|
457
|
-
const serverToolType =
|
|
466
|
+
const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
467
|
+
const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
|
|
458
468
|
if (serverToolCallId && serverToolType) {
|
|
459
469
|
return {
|
|
460
470
|
toolResponse: {
|
|
@@ -480,10 +490,10 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
480
490
|
continue;
|
|
481
491
|
}
|
|
482
492
|
const partProviderOpts = readProviderOpts(part);
|
|
483
|
-
const serverToolCallId =
|
|
484
|
-
const serverToolType =
|
|
493
|
+
const serverToolCallId = partProviderOpts?.serverToolCallId != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
494
|
+
const serverToolType = partProviderOpts?.serverToolType != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
485
495
|
if (serverToolCallId && serverToolType) {
|
|
486
|
-
const serverThoughtSignature =
|
|
496
|
+
const serverThoughtSignature = partProviderOpts?.thoughtSignature != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
487
497
|
if (contents.length > 0) {
|
|
488
498
|
const lastContent = contents[contents.length - 1];
|
|
489
499
|
if (lastContent.role === "model") {
|
|
@@ -507,7 +517,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
507
517
|
part.toolName,
|
|
508
518
|
output.value,
|
|
509
519
|
part.toolCallId,
|
|
510
|
-
includeFunctionCallIds
|
|
520
|
+
includeFunctionCallIds,
|
|
521
|
+
supportedFunctionResponseUrls
|
|
511
522
|
);
|
|
512
523
|
} else {
|
|
513
524
|
appendLegacyToolResultParts(
|
|
@@ -525,7 +536,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
525
536
|
name: part.toolName,
|
|
526
537
|
response: {
|
|
527
538
|
name: part.toolName,
|
|
528
|
-
content: output.type === "execution-denied" ?
|
|
539
|
+
content: output.type === "execution-denied" ? output.reason ?? "Tool call execution denied." : serializeFunctionResponseContent(output.value)
|
|
529
540
|
}
|
|
530
541
|
}
|
|
531
542
|
});
|
|
@@ -560,11 +571,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
560
571
|
import {
|
|
561
572
|
detectMediaType,
|
|
562
573
|
downloadBlob,
|
|
563
|
-
isFullMediaType as isFullMediaType2
|
|
574
|
+
isFullMediaType as isFullMediaType2,
|
|
575
|
+
isUrlSupported as isUrlSupported2
|
|
564
576
|
} from "@ai-sdk/provider-utils";
|
|
565
577
|
async function downloadToolResultFiles(prompt, {
|
|
566
578
|
abortSignal,
|
|
567
|
-
maxBytes
|
|
579
|
+
maxBytes,
|
|
580
|
+
supportedUrls = {}
|
|
568
581
|
}) {
|
|
569
582
|
const result = [];
|
|
570
583
|
for (const message of prompt) {
|
|
@@ -576,7 +589,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
576
589
|
...part,
|
|
577
590
|
output: await downloadToolResultOutput(part.output, {
|
|
578
591
|
abortSignal,
|
|
579
|
-
maxBytes
|
|
592
|
+
maxBytes,
|
|
593
|
+
supportedUrls
|
|
580
594
|
})
|
|
581
595
|
} : part
|
|
582
596
|
);
|
|
@@ -595,7 +609,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
595
609
|
...part,
|
|
596
610
|
output: await downloadToolResultOutput(part.output, {
|
|
597
611
|
abortSignal,
|
|
598
|
-
maxBytes
|
|
612
|
+
maxBytes,
|
|
613
|
+
supportedUrls
|
|
599
614
|
})
|
|
600
615
|
});
|
|
601
616
|
}
|
|
@@ -608,7 +623,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
608
623
|
}
|
|
609
624
|
async function downloadToolResultOutput(output, {
|
|
610
625
|
abortSignal,
|
|
611
|
-
maxBytes
|
|
626
|
+
maxBytes,
|
|
627
|
+
supportedUrls
|
|
612
628
|
}) {
|
|
613
629
|
if (output.type !== "content") {
|
|
614
630
|
return output;
|
|
@@ -619,6 +635,14 @@ async function downloadToolResultOutput(output, {
|
|
|
619
635
|
value.push(part);
|
|
620
636
|
continue;
|
|
621
637
|
}
|
|
638
|
+
if (isUrlSupported2({
|
|
639
|
+
url: part.data.url.toString(),
|
|
640
|
+
mediaType: part.mediaType,
|
|
641
|
+
supportedUrls
|
|
642
|
+
})) {
|
|
643
|
+
value.push(part);
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
622
646
|
const blob = await downloadBlob(part.data.url.toString(), {
|
|
623
647
|
abortSignal,
|
|
624
648
|
maxBytes
|
|
@@ -631,7 +655,7 @@ async function downloadToolResultOutput(output, {
|
|
|
631
655
|
value.push({
|
|
632
656
|
...part,
|
|
633
657
|
data: { type: "data", data },
|
|
634
|
-
mediaType: detectedMediaType
|
|
658
|
+
mediaType: detectedMediaType ?? (blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType)
|
|
635
659
|
});
|
|
636
660
|
}
|
|
637
661
|
return {
|
|
@@ -929,7 +953,7 @@ function prepareTools({
|
|
|
929
953
|
modelId,
|
|
930
954
|
isVertexProvider = false
|
|
931
955
|
}) {
|
|
932
|
-
tools =
|
|
956
|
+
tools = tools?.length ? tools : void 0;
|
|
933
957
|
const toolWarnings = [];
|
|
934
958
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
935
959
|
if (tools == null) {
|
|
@@ -1158,10 +1182,9 @@ function prepareTools({
|
|
|
1158
1182
|
}
|
|
1159
1183
|
}
|
|
1160
1184
|
function prepareFunctionDeclaration(tool) {
|
|
1161
|
-
var _a;
|
|
1162
1185
|
return {
|
|
1163
1186
|
name: tool.name,
|
|
1164
|
-
description:
|
|
1187
|
+
description: tool.description ?? "",
|
|
1165
1188
|
parametersJsonSchema: tool.inputSchema
|
|
1166
1189
|
};
|
|
1167
1190
|
}
|
|
@@ -1400,8 +1423,7 @@ function setNestedValue(obj, segments, value) {
|
|
|
1400
1423
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1401
1424
|
}
|
|
1402
1425
|
function resolvePartialArgValue(arg) {
|
|
1403
|
-
|
|
1404
|
-
const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1426
|
+
const value = arg.stringValue ?? arg.numberValue ?? arg.boolValue;
|
|
1405
1427
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1406
1428
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1407
1429
|
}
|
|
@@ -1440,13 +1462,19 @@ var configurableSafetySettingCategories = [
|
|
|
1440
1462
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1441
1463
|
];
|
|
1442
1464
|
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1465
|
+
var googleCloudStorageFunctionResponseUrls = {
|
|
1466
|
+
"image/png": [/^gs:\/\/.*$/],
|
|
1467
|
+
"image/jpeg": [/^gs:\/\/.*$/],
|
|
1468
|
+
"image/webp": [/^gs:\/\/.*$/],
|
|
1469
|
+
"application/pdf": [/^gs:\/\/.*$/],
|
|
1470
|
+
"text/plain": [/^gs:\/\/.*$/]
|
|
1471
|
+
};
|
|
1443
1472
|
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
1444
1473
|
constructor(modelId, config) {
|
|
1445
1474
|
this.specificationVersion = "v4";
|
|
1446
|
-
var _a;
|
|
1447
1475
|
this.modelId = modelId;
|
|
1448
1476
|
this.config = config;
|
|
1449
|
-
this.generateId =
|
|
1477
|
+
this.generateId = config.generateId ?? generateId;
|
|
1450
1478
|
}
|
|
1451
1479
|
static [WORKFLOW_SERIALIZE](model) {
|
|
1452
1480
|
return serializeModelOptions({
|
|
@@ -1461,8 +1489,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1461
1489
|
return this.config.provider;
|
|
1462
1490
|
}
|
|
1463
1491
|
get supportedUrls() {
|
|
1464
|
-
|
|
1465
|
-
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
1492
|
+
return this.config.supportedUrls?.() ?? {};
|
|
1466
1493
|
}
|
|
1467
1494
|
static async prepareRequest({
|
|
1468
1495
|
modelId,
|
|
@@ -1486,7 +1513,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1486
1513
|
},
|
|
1487
1514
|
isStreaming = false
|
|
1488
1515
|
}) {
|
|
1489
|
-
var _a, _b, _c;
|
|
1490
1516
|
const warnings = [];
|
|
1491
1517
|
const providerOptionsNames = config.provider.includes(
|
|
1492
1518
|
"vertex"
|
|
@@ -1508,33 +1534,33 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1508
1534
|
});
|
|
1509
1535
|
}
|
|
1510
1536
|
const isVertexProvider = config.provider.startsWith("google.vertex.");
|
|
1511
|
-
if (
|
|
1537
|
+
if (tools?.some(
|
|
1512
1538
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
1513
|
-
)
|
|
1539
|
+
) && !isVertexProvider) {
|
|
1514
1540
|
warnings.push({
|
|
1515
1541
|
type: "other",
|
|
1516
1542
|
message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${config.provider}).`
|
|
1517
1543
|
});
|
|
1518
1544
|
}
|
|
1519
|
-
if (
|
|
1545
|
+
if (googleOptions?.streamFunctionCallArguments && !isVertexProvider) {
|
|
1520
1546
|
warnings.push({
|
|
1521
1547
|
type: "other",
|
|
1522
1548
|
message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
|
|
1523
1549
|
});
|
|
1524
1550
|
}
|
|
1525
|
-
if (
|
|
1551
|
+
if (googleOptions?.serviceTier && isVertexProvider) {
|
|
1526
1552
|
warnings.push({
|
|
1527
1553
|
type: "other",
|
|
1528
1554
|
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"
|
|
1529
1555
|
});
|
|
1530
1556
|
}
|
|
1531
|
-
if ((
|
|
1557
|
+
if ((googleOptions?.sharedRequestType || googleOptions?.requestType) && !isVertexProvider) {
|
|
1532
1558
|
warnings.push({
|
|
1533
1559
|
type: "other",
|
|
1534
1560
|
message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${config.provider}).`
|
|
1535
1561
|
});
|
|
1536
1562
|
}
|
|
1537
|
-
const vertexPaygoHeaders = isVertexProvider && (
|
|
1563
|
+
const vertexPaygoHeaders = isVertexProvider && (googleOptions?.sharedRequestType || googleOptions?.requestType) ? {
|
|
1538
1564
|
...googleOptions.sharedRequestType && {
|
|
1539
1565
|
"X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
|
|
1540
1566
|
},
|
|
@@ -1542,8 +1568,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1542
1568
|
"X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
|
|
1543
1569
|
}
|
|
1544
1570
|
} : void 0;
|
|
1545
|
-
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions
|
|
1546
|
-
let imageConfig = googleOptions
|
|
1571
|
+
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions?.serviceTier;
|
|
1572
|
+
let imageConfig = googleOptions?.imageConfig;
|
|
1547
1573
|
if (imageConfig != null && !isVertexProvider) {
|
|
1548
1574
|
const {
|
|
1549
1575
|
personGeneration,
|
|
@@ -1579,9 +1605,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1579
1605
|
});
|
|
1580
1606
|
}
|
|
1581
1607
|
const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1608
|
+
const supportedFunctionResponseUrls = usesGemini3Features && config.downloadToolResultFiles?.supportsGoogleCloudStorageUrls ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
1582
1609
|
const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
|
|
1583
1610
|
abortSignal,
|
|
1584
|
-
maxBytes: config.downloadToolResultFiles.maxBytes
|
|
1611
|
+
maxBytes: config.downloadToolResultFiles.maxBytes,
|
|
1612
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
1585
1613
|
}) : prompt;
|
|
1586
1614
|
const { contents, systemInstruction } = convertToGoogleMessages(
|
|
1587
1615
|
promptWithDownloadedToolResultFiles,
|
|
@@ -1591,7 +1619,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1591
1619
|
onWarning: (warning) => warnings.push(warning),
|
|
1592
1620
|
providerOptionsNames,
|
|
1593
1621
|
supportsFunctionResponseParts: usesGemini3Features,
|
|
1594
|
-
includeFunctionCallIds: !isVertexProvider
|
|
1622
|
+
includeFunctionCallIds: !isVertexProvider,
|
|
1623
|
+
supportedFunctionResponseUrls
|
|
1595
1624
|
}
|
|
1596
1625
|
);
|
|
1597
1626
|
const {
|
|
@@ -1615,22 +1644,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1615
1644
|
modelId,
|
|
1616
1645
|
warnings
|
|
1617
1646
|
});
|
|
1618
|
-
const thinkingConfig =
|
|
1619
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ?
|
|
1620
|
-
const safetyThreshold = googleOptions
|
|
1621
|
-
const safetySettings =
|
|
1647
|
+
const thinkingConfig = googleOptions?.thinkingConfig || resolvedThinking ? { ...resolvedThinking, ...googleOptions?.thinkingConfig } : void 0;
|
|
1648
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? googleOptions?.streamFunctionCallArguments ?? false : void 0;
|
|
1649
|
+
const safetyThreshold = googleOptions?.threshold;
|
|
1650
|
+
const safetySettings = googleOptions?.safetySettings ?? (safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
1622
1651
|
category,
|
|
1623
1652
|
threshold: safetyThreshold
|
|
1624
|
-
})) : void 0;
|
|
1625
|
-
const toolConfig = googleToolConfig || streamFunctionCallArguments ||
|
|
1653
|
+
})) : void 0);
|
|
1654
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || googleOptions?.retrievalConfig ? {
|
|
1626
1655
|
...googleToolConfig,
|
|
1627
1656
|
...streamFunctionCallArguments && {
|
|
1628
1657
|
functionCallingConfig: {
|
|
1629
|
-
...googleToolConfig
|
|
1658
|
+
...googleToolConfig?.functionCallingConfig,
|
|
1630
1659
|
streamFunctionCallArguments: true
|
|
1631
1660
|
}
|
|
1632
1661
|
},
|
|
1633
|
-
...
|
|
1662
|
+
...googleOptions?.retrievalConfig && {
|
|
1634
1663
|
retrievalConfig: googleOptions.retrievalConfig
|
|
1635
1664
|
}
|
|
1636
1665
|
} : void 0;
|
|
@@ -1647,18 +1676,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1647
1676
|
stopSequences,
|
|
1648
1677
|
seed,
|
|
1649
1678
|
// response format:
|
|
1650
|
-
responseMimeType:
|
|
1651
|
-
responseJsonSchema:
|
|
1679
|
+
responseMimeType: responseFormat?.type === "json" ? "application/json" : void 0,
|
|
1680
|
+
responseJsonSchema: responseFormat?.type === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
|
|
1652
1681
|
// responseJsonSchema, so this is needed as an escape hatch:
|
|
1653
1682
|
// TODO convert into provider option
|
|
1654
|
-
(
|
|
1655
|
-
...
|
|
1683
|
+
(googleOptions?.structuredOutputs ?? true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
|
|
1684
|
+
...googleOptions?.audioTimestamp && {
|
|
1656
1685
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1657
1686
|
},
|
|
1658
1687
|
// provider options:
|
|
1659
|
-
responseModalities: googleOptions
|
|
1688
|
+
responseModalities: googleOptions?.responseModalities,
|
|
1660
1689
|
thinkingConfig,
|
|
1661
|
-
...
|
|
1690
|
+
...googleOptions?.mediaResolution && {
|
|
1662
1691
|
mediaResolution: googleOptions.mediaResolution
|
|
1663
1692
|
},
|
|
1664
1693
|
...imageConfig && { imageConfig }
|
|
@@ -1668,8 +1697,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1668
1697
|
safetySettings,
|
|
1669
1698
|
tools: googleTools2,
|
|
1670
1699
|
toolConfig,
|
|
1671
|
-
cachedContent: googleOptions
|
|
1672
|
-
labels: googleOptions
|
|
1700
|
+
cachedContent: googleOptions?.cachedContent,
|
|
1701
|
+
labels: googleOptions?.labels,
|
|
1673
1702
|
serviceTier: bodyServiceTier
|
|
1674
1703
|
},
|
|
1675
1704
|
warnings: [...warnings, ...toolWarnings],
|
|
@@ -1693,30 +1722,29 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1693
1722
|
providerOptionsNames,
|
|
1694
1723
|
toolNameMapping
|
|
1695
1724
|
}) {
|
|
1696
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1697
1725
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1698
1726
|
providerOptionsNames.map((name) => [name, payload])
|
|
1699
1727
|
);
|
|
1700
|
-
const candidate =
|
|
1701
|
-
const promptBlockReason =
|
|
1728
|
+
const candidate = response.candidates?.[0];
|
|
1729
|
+
const promptBlockReason = response.promptFeedback?.blockReason;
|
|
1702
1730
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1703
1731
|
promptBlockReason
|
|
1704
1732
|
) ? promptBlockReason : void 0;
|
|
1705
|
-
const isPromptBlocked =
|
|
1706
|
-
const rawFinishReason =
|
|
1733
|
+
const isPromptBlocked = candidate?.finishReason == null && confirmedPromptBlockReason != null;
|
|
1734
|
+
const rawFinishReason = candidate?.finishReason ?? confirmedPromptBlockReason;
|
|
1707
1735
|
const content = [];
|
|
1708
|
-
const parts =
|
|
1736
|
+
const parts = candidate?.content?.parts ?? [];
|
|
1709
1737
|
const usageMetadata = response.usageMetadata;
|
|
1710
1738
|
let lastCodeExecutionToolCallId;
|
|
1711
1739
|
let lastServerToolCallId;
|
|
1712
1740
|
for (const part of parts) {
|
|
1713
|
-
if ("executableCode" in part &&
|
|
1741
|
+
if ("executableCode" in part && part.executableCode?.code) {
|
|
1714
1742
|
const toolCallId = config.generateId();
|
|
1715
1743
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1716
1744
|
content.push({
|
|
1717
1745
|
type: "tool-call",
|
|
1718
1746
|
toolCallId,
|
|
1719
|
-
toolName:
|
|
1747
|
+
toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
|
|
1720
1748
|
input: JSON.stringify(part.executableCode),
|
|
1721
1749
|
providerExecuted: true
|
|
1722
1750
|
});
|
|
@@ -1725,10 +1753,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1725
1753
|
type: "tool-result",
|
|
1726
1754
|
// Results correspond to the most recent executable code part.
|
|
1727
1755
|
toolCallId: lastCodeExecutionToolCallId,
|
|
1728
|
-
toolName:
|
|
1756
|
+
toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
|
|
1729
1757
|
result: {
|
|
1730
1758
|
outcome: part.codeExecutionResult.outcome,
|
|
1731
|
-
output:
|
|
1759
|
+
output: part.codeExecutionResult.output ?? ""
|
|
1732
1760
|
}
|
|
1733
1761
|
});
|
|
1734
1762
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1752,7 +1780,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1752
1780
|
type: "tool-call",
|
|
1753
1781
|
toolCallId: part.functionCall.id || config.generateId(),
|
|
1754
1782
|
toolName: part.functionCall.name,
|
|
1755
|
-
input: JSON.stringify(
|
|
1783
|
+
input: JSON.stringify(part.functionCall.args ?? {}),
|
|
1756
1784
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1757
1785
|
thoughtSignature: part.thoughtSignature
|
|
1758
1786
|
}) : void 0
|
|
@@ -1775,7 +1803,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1775
1803
|
type: "tool-call",
|
|
1776
1804
|
toolCallId,
|
|
1777
1805
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1778
|
-
input: JSON.stringify(
|
|
1806
|
+
input: JSON.stringify(part.toolCall.args ?? {}),
|
|
1779
1807
|
providerExecuted: true,
|
|
1780
1808
|
dynamic: true,
|
|
1781
1809
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -1793,7 +1821,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1793
1821
|
type: "tool-result",
|
|
1794
1822
|
toolCallId: responseToolCallId,
|
|
1795
1823
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1796
|
-
result:
|
|
1824
|
+
result: part.toolResponse.response ?? {},
|
|
1797
1825
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1798
1826
|
thoughtSignature: part.thoughtSignature,
|
|
1799
1827
|
serverToolCallId: responseToolCallId,
|
|
@@ -1806,10 +1834,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1806
1834
|
lastServerToolCallId = void 0;
|
|
1807
1835
|
}
|
|
1808
1836
|
}
|
|
1809
|
-
const sources =
|
|
1810
|
-
groundingMetadata: candidate
|
|
1837
|
+
const sources = extractSources({
|
|
1838
|
+
groundingMetadata: candidate?.groundingMetadata,
|
|
1811
1839
|
generateId: config.generateId
|
|
1812
|
-
})
|
|
1840
|
+
}) ?? [];
|
|
1813
1841
|
for (const source of sources) {
|
|
1814
1842
|
content.push(source);
|
|
1815
1843
|
}
|
|
@@ -1828,17 +1856,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1828
1856
|
usage: convertGoogleUsage(usageMetadata),
|
|
1829
1857
|
warnings,
|
|
1830
1858
|
providerMetadata: wrapProviderMetadata({
|
|
1831
|
-
promptFeedback:
|
|
1832
|
-
groundingMetadata:
|
|
1833
|
-
urlContextMetadata:
|
|
1834
|
-
safetyRatings:
|
|
1835
|
-
usageMetadata: usageMetadata
|
|
1836
|
-
finishMessage:
|
|
1837
|
-
serviceTier:
|
|
1859
|
+
promptFeedback: response.promptFeedback ?? null,
|
|
1860
|
+
groundingMetadata: candidate?.groundingMetadata ?? null,
|
|
1861
|
+
urlContextMetadata: candidate?.urlContextMetadata ?? null,
|
|
1862
|
+
safetyRatings: candidate?.safetyRatings ?? null,
|
|
1863
|
+
usageMetadata: usageMetadata ?? null,
|
|
1864
|
+
finishMessage: candidate?.finishMessage ?? null,
|
|
1865
|
+
serviceTier: usageMetadata?.serviceTier ?? null
|
|
1838
1866
|
}),
|
|
1839
1867
|
response: {
|
|
1840
1868
|
// TODO timestamp, model id
|
|
1841
|
-
id:
|
|
1869
|
+
id: response.responseId ?? void 0
|
|
1842
1870
|
}
|
|
1843
1871
|
};
|
|
1844
1872
|
}
|
|
@@ -1970,7 +1998,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1970
1998
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1971
1999
|
},
|
|
1972
2000
|
transform(chunk, controller) {
|
|
1973
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1974
2001
|
if (options.includeRawChunks) {
|
|
1975
2002
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1976
2003
|
}
|
|
@@ -2000,7 +2027,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2000
2027
|
};
|
|
2001
2028
|
}
|
|
2002
2029
|
}
|
|
2003
|
-
const candidate =
|
|
2030
|
+
const candidate = value.candidates?.[0];
|
|
2004
2031
|
if (candidate != null) {
|
|
2005
2032
|
if (candidate.groundingMetadata != null) {
|
|
2006
2033
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2032,9 +2059,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2032
2059
|
}
|
|
2033
2060
|
}
|
|
2034
2061
|
if (content != null) {
|
|
2035
|
-
const parts =
|
|
2062
|
+
const parts = content.parts ?? [];
|
|
2036
2063
|
for (const part of parts) {
|
|
2037
|
-
if ("executableCode" in part &&
|
|
2064
|
+
if ("executableCode" in part && part.executableCode?.code) {
|
|
2038
2065
|
const toolCallId = generateId2();
|
|
2039
2066
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2040
2067
|
controller.enqueue({
|
|
@@ -2053,7 +2080,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2053
2080
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2054
2081
|
result: {
|
|
2055
2082
|
outcome: part.codeExecutionResult.outcome,
|
|
2056
|
-
output:
|
|
2083
|
+
output: part.codeExecutionResult.output ?? ""
|
|
2057
2084
|
}
|
|
2058
2085
|
});
|
|
2059
2086
|
}
|
|
@@ -2153,7 +2180,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2153
2180
|
type: "tool-call",
|
|
2154
2181
|
toolCallId,
|
|
2155
2182
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2156
|
-
input: JSON.stringify(
|
|
2183
|
+
input: JSON.stringify(part.toolCall.args ?? {}),
|
|
2157
2184
|
providerExecuted: true,
|
|
2158
2185
|
dynamic: true,
|
|
2159
2186
|
providerMetadata: serverMeta
|
|
@@ -2169,7 +2196,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2169
2196
|
type: "tool-result",
|
|
2170
2197
|
toolCallId: responseToolCallId,
|
|
2171
2198
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2172
|
-
result:
|
|
2199
|
+
result: part.toolResponse.response ?? {},
|
|
2173
2200
|
providerMetadata: serverMeta
|
|
2174
2201
|
});
|
|
2175
2202
|
lastServerToolCallId = void 0;
|
|
@@ -2236,7 +2263,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2236
2263
|
} else if (isCompleteCall) {
|
|
2237
2264
|
const toolCallId = part.functionCall.id || generateId2();
|
|
2238
2265
|
const toolName = part.functionCall.name;
|
|
2239
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify(
|
|
2266
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify(part.functionCall.args ?? {});
|
|
2240
2267
|
controller.enqueue({
|
|
2241
2268
|
type: "tool-input-start",
|
|
2242
2269
|
id: toolCallId,
|
|
@@ -2298,7 +2325,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2298
2325
|
}
|
|
2299
2326
|
},
|
|
2300
2327
|
flush(controller) {
|
|
2301
|
-
var _a;
|
|
2302
2328
|
if (currentTextBlockId !== null) {
|
|
2303
2329
|
controller.enqueue({
|
|
2304
2330
|
type: "text-end",
|
|
@@ -2320,9 +2346,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2320
2346
|
groundingMetadata: lastGroundingMetadata,
|
|
2321
2347
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2322
2348
|
safetyRatings: lastSafetyRatings,
|
|
2323
|
-
usageMetadata: usage
|
|
2349
|
+
usageMetadata: usage ?? null,
|
|
2324
2350
|
finishMessage: lastFinishMessage,
|
|
2325
|
-
serviceTier:
|
|
2351
|
+
serviceTier: usage?.serviceTier ?? null
|
|
2326
2352
|
})
|
|
2327
2353
|
});
|
|
2328
2354
|
}
|
|
@@ -2382,13 +2408,12 @@ function resolveGemini3ThinkingConfig({
|
|
|
2382
2408
|
return { thinkingLevel };
|
|
2383
2409
|
}
|
|
2384
2410
|
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2385
|
-
|
|
2386
|
-
const modelName = (_a = modelId.split("/").at(-1)) == null ? void 0 : _a.toLowerCase();
|
|
2411
|
+
const modelName = modelId.split("/").at(-1)?.toLowerCase();
|
|
2387
2412
|
if (modelName === "gemini-flash-latest") {
|
|
2388
2413
|
return "low";
|
|
2389
2414
|
}
|
|
2390
2415
|
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(
|
|
2391
|
-
modelName
|
|
2416
|
+
modelName ?? ""
|
|
2392
2417
|
);
|
|
2393
2418
|
if (versionMatch == null) {
|
|
2394
2419
|
return "minimal";
|
|
@@ -2421,8 +2446,7 @@ function extractSources({
|
|
|
2421
2446
|
groundingMetadata,
|
|
2422
2447
|
generateId: generateId2
|
|
2423
2448
|
}) {
|
|
2424
|
-
|
|
2425
|
-
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2449
|
+
if (!groundingMetadata?.groundingChunks) {
|
|
2426
2450
|
return void 0;
|
|
2427
2451
|
}
|
|
2428
2452
|
const sources = [];
|
|
@@ -2433,7 +2457,7 @@ function extractSources({
|
|
|
2433
2457
|
sourceType: "url",
|
|
2434
2458
|
id: generateId2(),
|
|
2435
2459
|
url: chunk.web.uri,
|
|
2436
|
-
title:
|
|
2460
|
+
title: chunk.web.title ?? void 0
|
|
2437
2461
|
});
|
|
2438
2462
|
} else if (chunk.image != null) {
|
|
2439
2463
|
sources.push({
|
|
@@ -2443,7 +2467,7 @@ function extractSources({
|
|
|
2443
2467
|
// Google requires attribution to the source URI, not the actual image URI.
|
|
2444
2468
|
// TODO: add another type in v7 to allow both the image and source URL to be included separately
|
|
2445
2469
|
url: chunk.image.sourceUri,
|
|
2446
|
-
title:
|
|
2470
|
+
title: chunk.image.title ?? void 0
|
|
2447
2471
|
});
|
|
2448
2472
|
} else if (chunk.retrievedContext != null) {
|
|
2449
2473
|
const uri = chunk.retrievedContext.uri;
|
|
@@ -2454,10 +2478,10 @@ function extractSources({
|
|
|
2454
2478
|
sourceType: "url",
|
|
2455
2479
|
id: generateId2(),
|
|
2456
2480
|
url: uri,
|
|
2457
|
-
title:
|
|
2481
|
+
title: chunk.retrievedContext.title ?? void 0
|
|
2458
2482
|
});
|
|
2459
2483
|
} else if (uri) {
|
|
2460
|
-
const title =
|
|
2484
|
+
const title = chunk.retrievedContext.title ?? "Unknown Document";
|
|
2461
2485
|
let mediaType = "application/octet-stream";
|
|
2462
2486
|
let filename = void 0;
|
|
2463
2487
|
if (uri.endsWith(".pdf")) {
|
|
@@ -2487,7 +2511,7 @@ function extractSources({
|
|
|
2487
2511
|
filename
|
|
2488
2512
|
});
|
|
2489
2513
|
} else if (fileSearchStore) {
|
|
2490
|
-
const title =
|
|
2514
|
+
const title = chunk.retrievedContext.title ?? "Unknown Document";
|
|
2491
2515
|
sources.push({
|
|
2492
2516
|
type: "source",
|
|
2493
2517
|
sourceType: "document",
|
|
@@ -2504,7 +2528,7 @@ function extractSources({
|
|
|
2504
2528
|
sourceType: "url",
|
|
2505
2529
|
id: generateId2(),
|
|
2506
2530
|
url: chunk.maps.uri,
|
|
2507
|
-
title:
|
|
2531
|
+
title: chunk.maps.title ?? void 0
|
|
2508
2532
|
});
|
|
2509
2533
|
}
|
|
2510
2534
|
}
|
|
@@ -2754,7 +2778,7 @@ function getGoogleSpeechInput({
|
|
|
2754
2778
|
voice,
|
|
2755
2779
|
providerOptions
|
|
2756
2780
|
}) {
|
|
2757
|
-
const google = providerOptions
|
|
2781
|
+
const google = providerOptions?.google;
|
|
2758
2782
|
const options = google != null && typeof google === "object" ? google : void 0;
|
|
2759
2783
|
const turns = options && "turns" in options ? options.turns : void 0;
|
|
2760
2784
|
const turnTexts = [];
|
|
@@ -2773,7 +2797,7 @@ function getGoogleSpeechInput({
|
|
|
2773
2797
|
const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
|
|
2774
2798
|
return {
|
|
2775
2799
|
text,
|
|
2776
|
-
usesCustomVoice:
|
|
2800
|
+
usesCustomVoice: voice?.startsWith("voice_") === true || voice?.startsWith("voicekey_") === true || speakers.some(
|
|
2777
2801
|
(speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
|
|
2778
2802
|
)
|
|
2779
2803
|
};
|
|
@@ -2862,7 +2886,6 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
2862
2886
|
language,
|
|
2863
2887
|
providerOptions
|
|
2864
2888
|
}) {
|
|
2865
|
-
var _a;
|
|
2866
2889
|
const warnings = [];
|
|
2867
2890
|
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
2868
2891
|
let googleOptions;
|
|
@@ -2895,7 +2918,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
2895
2918
|
message: "Custom voices are not supported. Use a prebuilt voice instead."
|
|
2896
2919
|
});
|
|
2897
2920
|
}
|
|
2898
|
-
const multiSpeakerVoiceConfig = googleOptions
|
|
2921
|
+
const multiSpeakerVoiceConfig = googleOptions?.multiSpeakerVoiceConfig;
|
|
2899
2922
|
const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
|
|
2900
2923
|
let promptText = text;
|
|
2901
2924
|
if (instructions != null && !usesStructuredSpeech) {
|
|
@@ -2911,25 +2934,24 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
2911
2934
|
}
|
|
2912
2935
|
let parts = [{ text: promptText }];
|
|
2913
2936
|
if (usesStructuredSpeech) {
|
|
2914
|
-
if (
|
|
2937
|
+
if (googleOptions?.turns && googleOptions.speechMetadata) {
|
|
2915
2938
|
throw new InvalidArgumentError({
|
|
2916
2939
|
argument: "providerOptions",
|
|
2917
2940
|
message: "Set speechMetadata on each turn when using turns."
|
|
2918
2941
|
});
|
|
2919
2942
|
}
|
|
2920
|
-
if (
|
|
2943
|
+
if (googleOptions?.turns && text !== "") {
|
|
2921
2944
|
warnings.push({
|
|
2922
2945
|
type: "unsupported",
|
|
2923
2946
|
feature: "text",
|
|
2924
2947
|
details: "Google TTS turns replace the top-level text."
|
|
2925
2948
|
});
|
|
2926
2949
|
}
|
|
2927
|
-
parts = (
|
|
2928
|
-
{ text, speechMetadata: googleOptions
|
|
2950
|
+
parts = (googleOptions?.turns ?? [
|
|
2951
|
+
{ text, speechMetadata: googleOptions?.speechMetadata }
|
|
2929
2952
|
]).map((part) => {
|
|
2930
|
-
|
|
2931
|
-
const
|
|
2932
|
-
const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
|
|
2953
|
+
const style = part.speechMetadata?.style ?? instructions;
|
|
2954
|
+
const speaker = part.speechMetadata?.speaker;
|
|
2933
2955
|
if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
|
|
2934
2956
|
(config) => config.speaker === speaker
|
|
2935
2957
|
)) {
|
|
@@ -2943,7 +2965,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
2943
2965
|
...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
|
|
2944
2966
|
};
|
|
2945
2967
|
});
|
|
2946
|
-
} else if (
|
|
2968
|
+
} else if (googleOptions?.turns || googleOptions?.speechMetadata) {
|
|
2947
2969
|
throw new InvalidArgumentError({
|
|
2948
2970
|
argument: "providerOptions",
|
|
2949
2971
|
message: "Structured speech metadata and turns require Gemini 3.8 TTS."
|
|
@@ -3009,8 +3031,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
3009
3031
|
};
|
|
3010
3032
|
}
|
|
3011
3033
|
async doGenerate(options) {
|
|
3012
|
-
|
|
3013
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3034
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
3014
3035
|
const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
|
|
3015
3036
|
const {
|
|
3016
3037
|
value: response,
|
|
@@ -3032,11 +3053,11 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
3032
3053
|
});
|
|
3033
3054
|
let base64Audio;
|
|
3034
3055
|
let mimeType;
|
|
3035
|
-
for (const candidate of
|
|
3036
|
-
for (const part of
|
|
3037
|
-
if (
|
|
3056
|
+
for (const candidate of response.candidates ?? []) {
|
|
3057
|
+
for (const part of candidate.content?.parts ?? []) {
|
|
3058
|
+
if (part.inlineData?.data) {
|
|
3038
3059
|
base64Audio = part.inlineData.data;
|
|
3039
|
-
mimeType =
|
|
3060
|
+
mimeType = part.inlineData.mimeType ?? void 0;
|
|
3040
3061
|
break;
|
|
3041
3062
|
}
|
|
3042
3063
|
}
|
|
@@ -3044,9 +3065,9 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
3044
3065
|
break;
|
|
3045
3066
|
}
|
|
3046
3067
|
}
|
|
3047
|
-
const sampleRate =
|
|
3068
|
+
const sampleRate = parseSampleRate(mimeType) ?? DEFAULT_SAMPLE_RATE;
|
|
3048
3069
|
const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
|
|
3049
|
-
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType
|
|
3070
|
+
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType ?? "") || mimeType == null && !usesStructuredSpeech;
|
|
3050
3071
|
const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
|
|
3051
3072
|
if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
|
|
3052
3073
|
warnings.push({
|
|
@@ -3070,7 +3091,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
3070
3091
|
providerMetadata: {
|
|
3071
3092
|
google: {
|
|
3072
3093
|
sampleRate,
|
|
3073
|
-
mimeType: mimeType
|
|
3094
|
+
mimeType: mimeType ?? null
|
|
3074
3095
|
}
|
|
3075
3096
|
}
|
|
3076
3097
|
};
|
|
@@ -3300,37 +3321,36 @@ import {
|
|
|
3300
3321
|
// src/interactions/convert-google-interactions-usage.ts
|
|
3301
3322
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
3302
3323
|
function convertGoogleInteractionsUsage(usage) {
|
|
3303
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3304
3324
|
if (usage == null) {
|
|
3305
3325
|
return createNullLanguageModelUsage2();
|
|
3306
3326
|
}
|
|
3307
|
-
const totalInput =
|
|
3308
|
-
const totalOutput =
|
|
3309
|
-
const totalThought =
|
|
3310
|
-
const totalCached =
|
|
3327
|
+
const totalInput = usage.total_input_tokens ?? 0;
|
|
3328
|
+
const totalOutput = usage.total_output_tokens ?? 0;
|
|
3329
|
+
const totalThought = usage.total_thought_tokens ?? 0;
|
|
3330
|
+
const totalCached = usage.total_cached_tokens ?? 0;
|
|
3311
3331
|
return {
|
|
3312
3332
|
inputTokens: {
|
|
3313
|
-
total:
|
|
3333
|
+
total: usage.total_input_tokens ?? void 0,
|
|
3314
3334
|
noCache: usage.total_input_tokens == null ? void 0 : totalInput - totalCached,
|
|
3315
|
-
cacheRead:
|
|
3335
|
+
cacheRead: usage.total_cached_tokens ?? void 0,
|
|
3316
3336
|
cacheWrite: void 0
|
|
3317
3337
|
},
|
|
3318
3338
|
outputTokens: {
|
|
3319
3339
|
total: usage.total_output_tokens == null && usage.total_thought_tokens == null ? void 0 : totalOutput + totalThought,
|
|
3320
|
-
text:
|
|
3321
|
-
reasoning:
|
|
3340
|
+
text: usage.total_output_tokens ?? void 0,
|
|
3341
|
+
reasoning: usage.total_thought_tokens ?? void 0
|
|
3322
3342
|
},
|
|
3323
3343
|
raw: usage
|
|
3324
3344
|
};
|
|
3325
3345
|
}
|
|
3326
3346
|
function getGoogleInteractionsOutputTokensByModality(usage) {
|
|
3327
|
-
const byModality = usage
|
|
3347
|
+
const byModality = usage?.output_tokens_by_modality;
|
|
3328
3348
|
if (byModality == null) {
|
|
3329
3349
|
return void 0;
|
|
3330
3350
|
}
|
|
3331
3351
|
const result = {};
|
|
3332
3352
|
for (const entry of byModality) {
|
|
3333
|
-
if (
|
|
3353
|
+
if (entry?.modality != null && entry.tokens != null) {
|
|
3334
3354
|
result[entry.modality] = entry.tokens;
|
|
3335
3355
|
}
|
|
3336
3356
|
}
|
|
@@ -3362,7 +3382,6 @@ function annotationToSource({
|
|
|
3362
3382
|
annotation,
|
|
3363
3383
|
generateId: generateId2
|
|
3364
3384
|
}) {
|
|
3365
|
-
var _a, _b, _c, _d, _e;
|
|
3366
3385
|
switch (annotation.type) {
|
|
3367
3386
|
case "url_citation": {
|
|
3368
3387
|
const urlCitation = annotation;
|
|
@@ -3379,7 +3398,7 @@ function annotationToSource({
|
|
|
3379
3398
|
}
|
|
3380
3399
|
case "file_citation": {
|
|
3381
3400
|
const fileCitation = annotation;
|
|
3382
|
-
const uri =
|
|
3401
|
+
const uri = fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
|
|
3383
3402
|
if (uri == null || uri.length === 0) return void 0;
|
|
3384
3403
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3385
3404
|
return {
|
|
@@ -3390,14 +3409,14 @@ function annotationToSource({
|
|
|
3390
3409
|
...fileCitation.file_name != null ? { title: fileCitation.file_name } : {}
|
|
3391
3410
|
};
|
|
3392
3411
|
}
|
|
3393
|
-
const filename =
|
|
3412
|
+
const filename = fileCitation.file_name ?? basename(uri);
|
|
3394
3413
|
const mediaType = inferDocMediaType(uri);
|
|
3395
3414
|
return {
|
|
3396
3415
|
type: "source",
|
|
3397
3416
|
sourceType: "document",
|
|
3398
3417
|
id: generateId2(),
|
|
3399
3418
|
mediaType,
|
|
3400
|
-
title:
|
|
3419
|
+
title: fileCitation.file_name ?? filename ?? uri,
|
|
3401
3420
|
...filename != null ? { filename } : {}
|
|
3402
3421
|
};
|
|
3403
3422
|
}
|
|
@@ -3422,13 +3441,12 @@ function builtinToolResultToSources({
|
|
|
3422
3441
|
block,
|
|
3423
3442
|
generateId: generateId2
|
|
3424
3443
|
}) {
|
|
3425
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3426
3444
|
const sources = [];
|
|
3427
3445
|
switch (block.type) {
|
|
3428
3446
|
case "url_context_result": {
|
|
3429
|
-
const result =
|
|
3447
|
+
const result = block.result ?? [];
|
|
3430
3448
|
for (const entry of result) {
|
|
3431
|
-
if (
|
|
3449
|
+
if (entry?.url == null || entry.url.length === 0) continue;
|
|
3432
3450
|
if (entry.status != null && entry.status !== "success") continue;
|
|
3433
3451
|
sources.push({
|
|
3434
3452
|
type: "source",
|
|
@@ -3440,9 +3458,9 @@ function builtinToolResultToSources({
|
|
|
3440
3458
|
break;
|
|
3441
3459
|
}
|
|
3442
3460
|
case "google_search_result": {
|
|
3443
|
-
const result =
|
|
3461
|
+
const result = block.result ?? [];
|
|
3444
3462
|
for (const entry of result) {
|
|
3445
|
-
const url = entry
|
|
3463
|
+
const url = entry?.url;
|
|
3446
3464
|
if (url == null || url.length === 0) continue;
|
|
3447
3465
|
sources.push({
|
|
3448
3466
|
type: "source",
|
|
@@ -3455,9 +3473,9 @@ function builtinToolResultToSources({
|
|
|
3455
3473
|
break;
|
|
3456
3474
|
}
|
|
3457
3475
|
case "google_maps_result": {
|
|
3458
|
-
const result =
|
|
3476
|
+
const result = block.result ?? [];
|
|
3459
3477
|
for (const entry of result) {
|
|
3460
|
-
for (const place of
|
|
3478
|
+
for (const place of entry.places ?? []) {
|
|
3461
3479
|
if (place.url == null || place.url.length === 0) continue;
|
|
3462
3480
|
sources.push({
|
|
3463
3481
|
type: "source",
|
|
@@ -3471,11 +3489,11 @@ function builtinToolResultToSources({
|
|
|
3471
3489
|
break;
|
|
3472
3490
|
}
|
|
3473
3491
|
case "file_search_result": {
|
|
3474
|
-
const result =
|
|
3492
|
+
const result = block.result ?? [];
|
|
3475
3493
|
for (const raw of result) {
|
|
3476
3494
|
if (raw == null || typeof raw !== "object") continue;
|
|
3477
3495
|
const entry = raw;
|
|
3478
|
-
const uri =
|
|
3496
|
+
const uri = entry.url ?? entry.document_uri ?? entry.file_name;
|
|
3479
3497
|
if (uri == null || uri.length === 0) continue;
|
|
3480
3498
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3481
3499
|
sources.push({
|
|
@@ -3487,14 +3505,14 @@ function builtinToolResultToSources({
|
|
|
3487
3505
|
});
|
|
3488
3506
|
continue;
|
|
3489
3507
|
}
|
|
3490
|
-
const filename =
|
|
3508
|
+
const filename = entry.file_name ?? basename(uri);
|
|
3491
3509
|
const mediaType = inferDocMediaType(uri);
|
|
3492
3510
|
sources.push({
|
|
3493
3511
|
type: "source",
|
|
3494
3512
|
sourceType: "document",
|
|
3495
3513
|
id: generateId2(),
|
|
3496
3514
|
mediaType,
|
|
3497
|
-
title:
|
|
3515
|
+
title: entry.title ?? entry.file_name ?? filename ?? uri,
|
|
3498
3516
|
...filename != null ? { filename } : {}
|
|
3499
3517
|
});
|
|
3500
3518
|
}
|
|
@@ -3509,14 +3527,13 @@ function annotationsToSources({
|
|
|
3509
3527
|
annotations,
|
|
3510
3528
|
generateId: generateId2
|
|
3511
3529
|
}) {
|
|
3512
|
-
var _a;
|
|
3513
3530
|
if (annotations == null) return [];
|
|
3514
3531
|
const seen = /* @__PURE__ */ new Set();
|
|
3515
3532
|
const sources = [];
|
|
3516
3533
|
for (const annotation of annotations) {
|
|
3517
3534
|
const source = annotationToSource({ annotation, generateId: generateId2 });
|
|
3518
3535
|
if (source == null) continue;
|
|
3519
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${
|
|
3536
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
3520
3537
|
if (seen.has(key)) continue;
|
|
3521
3538
|
seen.add(key);
|
|
3522
3539
|
sources.push(source);
|
|
@@ -3583,15 +3600,13 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3583
3600
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
3584
3601
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
3585
3602
|
function sourceKey(source) {
|
|
3586
|
-
|
|
3587
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a = source.filename) != null ? _a : source.title}`;
|
|
3603
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
3588
3604
|
}
|
|
3589
3605
|
return new TransformStream({
|
|
3590
3606
|
start(controller) {
|
|
3591
3607
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3592
3608
|
},
|
|
3593
3609
|
transform(chunk, controller) {
|
|
3594
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
3595
3610
|
if (includeRawChunks) {
|
|
3596
3611
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3597
3612
|
}
|
|
@@ -3606,8 +3621,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3606
3621
|
case "interaction.created": {
|
|
3607
3622
|
const event = value;
|
|
3608
3623
|
const interaction = event.interaction;
|
|
3609
|
-
interactionId =
|
|
3610
|
-
const created = interaction
|
|
3624
|
+
interactionId = interaction?.id != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
3625
|
+
const created = interaction?.created;
|
|
3611
3626
|
let timestamp;
|
|
3612
3627
|
if (typeof created === "string") {
|
|
3613
3628
|
const parsed = new Date(created);
|
|
@@ -3618,7 +3633,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3618
3633
|
controller.enqueue({
|
|
3619
3634
|
type: "response-metadata",
|
|
3620
3635
|
...interactionId != null ? { id: interactionId } : {},
|
|
3621
|
-
modelId: interaction
|
|
3636
|
+
modelId: interaction?.model,
|
|
3622
3637
|
...timestamp ? { timestamp } : {}
|
|
3623
3638
|
});
|
|
3624
3639
|
break;
|
|
@@ -3627,11 +3642,11 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3627
3642
|
const event = value;
|
|
3628
3643
|
const step = event.step;
|
|
3629
3644
|
const index = event.index;
|
|
3630
|
-
const blockId = `${interactionId
|
|
3631
|
-
const stepType = step
|
|
3645
|
+
const blockId = `${interactionId ?? "interaction"}:${index}`;
|
|
3646
|
+
const stepType = step?.type;
|
|
3632
3647
|
if (stepType === "model_output") {
|
|
3633
|
-
const initial =
|
|
3634
|
-
if (
|
|
3648
|
+
const initial = step?.content?.[0];
|
|
3649
|
+
if (initial?.type === "text") {
|
|
3635
3650
|
openBlocks.set(index, {
|
|
3636
3651
|
kind: "text",
|
|
3637
3652
|
id: blockId,
|
|
@@ -3648,7 +3663,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3648
3663
|
emittedSourceKeys.add(key);
|
|
3649
3664
|
controller.enqueue(source);
|
|
3650
3665
|
}
|
|
3651
|
-
} else if (
|
|
3666
|
+
} else if (initial?.type === "image") {
|
|
3652
3667
|
openBlocks.set(index, {
|
|
3653
3668
|
kind: "image",
|
|
3654
3669
|
id: blockId,
|
|
@@ -3663,16 +3678,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3663
3678
|
});
|
|
3664
3679
|
}
|
|
3665
3680
|
} else if (stepType === "thought") {
|
|
3666
|
-
const signature = step
|
|
3681
|
+
const signature = step?.signature;
|
|
3667
3682
|
openBlocks.set(index, {
|
|
3668
3683
|
kind: "reasoning",
|
|
3669
3684
|
id: blockId,
|
|
3670
3685
|
...signature != null ? { signature } : {}
|
|
3671
3686
|
});
|
|
3672
3687
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
3673
|
-
if (Array.isArray(step
|
|
3688
|
+
if (Array.isArray(step?.summary)) {
|
|
3674
3689
|
for (const item of step.summary) {
|
|
3675
|
-
if (
|
|
3690
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
3676
3691
|
controller.enqueue({
|
|
3677
3692
|
type: "reasoning-delta",
|
|
3678
3693
|
id: blockId,
|
|
@@ -3683,12 +3698,12 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3683
3698
|
}
|
|
3684
3699
|
} else if (stepType === "processing_call" || stepType === "processing_result") {
|
|
3685
3700
|
const google = {};
|
|
3686
|
-
if (
|
|
3701
|
+
if (step?.signature != null) google.signature = step.signature;
|
|
3687
3702
|
if (interactionId != null) google.interactionId = interactionId;
|
|
3688
3703
|
if (stepType === "processing_call") {
|
|
3689
|
-
google.processingId =
|
|
3704
|
+
google.processingId = step?.id || blockId;
|
|
3690
3705
|
} else {
|
|
3691
|
-
google.processingCallId =
|
|
3706
|
+
google.processingCallId = step?.call_id || blockId;
|
|
3692
3707
|
}
|
|
3693
3708
|
openBlocks.set(index, {
|
|
3694
3709
|
kind: "custom",
|
|
@@ -3697,8 +3712,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3697
3712
|
google
|
|
3698
3713
|
});
|
|
3699
3714
|
} else if (stepType === "function_call") {
|
|
3700
|
-
const toolCallId =
|
|
3701
|
-
const toolName =
|
|
3715
|
+
const toolCallId = step?.id || blockId;
|
|
3716
|
+
const toolName = step?.name ?? "unknown";
|
|
3702
3717
|
hasFunctionCall = true;
|
|
3703
3718
|
const state = {
|
|
3704
3719
|
kind: "function_call",
|
|
@@ -3706,7 +3721,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3706
3721
|
toolCallId,
|
|
3707
3722
|
toolName,
|
|
3708
3723
|
argumentsAccum: "",
|
|
3709
|
-
...
|
|
3724
|
+
...step?.signature != null ? { signature: step.signature } : {}
|
|
3710
3725
|
};
|
|
3711
3726
|
openBlocks.set(index, state);
|
|
3712
3727
|
controller.enqueue({
|
|
@@ -3715,29 +3730,29 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3715
3730
|
toolName
|
|
3716
3731
|
});
|
|
3717
3732
|
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
3718
|
-
const toolName = stepType === "mcp_server_tool_call" ?
|
|
3719
|
-
const toolCallId =
|
|
3733
|
+
const toolName = stepType === "mcp_server_tool_call" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
3734
|
+
const toolCallId = step?.id || blockId;
|
|
3720
3735
|
const state = {
|
|
3721
3736
|
kind: "builtin_tool_call",
|
|
3722
3737
|
id: blockId,
|
|
3723
3738
|
blockType: stepType,
|
|
3724
3739
|
toolCallId,
|
|
3725
3740
|
toolName,
|
|
3726
|
-
arguments:
|
|
3741
|
+
arguments: step?.arguments ?? {},
|
|
3727
3742
|
callEmitted: false
|
|
3728
3743
|
};
|
|
3729
3744
|
openBlocks.set(index, state);
|
|
3730
3745
|
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
3731
|
-
const toolName = stepType === "mcp_server_tool_result" ?
|
|
3732
|
-
const callId =
|
|
3746
|
+
const toolName = stepType === "mcp_server_tool_result" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
3747
|
+
const callId = step?.call_id || blockId;
|
|
3733
3748
|
const state = {
|
|
3734
3749
|
kind: "builtin_tool_result",
|
|
3735
3750
|
id: blockId,
|
|
3736
3751
|
blockType: stepType,
|
|
3737
3752
|
callId,
|
|
3738
3753
|
toolName,
|
|
3739
|
-
result:
|
|
3740
|
-
...
|
|
3754
|
+
result: step?.result ?? null,
|
|
3755
|
+
...step?.is_error != null ? { isError: step.is_error } : {},
|
|
3741
3756
|
resultEmitted: false
|
|
3742
3757
|
};
|
|
3743
3758
|
openBlocks.set(index, state);
|
|
@@ -3750,7 +3765,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3750
3765
|
const event = value;
|
|
3751
3766
|
let open = openBlocks.get(event.index);
|
|
3752
3767
|
if (open == null) break;
|
|
3753
|
-
const dtype =
|
|
3768
|
+
const dtype = event.delta?.type;
|
|
3754
3769
|
if (open.kind === "pending_model_output") {
|
|
3755
3770
|
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
3756
3771
|
const promoted = {
|
|
@@ -3768,17 +3783,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3768
3783
|
const google = {};
|
|
3769
3784
|
if (interactionId != null) google.interactionId = interactionId;
|
|
3770
3785
|
const providerMetadata = Object.keys(google).length > 0 ? { google } : void 0;
|
|
3771
|
-
if (
|
|
3786
|
+
if (imageDelta?.data != null && imageDelta.data.length > 0) {
|
|
3772
3787
|
controller.enqueue({
|
|
3773
3788
|
type: "file",
|
|
3774
|
-
mediaType:
|
|
3789
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
3775
3790
|
data: { type: "data", data: imageDelta.data },
|
|
3776
3791
|
...providerMetadata ? { providerMetadata } : {}
|
|
3777
3792
|
});
|
|
3778
|
-
} else if (
|
|
3793
|
+
} else if (imageDelta?.uri != null && imageDelta.uri.length > 0) {
|
|
3779
3794
|
controller.enqueue({
|
|
3780
3795
|
type: "file",
|
|
3781
|
-
mediaType:
|
|
3796
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
3782
3797
|
data: { type: "url", url: new URL(imageDelta.uri) },
|
|
3783
3798
|
...providerMetadata ? { providerMetadata } : {}
|
|
3784
3799
|
});
|
|
@@ -3794,17 +3809,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3794
3809
|
const google = {};
|
|
3795
3810
|
if (interactionId != null) google.interactionId = interactionId;
|
|
3796
3811
|
const providerMetadata = Object.keys(google).length > 0 ? { google } : void 0;
|
|
3797
|
-
if (
|
|
3812
|
+
if (videoDelta?.data != null && videoDelta.data.length > 0) {
|
|
3798
3813
|
controller.enqueue({
|
|
3799
3814
|
type: "file",
|
|
3800
|
-
mediaType:
|
|
3815
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
3801
3816
|
data: { type: "data", data: videoDelta.data },
|
|
3802
3817
|
...providerMetadata ? { providerMetadata } : {}
|
|
3803
3818
|
});
|
|
3804
|
-
} else if (
|
|
3819
|
+
} else if (videoDelta?.uri != null && videoDelta.uri.length > 0) {
|
|
3805
3820
|
controller.enqueue({
|
|
3806
3821
|
type: "file",
|
|
3807
|
-
mediaType:
|
|
3822
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
3808
3823
|
data: { type: "url", url: new URL(videoDelta.uri) },
|
|
3809
3824
|
...providerMetadata ? { providerMetadata } : {}
|
|
3810
3825
|
});
|
|
@@ -3812,7 +3827,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3812
3827
|
break;
|
|
3813
3828
|
}
|
|
3814
3829
|
const delta = event.delta;
|
|
3815
|
-
if (open.kind === "custom" && (
|
|
3830
|
+
if (open.kind === "custom" && (delta?.type === "processing_call" || delta?.type === "processing_result")) {
|
|
3816
3831
|
if (delta.signature != null)
|
|
3817
3832
|
open.google.signature = delta.signature;
|
|
3818
3833
|
if (delta.type === "processing_call" && delta.id != null && delta.id.length > 0) {
|
|
@@ -3821,8 +3836,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3821
3836
|
if (delta.type === "processing_result" && delta.call_id != null && delta.call_id.length > 0) {
|
|
3822
3837
|
open.google.processingCallId = delta.call_id;
|
|
3823
3838
|
}
|
|
3824
|
-
} else if (open.kind === "text" &&
|
|
3825
|
-
const text =
|
|
3839
|
+
} else if (open.kind === "text" && delta?.type === "text") {
|
|
3840
|
+
const text = delta.text ?? "";
|
|
3826
3841
|
if (text.length > 0) {
|
|
3827
3842
|
controller.enqueue({
|
|
3828
3843
|
type: "text-delta",
|
|
@@ -3830,7 +3845,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3830
3845
|
delta: text
|
|
3831
3846
|
});
|
|
3832
3847
|
}
|
|
3833
|
-
} else if (open.kind === "text" && (
|
|
3848
|
+
} else if (open.kind === "text" && (delta?.type === "text_annotation" || delta?.type === "text_annotation_delta")) {
|
|
3834
3849
|
const sources = annotationsToSources({
|
|
3835
3850
|
annotations: delta.annotations,
|
|
3836
3851
|
generateId: generateId2
|
|
@@ -3842,27 +3857,27 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3842
3857
|
open.emittedSourceKeys.add(key);
|
|
3843
3858
|
controller.enqueue(source);
|
|
3844
3859
|
}
|
|
3845
|
-
} else if (open.kind === "image" &&
|
|
3860
|
+
} else if (open.kind === "image" && delta?.type === "image") {
|
|
3846
3861
|
if (delta.data != null) open.data = delta.data;
|
|
3847
3862
|
if (delta.mime_type != null) open.mimeType = delta.mime_type;
|
|
3848
3863
|
if (delta.uri != null) open.uri = delta.uri;
|
|
3849
3864
|
} else if (open.kind === "reasoning") {
|
|
3850
|
-
if (
|
|
3865
|
+
if (delta?.type === "thought_summary") {
|
|
3851
3866
|
const item = delta.content;
|
|
3852
|
-
if (
|
|
3867
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
3853
3868
|
controller.enqueue({
|
|
3854
3869
|
type: "reasoning-delta",
|
|
3855
3870
|
id: open.id,
|
|
3856
3871
|
delta: item.text
|
|
3857
3872
|
});
|
|
3858
3873
|
}
|
|
3859
|
-
} else if (
|
|
3874
|
+
} else if (delta?.type === "thought_signature") {
|
|
3860
3875
|
const signature = delta.signature;
|
|
3861
3876
|
if (signature != null) {
|
|
3862
3877
|
open.signature = signature;
|
|
3863
3878
|
}
|
|
3864
3879
|
}
|
|
3865
|
-
} else if (open.kind === "function_call" &&
|
|
3880
|
+
} else if (open.kind === "function_call" && delta?.type === "arguments_delta") {
|
|
3866
3881
|
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
3867
3882
|
if (slice.length > 0) {
|
|
3868
3883
|
open.argumentsAccum += slice;
|
|
@@ -3879,7 +3894,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3879
3894
|
open.signature = delta.signature;
|
|
3880
3895
|
}
|
|
3881
3896
|
hasFunctionCall = true;
|
|
3882
|
-
} else if (open.kind === "builtin_tool_call" &&
|
|
3897
|
+
} else if (open.kind === "builtin_tool_call" && delta?.type === open.blockType) {
|
|
3883
3898
|
if (delta.id != null && delta.id.length > 0) {
|
|
3884
3899
|
open.toolCallId = delta.id;
|
|
3885
3900
|
}
|
|
@@ -3889,7 +3904,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3889
3904
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
3890
3905
|
open.toolName = delta.name;
|
|
3891
3906
|
}
|
|
3892
|
-
} else if (open.kind === "builtin_tool_result" &&
|
|
3907
|
+
} else if (open.kind === "builtin_tool_result" && delta?.type === open.blockType) {
|
|
3893
3908
|
if (delta.call_id != null && delta.call_id.length > 0) {
|
|
3894
3909
|
open.callId = delta.call_id;
|
|
3895
3910
|
}
|
|
@@ -3929,14 +3944,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3929
3944
|
if (open.data != null && open.data.length > 0) {
|
|
3930
3945
|
controller.enqueue({
|
|
3931
3946
|
type: "file",
|
|
3932
|
-
mediaType:
|
|
3947
|
+
mediaType: open.mimeType ?? "image/png",
|
|
3933
3948
|
data: { type: "data", data: open.data },
|
|
3934
3949
|
...providerMetadata ? { providerMetadata } : {}
|
|
3935
3950
|
});
|
|
3936
3951
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
3937
3952
|
controller.enqueue({
|
|
3938
3953
|
type: "file",
|
|
3939
|
-
mediaType:
|
|
3954
|
+
mediaType: open.mimeType ?? "image/png",
|
|
3940
3955
|
data: { type: "url", url: new URL(open.uri) },
|
|
3941
3956
|
...providerMetadata ? { providerMetadata } : {}
|
|
3942
3957
|
});
|
|
@@ -3969,7 +3984,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3969
3984
|
type: "tool-call",
|
|
3970
3985
|
toolCallId: open.toolCallId,
|
|
3971
3986
|
toolName: open.toolName,
|
|
3972
|
-
input: JSON.stringify(
|
|
3987
|
+
input: JSON.stringify(open.arguments ?? {}),
|
|
3973
3988
|
providerExecuted: true
|
|
3974
3989
|
});
|
|
3975
3990
|
open.callEmitted = true;
|
|
@@ -3978,7 +3993,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3978
3993
|
type: "tool-result",
|
|
3979
3994
|
toolCallId: open.callId,
|
|
3980
3995
|
toolName: open.toolName,
|
|
3981
|
-
result:
|
|
3996
|
+
result: open.result ?? null
|
|
3982
3997
|
});
|
|
3983
3998
|
open.resultEmitted = true;
|
|
3984
3999
|
const sources = builtinToolResultToSources({
|
|
@@ -4015,16 +4030,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4015
4030
|
case "interaction.completed": {
|
|
4016
4031
|
const event = value;
|
|
4017
4032
|
const interaction = event.interaction;
|
|
4018
|
-
if (
|
|
4033
|
+
if (interaction?.id != null && interaction.id.length > 0) {
|
|
4019
4034
|
interactionId = interaction.id;
|
|
4020
4035
|
}
|
|
4021
|
-
if (
|
|
4036
|
+
if (interaction?.status != null) {
|
|
4022
4037
|
finishStatus = interaction.status;
|
|
4023
4038
|
}
|
|
4024
|
-
if (
|
|
4039
|
+
if (interaction?.usage != null) {
|
|
4025
4040
|
usage = interaction.usage;
|
|
4026
4041
|
}
|
|
4027
|
-
if (
|
|
4042
|
+
if (interaction?.service_tier != null) {
|
|
4028
4043
|
serviceTier = interaction.service_tier;
|
|
4029
4044
|
}
|
|
4030
4045
|
break;
|
|
@@ -4035,9 +4050,9 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4035
4050
|
controller.enqueue({
|
|
4036
4051
|
type: "error",
|
|
4037
4052
|
error: createProviderStreamError({
|
|
4038
|
-
message:
|
|
4053
|
+
message: event.error?.message ?? "Unknown interaction error",
|
|
4039
4054
|
type: event.event_type,
|
|
4040
|
-
code:
|
|
4055
|
+
code: event.error?.code ?? void 0,
|
|
4041
4056
|
data: event
|
|
4042
4057
|
})
|
|
4043
4058
|
});
|
|
@@ -4088,7 +4103,6 @@ function convertToGoogleInteractionsInput({
|
|
|
4088
4103
|
store,
|
|
4089
4104
|
mediaResolution
|
|
4090
4105
|
}) {
|
|
4091
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4092
4106
|
const warnings = [];
|
|
4093
4107
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
4094
4108
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -4145,7 +4159,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4145
4159
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
4146
4160
|
} else if (part.type === "reasoning") {
|
|
4147
4161
|
flushModelOutput();
|
|
4148
|
-
const signature =
|
|
4162
|
+
const signature = part.providerOptions?.google?.signature;
|
|
4149
4163
|
steps.push({
|
|
4150
4164
|
type: "thought",
|
|
4151
4165
|
...signature != null ? { signature } : {},
|
|
@@ -4162,15 +4176,15 @@ function convertToGoogleInteractionsInput({
|
|
|
4162
4176
|
}
|
|
4163
4177
|
} else if (part.type === "custom") {
|
|
4164
4178
|
flushModelOutput();
|
|
4165
|
-
const google =
|
|
4166
|
-
const signature = typeof
|
|
4167
|
-
if (part.kind === "google.processing_call" && typeof
|
|
4179
|
+
const google = part.providerOptions?.google;
|
|
4180
|
+
const signature = typeof google?.signature === "string" ? google.signature : void 0;
|
|
4181
|
+
if (part.kind === "google.processing_call" && typeof google?.processingId === "string") {
|
|
4168
4182
|
steps.push({
|
|
4169
4183
|
type: "processing_call",
|
|
4170
4184
|
id: google.processingId,
|
|
4171
4185
|
...signature != null ? { signature } : {}
|
|
4172
4186
|
});
|
|
4173
|
-
} else if (part.kind === "google.processing_result" && typeof
|
|
4187
|
+
} else if (part.kind === "google.processing_result" && typeof google?.processingCallId === "string") {
|
|
4174
4188
|
steps.push({
|
|
4175
4189
|
type: "processing_result",
|
|
4176
4190
|
call_id: google.processingCallId,
|
|
@@ -4184,8 +4198,8 @@ function convertToGoogleInteractionsInput({
|
|
|
4184
4198
|
}
|
|
4185
4199
|
} else if (part.type === "tool-call") {
|
|
4186
4200
|
flushModelOutput();
|
|
4187
|
-
const signature =
|
|
4188
|
-
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) :
|
|
4201
|
+
const signature = part.providerOptions?.google?.signature;
|
|
4202
|
+
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : part.input ?? {};
|
|
4189
4203
|
steps.push({
|
|
4190
4204
|
type: "function_call",
|
|
4191
4205
|
id: part.toolCallId,
|
|
@@ -4217,7 +4231,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4217
4231
|
toolCallId: part.toolCallId,
|
|
4218
4232
|
toolName: part.toolName,
|
|
4219
4233
|
output: part.output,
|
|
4220
|
-
signature:
|
|
4234
|
+
signature: part.providerOptions?.google?.signature,
|
|
4221
4235
|
warnings
|
|
4222
4236
|
});
|
|
4223
4237
|
content.push(block);
|
|
@@ -4310,8 +4324,7 @@ function getVideoProcessingField({
|
|
|
4310
4324
|
part,
|
|
4311
4325
|
warnings
|
|
4312
4326
|
}) {
|
|
4313
|
-
|
|
4314
|
-
const processing = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.processing;
|
|
4327
|
+
const processing = part.providerOptions?.google?.processing;
|
|
4315
4328
|
if (processing == null) {
|
|
4316
4329
|
return {};
|
|
4317
4330
|
}
|
|
@@ -4323,8 +4336,8 @@ function getVideoProcessingField({
|
|
|
4323
4336
|
return {
|
|
4324
4337
|
processing: {
|
|
4325
4338
|
type: "static",
|
|
4326
|
-
...typeof config.startOffset === "number" ? { start_offset: config.startOffset } : {},
|
|
4327
|
-
...typeof config.endOffset === "number" ? { end_offset: config.endOffset } : {},
|
|
4339
|
+
...typeof config.startOffset === "number" ? { start_offset: `${config.startOffset}s` } : {},
|
|
4340
|
+
...typeof config.endOffset === "number" ? { end_offset: `${config.endOffset}s` } : {},
|
|
4328
4341
|
...typeof config.fps === "number" ? { fps: config.fps } : {}
|
|
4329
4342
|
}
|
|
4330
4343
|
};
|
|
@@ -4344,8 +4357,7 @@ function compactPromptForPreviousInteraction({
|
|
|
4344
4357
|
for (const message of prompt) {
|
|
4345
4358
|
if (message.role === "assistant") {
|
|
4346
4359
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
4347
|
-
|
|
4348
|
-
const partInteractionId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.interactionId;
|
|
4360
|
+
const partInteractionId = part.providerOptions?.google?.interactionId;
|
|
4349
4361
|
return partInteractionId === previousInteractionId;
|
|
4350
4362
|
});
|
|
4351
4363
|
if (matchesLinkedInteraction) {
|
|
@@ -4386,7 +4398,7 @@ function safeParseToolArgs(input) {
|
|
|
4386
4398
|
return parsed;
|
|
4387
4399
|
}
|
|
4388
4400
|
return { value: parsed };
|
|
4389
|
-
} catch
|
|
4401
|
+
} catch {
|
|
4390
4402
|
return { value: input };
|
|
4391
4403
|
}
|
|
4392
4404
|
}
|
|
@@ -4397,7 +4409,6 @@ function convertToolResultPart({
|
|
|
4397
4409
|
signature,
|
|
4398
4410
|
warnings
|
|
4399
4411
|
}) {
|
|
4400
|
-
var _a;
|
|
4401
4412
|
const base = {
|
|
4402
4413
|
type: "function_result",
|
|
4403
4414
|
call_id: toolCallId,
|
|
@@ -4417,7 +4428,7 @@ function convertToolResultPart({
|
|
|
4417
4428
|
return {
|
|
4418
4429
|
...base,
|
|
4419
4430
|
is_error: true,
|
|
4420
|
-
result:
|
|
4431
|
+
result: output.reason ?? "Tool execution denied by user."
|
|
4421
4432
|
};
|
|
4422
4433
|
case "content": {
|
|
4423
4434
|
const blocks = [];
|
|
@@ -5108,7 +5119,6 @@ function parseGoogleInteractionsOutputs({
|
|
|
5108
5119
|
generateId: generateId2,
|
|
5109
5120
|
interactionId
|
|
5110
5121
|
}) {
|
|
5111
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5112
5122
|
const content = [];
|
|
5113
5123
|
let hasFunctionCall = false;
|
|
5114
5124
|
if (steps == null) {
|
|
@@ -5123,12 +5133,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
5123
5133
|
break;
|
|
5124
5134
|
}
|
|
5125
5135
|
case "model_output": {
|
|
5126
|
-
const blocks =
|
|
5136
|
+
const blocks = step.content ?? [];
|
|
5127
5137
|
for (const block of blocks) {
|
|
5128
5138
|
if (block == null || typeof block !== "object") continue;
|
|
5129
5139
|
const blockType = block.type;
|
|
5130
5140
|
if (blockType === "text") {
|
|
5131
|
-
const text =
|
|
5141
|
+
const text = block.text ?? "";
|
|
5132
5142
|
const annotations = block.annotations;
|
|
5133
5143
|
content.push({
|
|
5134
5144
|
type: "text",
|
|
@@ -5144,14 +5154,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
5144
5154
|
if (image.data != null && image.data.length > 0) {
|
|
5145
5155
|
content.push({
|
|
5146
5156
|
type: "file",
|
|
5147
|
-
mediaType:
|
|
5157
|
+
mediaType: image.mime_type ?? "image/png",
|
|
5148
5158
|
data: { type: "data", data: image.data },
|
|
5149
5159
|
...googleProviderMetadata({ interactionId })
|
|
5150
5160
|
});
|
|
5151
5161
|
} else if (image.uri != null && image.uri.length > 0) {
|
|
5152
5162
|
content.push({
|
|
5153
5163
|
type: "file",
|
|
5154
|
-
mediaType:
|
|
5164
|
+
mediaType: image.mime_type ?? "image/png",
|
|
5155
5165
|
data: { type: "url", url: new URL(image.uri) },
|
|
5156
5166
|
...googleProviderMetadata({ interactionId })
|
|
5157
5167
|
});
|
|
@@ -5161,14 +5171,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
5161
5171
|
if (video.data != null && video.data.length > 0) {
|
|
5162
5172
|
content.push({
|
|
5163
5173
|
type: "file",
|
|
5164
|
-
mediaType:
|
|
5174
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
5165
5175
|
data: { type: "data", data: video.data },
|
|
5166
5176
|
...googleProviderMetadata({ interactionId })
|
|
5167
5177
|
});
|
|
5168
5178
|
} else if (video.uri != null && video.uri.length > 0) {
|
|
5169
5179
|
content.push({
|
|
5170
5180
|
type: "file",
|
|
5171
|
-
mediaType:
|
|
5181
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
5172
5182
|
data: { type: "url", url: new URL(video.uri) },
|
|
5173
5183
|
...googleProviderMetadata({ interactionId })
|
|
5174
5184
|
});
|
|
@@ -5181,7 +5191,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5181
5191
|
const thought = step;
|
|
5182
5192
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
5183
5193
|
const text = summary.filter(
|
|
5184
|
-
(item) =>
|
|
5194
|
+
(item) => item?.type === "text" && typeof item.text === "string"
|
|
5185
5195
|
).map((item) => item.text).join("\n");
|
|
5186
5196
|
content.push({
|
|
5187
5197
|
type: "reasoning",
|
|
@@ -5228,7 +5238,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5228
5238
|
type: "tool-call",
|
|
5229
5239
|
toolCallId: call.id,
|
|
5230
5240
|
toolName: call.name,
|
|
5231
|
-
input: JSON.stringify(
|
|
5241
|
+
input: JSON.stringify(call.arguments ?? {}),
|
|
5232
5242
|
...googleProviderMetadata({
|
|
5233
5243
|
signature: call.signature,
|
|
5234
5244
|
interactionId
|
|
@@ -5239,8 +5249,8 @@ function parseGoogleInteractionsOutputs({
|
|
|
5239
5249
|
default: {
|
|
5240
5250
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
5241
5251
|
const call = step;
|
|
5242
|
-
const toolName = type === "mcp_server_tool_call" ?
|
|
5243
|
-
const input = JSON.stringify(
|
|
5252
|
+
const toolName = type === "mcp_server_tool_call" ? call.name ?? "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
5253
|
+
const input = JSON.stringify(call.arguments ?? {});
|
|
5244
5254
|
content.push({
|
|
5245
5255
|
type: "tool-call",
|
|
5246
5256
|
toolCallId: call.id || generateId2(),
|
|
@@ -5250,12 +5260,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
5250
5260
|
});
|
|
5251
5261
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
5252
5262
|
const result = step;
|
|
5253
|
-
const toolName = type === "mcp_server_tool_result" ?
|
|
5263
|
+
const toolName = type === "mcp_server_tool_result" ? result.name ?? "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
5254
5264
|
content.push({
|
|
5255
5265
|
type: "tool-result",
|
|
5256
5266
|
toolCallId: result.call_id || generateId2(),
|
|
5257
5267
|
toolName,
|
|
5258
|
-
result:
|
|
5268
|
+
result: result.result ?? null
|
|
5259
5269
|
});
|
|
5260
5270
|
const sources = builtinToolResultToSources({
|
|
5261
5271
|
block: step,
|
|
@@ -5308,9 +5318,9 @@ async function cancelGoogleInteraction({
|
|
|
5308
5318
|
});
|
|
5309
5319
|
try {
|
|
5310
5320
|
await response.text();
|
|
5311
|
-
} catch
|
|
5321
|
+
} catch {
|
|
5312
5322
|
}
|
|
5313
|
-
} catch
|
|
5323
|
+
} catch {
|
|
5314
5324
|
}
|
|
5315
5325
|
}
|
|
5316
5326
|
|
|
@@ -5343,7 +5353,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
5343
5353
|
const cancelOnServer = () => cancelGoogleInteraction({ baseURL, interactionId, headers, fetch });
|
|
5344
5354
|
try {
|
|
5345
5355
|
while (true) {
|
|
5346
|
-
if (abortSignal
|
|
5356
|
+
if (abortSignal?.aborted) {
|
|
5347
5357
|
await cancelOnServer();
|
|
5348
5358
|
throw new DOMException("Polling was aborted", "AbortError");
|
|
5349
5359
|
}
|
|
@@ -5386,9 +5396,8 @@ function prepareGoogleInteractionsTools({
|
|
|
5386
5396
|
tools,
|
|
5387
5397
|
toolChoice
|
|
5388
5398
|
}) {
|
|
5389
|
-
var _a, _b, _c, _d;
|
|
5390
5399
|
const toolWarnings = [];
|
|
5391
|
-
const normalized =
|
|
5400
|
+
const normalized = tools?.length ? tools : void 0;
|
|
5392
5401
|
if (normalized == null) {
|
|
5393
5402
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
5394
5403
|
}
|
|
@@ -5398,13 +5407,13 @@ function prepareGoogleInteractionsTools({
|
|
|
5398
5407
|
interactionsTools.push({
|
|
5399
5408
|
type: "function",
|
|
5400
5409
|
name: tool.name,
|
|
5401
|
-
description:
|
|
5410
|
+
description: tool.description ?? "",
|
|
5402
5411
|
parameters: tool.inputSchema
|
|
5403
5412
|
});
|
|
5404
5413
|
continue;
|
|
5405
5414
|
}
|
|
5406
5415
|
if (tool.type === "provider") {
|
|
5407
|
-
const args =
|
|
5416
|
+
const args = tool.args ?? {};
|
|
5408
5417
|
switch (tool.id) {
|
|
5409
5418
|
case "google.google_search": {
|
|
5410
5419
|
const searchTypesArg = args.searchTypes;
|
|
@@ -5454,7 +5463,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5454
5463
|
case "google.computer_use": {
|
|
5455
5464
|
interactionsTools.push({
|
|
5456
5465
|
type: "computer_use",
|
|
5457
|
-
environment:
|
|
5466
|
+
environment: args.environment ?? "browser",
|
|
5458
5467
|
...args.excludedPredefinedFunctions != null ? {
|
|
5459
5468
|
excludedPredefinedFunctions: args.excludedPredefinedFunctions
|
|
5460
5469
|
} : {}
|
|
@@ -5472,7 +5481,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5472
5481
|
break;
|
|
5473
5482
|
}
|
|
5474
5483
|
case "google.retrieval": {
|
|
5475
|
-
const vertexAiSearchConfig =
|
|
5484
|
+
const vertexAiSearchConfig = args.vertexAiSearchConfig ?? void 0;
|
|
5476
5485
|
interactionsTools.push({
|
|
5477
5486
|
type: "retrieval",
|
|
5478
5487
|
...args.retrievalTypes != null ? {
|
|
@@ -5676,7 +5685,7 @@ function streamGoogleInteractionEvents({
|
|
|
5676
5685
|
if (abortSignal != null) {
|
|
5677
5686
|
abortSignal.removeEventListener("abort", upstreamAbortHandler);
|
|
5678
5687
|
}
|
|
5679
|
-
currentReader
|
|
5688
|
+
currentReader?.cancel().catch(() => {
|
|
5680
5689
|
});
|
|
5681
5690
|
currentReader = void 0;
|
|
5682
5691
|
if (effectiveSignal.aborted && !complete) {
|
|
@@ -5691,7 +5700,7 @@ function streamGoogleInteractionEvents({
|
|
|
5691
5700
|
},
|
|
5692
5701
|
cancel() {
|
|
5693
5702
|
internalAbort.abort();
|
|
5694
|
-
currentReader
|
|
5703
|
+
currentReader?.cancel().catch(() => {
|
|
5695
5704
|
});
|
|
5696
5705
|
currentReader = void 0;
|
|
5697
5706
|
}
|
|
@@ -5708,7 +5717,6 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
5708
5717
|
}) {
|
|
5709
5718
|
return new ReadableStream({
|
|
5710
5719
|
start(controller) {
|
|
5711
|
-
var _a, _b, _c;
|
|
5712
5720
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5713
5721
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
5714
5722
|
let timestamp;
|
|
@@ -5722,19 +5730,19 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
5722
5730
|
controller.enqueue({
|
|
5723
5731
|
type: "response-metadata",
|
|
5724
5732
|
...interactionId != null ? { id: interactionId } : {},
|
|
5725
|
-
modelId:
|
|
5733
|
+
modelId: response.model ?? void 0,
|
|
5726
5734
|
...timestamp ? { timestamp } : {}
|
|
5727
5735
|
});
|
|
5728
5736
|
if (includeRawChunks) {
|
|
5729
5737
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
5730
5738
|
}
|
|
5731
5739
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5732
|
-
steps:
|
|
5740
|
+
steps: response.steps ?? null,
|
|
5733
5741
|
generateId: generateId2,
|
|
5734
5742
|
interactionId
|
|
5735
5743
|
});
|
|
5736
5744
|
let blockCounter = 0;
|
|
5737
|
-
const nextBlockId = () => `${interactionId
|
|
5745
|
+
const nextBlockId = () => `${interactionId ?? "agent"}:${blockCounter++}`;
|
|
5738
5746
|
for (const part of content) {
|
|
5739
5747
|
switch (part.type) {
|
|
5740
5748
|
case "text": {
|
|
@@ -5814,7 +5822,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
5814
5822
|
break;
|
|
5815
5823
|
}
|
|
5816
5824
|
}
|
|
5817
|
-
const serviceTier =
|
|
5825
|
+
const serviceTier = response.service_tier ?? headerServiceTier;
|
|
5818
5826
|
const finishReason = {
|
|
5819
5827
|
unified: mapGoogleInteractionsFinishReason({
|
|
5820
5828
|
status: response.status,
|
|
@@ -5889,7 +5897,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5889
5897
|
};
|
|
5890
5898
|
}
|
|
5891
5899
|
async getArgs(options) {
|
|
5892
|
-
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, _D, _E, _F;
|
|
5893
5900
|
const warnings = [];
|
|
5894
5901
|
const googleOptions = await parseProviderOptions3({
|
|
5895
5902
|
provider: "google",
|
|
@@ -5924,7 +5931,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5924
5931
|
warnings.push(...prepared.toolWarnings);
|
|
5925
5932
|
}
|
|
5926
5933
|
const responseFormatEntries = [];
|
|
5927
|
-
if (
|
|
5934
|
+
if (options.responseFormat?.type === "json") {
|
|
5928
5935
|
if (isAgent) {
|
|
5929
5936
|
warnings.push({
|
|
5930
5937
|
type: "other",
|
|
@@ -5939,41 +5946,41 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5939
5946
|
responseFormatEntries.push(entry);
|
|
5940
5947
|
}
|
|
5941
5948
|
}
|
|
5942
|
-
if (
|
|
5949
|
+
if (googleOptions?.responseFormat != null) {
|
|
5943
5950
|
for (const entry of googleOptions.responseFormat) {
|
|
5944
5951
|
if (entry.type === "text") {
|
|
5945
5952
|
responseFormatEntries.push(
|
|
5946
5953
|
pruneUndefined({
|
|
5947
5954
|
type: "text",
|
|
5948
|
-
mime_type:
|
|
5949
|
-
schema:
|
|
5955
|
+
mime_type: entry.mimeType ?? void 0,
|
|
5956
|
+
schema: entry.schema ?? void 0
|
|
5950
5957
|
})
|
|
5951
5958
|
);
|
|
5952
5959
|
} else if (entry.type === "image") {
|
|
5953
5960
|
responseFormatEntries.push(
|
|
5954
5961
|
pruneUndefined({
|
|
5955
5962
|
type: "image",
|
|
5956
|
-
mime_type:
|
|
5957
|
-
aspect_ratio:
|
|
5958
|
-
image_size:
|
|
5963
|
+
mime_type: entry.mimeType ?? void 0,
|
|
5964
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
5965
|
+
image_size: entry.imageSize ?? void 0
|
|
5959
5966
|
})
|
|
5960
5967
|
);
|
|
5961
5968
|
} else if (entry.type === "audio") {
|
|
5962
5969
|
responseFormatEntries.push(
|
|
5963
5970
|
pruneUndefined({
|
|
5964
5971
|
type: "audio",
|
|
5965
|
-
mime_type:
|
|
5972
|
+
mime_type: entry.mimeType ?? void 0
|
|
5966
5973
|
})
|
|
5967
5974
|
);
|
|
5968
5975
|
} else if (entry.type === "video") {
|
|
5969
5976
|
responseFormatEntries.push(
|
|
5970
5977
|
pruneUndefined({
|
|
5971
5978
|
type: "video",
|
|
5972
|
-
aspect_ratio:
|
|
5973
|
-
resolution:
|
|
5974
|
-
duration:
|
|
5975
|
-
delivery:
|
|
5976
|
-
gcs_uri:
|
|
5979
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
5980
|
+
resolution: entry.resolution ?? void 0,
|
|
5981
|
+
duration: entry.duration ?? void 0,
|
|
5982
|
+
delivery: entry.delivery ?? void 0,
|
|
5983
|
+
gcs_uri: entry.gcsUri ?? void 0
|
|
5977
5984
|
})
|
|
5978
5985
|
);
|
|
5979
5986
|
}
|
|
@@ -5985,13 +5992,13 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5985
5992
|
warnings: convWarnings
|
|
5986
5993
|
} = convertToGoogleInteractionsInput({
|
|
5987
5994
|
prompt: options.prompt,
|
|
5988
|
-
previousInteractionId:
|
|
5989
|
-
store:
|
|
5990
|
-
mediaResolution:
|
|
5995
|
+
previousInteractionId: googleOptions?.previousInteractionId ?? void 0,
|
|
5996
|
+
store: googleOptions?.store ?? void 0,
|
|
5997
|
+
mediaResolution: googleOptions?.mediaResolution ?? void 0
|
|
5991
5998
|
});
|
|
5992
5999
|
warnings.push(...convWarnings);
|
|
5993
6000
|
let systemInstruction = convertedSystemInstruction;
|
|
5994
|
-
const optionSystemInstruction =
|
|
6001
|
+
const optionSystemInstruction = googleOptions?.systemInstruction ?? void 0;
|
|
5995
6002
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
5996
6003
|
warnings.push({
|
|
5997
6004
|
type: "other",
|
|
@@ -6016,12 +6023,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6016
6023
|
}
|
|
6017
6024
|
if (options.maxOutputTokens != null)
|
|
6018
6025
|
droppedFields.push("maxOutputTokens");
|
|
6019
|
-
if (
|
|
6026
|
+
if (googleOptions?.thinkingLevel != null)
|
|
6020
6027
|
droppedFields.push("thinkingLevel");
|
|
6021
|
-
if (
|
|
6028
|
+
if (googleOptions?.thinkingSummaries != null) {
|
|
6022
6029
|
droppedFields.push("thinkingSummaries");
|
|
6023
6030
|
}
|
|
6024
|
-
if (
|
|
6031
|
+
if (googleOptions?.imageConfig != null) droppedFields.push("imageConfig");
|
|
6025
6032
|
if (droppedFields.length > 0) {
|
|
6026
6033
|
warnings.push({
|
|
6027
6034
|
type: "other",
|
|
@@ -6031,17 +6038,17 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6031
6038
|
generationConfig = void 0;
|
|
6032
6039
|
} else {
|
|
6033
6040
|
generationConfig = pruneUndefined({
|
|
6034
|
-
temperature:
|
|
6035
|
-
top_p:
|
|
6036
|
-
top_k:
|
|
6037
|
-
seed:
|
|
6041
|
+
temperature: options.temperature ?? void 0,
|
|
6042
|
+
top_p: options.topP ?? void 0,
|
|
6043
|
+
top_k: options.topK ?? void 0,
|
|
6044
|
+
seed: options.seed ?? void 0,
|
|
6038
6045
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
6039
|
-
max_output_tokens:
|
|
6040
|
-
thinking_level:
|
|
6041
|
-
thinking_summaries:
|
|
6046
|
+
max_output_tokens: options.maxOutputTokens ?? void 0,
|
|
6047
|
+
thinking_level: googleOptions?.thinkingLevel ?? void 0,
|
|
6048
|
+
thinking_summaries: googleOptions?.thinkingSummaries ?? void 0,
|
|
6042
6049
|
tool_choice: toolChoiceForBody
|
|
6043
6050
|
});
|
|
6044
|
-
if (
|
|
6051
|
+
if (googleOptions?.imageConfig != null) {
|
|
6045
6052
|
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
6046
6053
|
(entry) => entry.type === "image"
|
|
6047
6054
|
);
|
|
@@ -6060,21 +6067,21 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6060
6067
|
}
|
|
6061
6068
|
}
|
|
6062
6069
|
let agentConfig;
|
|
6063
|
-
if (isAgent &&
|
|
6070
|
+
if (isAgent && googleOptions?.agentConfig != null) {
|
|
6064
6071
|
const agentConfigOptions = googleOptions.agentConfig;
|
|
6065
6072
|
if (agentConfigOptions.type === "deep-research") {
|
|
6066
6073
|
agentConfig = pruneUndefined({
|
|
6067
6074
|
type: "deep-research",
|
|
6068
|
-
thinking_summaries:
|
|
6069
|
-
visualization:
|
|
6070
|
-
collaborative_planning:
|
|
6075
|
+
thinking_summaries: agentConfigOptions.thinkingSummaries ?? void 0,
|
|
6076
|
+
visualization: agentConfigOptions.visualization ?? void 0,
|
|
6077
|
+
collaborative_planning: agentConfigOptions.collaborativePlanning ?? void 0
|
|
6071
6078
|
});
|
|
6072
6079
|
} else if (agentConfigOptions.type === "dynamic") {
|
|
6073
6080
|
agentConfig = { type: "dynamic" };
|
|
6074
6081
|
}
|
|
6075
6082
|
}
|
|
6076
6083
|
let environment;
|
|
6077
|
-
if (
|
|
6084
|
+
if (googleOptions?.environment != null) {
|
|
6078
6085
|
if (!isAgent) {
|
|
6079
6086
|
warnings.push({
|
|
6080
6087
|
type: "other",
|
|
@@ -6084,8 +6091,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6084
6091
|
environment = googleOptions.environment;
|
|
6085
6092
|
} else {
|
|
6086
6093
|
const environmentOptions = googleOptions.environment;
|
|
6087
|
-
const sources =
|
|
6088
|
-
var _a2;
|
|
6094
|
+
const sources = environmentOptions.sources?.map((source) => {
|
|
6089
6095
|
if (source.type === "inline") {
|
|
6090
6096
|
return {
|
|
6091
6097
|
type: "inline",
|
|
@@ -6096,7 +6102,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6096
6102
|
return pruneUndefined({
|
|
6097
6103
|
type: source.type,
|
|
6098
6104
|
source: source.source,
|
|
6099
|
-
target:
|
|
6105
|
+
target: source.target ?? void 0
|
|
6100
6106
|
});
|
|
6101
6107
|
});
|
|
6102
6108
|
let network;
|
|
@@ -6105,13 +6111,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6105
6111
|
} else if (environmentOptions.network != null) {
|
|
6106
6112
|
network = {
|
|
6107
6113
|
allowlist: environmentOptions.network.allowlist.map(
|
|
6108
|
-
(entry) => {
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
transform: (_a2 = entry.transform) != null ? _a2 : void 0
|
|
6113
|
-
});
|
|
6114
|
-
}
|
|
6114
|
+
(entry) => pruneUndefined({
|
|
6115
|
+
domain: entry.domain,
|
|
6116
|
+
transform: entry.transform ?? void 0
|
|
6117
|
+
})
|
|
6115
6118
|
)
|
|
6116
6119
|
};
|
|
6117
6120
|
}
|
|
@@ -6128,25 +6131,24 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6128
6131
|
system_instruction: systemInstruction,
|
|
6129
6132
|
tools: toolsForBody,
|
|
6130
6133
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
6131
|
-
response_modalities:
|
|
6132
|
-
previous_interaction_id:
|
|
6133
|
-
service_tier:
|
|
6134
|
-
store:
|
|
6134
|
+
response_modalities: googleOptions?.responseModalities != null ? googleOptions.responseModalities : void 0,
|
|
6135
|
+
previous_interaction_id: googleOptions?.previousInteractionId ?? void 0,
|
|
6136
|
+
service_tier: googleOptions?.serviceTier ?? void 0,
|
|
6137
|
+
store: googleOptions?.store ?? void 0,
|
|
6135
6138
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
6136
6139
|
agent_config: agentConfig,
|
|
6137
6140
|
environment,
|
|
6138
|
-
background:
|
|
6141
|
+
background: googleOptions?.background ?? void 0
|
|
6139
6142
|
});
|
|
6140
6143
|
return {
|
|
6141
6144
|
args,
|
|
6142
6145
|
warnings,
|
|
6143
6146
|
isAgent,
|
|
6144
|
-
isBackground:
|
|
6145
|
-
pollingTimeoutMs:
|
|
6147
|
+
isBackground: googleOptions?.background === true,
|
|
6148
|
+
pollingTimeoutMs: googleOptions?.pollingTimeoutMs ?? void 0
|
|
6146
6149
|
};
|
|
6147
6150
|
}
|
|
6148
6151
|
async doGenerate(options) {
|
|
6149
|
-
var _a, _b, _c, _d, _e, _f;
|
|
6150
6152
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6151
6153
|
const url = `${this.config.baseURL}/interactions`;
|
|
6152
6154
|
const mergedHeaders = combineHeaders4(
|
|
@@ -6180,12 +6182,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6180
6182
|
});
|
|
6181
6183
|
response = polled.response;
|
|
6182
6184
|
rawResponse = polled.rawResponse;
|
|
6183
|
-
responseHeaders =
|
|
6185
|
+
responseHeaders = polled.responseHeaders ?? responseHeaders;
|
|
6184
6186
|
}
|
|
6185
6187
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6186
6188
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
6187
|
-
steps:
|
|
6188
|
-
generateId:
|
|
6189
|
+
steps: response.steps ?? null,
|
|
6190
|
+
generateId: this.config.generateId ?? defaultGenerateId,
|
|
6189
6191
|
interactionId
|
|
6190
6192
|
});
|
|
6191
6193
|
const finishReason = {
|
|
@@ -6195,7 +6197,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6195
6197
|
}),
|
|
6196
6198
|
raw: response.status
|
|
6197
6199
|
};
|
|
6198
|
-
const serviceTier =
|
|
6200
|
+
const serviceTier = response.service_tier ?? responseHeaders?.["x-gemini-service-tier"] ?? void 0;
|
|
6199
6201
|
const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
|
|
6200
6202
|
response.usage
|
|
6201
6203
|
);
|
|
@@ -6225,12 +6227,11 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6225
6227
|
body: rawResponse,
|
|
6226
6228
|
...interactionId != null ? { id: interactionId } : {},
|
|
6227
6229
|
...timestamp ? { timestamp } : {},
|
|
6228
|
-
modelId:
|
|
6230
|
+
modelId: response.model ?? void 0
|
|
6229
6231
|
}
|
|
6230
6232
|
};
|
|
6231
6233
|
}
|
|
6232
6234
|
async doStream(options) {
|
|
6233
|
-
var _a;
|
|
6234
6235
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6235
6236
|
const url = `${this.config.baseURL}/interactions`;
|
|
6236
6237
|
const mergedHeaders = combineHeaders4(
|
|
@@ -6259,10 +6260,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6259
6260
|
abortSignal: options.abortSignal,
|
|
6260
6261
|
fetch: this.config.fetch
|
|
6261
6262
|
});
|
|
6262
|
-
const headerServiceTier = responseHeaders
|
|
6263
|
+
const headerServiceTier = responseHeaders?.["x-gemini-service-tier"];
|
|
6263
6264
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6264
6265
|
warnings,
|
|
6265
|
-
generateId:
|
|
6266
|
+
generateId: this.config.generateId ?? defaultGenerateId,
|
|
6266
6267
|
includeRawChunks: options.includeRawChunks,
|
|
6267
6268
|
serviceTier: headerServiceTier
|
|
6268
6269
|
});
|
|
@@ -6298,7 +6299,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6298
6299
|
options,
|
|
6299
6300
|
pollingTimeoutMs
|
|
6300
6301
|
}) {
|
|
6301
|
-
var _a, _b;
|
|
6302
6302
|
const postResult = await postJsonToApi3({
|
|
6303
6303
|
url,
|
|
6304
6304
|
headers: mergedHeaders,
|
|
@@ -6317,12 +6317,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6317
6317
|
"google.interactions: background POST response did not include an interaction id; cannot stream the result."
|
|
6318
6318
|
);
|
|
6319
6319
|
}
|
|
6320
|
-
const headerServiceTier = postHeaders
|
|
6320
|
+
const headerServiceTier = postHeaders?.["x-gemini-service-tier"];
|
|
6321
6321
|
if (isTerminalStatus(postResponse.status)) {
|
|
6322
6322
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
6323
6323
|
response: postResponse,
|
|
6324
6324
|
warnings,
|
|
6325
|
-
generateId:
|
|
6325
|
+
generateId: this.config.generateId ?? defaultGenerateId,
|
|
6326
6326
|
includeRawChunks: options.includeRawChunks,
|
|
6327
6327
|
headerServiceTier
|
|
6328
6328
|
});
|
|
@@ -6342,7 +6342,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6342
6342
|
});
|
|
6343
6343
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6344
6344
|
warnings,
|
|
6345
|
-
generateId:
|
|
6345
|
+
generateId: this.config.generateId ?? defaultGenerateId,
|
|
6346
6346
|
includeRawChunks: options.includeRawChunks,
|
|
6347
6347
|
serviceTier: headerServiceTier
|
|
6348
6348
|
});
|