@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/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { Experimental_EvaluationLanguageModel as EvaluationLanguageModel } from "@ai-sdk/provider-utils/experimental-evaluation";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "4.0.
|
|
11
|
+
var VERSION = true ? "4.0.82" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/google-embedding-model.ts
|
|
14
14
|
import {
|
|
@@ -126,8 +126,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
126
126
|
this.maxEmbeddingsPerCall = 100;
|
|
127
127
|
this.supportsParallelCalls = true;
|
|
128
128
|
this[_a] = ({ providerOptions, values, startIndex, endIndex }) => {
|
|
129
|
-
|
|
130
|
-
const multimodalContent = (_a2 = providerOptions == null ? void 0 : providerOptions.google) == null ? void 0 : _a2.content;
|
|
129
|
+
const multimodalContent = providerOptions?.google?.content;
|
|
131
130
|
if (!Array.isArray(multimodalContent)) {
|
|
132
131
|
return providerOptions;
|
|
133
132
|
}
|
|
@@ -138,7 +137,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
138
137
|
return {
|
|
139
138
|
...providerOptions,
|
|
140
139
|
google: {
|
|
141
|
-
...providerOptions
|
|
140
|
+
...providerOptions?.google,
|
|
142
141
|
content: multimodalContent.slice(startIndex, endIndex)
|
|
143
142
|
}
|
|
144
143
|
};
|
|
@@ -181,10 +180,10 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
181
180
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
182
181
|
headers
|
|
183
182
|
);
|
|
184
|
-
const multimodalContent = googleOptions
|
|
183
|
+
const multimodalContent = googleOptions?.content;
|
|
185
184
|
validateMultimodalContentLength({ multimodalContent, values });
|
|
186
185
|
if (values.length === 1) {
|
|
187
|
-
const valueParts = multimodalContent
|
|
186
|
+
const valueParts = multimodalContent?.[0];
|
|
188
187
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
189
188
|
const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
|
|
190
189
|
const {
|
|
@@ -199,8 +198,8 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
199
198
|
content: {
|
|
200
199
|
parts
|
|
201
200
|
},
|
|
202
|
-
outputDimensionality: googleOptions
|
|
203
|
-
taskType: googleOptions
|
|
201
|
+
outputDimensionality: googleOptions?.outputDimensionality,
|
|
202
|
+
taskType: googleOptions?.taskType
|
|
204
203
|
},
|
|
205
204
|
failedResponseHandler: googleFailedResponseHandler,
|
|
206
205
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -225,7 +224,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
225
224
|
headers: mergedHeaders,
|
|
226
225
|
body: {
|
|
227
226
|
requests: values.map((value, index) => {
|
|
228
|
-
const valueParts = multimodalContent
|
|
227
|
+
const valueParts = multimodalContent?.[index];
|
|
229
228
|
const textPart = value ? [{ text: value }] : [];
|
|
230
229
|
return {
|
|
231
230
|
model: `models/${this.modelId}`,
|
|
@@ -233,8 +232,8 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
233
232
|
role: "user",
|
|
234
233
|
parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
|
|
235
234
|
},
|
|
236
|
-
outputDimensionality: googleOptions
|
|
237
|
-
taskType: googleOptions
|
|
235
|
+
outputDimensionality: googleOptions?.outputDimensionality,
|
|
236
|
+
taskType: googleOptions?.taskType
|
|
238
237
|
};
|
|
239
238
|
})
|
|
240
239
|
},
|
|
@@ -332,15 +331,14 @@ import { z as z6 } from "zod/v4";
|
|
|
332
331
|
// src/convert-google-usage.ts
|
|
333
332
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
334
333
|
function convertGoogleUsage(usage) {
|
|
335
|
-
var _a2, _b, _c, _d, _e;
|
|
336
334
|
if (usage == null) {
|
|
337
335
|
return createNullLanguageModelUsage();
|
|
338
336
|
}
|
|
339
|
-
const promptTokens =
|
|
340
|
-
const candidatesTokens =
|
|
341
|
-
const toolUsePromptTokens =
|
|
342
|
-
const cachedContentTokens =
|
|
343
|
-
const thoughtsTokens =
|
|
337
|
+
const promptTokens = usage.promptTokenCount ?? 0;
|
|
338
|
+
const candidatesTokens = usage.candidatesTokenCount ?? 0;
|
|
339
|
+
const toolUsePromptTokens = usage.toolUsePromptTokenCount ?? 0;
|
|
340
|
+
const cachedContentTokens = usage.cachedContentTokenCount ?? 0;
|
|
341
|
+
const thoughtsTokens = usage.thoughtsTokenCount ?? 0;
|
|
344
342
|
const inputTokens = promptTokens + toolUsePromptTokens;
|
|
345
343
|
return {
|
|
346
344
|
inputTokens: {
|
|
@@ -366,6 +364,7 @@ import {
|
|
|
366
364
|
convertToBase64,
|
|
367
365
|
getTopLevelMediaType,
|
|
368
366
|
isFullMediaType,
|
|
367
|
+
isUrlSupported,
|
|
369
368
|
resolveFullMediaType,
|
|
370
369
|
resolveProviderReference,
|
|
371
370
|
secureJsonParse
|
|
@@ -427,7 +426,7 @@ function containsJSONSchemaReference(value) {
|
|
|
427
426
|
function serializeFunctionResponseContent(value) {
|
|
428
427
|
return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
|
|
429
428
|
}
|
|
430
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
429
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedUrls = {}) {
|
|
431
430
|
const functionResponseParts = [];
|
|
432
431
|
const responseTextParts = [];
|
|
433
432
|
for (const contentPart of outputValue) {
|
|
@@ -445,11 +444,22 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
|
|
|
445
444
|
}
|
|
446
445
|
});
|
|
447
446
|
} else if (contentPart.data.type === "url") {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (
|
|
452
|
-
functionResponseParts.push(
|
|
447
|
+
const url = contentPart.data.url.toString();
|
|
448
|
+
const convertedUrlPart = convertUrlToolResultPart(url);
|
|
449
|
+
const supportedUrl = contentPart.data.url.protocol === "gs:" && contentPart.data.originalUrl != null ? contentPart.data.originalUrl : url;
|
|
450
|
+
if (convertedUrlPart != null) {
|
|
451
|
+
functionResponseParts.push(convertedUrlPart);
|
|
452
|
+
} else if (isFullMediaType(contentPart.mediaType) && isUrlSupported({
|
|
453
|
+
url: supportedUrl,
|
|
454
|
+
mediaType: contentPart.mediaType,
|
|
455
|
+
supportedUrls
|
|
456
|
+
})) {
|
|
457
|
+
functionResponseParts.push({
|
|
458
|
+
fileData: {
|
|
459
|
+
mimeType: contentPart.mediaType,
|
|
460
|
+
fileUri: supportedUrl
|
|
461
|
+
}
|
|
462
|
+
});
|
|
453
463
|
} else {
|
|
454
464
|
responseTextParts.push(JSON.stringify(contentPart));
|
|
455
465
|
}
|
|
@@ -517,17 +527,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
517
527
|
}
|
|
518
528
|
}
|
|
519
529
|
function convertToGoogleMessages(prompt, options) {
|
|
520
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
521
530
|
const systemInstructionParts = [];
|
|
522
531
|
const contents = [];
|
|
523
532
|
let systemMessagesAllowed = true;
|
|
524
|
-
const isGemmaModel =
|
|
525
|
-
const isGemini3Model =
|
|
526
|
-
const onWarning = options
|
|
527
|
-
const providerOptionsNames =
|
|
533
|
+
const isGemmaModel = options?.isGemmaModel ?? false;
|
|
534
|
+
const isGemini3Model = options?.isGemini3Model ?? false;
|
|
535
|
+
const onWarning = options?.onWarning;
|
|
536
|
+
const providerOptionsNames = options?.providerOptionsNames ?? ["google"];
|
|
528
537
|
const isVertexLike = !providerOptionsNames.includes("google");
|
|
529
|
-
const supportsFunctionResponseParts =
|
|
530
|
-
const includeFunctionCallIds =
|
|
538
|
+
const supportsFunctionResponseParts = options?.supportsFunctionResponseParts ?? true;
|
|
539
|
+
const includeFunctionCallIds = options?.includeFunctionCallIds ?? true;
|
|
540
|
+
const supportedFunctionResponseUrls = options?.supportedFunctionResponseUrls ?? {};
|
|
531
541
|
let sentinelInjected = false;
|
|
532
542
|
const missingSignatureToolNames = [];
|
|
533
543
|
const injectSkipSignature = (toolName) => {
|
|
@@ -536,15 +546,14 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
536
546
|
return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
537
547
|
};
|
|
538
548
|
const readProviderOpts = (part) => {
|
|
539
|
-
var _a3, _b2, _c2, _d2, _e2;
|
|
540
549
|
for (const name of providerOptionsNames) {
|
|
541
|
-
const v =
|
|
550
|
+
const v = part.providerOptions?.[name];
|
|
542
551
|
if (v != null) return v;
|
|
543
552
|
}
|
|
544
553
|
if (isVertexLike) {
|
|
545
|
-
return
|
|
554
|
+
return part.providerOptions?.google;
|
|
546
555
|
}
|
|
547
|
-
return
|
|
556
|
+
return part.providerOptions?.googleVertex ?? part.providerOptions?.vertex;
|
|
548
557
|
};
|
|
549
558
|
for (const { role, content } of prompt) {
|
|
550
559
|
switch (role) {
|
|
@@ -629,7 +638,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
629
638
|
role: "model",
|
|
630
639
|
parts: content.map((part) => {
|
|
631
640
|
const providerOpts = readProviderOpts(part);
|
|
632
|
-
const thoughtSignature =
|
|
641
|
+
const thoughtSignature = providerOpts?.thoughtSignature != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
633
642
|
switch (part.type) {
|
|
634
643
|
case "text": {
|
|
635
644
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -685,7 +694,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
685
694
|
provider: "google"
|
|
686
695
|
})
|
|
687
696
|
},
|
|
688
|
-
...
|
|
697
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
689
698
|
thoughtSignature
|
|
690
699
|
};
|
|
691
700
|
}
|
|
@@ -697,7 +706,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
697
706
|
new TextEncoder().encode(part.data.text)
|
|
698
707
|
)
|
|
699
708
|
},
|
|
700
|
-
...
|
|
709
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
701
710
|
thoughtSignature
|
|
702
711
|
};
|
|
703
712
|
}
|
|
@@ -707,7 +716,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
707
716
|
mimeType: part.mediaType,
|
|
708
717
|
data: convertToBase64(part.data.data)
|
|
709
718
|
},
|
|
710
|
-
...
|
|
719
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
711
720
|
thoughtSignature
|
|
712
721
|
};
|
|
713
722
|
}
|
|
@@ -722,8 +731,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
722
731
|
)
|
|
723
732
|
};
|
|
724
733
|
}
|
|
725
|
-
const serverToolCallId =
|
|
726
|
-
const serverToolType =
|
|
734
|
+
const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
735
|
+
const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
|
|
727
736
|
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
728
737
|
const shouldSkipMissingSignatureMitigation = (
|
|
729
738
|
// Gemini 3 returns a single signature for a parallel
|
|
@@ -732,7 +741,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
732
741
|
// model response legitimately have no signature.
|
|
733
742
|
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
734
743
|
);
|
|
735
|
-
const effectiveThoughtSignature = thoughtSignature
|
|
744
|
+
const effectiveThoughtSignature = thoughtSignature ?? (isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0);
|
|
736
745
|
if (!isServerToolCall && thoughtSignature != null) {
|
|
737
746
|
modelResponseHasSignedFunctionCall = true;
|
|
738
747
|
}
|
|
@@ -763,8 +772,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
763
772
|
)
|
|
764
773
|
};
|
|
765
774
|
}
|
|
766
|
-
const serverToolCallId =
|
|
767
|
-
const serverToolType =
|
|
775
|
+
const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
776
|
+
const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
|
|
768
777
|
if (serverToolCallId && serverToolType) {
|
|
769
778
|
return {
|
|
770
779
|
toolResponse: {
|
|
@@ -790,10 +799,10 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
790
799
|
continue;
|
|
791
800
|
}
|
|
792
801
|
const partProviderOpts = readProviderOpts(part);
|
|
793
|
-
const serverToolCallId =
|
|
794
|
-
const serverToolType =
|
|
802
|
+
const serverToolCallId = partProviderOpts?.serverToolCallId != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
803
|
+
const serverToolType = partProviderOpts?.serverToolType != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
795
804
|
if (serverToolCallId && serverToolType) {
|
|
796
|
-
const serverThoughtSignature =
|
|
805
|
+
const serverThoughtSignature = partProviderOpts?.thoughtSignature != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
797
806
|
if (contents.length > 0) {
|
|
798
807
|
const lastContent = contents[contents.length - 1];
|
|
799
808
|
if (lastContent.role === "model") {
|
|
@@ -817,7 +826,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
817
826
|
part.toolName,
|
|
818
827
|
output.value,
|
|
819
828
|
part.toolCallId,
|
|
820
|
-
includeFunctionCallIds
|
|
829
|
+
includeFunctionCallIds,
|
|
830
|
+
supportedFunctionResponseUrls
|
|
821
831
|
);
|
|
822
832
|
} else {
|
|
823
833
|
appendLegacyToolResultParts(
|
|
@@ -835,7 +845,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
835
845
|
name: part.toolName,
|
|
836
846
|
response: {
|
|
837
847
|
name: part.toolName,
|
|
838
|
-
content: output.type === "execution-denied" ?
|
|
848
|
+
content: output.type === "execution-denied" ? output.reason ?? "Tool call execution denied." : serializeFunctionResponseContent(output.value)
|
|
839
849
|
}
|
|
840
850
|
}
|
|
841
851
|
});
|
|
@@ -870,11 +880,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
870
880
|
import {
|
|
871
881
|
detectMediaType,
|
|
872
882
|
downloadBlob,
|
|
873
|
-
isFullMediaType as isFullMediaType2
|
|
883
|
+
isFullMediaType as isFullMediaType2,
|
|
884
|
+
isUrlSupported as isUrlSupported2
|
|
874
885
|
} from "@ai-sdk/provider-utils";
|
|
875
886
|
async function downloadToolResultFiles(prompt, {
|
|
876
887
|
abortSignal,
|
|
877
|
-
maxBytes
|
|
888
|
+
maxBytes,
|
|
889
|
+
supportedUrls = {}
|
|
878
890
|
}) {
|
|
879
891
|
const result = [];
|
|
880
892
|
for (const message of prompt) {
|
|
@@ -886,7 +898,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
886
898
|
...part,
|
|
887
899
|
output: await downloadToolResultOutput(part.output, {
|
|
888
900
|
abortSignal,
|
|
889
|
-
maxBytes
|
|
901
|
+
maxBytes,
|
|
902
|
+
supportedUrls
|
|
890
903
|
})
|
|
891
904
|
} : part
|
|
892
905
|
);
|
|
@@ -905,7 +918,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
905
918
|
...part,
|
|
906
919
|
output: await downloadToolResultOutput(part.output, {
|
|
907
920
|
abortSignal,
|
|
908
|
-
maxBytes
|
|
921
|
+
maxBytes,
|
|
922
|
+
supportedUrls
|
|
909
923
|
})
|
|
910
924
|
});
|
|
911
925
|
}
|
|
@@ -918,7 +932,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
918
932
|
}
|
|
919
933
|
async function downloadToolResultOutput(output, {
|
|
920
934
|
abortSignal,
|
|
921
|
-
maxBytes
|
|
935
|
+
maxBytes,
|
|
936
|
+
supportedUrls
|
|
922
937
|
}) {
|
|
923
938
|
if (output.type !== "content") {
|
|
924
939
|
return output;
|
|
@@ -929,6 +944,14 @@ async function downloadToolResultOutput(output, {
|
|
|
929
944
|
value.push(part);
|
|
930
945
|
continue;
|
|
931
946
|
}
|
|
947
|
+
if (isUrlSupported2({
|
|
948
|
+
url: part.data.url.toString(),
|
|
949
|
+
mediaType: part.mediaType,
|
|
950
|
+
supportedUrls
|
|
951
|
+
})) {
|
|
952
|
+
value.push(part);
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
932
955
|
const blob = await downloadBlob(part.data.url.toString(), {
|
|
933
956
|
abortSignal,
|
|
934
957
|
maxBytes
|
|
@@ -941,7 +964,7 @@ async function downloadToolResultOutput(output, {
|
|
|
941
964
|
value.push({
|
|
942
965
|
...part,
|
|
943
966
|
data: { type: "data", data },
|
|
944
|
-
mediaType: detectedMediaType
|
|
967
|
+
mediaType: detectedMediaType ?? (blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType)
|
|
945
968
|
});
|
|
946
969
|
}
|
|
947
970
|
return {
|
|
@@ -1210,7 +1233,7 @@ function prepareTools({
|
|
|
1210
1233
|
modelId,
|
|
1211
1234
|
isVertexProvider = false
|
|
1212
1235
|
}) {
|
|
1213
|
-
tools =
|
|
1236
|
+
tools = tools?.length ? tools : void 0;
|
|
1214
1237
|
const toolWarnings = [];
|
|
1215
1238
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1216
1239
|
if (tools == null) {
|
|
@@ -1439,10 +1462,9 @@ function prepareTools({
|
|
|
1439
1462
|
}
|
|
1440
1463
|
}
|
|
1441
1464
|
function prepareFunctionDeclaration(tool) {
|
|
1442
|
-
var _a2;
|
|
1443
1465
|
return {
|
|
1444
1466
|
name: tool.name,
|
|
1445
|
-
description:
|
|
1467
|
+
description: tool.description ?? "",
|
|
1446
1468
|
parametersJsonSchema: tool.inputSchema
|
|
1447
1469
|
};
|
|
1448
1470
|
}
|
|
@@ -1681,8 +1703,7 @@ function setNestedValue(obj, segments, value) {
|
|
|
1681
1703
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1682
1704
|
}
|
|
1683
1705
|
function resolvePartialArgValue(arg) {
|
|
1684
|
-
|
|
1685
|
-
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1706
|
+
const value = arg.stringValue ?? arg.numberValue ?? arg.boolValue;
|
|
1686
1707
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1687
1708
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1688
1709
|
}
|
|
@@ -1721,13 +1742,19 @@ var configurableSafetySettingCategories = [
|
|
|
1721
1742
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1722
1743
|
];
|
|
1723
1744
|
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1745
|
+
var googleCloudStorageFunctionResponseUrls = {
|
|
1746
|
+
"image/png": [/^gs:\/\/.*$/],
|
|
1747
|
+
"image/jpeg": [/^gs:\/\/.*$/],
|
|
1748
|
+
"image/webp": [/^gs:\/\/.*$/],
|
|
1749
|
+
"application/pdf": [/^gs:\/\/.*$/],
|
|
1750
|
+
"text/plain": [/^gs:\/\/.*$/]
|
|
1751
|
+
};
|
|
1724
1752
|
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
1725
1753
|
constructor(modelId, config) {
|
|
1726
1754
|
this.specificationVersion = "v4";
|
|
1727
|
-
var _a2;
|
|
1728
1755
|
this.modelId = modelId;
|
|
1729
1756
|
this.config = config;
|
|
1730
|
-
this.generateId =
|
|
1757
|
+
this.generateId = config.generateId ?? generateId;
|
|
1731
1758
|
}
|
|
1732
1759
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
1733
1760
|
return serializeModelOptions2({
|
|
@@ -1742,8 +1769,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1742
1769
|
return this.config.provider;
|
|
1743
1770
|
}
|
|
1744
1771
|
get supportedUrls() {
|
|
1745
|
-
|
|
1746
|
-
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1772
|
+
return this.config.supportedUrls?.() ?? {};
|
|
1747
1773
|
}
|
|
1748
1774
|
static async prepareRequest({
|
|
1749
1775
|
modelId,
|
|
@@ -1767,7 +1793,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1767
1793
|
},
|
|
1768
1794
|
isStreaming = false
|
|
1769
1795
|
}) {
|
|
1770
|
-
var _a2, _b, _c;
|
|
1771
1796
|
const warnings = [];
|
|
1772
1797
|
const providerOptionsNames = config.provider.includes(
|
|
1773
1798
|
"vertex"
|
|
@@ -1789,33 +1814,33 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1789
1814
|
});
|
|
1790
1815
|
}
|
|
1791
1816
|
const isVertexProvider = config.provider.startsWith("google.vertex.");
|
|
1792
|
-
if (
|
|
1817
|
+
if (tools?.some(
|
|
1793
1818
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
1794
|
-
)
|
|
1819
|
+
) && !isVertexProvider) {
|
|
1795
1820
|
warnings.push({
|
|
1796
1821
|
type: "other",
|
|
1797
1822
|
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}).`
|
|
1798
1823
|
});
|
|
1799
1824
|
}
|
|
1800
|
-
if (
|
|
1825
|
+
if (googleOptions?.streamFunctionCallArguments && !isVertexProvider) {
|
|
1801
1826
|
warnings.push({
|
|
1802
1827
|
type: "other",
|
|
1803
1828
|
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`
|
|
1804
1829
|
});
|
|
1805
1830
|
}
|
|
1806
|
-
if (
|
|
1831
|
+
if (googleOptions?.serviceTier && isVertexProvider) {
|
|
1807
1832
|
warnings.push({
|
|
1808
1833
|
type: "other",
|
|
1809
1834
|
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"
|
|
1810
1835
|
});
|
|
1811
1836
|
}
|
|
1812
|
-
if ((
|
|
1837
|
+
if ((googleOptions?.sharedRequestType || googleOptions?.requestType) && !isVertexProvider) {
|
|
1813
1838
|
warnings.push({
|
|
1814
1839
|
type: "other",
|
|
1815
1840
|
message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${config.provider}).`
|
|
1816
1841
|
});
|
|
1817
1842
|
}
|
|
1818
|
-
const vertexPaygoHeaders = isVertexProvider && (
|
|
1843
|
+
const vertexPaygoHeaders = isVertexProvider && (googleOptions?.sharedRequestType || googleOptions?.requestType) ? {
|
|
1819
1844
|
...googleOptions.sharedRequestType && {
|
|
1820
1845
|
"X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
|
|
1821
1846
|
},
|
|
@@ -1823,8 +1848,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1823
1848
|
"X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
|
|
1824
1849
|
}
|
|
1825
1850
|
} : void 0;
|
|
1826
|
-
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions
|
|
1827
|
-
let imageConfig = googleOptions
|
|
1851
|
+
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions?.serviceTier;
|
|
1852
|
+
let imageConfig = googleOptions?.imageConfig;
|
|
1828
1853
|
if (imageConfig != null && !isVertexProvider) {
|
|
1829
1854
|
const {
|
|
1830
1855
|
personGeneration,
|
|
@@ -1860,9 +1885,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1860
1885
|
});
|
|
1861
1886
|
}
|
|
1862
1887
|
const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1888
|
+
const supportedFunctionResponseUrls = usesGemini3Features && config.downloadToolResultFiles?.supportsGoogleCloudStorageUrls ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
1863
1889
|
const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
|
|
1864
1890
|
abortSignal,
|
|
1865
|
-
maxBytes: config.downloadToolResultFiles.maxBytes
|
|
1891
|
+
maxBytes: config.downloadToolResultFiles.maxBytes,
|
|
1892
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
1866
1893
|
}) : prompt;
|
|
1867
1894
|
const { contents, systemInstruction } = convertToGoogleMessages(
|
|
1868
1895
|
promptWithDownloadedToolResultFiles,
|
|
@@ -1872,7 +1899,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1872
1899
|
onWarning: (warning) => warnings.push(warning),
|
|
1873
1900
|
providerOptionsNames,
|
|
1874
1901
|
supportsFunctionResponseParts: usesGemini3Features,
|
|
1875
|
-
includeFunctionCallIds: !isVertexProvider
|
|
1902
|
+
includeFunctionCallIds: !isVertexProvider,
|
|
1903
|
+
supportedFunctionResponseUrls
|
|
1876
1904
|
}
|
|
1877
1905
|
);
|
|
1878
1906
|
const {
|
|
@@ -1896,22 +1924,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1896
1924
|
modelId,
|
|
1897
1925
|
warnings
|
|
1898
1926
|
});
|
|
1899
|
-
const thinkingConfig =
|
|
1900
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ?
|
|
1901
|
-
const safetyThreshold = googleOptions
|
|
1902
|
-
const safetySettings =
|
|
1927
|
+
const thinkingConfig = googleOptions?.thinkingConfig || resolvedThinking ? { ...resolvedThinking, ...googleOptions?.thinkingConfig } : void 0;
|
|
1928
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? googleOptions?.streamFunctionCallArguments ?? false : void 0;
|
|
1929
|
+
const safetyThreshold = googleOptions?.threshold;
|
|
1930
|
+
const safetySettings = googleOptions?.safetySettings ?? (safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
1903
1931
|
category,
|
|
1904
1932
|
threshold: safetyThreshold
|
|
1905
|
-
})) : void 0;
|
|
1906
|
-
const toolConfig = googleToolConfig || streamFunctionCallArguments ||
|
|
1933
|
+
})) : void 0);
|
|
1934
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || googleOptions?.retrievalConfig ? {
|
|
1907
1935
|
...googleToolConfig,
|
|
1908
1936
|
...streamFunctionCallArguments && {
|
|
1909
1937
|
functionCallingConfig: {
|
|
1910
|
-
...googleToolConfig
|
|
1938
|
+
...googleToolConfig?.functionCallingConfig,
|
|
1911
1939
|
streamFunctionCallArguments: true
|
|
1912
1940
|
}
|
|
1913
1941
|
},
|
|
1914
|
-
...
|
|
1942
|
+
...googleOptions?.retrievalConfig && {
|
|
1915
1943
|
retrievalConfig: googleOptions.retrievalConfig
|
|
1916
1944
|
}
|
|
1917
1945
|
} : void 0;
|
|
@@ -1928,18 +1956,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1928
1956
|
stopSequences,
|
|
1929
1957
|
seed,
|
|
1930
1958
|
// response format:
|
|
1931
|
-
responseMimeType:
|
|
1932
|
-
responseJsonSchema:
|
|
1959
|
+
responseMimeType: responseFormat?.type === "json" ? "application/json" : void 0,
|
|
1960
|
+
responseJsonSchema: responseFormat?.type === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
|
|
1933
1961
|
// responseJsonSchema, so this is needed as an escape hatch:
|
|
1934
1962
|
// TODO convert into provider option
|
|
1935
|
-
(
|
|
1936
|
-
...
|
|
1963
|
+
(googleOptions?.structuredOutputs ?? true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
|
|
1964
|
+
...googleOptions?.audioTimestamp && {
|
|
1937
1965
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1938
1966
|
},
|
|
1939
1967
|
// provider options:
|
|
1940
|
-
responseModalities: googleOptions
|
|
1968
|
+
responseModalities: googleOptions?.responseModalities,
|
|
1941
1969
|
thinkingConfig,
|
|
1942
|
-
...
|
|
1970
|
+
...googleOptions?.mediaResolution && {
|
|
1943
1971
|
mediaResolution: googleOptions.mediaResolution
|
|
1944
1972
|
},
|
|
1945
1973
|
...imageConfig && { imageConfig }
|
|
@@ -1949,8 +1977,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1949
1977
|
safetySettings,
|
|
1950
1978
|
tools: googleTools2,
|
|
1951
1979
|
toolConfig,
|
|
1952
|
-
cachedContent: googleOptions
|
|
1953
|
-
labels: googleOptions
|
|
1980
|
+
cachedContent: googleOptions?.cachedContent,
|
|
1981
|
+
labels: googleOptions?.labels,
|
|
1954
1982
|
serviceTier: bodyServiceTier
|
|
1955
1983
|
},
|
|
1956
1984
|
warnings: [...warnings, ...toolWarnings],
|
|
@@ -1974,30 +2002,29 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1974
2002
|
providerOptionsNames,
|
|
1975
2003
|
toolNameMapping
|
|
1976
2004
|
}) {
|
|
1977
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1978
2005
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1979
2006
|
providerOptionsNames.map((name) => [name, payload])
|
|
1980
2007
|
);
|
|
1981
|
-
const candidate =
|
|
1982
|
-
const promptBlockReason =
|
|
2008
|
+
const candidate = response.candidates?.[0];
|
|
2009
|
+
const promptBlockReason = response.promptFeedback?.blockReason;
|
|
1983
2010
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1984
2011
|
promptBlockReason
|
|
1985
2012
|
) ? promptBlockReason : void 0;
|
|
1986
|
-
const isPromptBlocked =
|
|
1987
|
-
const rawFinishReason =
|
|
2013
|
+
const isPromptBlocked = candidate?.finishReason == null && confirmedPromptBlockReason != null;
|
|
2014
|
+
const rawFinishReason = candidate?.finishReason ?? confirmedPromptBlockReason;
|
|
1988
2015
|
const content = [];
|
|
1989
|
-
const parts =
|
|
2016
|
+
const parts = candidate?.content?.parts ?? [];
|
|
1990
2017
|
const usageMetadata = response.usageMetadata;
|
|
1991
2018
|
let lastCodeExecutionToolCallId;
|
|
1992
2019
|
let lastServerToolCallId;
|
|
1993
2020
|
for (const part of parts) {
|
|
1994
|
-
if ("executableCode" in part &&
|
|
2021
|
+
if ("executableCode" in part && part.executableCode?.code) {
|
|
1995
2022
|
const toolCallId = config.generateId();
|
|
1996
2023
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1997
2024
|
content.push({
|
|
1998
2025
|
type: "tool-call",
|
|
1999
2026
|
toolCallId,
|
|
2000
|
-
toolName:
|
|
2027
|
+
toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
|
|
2001
2028
|
input: JSON.stringify(part.executableCode),
|
|
2002
2029
|
providerExecuted: true
|
|
2003
2030
|
});
|
|
@@ -2006,10 +2033,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2006
2033
|
type: "tool-result",
|
|
2007
2034
|
// Results correspond to the most recent executable code part.
|
|
2008
2035
|
toolCallId: lastCodeExecutionToolCallId,
|
|
2009
|
-
toolName:
|
|
2036
|
+
toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
|
|
2010
2037
|
result: {
|
|
2011
2038
|
outcome: part.codeExecutionResult.outcome,
|
|
2012
|
-
output:
|
|
2039
|
+
output: part.codeExecutionResult.output ?? ""
|
|
2013
2040
|
}
|
|
2014
2041
|
});
|
|
2015
2042
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2033,7 +2060,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2033
2060
|
type: "tool-call",
|
|
2034
2061
|
toolCallId: part.functionCall.id || config.generateId(),
|
|
2035
2062
|
toolName: part.functionCall.name,
|
|
2036
|
-
input: JSON.stringify(
|
|
2063
|
+
input: JSON.stringify(part.functionCall.args ?? {}),
|
|
2037
2064
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2038
2065
|
thoughtSignature: part.thoughtSignature
|
|
2039
2066
|
}) : void 0
|
|
@@ -2056,7 +2083,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2056
2083
|
type: "tool-call",
|
|
2057
2084
|
toolCallId,
|
|
2058
2085
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2059
|
-
input: JSON.stringify(
|
|
2086
|
+
input: JSON.stringify(part.toolCall.args ?? {}),
|
|
2060
2087
|
providerExecuted: true,
|
|
2061
2088
|
dynamic: true,
|
|
2062
2089
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -2074,7 +2101,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2074
2101
|
type: "tool-result",
|
|
2075
2102
|
toolCallId: responseToolCallId,
|
|
2076
2103
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2077
|
-
result:
|
|
2104
|
+
result: part.toolResponse.response ?? {},
|
|
2078
2105
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2079
2106
|
thoughtSignature: part.thoughtSignature,
|
|
2080
2107
|
serverToolCallId: responseToolCallId,
|
|
@@ -2087,10 +2114,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2087
2114
|
lastServerToolCallId = void 0;
|
|
2088
2115
|
}
|
|
2089
2116
|
}
|
|
2090
|
-
const sources =
|
|
2091
|
-
groundingMetadata: candidate
|
|
2117
|
+
const sources = extractSources({
|
|
2118
|
+
groundingMetadata: candidate?.groundingMetadata,
|
|
2092
2119
|
generateId: config.generateId
|
|
2093
|
-
})
|
|
2120
|
+
}) ?? [];
|
|
2094
2121
|
for (const source of sources) {
|
|
2095
2122
|
content.push(source);
|
|
2096
2123
|
}
|
|
@@ -2109,17 +2136,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2109
2136
|
usage: convertGoogleUsage(usageMetadata),
|
|
2110
2137
|
warnings,
|
|
2111
2138
|
providerMetadata: wrapProviderMetadata({
|
|
2112
|
-
promptFeedback:
|
|
2113
|
-
groundingMetadata:
|
|
2114
|
-
urlContextMetadata:
|
|
2115
|
-
safetyRatings:
|
|
2116
|
-
usageMetadata: usageMetadata
|
|
2117
|
-
finishMessage:
|
|
2118
|
-
serviceTier:
|
|
2139
|
+
promptFeedback: response.promptFeedback ?? null,
|
|
2140
|
+
groundingMetadata: candidate?.groundingMetadata ?? null,
|
|
2141
|
+
urlContextMetadata: candidate?.urlContextMetadata ?? null,
|
|
2142
|
+
safetyRatings: candidate?.safetyRatings ?? null,
|
|
2143
|
+
usageMetadata: usageMetadata ?? null,
|
|
2144
|
+
finishMessage: candidate?.finishMessage ?? null,
|
|
2145
|
+
serviceTier: usageMetadata?.serviceTier ?? null
|
|
2119
2146
|
}),
|
|
2120
2147
|
response: {
|
|
2121
2148
|
// TODO timestamp, model id
|
|
2122
|
-
id:
|
|
2149
|
+
id: response.responseId ?? void 0
|
|
2123
2150
|
}
|
|
2124
2151
|
};
|
|
2125
2152
|
}
|
|
@@ -2251,7 +2278,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2251
2278
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2252
2279
|
},
|
|
2253
2280
|
transform(chunk, controller) {
|
|
2254
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2255
2281
|
if (options.includeRawChunks) {
|
|
2256
2282
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2257
2283
|
}
|
|
@@ -2281,7 +2307,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2281
2307
|
};
|
|
2282
2308
|
}
|
|
2283
2309
|
}
|
|
2284
|
-
const candidate =
|
|
2310
|
+
const candidate = value.candidates?.[0];
|
|
2285
2311
|
if (candidate != null) {
|
|
2286
2312
|
if (candidate.groundingMetadata != null) {
|
|
2287
2313
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2313,9 +2339,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2313
2339
|
}
|
|
2314
2340
|
}
|
|
2315
2341
|
if (content != null) {
|
|
2316
|
-
const parts =
|
|
2342
|
+
const parts = content.parts ?? [];
|
|
2317
2343
|
for (const part of parts) {
|
|
2318
|
-
if ("executableCode" in part &&
|
|
2344
|
+
if ("executableCode" in part && part.executableCode?.code) {
|
|
2319
2345
|
const toolCallId = generateId4();
|
|
2320
2346
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2321
2347
|
controller.enqueue({
|
|
@@ -2334,7 +2360,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2334
2360
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2335
2361
|
result: {
|
|
2336
2362
|
outcome: part.codeExecutionResult.outcome,
|
|
2337
|
-
output:
|
|
2363
|
+
output: part.codeExecutionResult.output ?? ""
|
|
2338
2364
|
}
|
|
2339
2365
|
});
|
|
2340
2366
|
}
|
|
@@ -2434,7 +2460,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2434
2460
|
type: "tool-call",
|
|
2435
2461
|
toolCallId,
|
|
2436
2462
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2437
|
-
input: JSON.stringify(
|
|
2463
|
+
input: JSON.stringify(part.toolCall.args ?? {}),
|
|
2438
2464
|
providerExecuted: true,
|
|
2439
2465
|
dynamic: true,
|
|
2440
2466
|
providerMetadata: serverMeta
|
|
@@ -2450,7 +2476,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2450
2476
|
type: "tool-result",
|
|
2451
2477
|
toolCallId: responseToolCallId,
|
|
2452
2478
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2453
|
-
result:
|
|
2479
|
+
result: part.toolResponse.response ?? {},
|
|
2454
2480
|
providerMetadata: serverMeta
|
|
2455
2481
|
});
|
|
2456
2482
|
lastServerToolCallId = void 0;
|
|
@@ -2517,7 +2543,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2517
2543
|
} else if (isCompleteCall) {
|
|
2518
2544
|
const toolCallId = part.functionCall.id || generateId4();
|
|
2519
2545
|
const toolName = part.functionCall.name;
|
|
2520
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify(
|
|
2546
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify(part.functionCall.args ?? {});
|
|
2521
2547
|
controller.enqueue({
|
|
2522
2548
|
type: "tool-input-start",
|
|
2523
2549
|
id: toolCallId,
|
|
@@ -2579,7 +2605,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2579
2605
|
}
|
|
2580
2606
|
},
|
|
2581
2607
|
flush(controller) {
|
|
2582
|
-
var _a2;
|
|
2583
2608
|
if (currentTextBlockId !== null) {
|
|
2584
2609
|
controller.enqueue({
|
|
2585
2610
|
type: "text-end",
|
|
@@ -2601,9 +2626,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2601
2626
|
groundingMetadata: lastGroundingMetadata,
|
|
2602
2627
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2603
2628
|
safetyRatings: lastSafetyRatings,
|
|
2604
|
-
usageMetadata: usage
|
|
2629
|
+
usageMetadata: usage ?? null,
|
|
2605
2630
|
finishMessage: lastFinishMessage,
|
|
2606
|
-
serviceTier:
|
|
2631
|
+
serviceTier: usage?.serviceTier ?? null
|
|
2607
2632
|
})
|
|
2608
2633
|
});
|
|
2609
2634
|
}
|
|
@@ -2663,13 +2688,12 @@ function resolveGemini3ThinkingConfig({
|
|
|
2663
2688
|
return { thinkingLevel };
|
|
2664
2689
|
}
|
|
2665
2690
|
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2666
|
-
|
|
2667
|
-
const modelName = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase();
|
|
2691
|
+
const modelName = modelId.split("/").at(-1)?.toLowerCase();
|
|
2668
2692
|
if (modelName === "gemini-flash-latest") {
|
|
2669
2693
|
return "low";
|
|
2670
2694
|
}
|
|
2671
2695
|
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(
|
|
2672
|
-
modelName
|
|
2696
|
+
modelName ?? ""
|
|
2673
2697
|
);
|
|
2674
2698
|
if (versionMatch == null) {
|
|
2675
2699
|
return "minimal";
|
|
@@ -2702,8 +2726,7 @@ function extractSources({
|
|
|
2702
2726
|
groundingMetadata,
|
|
2703
2727
|
generateId: generateId4
|
|
2704
2728
|
}) {
|
|
2705
|
-
|
|
2706
|
-
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2729
|
+
if (!groundingMetadata?.groundingChunks) {
|
|
2707
2730
|
return void 0;
|
|
2708
2731
|
}
|
|
2709
2732
|
const sources = [];
|
|
@@ -2714,7 +2737,7 @@ function extractSources({
|
|
|
2714
2737
|
sourceType: "url",
|
|
2715
2738
|
id: generateId4(),
|
|
2716
2739
|
url: chunk.web.uri,
|
|
2717
|
-
title:
|
|
2740
|
+
title: chunk.web.title ?? void 0
|
|
2718
2741
|
});
|
|
2719
2742
|
} else if (chunk.image != null) {
|
|
2720
2743
|
sources.push({
|
|
@@ -2724,7 +2747,7 @@ function extractSources({
|
|
|
2724
2747
|
// Google requires attribution to the source URI, not the actual image URI.
|
|
2725
2748
|
// TODO: add another type in v7 to allow both the image and source URL to be included separately
|
|
2726
2749
|
url: chunk.image.sourceUri,
|
|
2727
|
-
title:
|
|
2750
|
+
title: chunk.image.title ?? void 0
|
|
2728
2751
|
});
|
|
2729
2752
|
} else if (chunk.retrievedContext != null) {
|
|
2730
2753
|
const uri = chunk.retrievedContext.uri;
|
|
@@ -2735,10 +2758,10 @@ function extractSources({
|
|
|
2735
2758
|
sourceType: "url",
|
|
2736
2759
|
id: generateId4(),
|
|
2737
2760
|
url: uri,
|
|
2738
|
-
title:
|
|
2761
|
+
title: chunk.retrievedContext.title ?? void 0
|
|
2739
2762
|
});
|
|
2740
2763
|
} else if (uri) {
|
|
2741
|
-
const title =
|
|
2764
|
+
const title = chunk.retrievedContext.title ?? "Unknown Document";
|
|
2742
2765
|
let mediaType = "application/octet-stream";
|
|
2743
2766
|
let filename = void 0;
|
|
2744
2767
|
if (uri.endsWith(".pdf")) {
|
|
@@ -2768,7 +2791,7 @@ function extractSources({
|
|
|
2768
2791
|
filename
|
|
2769
2792
|
});
|
|
2770
2793
|
} else if (fileSearchStore) {
|
|
2771
|
-
const title =
|
|
2794
|
+
const title = chunk.retrievedContext.title ?? "Unknown Document";
|
|
2772
2795
|
sources.push({
|
|
2773
2796
|
type: "source",
|
|
2774
2797
|
sourceType: "document",
|
|
@@ -2785,7 +2808,7 @@ function extractSources({
|
|
|
2785
2808
|
sourceType: "url",
|
|
2786
2809
|
id: generateId4(),
|
|
2787
2810
|
url: chunk.maps.uri,
|
|
2788
|
-
title:
|
|
2811
|
+
title: chunk.maps.title ?? void 0
|
|
2789
2812
|
});
|
|
2790
2813
|
}
|
|
2791
2814
|
}
|
|
@@ -3132,11 +3155,10 @@ var googleBatchResponsePreviewSchema = lazySchema8(
|
|
|
3132
3155
|
var GoogleBatch = class {
|
|
3133
3156
|
constructor(options) {
|
|
3134
3157
|
this.specificationVersion = "v4";
|
|
3135
|
-
var _a2;
|
|
3136
3158
|
this.provider = options.provider;
|
|
3137
3159
|
this.batchConfig = options.config;
|
|
3138
3160
|
this.supportedUrls = options.supportedUrls;
|
|
3139
|
-
this.batchGenerateId =
|
|
3161
|
+
this.batchGenerateId = options.config.generateId ?? generateId2;
|
|
3140
3162
|
}
|
|
3141
3163
|
async doStartBatch(options) {
|
|
3142
3164
|
assertSupportedBatchRequests(options.requests);
|
|
@@ -3331,7 +3353,6 @@ var GoogleBatch = class {
|
|
|
3331
3353
|
return {};
|
|
3332
3354
|
}
|
|
3333
3355
|
async doListBatches(options) {
|
|
3334
|
-
var _a2;
|
|
3335
3356
|
const url = new URL(`${this.batchConfig.baseURL}/batches`);
|
|
3336
3357
|
if (options.limit != null) {
|
|
3337
3358
|
url.searchParams.set("pageSize", String(options.limit));
|
|
@@ -3351,7 +3372,7 @@ var GoogleBatch = class {
|
|
|
3351
3372
|
validateUrl: false
|
|
3352
3373
|
});
|
|
3353
3374
|
return {
|
|
3354
|
-
batches: (
|
|
3375
|
+
batches: (page.operations ?? []).map((operation) => ({
|
|
3355
3376
|
batchId: operation.name,
|
|
3356
3377
|
...convertGoogleBatchStatus(operation)
|
|
3357
3378
|
})),
|
|
@@ -3359,7 +3380,6 @@ var GoogleBatch = class {
|
|
|
3359
3380
|
};
|
|
3360
3381
|
}
|
|
3361
3382
|
async doGetBatchResults(options) {
|
|
3362
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3363
3383
|
const operation = await this.retrieveBatch(options);
|
|
3364
3384
|
const batchStatus = convertGoogleBatchStatus(operation);
|
|
3365
3385
|
if (batchStatus.status === "pending") {
|
|
@@ -3368,7 +3388,7 @@ var GoogleBatch = class {
|
|
|
3368
3388
|
message: `Google batch "${options.batchId}" is not complete.`
|
|
3369
3389
|
});
|
|
3370
3390
|
}
|
|
3371
|
-
const inlinedResponses =
|
|
3391
|
+
const inlinedResponses = operation.metadata?.output?.inlinedResponses?.inlinedResponses ?? operation.response?.inlinedResponses?.inlinedResponses;
|
|
3372
3392
|
if (inlinedResponses != null) {
|
|
3373
3393
|
return convertAsyncIteratorToReadableStream(
|
|
3374
3394
|
this.iterateBatchResults(
|
|
@@ -3380,7 +3400,7 @@ var GoogleBatch = class {
|
|
|
3380
3400
|
)
|
|
3381
3401
|
);
|
|
3382
3402
|
}
|
|
3383
|
-
const responsesFile =
|
|
3403
|
+
const responsesFile = operation.metadata?.output?.responsesFile ?? operation.response?.responsesFile;
|
|
3384
3404
|
if (responsesFile == null) {
|
|
3385
3405
|
if (batchStatus.status === "completed") {
|
|
3386
3406
|
throw new InvalidResponseDataError({
|
|
@@ -3425,7 +3445,6 @@ var GoogleBatch = class {
|
|
|
3425
3445
|
return operation;
|
|
3426
3446
|
}
|
|
3427
3447
|
async *iterateBatchResults(results) {
|
|
3428
|
-
var _a2, _b, _c;
|
|
3429
3448
|
for await (const line of results) {
|
|
3430
3449
|
if (line.error != null) {
|
|
3431
3450
|
const error = convertGoogleRpcError(
|
|
@@ -3453,8 +3472,8 @@ var GoogleBatch = class {
|
|
|
3453
3472
|
schema: googleBatchResponsePreviewSchema
|
|
3454
3473
|
});
|
|
3455
3474
|
if (preview.success && (preview.value.candidates == null || preview.value.candidates.length === 0)) {
|
|
3456
|
-
const promptFeedback =
|
|
3457
|
-
const blockReason =
|
|
3475
|
+
const promptFeedback = preview.value.promptFeedback ?? void 0;
|
|
3476
|
+
const blockReason = promptFeedback?.blockReason ?? void 0;
|
|
3458
3477
|
yield {
|
|
3459
3478
|
type: "text",
|
|
3460
3479
|
id: line.key,
|
|
@@ -3468,7 +3487,7 @@ var GoogleBatch = class {
|
|
|
3468
3487
|
providerMetadata: {
|
|
3469
3488
|
google: {
|
|
3470
3489
|
promptFeedback: {
|
|
3471
|
-
blockReason:
|
|
3490
|
+
blockReason: promptFeedback.blockReason ?? null
|
|
3472
3491
|
}
|
|
3473
3492
|
}
|
|
3474
3493
|
}
|
|
@@ -3527,7 +3546,6 @@ var GoogleBatch = class {
|
|
|
3527
3546
|
}
|
|
3528
3547
|
}
|
|
3529
3548
|
async prepareImageRequest(request) {
|
|
3530
|
-
var _a2;
|
|
3531
3549
|
const { prompt, n, size, aspectRatio, seed, files, mask, providerOptions } = request.options;
|
|
3532
3550
|
const warnings = [];
|
|
3533
3551
|
if (mask != null) {
|
|
@@ -3549,7 +3567,7 @@ var GoogleBatch = class {
|
|
|
3549
3567
|
}
|
|
3550
3568
|
const userContent = [];
|
|
3551
3569
|
if (prompt != null) userContent.push({ type: "text", text: prompt });
|
|
3552
|
-
for (const file of files
|
|
3570
|
+
for (const file of files ?? []) {
|
|
3553
3571
|
userContent.push(
|
|
3554
3572
|
file.type === "url" ? {
|
|
3555
3573
|
type: "file",
|
|
@@ -3571,11 +3589,11 @@ var GoogleBatch = class {
|
|
|
3571
3589
|
responseModalities: _responseModalities,
|
|
3572
3590
|
imageConfig: userImageConfig,
|
|
3573
3591
|
...passthroughGoogleOptions
|
|
3574
|
-
} =
|
|
3592
|
+
} = await parseProviderOptions3({
|
|
3575
3593
|
provider: "google",
|
|
3576
3594
|
providerOptions,
|
|
3577
3595
|
schema: googleLanguageModelOptions
|
|
3578
|
-
})
|
|
3596
|
+
}) ?? {};
|
|
3579
3597
|
const preparedGoogleOptions = await parseProviderOptions3({
|
|
3580
3598
|
provider: "google",
|
|
3581
3599
|
providerOptions: {
|
|
@@ -3597,9 +3615,9 @@ var GoogleBatch = class {
|
|
|
3597
3615
|
prompt: [{ role: "user", content: userContent }],
|
|
3598
3616
|
seed,
|
|
3599
3617
|
providerOptions: {
|
|
3600
|
-
google: preparedGoogleOptions
|
|
3618
|
+
google: preparedGoogleOptions ?? { responseModalities: ["IMAGE"] }
|
|
3601
3619
|
},
|
|
3602
|
-
tools:
|
|
3620
|
+
tools: googleImageOptions?.googleSearch != null ? [
|
|
3603
3621
|
{
|
|
3604
3622
|
type: "provider",
|
|
3605
3623
|
id: "google.google_search",
|
|
@@ -3622,17 +3640,16 @@ var GoogleBatch = class {
|
|
|
3622
3640
|
}
|
|
3623
3641
|
};
|
|
3624
3642
|
function convertGoogleBatchStatus(operation) {
|
|
3625
|
-
|
|
3626
|
-
const rawStatus = (_b = (_a2 = operation.metadata) == null ? void 0 : _a2.state) != null ? _b : void 0;
|
|
3643
|
+
const rawStatus = operation.metadata?.state ?? void 0;
|
|
3627
3644
|
const requestCounts = convertGoogleRequestCounts(
|
|
3628
|
-
|
|
3645
|
+
operation.metadata?.batchStats
|
|
3629
3646
|
);
|
|
3630
|
-
const createdAt =
|
|
3647
|
+
const createdAt = operation.metadata?.createTime ?? void 0;
|
|
3631
3648
|
const error = operation.error != null ? convertGoogleRpcError(operation.error, "Google batch failed.") : void 0;
|
|
3632
3649
|
return {
|
|
3633
3650
|
status: mapGoogleBatchStatus({
|
|
3634
3651
|
rawStatus,
|
|
3635
|
-
done:
|
|
3652
|
+
done: operation.done ?? void 0,
|
|
3636
3653
|
hasError: error != null
|
|
3637
3654
|
}),
|
|
3638
3655
|
...rawStatus != null ? { rawStatus } : {},
|
|
@@ -3668,11 +3685,10 @@ function mapGoogleBatchStatus({
|
|
|
3668
3685
|
}
|
|
3669
3686
|
}
|
|
3670
3687
|
function convertGoogleRequestCounts(counts) {
|
|
3671
|
-
|
|
3672
|
-
const
|
|
3673
|
-
const
|
|
3674
|
-
const
|
|
3675
|
-
const pending = parseCount((_c = counts == null ? void 0 : counts.pendingRequestCount) != null ? _c : 0);
|
|
3688
|
+
const total = parseCount(counts?.requestCount);
|
|
3689
|
+
const completed = parseCount(counts?.successfulRequestCount ?? 0);
|
|
3690
|
+
const failed = parseCount(counts?.failedRequestCount ?? 0);
|
|
3691
|
+
const pending = parseCount(counts?.pendingRequestCount ?? 0);
|
|
3676
3692
|
return normalizeBatchRequestCounts({
|
|
3677
3693
|
total,
|
|
3678
3694
|
pending,
|
|
@@ -3685,9 +3701,8 @@ function parseCount(value) {
|
|
|
3685
3701
|
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
|
|
3686
3702
|
}
|
|
3687
3703
|
function convertGoogleRpcError(error, fallbackMessage) {
|
|
3688
|
-
var _a2;
|
|
3689
3704
|
return {
|
|
3690
|
-
message:
|
|
3705
|
+
message: error.message ?? fallbackMessage,
|
|
3691
3706
|
...error.status != null ? { type: error.status } : {},
|
|
3692
3707
|
...error.code != null ? { code: String(error.code) } : {}
|
|
3693
3708
|
};
|
|
@@ -3705,8 +3720,7 @@ var googleUploadUrlResponseHandler = async ({
|
|
|
3705
3720
|
return { value: uploadUrl };
|
|
3706
3721
|
};
|
|
3707
3722
|
function getGoogleBatchModelId(requests) {
|
|
3708
|
-
|
|
3709
|
-
const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
|
|
3723
|
+
const modelId = requests[0]?.modelId;
|
|
3710
3724
|
if (modelId == null) {
|
|
3711
3725
|
throw new InvalidArgumentError({
|
|
3712
3726
|
argument: "requests",
|
|
@@ -3724,12 +3738,11 @@ function getGoogleBatchModelId(requests) {
|
|
|
3724
3738
|
return modelId;
|
|
3725
3739
|
}
|
|
3726
3740
|
function convertGoogleImageBatchResult(result) {
|
|
3727
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
3728
3741
|
const images = result.content.flatMap(
|
|
3729
3742
|
(part) => part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data" ? [convertToBase642(part.data.data)] : []
|
|
3730
3743
|
);
|
|
3731
3744
|
if (images.length === 0) return void 0;
|
|
3732
|
-
const googleMetadata =
|
|
3745
|
+
const googleMetadata = result.providerMetadata?.google ?? {};
|
|
3733
3746
|
return {
|
|
3734
3747
|
images,
|
|
3735
3748
|
warnings: result.warnings,
|
|
@@ -3738,13 +3751,13 @@ function convertGoogleImageBatchResult(result) {
|
|
|
3738
3751
|
},
|
|
3739
3752
|
response: {
|
|
3740
3753
|
timestamp: /* @__PURE__ */ new Date(),
|
|
3741
|
-
modelId:
|
|
3742
|
-
headers:
|
|
3754
|
+
modelId: result.response?.modelId ?? "",
|
|
3755
|
+
headers: result.response?.headers
|
|
3743
3756
|
},
|
|
3744
3757
|
usage: {
|
|
3745
3758
|
inputTokens: result.usage.inputTokens.total,
|
|
3746
3759
|
outputTokens: result.usage.outputTokens.total,
|
|
3747
|
-
totalTokens: (
|
|
3760
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
3748
3761
|
}
|
|
3749
3762
|
};
|
|
3750
3763
|
}
|
|
@@ -3925,7 +3938,6 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3925
3938
|
return this.config.provider;
|
|
3926
3939
|
}
|
|
3927
3940
|
async doGenerate(options) {
|
|
3928
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3929
3941
|
if (!this.modelId.startsWith("gemini-")) {
|
|
3930
3942
|
throw new Error(
|
|
3931
3943
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -3992,13 +4004,13 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3992
4004
|
responseModalities: _strippedResponseModalities,
|
|
3993
4005
|
imageConfig: userImageConfig,
|
|
3994
4006
|
...passthroughGoogleOptions
|
|
3995
|
-
} =
|
|
4007
|
+
} = providerOptions?.google ?? {};
|
|
3996
4008
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
3997
4009
|
provider: this.config.provider,
|
|
3998
4010
|
baseURL: this.config.baseURL,
|
|
3999
|
-
headers:
|
|
4011
|
+
headers: this.config.headers ?? {},
|
|
4000
4012
|
fetch: this.config.fetch,
|
|
4001
|
-
generateId:
|
|
4013
|
+
generateId: this.config.generateId ?? defaultGenerateId
|
|
4002
4014
|
});
|
|
4003
4015
|
const result = await languageModel.doGenerate({
|
|
4004
4016
|
prompt: languageModelPrompt,
|
|
@@ -4015,7 +4027,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4015
4027
|
} : void 0
|
|
4016
4028
|
}
|
|
4017
4029
|
},
|
|
4018
|
-
tools:
|
|
4030
|
+
tools: googleImageOptions?.googleSearch != null ? [
|
|
4019
4031
|
{
|
|
4020
4032
|
type: "provider",
|
|
4021
4033
|
id: "google.google_search",
|
|
@@ -4026,14 +4038,14 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4026
4038
|
headers,
|
|
4027
4039
|
abortSignal
|
|
4028
4040
|
});
|
|
4029
|
-
const currentDate =
|
|
4041
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4030
4042
|
const images = [];
|
|
4031
4043
|
for (const part of result.content) {
|
|
4032
4044
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
4033
4045
|
images.push(convertToBase643(part.data.data));
|
|
4034
4046
|
}
|
|
4035
4047
|
}
|
|
4036
|
-
const languageModelGoogleMetadata =
|
|
4048
|
+
const languageModelGoogleMetadata = result.providerMetadata?.google ?? {};
|
|
4037
4049
|
return {
|
|
4038
4050
|
images,
|
|
4039
4051
|
...result.finishReason.unified === "content-filter" ? { isRetryable: false } : {},
|
|
@@ -4041,19 +4053,19 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4041
4053
|
providerMetadata: {
|
|
4042
4054
|
google: {
|
|
4043
4055
|
...languageModelGoogleMetadata,
|
|
4044
|
-
finishReason:
|
|
4056
|
+
finishReason: result.finishReason.raw ?? null,
|
|
4045
4057
|
images: images.map(() => ({}))
|
|
4046
4058
|
}
|
|
4047
4059
|
},
|
|
4048
4060
|
response: {
|
|
4049
4061
|
timestamp: currentDate,
|
|
4050
4062
|
modelId: this.modelId,
|
|
4051
|
-
headers:
|
|
4063
|
+
headers: result.response?.headers
|
|
4052
4064
|
},
|
|
4053
4065
|
usage: result.usage ? {
|
|
4054
4066
|
inputTokens: result.usage.inputTokens.total,
|
|
4055
4067
|
outputTokens: result.usage.outputTokens.total,
|
|
4056
|
-
totalTokens: (
|
|
4068
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
4057
4069
|
} : void 0
|
|
4058
4070
|
};
|
|
4059
4071
|
}
|
|
@@ -4087,7 +4099,6 @@ var GoogleFiles = class {
|
|
|
4087
4099
|
return this.config.provider;
|
|
4088
4100
|
}
|
|
4089
4101
|
async uploadFile(options) {
|
|
4090
|
-
var _a2, _b, _c, _d;
|
|
4091
4102
|
const googleOptions = await parseProviderOptions5({
|
|
4092
4103
|
provider: "google",
|
|
4093
4104
|
providerOptions: options.providerOptions,
|
|
@@ -4097,14 +4108,14 @@ var GoogleFiles = class {
|
|
|
4097
4108
|
this.config.headers(),
|
|
4098
4109
|
options.headers
|
|
4099
4110
|
);
|
|
4100
|
-
const fetchFn =
|
|
4111
|
+
const fetchFn = this.config.fetch ?? globalThis.fetch;
|
|
4101
4112
|
const warnings = [];
|
|
4102
4113
|
if (options.filename != null) {
|
|
4103
4114
|
warnings.push({ type: "unsupported", feature: "filename" });
|
|
4104
4115
|
}
|
|
4105
4116
|
const fileBytes = convertInlineFileDataToUint8Array(options.data);
|
|
4106
4117
|
const mediaType = options.mediaType;
|
|
4107
|
-
const displayName = googleOptions
|
|
4118
|
+
const displayName = googleOptions?.displayName;
|
|
4108
4119
|
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|
|
4109
4120
|
const initResponse = await fetchFn(`${baseOrigin}/upload/v1beta/files`, {
|
|
4110
4121
|
method: "POST",
|
|
@@ -4155,8 +4166,8 @@ var GoogleFiles = class {
|
|
|
4155
4166
|
}
|
|
4156
4167
|
const uploadResult = await uploadResponse.json();
|
|
4157
4168
|
let file = uploadResult.file;
|
|
4158
|
-
const pollIntervalMs =
|
|
4159
|
-
const pollTimeoutMs =
|
|
4169
|
+
const pollIntervalMs = googleOptions?.pollIntervalMs ?? 2e3;
|
|
4170
|
+
const pollTimeoutMs = googleOptions?.pollTimeoutMs ?? 3e5;
|
|
4160
4171
|
const startTime = Date.now();
|
|
4161
4172
|
while (file.state === "PROCESSING") {
|
|
4162
4173
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
@@ -4190,7 +4201,7 @@ var GoogleFiles = class {
|
|
|
4190
4201
|
return {
|
|
4191
4202
|
warnings,
|
|
4192
4203
|
providerReference: { google: file.uri },
|
|
4193
|
-
mediaType:
|
|
4204
|
+
mediaType: file.mimeType ?? options.mediaType,
|
|
4194
4205
|
providerMetadata: {
|
|
4195
4206
|
google: {
|
|
4196
4207
|
name: file.name,
|
|
@@ -4278,16 +4289,13 @@ var googleVideoModelOptionsSchema = lazySchema15(
|
|
|
4278
4289
|
|
|
4279
4290
|
// src/google-video-model.ts
|
|
4280
4291
|
function getFirstFrameImage(options) {
|
|
4281
|
-
|
|
4282
|
-
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
4292
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
4283
4293
|
}
|
|
4284
4294
|
function resolveStartImage(options) {
|
|
4285
|
-
|
|
4286
|
-
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
4295
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
4287
4296
|
}
|
|
4288
4297
|
function getLastFrameImage(options) {
|
|
4289
|
-
|
|
4290
|
-
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
4298
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
4291
4299
|
}
|
|
4292
4300
|
function getInputReferences(options) {
|
|
4293
4301
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -4385,7 +4393,7 @@ var GoogleVideoModel = class {
|
|
|
4385
4393
|
const converted = convertInputReferenceImage(reference, warnings);
|
|
4386
4394
|
return converted != null ? [converted] : [];
|
|
4387
4395
|
});
|
|
4388
|
-
} else if (
|
|
4396
|
+
} else if (googleOptions?.referenceImages != null) {
|
|
4389
4397
|
instance.referenceImages = googleOptions.referenceImages.map(
|
|
4390
4398
|
(refImg) => convertProviderReferenceImage(refImg)
|
|
4391
4399
|
);
|
|
@@ -4433,9 +4441,8 @@ var GoogleVideoModel = class {
|
|
|
4433
4441
|
return { instances, parameters, warnings, googleOptions };
|
|
4434
4442
|
}
|
|
4435
4443
|
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
4436
|
-
var _a2, _b;
|
|
4437
4444
|
const response = finalOperation.response;
|
|
4438
|
-
if (!
|
|
4445
|
+
if (!response?.generateVideoResponse?.generatedSamples || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
4439
4446
|
throw new AISDKError2({
|
|
4440
4447
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
4441
4448
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -4444,9 +4451,9 @@ var GoogleVideoModel = class {
|
|
|
4444
4451
|
const videos = [];
|
|
4445
4452
|
const videoMetadata = [];
|
|
4446
4453
|
const resolvedHeaders = await resolve4(this.config.headers);
|
|
4447
|
-
const apiKey = resolvedHeaders
|
|
4454
|
+
const apiKey = resolvedHeaders?.["x-goog-api-key"];
|
|
4448
4455
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
4449
|
-
if (
|
|
4456
|
+
if (generatedSample.video?.uri) {
|
|
4450
4457
|
const urlWithAuth = apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
4451
4458
|
videos.push({
|
|
4452
4459
|
type: "url",
|
|
@@ -4481,8 +4488,7 @@ var GoogleVideoModel = class {
|
|
|
4481
4488
|
};
|
|
4482
4489
|
}
|
|
4483
4490
|
async doStart(options) {
|
|
4484
|
-
|
|
4485
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4491
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4486
4492
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
4487
4493
|
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
4488
4494
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -4519,8 +4525,7 @@ var GoogleVideoModel = class {
|
|
|
4519
4525
|
};
|
|
4520
4526
|
}
|
|
4521
4527
|
async doStatus(options) {
|
|
4522
|
-
|
|
4523
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4528
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4524
4529
|
const { operationName } = options.operation;
|
|
4525
4530
|
const { value: statusOperation, responseHeaders } = await getFromApi3({
|
|
4526
4531
|
url: `${this.config.baseURL}/${operationName}`,
|
|
@@ -4632,7 +4637,7 @@ function getGoogleSpeechInput({
|
|
|
4632
4637
|
voice,
|
|
4633
4638
|
providerOptions
|
|
4634
4639
|
}) {
|
|
4635
|
-
const google2 = providerOptions
|
|
4640
|
+
const google2 = providerOptions?.google;
|
|
4636
4641
|
const options = google2 != null && typeof google2 === "object" ? google2 : void 0;
|
|
4637
4642
|
const turns = options && "turns" in options ? options.turns : void 0;
|
|
4638
4643
|
const turnTexts = [];
|
|
@@ -4651,7 +4656,7 @@ function getGoogleSpeechInput({
|
|
|
4651
4656
|
const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
|
|
4652
4657
|
return {
|
|
4653
4658
|
text,
|
|
4654
|
-
usesCustomVoice:
|
|
4659
|
+
usesCustomVoice: voice?.startsWith("voice_") === true || voice?.startsWith("voicekey_") === true || speakers.some(
|
|
4655
4660
|
(speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
|
|
4656
4661
|
)
|
|
4657
4662
|
};
|
|
@@ -4740,7 +4745,6 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4740
4745
|
language,
|
|
4741
4746
|
providerOptions
|
|
4742
4747
|
}) {
|
|
4743
|
-
var _a2;
|
|
4744
4748
|
const warnings = [];
|
|
4745
4749
|
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
4746
4750
|
let googleOptions;
|
|
@@ -4773,7 +4777,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4773
4777
|
message: "Custom voices are not supported. Use a prebuilt voice instead."
|
|
4774
4778
|
});
|
|
4775
4779
|
}
|
|
4776
|
-
const multiSpeakerVoiceConfig = googleOptions
|
|
4780
|
+
const multiSpeakerVoiceConfig = googleOptions?.multiSpeakerVoiceConfig;
|
|
4777
4781
|
const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
|
|
4778
4782
|
let promptText = text;
|
|
4779
4783
|
if (instructions != null && !usesStructuredSpeech) {
|
|
@@ -4789,25 +4793,24 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4789
4793
|
}
|
|
4790
4794
|
let parts = [{ text: promptText }];
|
|
4791
4795
|
if (usesStructuredSpeech) {
|
|
4792
|
-
if (
|
|
4796
|
+
if (googleOptions?.turns && googleOptions.speechMetadata) {
|
|
4793
4797
|
throw new InvalidArgumentError2({
|
|
4794
4798
|
argument: "providerOptions",
|
|
4795
4799
|
message: "Set speechMetadata on each turn when using turns."
|
|
4796
4800
|
});
|
|
4797
4801
|
}
|
|
4798
|
-
if (
|
|
4802
|
+
if (googleOptions?.turns && text !== "") {
|
|
4799
4803
|
warnings.push({
|
|
4800
4804
|
type: "unsupported",
|
|
4801
4805
|
feature: "text",
|
|
4802
4806
|
details: "Google TTS turns replace the top-level text."
|
|
4803
4807
|
});
|
|
4804
4808
|
}
|
|
4805
|
-
parts = (
|
|
4806
|
-
{ text, speechMetadata: googleOptions
|
|
4809
|
+
parts = (googleOptions?.turns ?? [
|
|
4810
|
+
{ text, speechMetadata: googleOptions?.speechMetadata }
|
|
4807
4811
|
]).map((part) => {
|
|
4808
|
-
|
|
4809
|
-
const
|
|
4810
|
-
const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
|
|
4812
|
+
const style = part.speechMetadata?.style ?? instructions;
|
|
4813
|
+
const speaker = part.speechMetadata?.speaker;
|
|
4811
4814
|
if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
|
|
4812
4815
|
(config) => config.speaker === speaker
|
|
4813
4816
|
)) {
|
|
@@ -4821,7 +4824,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4821
4824
|
...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
|
|
4822
4825
|
};
|
|
4823
4826
|
});
|
|
4824
|
-
} else if (
|
|
4827
|
+
} else if (googleOptions?.turns || googleOptions?.speechMetadata) {
|
|
4825
4828
|
throw new InvalidArgumentError2({
|
|
4826
4829
|
argument: "providerOptions",
|
|
4827
4830
|
message: "Structured speech metadata and turns require Gemini 3.8 TTS."
|
|
@@ -4887,8 +4890,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4887
4890
|
};
|
|
4888
4891
|
}
|
|
4889
4892
|
async doGenerate(options) {
|
|
4890
|
-
|
|
4891
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4893
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4892
4894
|
const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
|
|
4893
4895
|
const {
|
|
4894
4896
|
value: response,
|
|
@@ -4910,11 +4912,11 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4910
4912
|
});
|
|
4911
4913
|
let base64Audio;
|
|
4912
4914
|
let mimeType;
|
|
4913
|
-
for (const candidate of
|
|
4914
|
-
for (const part of
|
|
4915
|
-
if (
|
|
4915
|
+
for (const candidate of response.candidates ?? []) {
|
|
4916
|
+
for (const part of candidate.content?.parts ?? []) {
|
|
4917
|
+
if (part.inlineData?.data) {
|
|
4916
4918
|
base64Audio = part.inlineData.data;
|
|
4917
|
-
mimeType =
|
|
4919
|
+
mimeType = part.inlineData.mimeType ?? void 0;
|
|
4918
4920
|
break;
|
|
4919
4921
|
}
|
|
4920
4922
|
}
|
|
@@ -4922,9 +4924,9 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4922
4924
|
break;
|
|
4923
4925
|
}
|
|
4924
4926
|
}
|
|
4925
|
-
const sampleRate =
|
|
4927
|
+
const sampleRate = parseSampleRate(mimeType) ?? DEFAULT_SAMPLE_RATE;
|
|
4926
4928
|
const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
|
|
4927
|
-
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType
|
|
4929
|
+
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType ?? "") || mimeType == null && !usesStructuredSpeech;
|
|
4928
4930
|
const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
|
|
4929
4931
|
if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
|
|
4930
4932
|
warnings.push({
|
|
@@ -4948,7 +4950,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4948
4950
|
providerMetadata: {
|
|
4949
4951
|
google: {
|
|
4950
4952
|
sampleRate,
|
|
4951
|
-
mimeType: mimeType
|
|
4953
|
+
mimeType: mimeType ?? null
|
|
4952
4954
|
}
|
|
4953
4955
|
}
|
|
4954
4956
|
};
|
|
@@ -5014,37 +5016,36 @@ import {
|
|
|
5014
5016
|
// src/interactions/convert-google-interactions-usage.ts
|
|
5015
5017
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
5016
5018
|
function convertGoogleInteractionsUsage(usage) {
|
|
5017
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5018
5019
|
if (usage == null) {
|
|
5019
5020
|
return createNullLanguageModelUsage2();
|
|
5020
5021
|
}
|
|
5021
|
-
const totalInput =
|
|
5022
|
-
const totalOutput =
|
|
5023
|
-
const totalThought =
|
|
5024
|
-
const totalCached =
|
|
5022
|
+
const totalInput = usage.total_input_tokens ?? 0;
|
|
5023
|
+
const totalOutput = usage.total_output_tokens ?? 0;
|
|
5024
|
+
const totalThought = usage.total_thought_tokens ?? 0;
|
|
5025
|
+
const totalCached = usage.total_cached_tokens ?? 0;
|
|
5025
5026
|
return {
|
|
5026
5027
|
inputTokens: {
|
|
5027
|
-
total:
|
|
5028
|
+
total: usage.total_input_tokens ?? void 0,
|
|
5028
5029
|
noCache: usage.total_input_tokens == null ? void 0 : totalInput - totalCached,
|
|
5029
|
-
cacheRead:
|
|
5030
|
+
cacheRead: usage.total_cached_tokens ?? void 0,
|
|
5030
5031
|
cacheWrite: void 0
|
|
5031
5032
|
},
|
|
5032
5033
|
outputTokens: {
|
|
5033
5034
|
total: usage.total_output_tokens == null && usage.total_thought_tokens == null ? void 0 : totalOutput + totalThought,
|
|
5034
|
-
text:
|
|
5035
|
-
reasoning:
|
|
5035
|
+
text: usage.total_output_tokens ?? void 0,
|
|
5036
|
+
reasoning: usage.total_thought_tokens ?? void 0
|
|
5036
5037
|
},
|
|
5037
5038
|
raw: usage
|
|
5038
5039
|
};
|
|
5039
5040
|
}
|
|
5040
5041
|
function getGoogleInteractionsOutputTokensByModality(usage) {
|
|
5041
|
-
const byModality = usage
|
|
5042
|
+
const byModality = usage?.output_tokens_by_modality;
|
|
5042
5043
|
if (byModality == null) {
|
|
5043
5044
|
return void 0;
|
|
5044
5045
|
}
|
|
5045
5046
|
const result = {};
|
|
5046
5047
|
for (const entry of byModality) {
|
|
5047
|
-
if (
|
|
5048
|
+
if (entry?.modality != null && entry.tokens != null) {
|
|
5048
5049
|
result[entry.modality] = entry.tokens;
|
|
5049
5050
|
}
|
|
5050
5051
|
}
|
|
@@ -5076,7 +5077,6 @@ function annotationToSource({
|
|
|
5076
5077
|
annotation,
|
|
5077
5078
|
generateId: generateId4
|
|
5078
5079
|
}) {
|
|
5079
|
-
var _a2, _b, _c, _d, _e;
|
|
5080
5080
|
switch (annotation.type) {
|
|
5081
5081
|
case "url_citation": {
|
|
5082
5082
|
const urlCitation = annotation;
|
|
@@ -5093,7 +5093,7 @@ function annotationToSource({
|
|
|
5093
5093
|
}
|
|
5094
5094
|
case "file_citation": {
|
|
5095
5095
|
const fileCitation = annotation;
|
|
5096
|
-
const uri =
|
|
5096
|
+
const uri = fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
|
|
5097
5097
|
if (uri == null || uri.length === 0) return void 0;
|
|
5098
5098
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
5099
5099
|
return {
|
|
@@ -5104,14 +5104,14 @@ function annotationToSource({
|
|
|
5104
5104
|
...fileCitation.file_name != null ? { title: fileCitation.file_name } : {}
|
|
5105
5105
|
};
|
|
5106
5106
|
}
|
|
5107
|
-
const filename =
|
|
5107
|
+
const filename = fileCitation.file_name ?? basename(uri);
|
|
5108
5108
|
const mediaType = inferDocMediaType(uri);
|
|
5109
5109
|
return {
|
|
5110
5110
|
type: "source",
|
|
5111
5111
|
sourceType: "document",
|
|
5112
5112
|
id: generateId4(),
|
|
5113
5113
|
mediaType,
|
|
5114
|
-
title:
|
|
5114
|
+
title: fileCitation.file_name ?? filename ?? uri,
|
|
5115
5115
|
...filename != null ? { filename } : {}
|
|
5116
5116
|
};
|
|
5117
5117
|
}
|
|
@@ -5136,13 +5136,12 @@ function builtinToolResultToSources({
|
|
|
5136
5136
|
block,
|
|
5137
5137
|
generateId: generateId4
|
|
5138
5138
|
}) {
|
|
5139
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5140
5139
|
const sources = [];
|
|
5141
5140
|
switch (block.type) {
|
|
5142
5141
|
case "url_context_result": {
|
|
5143
|
-
const result =
|
|
5142
|
+
const result = block.result ?? [];
|
|
5144
5143
|
for (const entry of result) {
|
|
5145
|
-
if (
|
|
5144
|
+
if (entry?.url == null || entry.url.length === 0) continue;
|
|
5146
5145
|
if (entry.status != null && entry.status !== "success") continue;
|
|
5147
5146
|
sources.push({
|
|
5148
5147
|
type: "source",
|
|
@@ -5154,9 +5153,9 @@ function builtinToolResultToSources({
|
|
|
5154
5153
|
break;
|
|
5155
5154
|
}
|
|
5156
5155
|
case "google_search_result": {
|
|
5157
|
-
const result =
|
|
5156
|
+
const result = block.result ?? [];
|
|
5158
5157
|
for (const entry of result) {
|
|
5159
|
-
const url = entry
|
|
5158
|
+
const url = entry?.url;
|
|
5160
5159
|
if (url == null || url.length === 0) continue;
|
|
5161
5160
|
sources.push({
|
|
5162
5161
|
type: "source",
|
|
@@ -5169,9 +5168,9 @@ function builtinToolResultToSources({
|
|
|
5169
5168
|
break;
|
|
5170
5169
|
}
|
|
5171
5170
|
case "google_maps_result": {
|
|
5172
|
-
const result =
|
|
5171
|
+
const result = block.result ?? [];
|
|
5173
5172
|
for (const entry of result) {
|
|
5174
|
-
for (const place of
|
|
5173
|
+
for (const place of entry.places ?? []) {
|
|
5175
5174
|
if (place.url == null || place.url.length === 0) continue;
|
|
5176
5175
|
sources.push({
|
|
5177
5176
|
type: "source",
|
|
@@ -5185,11 +5184,11 @@ function builtinToolResultToSources({
|
|
|
5185
5184
|
break;
|
|
5186
5185
|
}
|
|
5187
5186
|
case "file_search_result": {
|
|
5188
|
-
const result =
|
|
5187
|
+
const result = block.result ?? [];
|
|
5189
5188
|
for (const raw of result) {
|
|
5190
5189
|
if (raw == null || typeof raw !== "object") continue;
|
|
5191
5190
|
const entry = raw;
|
|
5192
|
-
const uri =
|
|
5191
|
+
const uri = entry.url ?? entry.document_uri ?? entry.file_name;
|
|
5193
5192
|
if (uri == null || uri.length === 0) continue;
|
|
5194
5193
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
5195
5194
|
sources.push({
|
|
@@ -5201,14 +5200,14 @@ function builtinToolResultToSources({
|
|
|
5201
5200
|
});
|
|
5202
5201
|
continue;
|
|
5203
5202
|
}
|
|
5204
|
-
const filename =
|
|
5203
|
+
const filename = entry.file_name ?? basename(uri);
|
|
5205
5204
|
const mediaType = inferDocMediaType(uri);
|
|
5206
5205
|
sources.push({
|
|
5207
5206
|
type: "source",
|
|
5208
5207
|
sourceType: "document",
|
|
5209
5208
|
id: generateId4(),
|
|
5210
5209
|
mediaType,
|
|
5211
|
-
title:
|
|
5210
|
+
title: entry.title ?? entry.file_name ?? filename ?? uri,
|
|
5212
5211
|
...filename != null ? { filename } : {}
|
|
5213
5212
|
});
|
|
5214
5213
|
}
|
|
@@ -5223,14 +5222,13 @@ function annotationsToSources({
|
|
|
5223
5222
|
annotations,
|
|
5224
5223
|
generateId: generateId4
|
|
5225
5224
|
}) {
|
|
5226
|
-
var _a2;
|
|
5227
5225
|
if (annotations == null) return [];
|
|
5228
5226
|
const seen = /* @__PURE__ */ new Set();
|
|
5229
5227
|
const sources = [];
|
|
5230
5228
|
for (const annotation of annotations) {
|
|
5231
5229
|
const source = annotationToSource({ annotation, generateId: generateId4 });
|
|
5232
5230
|
if (source == null) continue;
|
|
5233
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${
|
|
5231
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
5234
5232
|
if (seen.has(key)) continue;
|
|
5235
5233
|
seen.add(key);
|
|
5236
5234
|
sources.push(source);
|
|
@@ -5297,15 +5295,13 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5297
5295
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
5298
5296
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
5299
5297
|
function sourceKey(source) {
|
|
5300
|
-
|
|
5301
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5298
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
5302
5299
|
}
|
|
5303
5300
|
return new TransformStream({
|
|
5304
5301
|
start(controller) {
|
|
5305
5302
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5306
5303
|
},
|
|
5307
5304
|
transform(chunk, controller) {
|
|
5308
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5309
5305
|
if (includeRawChunks) {
|
|
5310
5306
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5311
5307
|
}
|
|
@@ -5320,8 +5316,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5320
5316
|
case "interaction.created": {
|
|
5321
5317
|
const event = value;
|
|
5322
5318
|
const interaction = event.interaction;
|
|
5323
|
-
interactionId =
|
|
5324
|
-
const created = interaction
|
|
5319
|
+
interactionId = interaction?.id != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
5320
|
+
const created = interaction?.created;
|
|
5325
5321
|
let timestamp;
|
|
5326
5322
|
if (typeof created === "string") {
|
|
5327
5323
|
const parsed = new Date(created);
|
|
@@ -5332,7 +5328,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5332
5328
|
controller.enqueue({
|
|
5333
5329
|
type: "response-metadata",
|
|
5334
5330
|
...interactionId != null ? { id: interactionId } : {},
|
|
5335
|
-
modelId: interaction
|
|
5331
|
+
modelId: interaction?.model,
|
|
5336
5332
|
...timestamp ? { timestamp } : {}
|
|
5337
5333
|
});
|
|
5338
5334
|
break;
|
|
@@ -5341,11 +5337,11 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5341
5337
|
const event = value;
|
|
5342
5338
|
const step = event.step;
|
|
5343
5339
|
const index = event.index;
|
|
5344
|
-
const blockId = `${interactionId
|
|
5345
|
-
const stepType = step
|
|
5340
|
+
const blockId = `${interactionId ?? "interaction"}:${index}`;
|
|
5341
|
+
const stepType = step?.type;
|
|
5346
5342
|
if (stepType === "model_output") {
|
|
5347
|
-
const initial =
|
|
5348
|
-
if (
|
|
5343
|
+
const initial = step?.content?.[0];
|
|
5344
|
+
if (initial?.type === "text") {
|
|
5349
5345
|
openBlocks.set(index, {
|
|
5350
5346
|
kind: "text",
|
|
5351
5347
|
id: blockId,
|
|
@@ -5362,7 +5358,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5362
5358
|
emittedSourceKeys.add(key);
|
|
5363
5359
|
controller.enqueue(source);
|
|
5364
5360
|
}
|
|
5365
|
-
} else if (
|
|
5361
|
+
} else if (initial?.type === "image") {
|
|
5366
5362
|
openBlocks.set(index, {
|
|
5367
5363
|
kind: "image",
|
|
5368
5364
|
id: blockId,
|
|
@@ -5377,16 +5373,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5377
5373
|
});
|
|
5378
5374
|
}
|
|
5379
5375
|
} else if (stepType === "thought") {
|
|
5380
|
-
const signature = step
|
|
5376
|
+
const signature = step?.signature;
|
|
5381
5377
|
openBlocks.set(index, {
|
|
5382
5378
|
kind: "reasoning",
|
|
5383
5379
|
id: blockId,
|
|
5384
5380
|
...signature != null ? { signature } : {}
|
|
5385
5381
|
});
|
|
5386
5382
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
5387
|
-
if (Array.isArray(step
|
|
5383
|
+
if (Array.isArray(step?.summary)) {
|
|
5388
5384
|
for (const item of step.summary) {
|
|
5389
|
-
if (
|
|
5385
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
5390
5386
|
controller.enqueue({
|
|
5391
5387
|
type: "reasoning-delta",
|
|
5392
5388
|
id: blockId,
|
|
@@ -5397,12 +5393,12 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5397
5393
|
}
|
|
5398
5394
|
} else if (stepType === "processing_call" || stepType === "processing_result") {
|
|
5399
5395
|
const google2 = {};
|
|
5400
|
-
if (
|
|
5396
|
+
if (step?.signature != null) google2.signature = step.signature;
|
|
5401
5397
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5402
5398
|
if (stepType === "processing_call") {
|
|
5403
|
-
google2.processingId =
|
|
5399
|
+
google2.processingId = step?.id || blockId;
|
|
5404
5400
|
} else {
|
|
5405
|
-
google2.processingCallId =
|
|
5401
|
+
google2.processingCallId = step?.call_id || blockId;
|
|
5406
5402
|
}
|
|
5407
5403
|
openBlocks.set(index, {
|
|
5408
5404
|
kind: "custom",
|
|
@@ -5411,8 +5407,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5411
5407
|
google: google2
|
|
5412
5408
|
});
|
|
5413
5409
|
} else if (stepType === "function_call") {
|
|
5414
|
-
const toolCallId =
|
|
5415
|
-
const toolName =
|
|
5410
|
+
const toolCallId = step?.id || blockId;
|
|
5411
|
+
const toolName = step?.name ?? "unknown";
|
|
5416
5412
|
hasFunctionCall = true;
|
|
5417
5413
|
const state = {
|
|
5418
5414
|
kind: "function_call",
|
|
@@ -5420,7 +5416,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5420
5416
|
toolCallId,
|
|
5421
5417
|
toolName,
|
|
5422
5418
|
argumentsAccum: "",
|
|
5423
|
-
...
|
|
5419
|
+
...step?.signature != null ? { signature: step.signature } : {}
|
|
5424
5420
|
};
|
|
5425
5421
|
openBlocks.set(index, state);
|
|
5426
5422
|
controller.enqueue({
|
|
@@ -5429,29 +5425,29 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5429
5425
|
toolName
|
|
5430
5426
|
});
|
|
5431
5427
|
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
5432
|
-
const toolName = stepType === "mcp_server_tool_call" ?
|
|
5433
|
-
const toolCallId =
|
|
5428
|
+
const toolName = stepType === "mcp_server_tool_call" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
5429
|
+
const toolCallId = step?.id || blockId;
|
|
5434
5430
|
const state = {
|
|
5435
5431
|
kind: "builtin_tool_call",
|
|
5436
5432
|
id: blockId,
|
|
5437
5433
|
blockType: stepType,
|
|
5438
5434
|
toolCallId,
|
|
5439
5435
|
toolName,
|
|
5440
|
-
arguments:
|
|
5436
|
+
arguments: step?.arguments ?? {},
|
|
5441
5437
|
callEmitted: false
|
|
5442
5438
|
};
|
|
5443
5439
|
openBlocks.set(index, state);
|
|
5444
5440
|
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
5445
|
-
const toolName = stepType === "mcp_server_tool_result" ?
|
|
5446
|
-
const callId =
|
|
5441
|
+
const toolName = stepType === "mcp_server_tool_result" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
5442
|
+
const callId = step?.call_id || blockId;
|
|
5447
5443
|
const state = {
|
|
5448
5444
|
kind: "builtin_tool_result",
|
|
5449
5445
|
id: blockId,
|
|
5450
5446
|
blockType: stepType,
|
|
5451
5447
|
callId,
|
|
5452
5448
|
toolName,
|
|
5453
|
-
result:
|
|
5454
|
-
...
|
|
5449
|
+
result: step?.result ?? null,
|
|
5450
|
+
...step?.is_error != null ? { isError: step.is_error } : {},
|
|
5455
5451
|
resultEmitted: false
|
|
5456
5452
|
};
|
|
5457
5453
|
openBlocks.set(index, state);
|
|
@@ -5464,7 +5460,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5464
5460
|
const event = value;
|
|
5465
5461
|
let open = openBlocks.get(event.index);
|
|
5466
5462
|
if (open == null) break;
|
|
5467
|
-
const dtype =
|
|
5463
|
+
const dtype = event.delta?.type;
|
|
5468
5464
|
if (open.kind === "pending_model_output") {
|
|
5469
5465
|
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
5470
5466
|
const promoted = {
|
|
@@ -5482,17 +5478,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5482
5478
|
const google2 = {};
|
|
5483
5479
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5484
5480
|
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
5485
|
-
if (
|
|
5481
|
+
if (imageDelta?.data != null && imageDelta.data.length > 0) {
|
|
5486
5482
|
controller.enqueue({
|
|
5487
5483
|
type: "file",
|
|
5488
|
-
mediaType:
|
|
5484
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
5489
5485
|
data: { type: "data", data: imageDelta.data },
|
|
5490
5486
|
...providerMetadata ? { providerMetadata } : {}
|
|
5491
5487
|
});
|
|
5492
|
-
} else if (
|
|
5488
|
+
} else if (imageDelta?.uri != null && imageDelta.uri.length > 0) {
|
|
5493
5489
|
controller.enqueue({
|
|
5494
5490
|
type: "file",
|
|
5495
|
-
mediaType:
|
|
5491
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
5496
5492
|
data: { type: "url", url: new URL(imageDelta.uri) },
|
|
5497
5493
|
...providerMetadata ? { providerMetadata } : {}
|
|
5498
5494
|
});
|
|
@@ -5508,17 +5504,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5508
5504
|
const google2 = {};
|
|
5509
5505
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5510
5506
|
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
5511
|
-
if (
|
|
5507
|
+
if (videoDelta?.data != null && videoDelta.data.length > 0) {
|
|
5512
5508
|
controller.enqueue({
|
|
5513
5509
|
type: "file",
|
|
5514
|
-
mediaType:
|
|
5510
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
5515
5511
|
data: { type: "data", data: videoDelta.data },
|
|
5516
5512
|
...providerMetadata ? { providerMetadata } : {}
|
|
5517
5513
|
});
|
|
5518
|
-
} else if (
|
|
5514
|
+
} else if (videoDelta?.uri != null && videoDelta.uri.length > 0) {
|
|
5519
5515
|
controller.enqueue({
|
|
5520
5516
|
type: "file",
|
|
5521
|
-
mediaType:
|
|
5517
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
5522
5518
|
data: { type: "url", url: new URL(videoDelta.uri) },
|
|
5523
5519
|
...providerMetadata ? { providerMetadata } : {}
|
|
5524
5520
|
});
|
|
@@ -5526,7 +5522,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5526
5522
|
break;
|
|
5527
5523
|
}
|
|
5528
5524
|
const delta = event.delta;
|
|
5529
|
-
if (open.kind === "custom" && (
|
|
5525
|
+
if (open.kind === "custom" && (delta?.type === "processing_call" || delta?.type === "processing_result")) {
|
|
5530
5526
|
if (delta.signature != null)
|
|
5531
5527
|
open.google.signature = delta.signature;
|
|
5532
5528
|
if (delta.type === "processing_call" && delta.id != null && delta.id.length > 0) {
|
|
@@ -5535,8 +5531,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5535
5531
|
if (delta.type === "processing_result" && delta.call_id != null && delta.call_id.length > 0) {
|
|
5536
5532
|
open.google.processingCallId = delta.call_id;
|
|
5537
5533
|
}
|
|
5538
|
-
} else if (open.kind === "text" &&
|
|
5539
|
-
const text =
|
|
5534
|
+
} else if (open.kind === "text" && delta?.type === "text") {
|
|
5535
|
+
const text = delta.text ?? "";
|
|
5540
5536
|
if (text.length > 0) {
|
|
5541
5537
|
controller.enqueue({
|
|
5542
5538
|
type: "text-delta",
|
|
@@ -5544,7 +5540,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5544
5540
|
delta: text
|
|
5545
5541
|
});
|
|
5546
5542
|
}
|
|
5547
|
-
} else if (open.kind === "text" && (
|
|
5543
|
+
} else if (open.kind === "text" && (delta?.type === "text_annotation" || delta?.type === "text_annotation_delta")) {
|
|
5548
5544
|
const sources = annotationsToSources({
|
|
5549
5545
|
annotations: delta.annotations,
|
|
5550
5546
|
generateId: generateId4
|
|
@@ -5556,27 +5552,27 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5556
5552
|
open.emittedSourceKeys.add(key);
|
|
5557
5553
|
controller.enqueue(source);
|
|
5558
5554
|
}
|
|
5559
|
-
} else if (open.kind === "image" &&
|
|
5555
|
+
} else if (open.kind === "image" && delta?.type === "image") {
|
|
5560
5556
|
if (delta.data != null) open.data = delta.data;
|
|
5561
5557
|
if (delta.mime_type != null) open.mimeType = delta.mime_type;
|
|
5562
5558
|
if (delta.uri != null) open.uri = delta.uri;
|
|
5563
5559
|
} else if (open.kind === "reasoning") {
|
|
5564
|
-
if (
|
|
5560
|
+
if (delta?.type === "thought_summary") {
|
|
5565
5561
|
const item = delta.content;
|
|
5566
|
-
if (
|
|
5562
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
5567
5563
|
controller.enqueue({
|
|
5568
5564
|
type: "reasoning-delta",
|
|
5569
5565
|
id: open.id,
|
|
5570
5566
|
delta: item.text
|
|
5571
5567
|
});
|
|
5572
5568
|
}
|
|
5573
|
-
} else if (
|
|
5569
|
+
} else if (delta?.type === "thought_signature") {
|
|
5574
5570
|
const signature = delta.signature;
|
|
5575
5571
|
if (signature != null) {
|
|
5576
5572
|
open.signature = signature;
|
|
5577
5573
|
}
|
|
5578
5574
|
}
|
|
5579
|
-
} else if (open.kind === "function_call" &&
|
|
5575
|
+
} else if (open.kind === "function_call" && delta?.type === "arguments_delta") {
|
|
5580
5576
|
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
5581
5577
|
if (slice.length > 0) {
|
|
5582
5578
|
open.argumentsAccum += slice;
|
|
@@ -5593,7 +5589,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5593
5589
|
open.signature = delta.signature;
|
|
5594
5590
|
}
|
|
5595
5591
|
hasFunctionCall = true;
|
|
5596
|
-
} else if (open.kind === "builtin_tool_call" &&
|
|
5592
|
+
} else if (open.kind === "builtin_tool_call" && delta?.type === open.blockType) {
|
|
5597
5593
|
if (delta.id != null && delta.id.length > 0) {
|
|
5598
5594
|
open.toolCallId = delta.id;
|
|
5599
5595
|
}
|
|
@@ -5603,7 +5599,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5603
5599
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
5604
5600
|
open.toolName = delta.name;
|
|
5605
5601
|
}
|
|
5606
|
-
} else if (open.kind === "builtin_tool_result" &&
|
|
5602
|
+
} else if (open.kind === "builtin_tool_result" && delta?.type === open.blockType) {
|
|
5607
5603
|
if (delta.call_id != null && delta.call_id.length > 0) {
|
|
5608
5604
|
open.callId = delta.call_id;
|
|
5609
5605
|
}
|
|
@@ -5643,14 +5639,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5643
5639
|
if (open.data != null && open.data.length > 0) {
|
|
5644
5640
|
controller.enqueue({
|
|
5645
5641
|
type: "file",
|
|
5646
|
-
mediaType:
|
|
5642
|
+
mediaType: open.mimeType ?? "image/png",
|
|
5647
5643
|
data: { type: "data", data: open.data },
|
|
5648
5644
|
...providerMetadata ? { providerMetadata } : {}
|
|
5649
5645
|
});
|
|
5650
5646
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
5651
5647
|
controller.enqueue({
|
|
5652
5648
|
type: "file",
|
|
5653
|
-
mediaType:
|
|
5649
|
+
mediaType: open.mimeType ?? "image/png",
|
|
5654
5650
|
data: { type: "url", url: new URL(open.uri) },
|
|
5655
5651
|
...providerMetadata ? { providerMetadata } : {}
|
|
5656
5652
|
});
|
|
@@ -5683,7 +5679,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5683
5679
|
type: "tool-call",
|
|
5684
5680
|
toolCallId: open.toolCallId,
|
|
5685
5681
|
toolName: open.toolName,
|
|
5686
|
-
input: JSON.stringify(
|
|
5682
|
+
input: JSON.stringify(open.arguments ?? {}),
|
|
5687
5683
|
providerExecuted: true
|
|
5688
5684
|
});
|
|
5689
5685
|
open.callEmitted = true;
|
|
@@ -5692,7 +5688,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5692
5688
|
type: "tool-result",
|
|
5693
5689
|
toolCallId: open.callId,
|
|
5694
5690
|
toolName: open.toolName,
|
|
5695
|
-
result:
|
|
5691
|
+
result: open.result ?? null
|
|
5696
5692
|
});
|
|
5697
5693
|
open.resultEmitted = true;
|
|
5698
5694
|
const sources = builtinToolResultToSources({
|
|
@@ -5729,16 +5725,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5729
5725
|
case "interaction.completed": {
|
|
5730
5726
|
const event = value;
|
|
5731
5727
|
const interaction = event.interaction;
|
|
5732
|
-
if (
|
|
5728
|
+
if (interaction?.id != null && interaction.id.length > 0) {
|
|
5733
5729
|
interactionId = interaction.id;
|
|
5734
5730
|
}
|
|
5735
|
-
if (
|
|
5731
|
+
if (interaction?.status != null) {
|
|
5736
5732
|
finishStatus = interaction.status;
|
|
5737
5733
|
}
|
|
5738
|
-
if (
|
|
5734
|
+
if (interaction?.usage != null) {
|
|
5739
5735
|
usage = interaction.usage;
|
|
5740
5736
|
}
|
|
5741
|
-
if (
|
|
5737
|
+
if (interaction?.service_tier != null) {
|
|
5742
5738
|
serviceTier = interaction.service_tier;
|
|
5743
5739
|
}
|
|
5744
5740
|
break;
|
|
@@ -5749,9 +5745,9 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5749
5745
|
controller.enqueue({
|
|
5750
5746
|
type: "error",
|
|
5751
5747
|
error: createProviderStreamError({
|
|
5752
|
-
message:
|
|
5748
|
+
message: event.error?.message ?? "Unknown interaction error",
|
|
5753
5749
|
type: event.event_type,
|
|
5754
|
-
code:
|
|
5750
|
+
code: event.error?.code ?? void 0,
|
|
5755
5751
|
data: event
|
|
5756
5752
|
})
|
|
5757
5753
|
});
|
|
@@ -5802,7 +5798,6 @@ function convertToGoogleInteractionsInput({
|
|
|
5802
5798
|
store,
|
|
5803
5799
|
mediaResolution
|
|
5804
5800
|
}) {
|
|
5805
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5806
5801
|
const warnings = [];
|
|
5807
5802
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
5808
5803
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -5859,7 +5854,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5859
5854
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
5860
5855
|
} else if (part.type === "reasoning") {
|
|
5861
5856
|
flushModelOutput();
|
|
5862
|
-
const signature =
|
|
5857
|
+
const signature = part.providerOptions?.google?.signature;
|
|
5863
5858
|
steps.push({
|
|
5864
5859
|
type: "thought",
|
|
5865
5860
|
...signature != null ? { signature } : {},
|
|
@@ -5876,15 +5871,15 @@ function convertToGoogleInteractionsInput({
|
|
|
5876
5871
|
}
|
|
5877
5872
|
} else if (part.type === "custom") {
|
|
5878
5873
|
flushModelOutput();
|
|
5879
|
-
const google2 =
|
|
5880
|
-
const signature = typeof
|
|
5881
|
-
if (part.kind === "google.processing_call" && typeof
|
|
5874
|
+
const google2 = part.providerOptions?.google;
|
|
5875
|
+
const signature = typeof google2?.signature === "string" ? google2.signature : void 0;
|
|
5876
|
+
if (part.kind === "google.processing_call" && typeof google2?.processingId === "string") {
|
|
5882
5877
|
steps.push({
|
|
5883
5878
|
type: "processing_call",
|
|
5884
5879
|
id: google2.processingId,
|
|
5885
5880
|
...signature != null ? { signature } : {}
|
|
5886
5881
|
});
|
|
5887
|
-
} else if (part.kind === "google.processing_result" && typeof
|
|
5882
|
+
} else if (part.kind === "google.processing_result" && typeof google2?.processingCallId === "string") {
|
|
5888
5883
|
steps.push({
|
|
5889
5884
|
type: "processing_result",
|
|
5890
5885
|
call_id: google2.processingCallId,
|
|
@@ -5898,8 +5893,8 @@ function convertToGoogleInteractionsInput({
|
|
|
5898
5893
|
}
|
|
5899
5894
|
} else if (part.type === "tool-call") {
|
|
5900
5895
|
flushModelOutput();
|
|
5901
|
-
const signature =
|
|
5902
|
-
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) :
|
|
5896
|
+
const signature = part.providerOptions?.google?.signature;
|
|
5897
|
+
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : part.input ?? {};
|
|
5903
5898
|
steps.push({
|
|
5904
5899
|
type: "function_call",
|
|
5905
5900
|
id: part.toolCallId,
|
|
@@ -5931,7 +5926,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5931
5926
|
toolCallId: part.toolCallId,
|
|
5932
5927
|
toolName: part.toolName,
|
|
5933
5928
|
output: part.output,
|
|
5934
|
-
signature:
|
|
5929
|
+
signature: part.providerOptions?.google?.signature,
|
|
5935
5930
|
warnings
|
|
5936
5931
|
});
|
|
5937
5932
|
content.push(block);
|
|
@@ -6024,8 +6019,7 @@ function getVideoProcessingField({
|
|
|
6024
6019
|
part,
|
|
6025
6020
|
warnings
|
|
6026
6021
|
}) {
|
|
6027
|
-
|
|
6028
|
-
const processing = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.processing;
|
|
6022
|
+
const processing = part.providerOptions?.google?.processing;
|
|
6029
6023
|
if (processing == null) {
|
|
6030
6024
|
return {};
|
|
6031
6025
|
}
|
|
@@ -6037,8 +6031,8 @@ function getVideoProcessingField({
|
|
|
6037
6031
|
return {
|
|
6038
6032
|
processing: {
|
|
6039
6033
|
type: "static",
|
|
6040
|
-
...typeof config.startOffset === "number" ? { start_offset: config.startOffset } : {},
|
|
6041
|
-
...typeof config.endOffset === "number" ? { end_offset: config.endOffset } : {},
|
|
6034
|
+
...typeof config.startOffset === "number" ? { start_offset: `${config.startOffset}s` } : {},
|
|
6035
|
+
...typeof config.endOffset === "number" ? { end_offset: `${config.endOffset}s` } : {},
|
|
6042
6036
|
...typeof config.fps === "number" ? { fps: config.fps } : {}
|
|
6043
6037
|
}
|
|
6044
6038
|
};
|
|
@@ -6058,8 +6052,7 @@ function compactPromptForPreviousInteraction({
|
|
|
6058
6052
|
for (const message of prompt) {
|
|
6059
6053
|
if (message.role === "assistant") {
|
|
6060
6054
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
6061
|
-
|
|
6062
|
-
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
6055
|
+
const partInteractionId = part.providerOptions?.google?.interactionId;
|
|
6063
6056
|
return partInteractionId === previousInteractionId;
|
|
6064
6057
|
});
|
|
6065
6058
|
if (matchesLinkedInteraction) {
|
|
@@ -6100,7 +6093,7 @@ function safeParseToolArgs(input) {
|
|
|
6100
6093
|
return parsed;
|
|
6101
6094
|
}
|
|
6102
6095
|
return { value: parsed };
|
|
6103
|
-
} catch
|
|
6096
|
+
} catch {
|
|
6104
6097
|
return { value: input };
|
|
6105
6098
|
}
|
|
6106
6099
|
}
|
|
@@ -6111,7 +6104,6 @@ function convertToolResultPart({
|
|
|
6111
6104
|
signature,
|
|
6112
6105
|
warnings
|
|
6113
6106
|
}) {
|
|
6114
|
-
var _a2;
|
|
6115
6107
|
const base = {
|
|
6116
6108
|
type: "function_result",
|
|
6117
6109
|
call_id: toolCallId,
|
|
@@ -6131,7 +6123,7 @@ function convertToolResultPart({
|
|
|
6131
6123
|
return {
|
|
6132
6124
|
...base,
|
|
6133
6125
|
is_error: true,
|
|
6134
|
-
result:
|
|
6126
|
+
result: output.reason ?? "Tool execution denied by user."
|
|
6135
6127
|
};
|
|
6136
6128
|
case "content": {
|
|
6137
6129
|
const blocks = [];
|
|
@@ -6822,7 +6814,6 @@ function parseGoogleInteractionsOutputs({
|
|
|
6822
6814
|
generateId: generateId4,
|
|
6823
6815
|
interactionId
|
|
6824
6816
|
}) {
|
|
6825
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6826
6817
|
const content = [];
|
|
6827
6818
|
let hasFunctionCall = false;
|
|
6828
6819
|
if (steps == null) {
|
|
@@ -6837,12 +6828,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
6837
6828
|
break;
|
|
6838
6829
|
}
|
|
6839
6830
|
case "model_output": {
|
|
6840
|
-
const blocks =
|
|
6831
|
+
const blocks = step.content ?? [];
|
|
6841
6832
|
for (const block of blocks) {
|
|
6842
6833
|
if (block == null || typeof block !== "object") continue;
|
|
6843
6834
|
const blockType = block.type;
|
|
6844
6835
|
if (blockType === "text") {
|
|
6845
|
-
const text =
|
|
6836
|
+
const text = block.text ?? "";
|
|
6846
6837
|
const annotations = block.annotations;
|
|
6847
6838
|
content.push({
|
|
6848
6839
|
type: "text",
|
|
@@ -6858,14 +6849,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
6858
6849
|
if (image.data != null && image.data.length > 0) {
|
|
6859
6850
|
content.push({
|
|
6860
6851
|
type: "file",
|
|
6861
|
-
mediaType:
|
|
6852
|
+
mediaType: image.mime_type ?? "image/png",
|
|
6862
6853
|
data: { type: "data", data: image.data },
|
|
6863
6854
|
...googleProviderMetadata({ interactionId })
|
|
6864
6855
|
});
|
|
6865
6856
|
} else if (image.uri != null && image.uri.length > 0) {
|
|
6866
6857
|
content.push({
|
|
6867
6858
|
type: "file",
|
|
6868
|
-
mediaType:
|
|
6859
|
+
mediaType: image.mime_type ?? "image/png",
|
|
6869
6860
|
data: { type: "url", url: new URL(image.uri) },
|
|
6870
6861
|
...googleProviderMetadata({ interactionId })
|
|
6871
6862
|
});
|
|
@@ -6875,14 +6866,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
6875
6866
|
if (video.data != null && video.data.length > 0) {
|
|
6876
6867
|
content.push({
|
|
6877
6868
|
type: "file",
|
|
6878
|
-
mediaType:
|
|
6869
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
6879
6870
|
data: { type: "data", data: video.data },
|
|
6880
6871
|
...googleProviderMetadata({ interactionId })
|
|
6881
6872
|
});
|
|
6882
6873
|
} else if (video.uri != null && video.uri.length > 0) {
|
|
6883
6874
|
content.push({
|
|
6884
6875
|
type: "file",
|
|
6885
|
-
mediaType:
|
|
6876
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
6886
6877
|
data: { type: "url", url: new URL(video.uri) },
|
|
6887
6878
|
...googleProviderMetadata({ interactionId })
|
|
6888
6879
|
});
|
|
@@ -6895,7 +6886,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6895
6886
|
const thought = step;
|
|
6896
6887
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
6897
6888
|
const text = summary.filter(
|
|
6898
|
-
(item) =>
|
|
6889
|
+
(item) => item?.type === "text" && typeof item.text === "string"
|
|
6899
6890
|
).map((item) => item.text).join("\n");
|
|
6900
6891
|
content.push({
|
|
6901
6892
|
type: "reasoning",
|
|
@@ -6942,7 +6933,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6942
6933
|
type: "tool-call",
|
|
6943
6934
|
toolCallId: call.id,
|
|
6944
6935
|
toolName: call.name,
|
|
6945
|
-
input: JSON.stringify(
|
|
6936
|
+
input: JSON.stringify(call.arguments ?? {}),
|
|
6946
6937
|
...googleProviderMetadata({
|
|
6947
6938
|
signature: call.signature,
|
|
6948
6939
|
interactionId
|
|
@@ -6953,8 +6944,8 @@ function parseGoogleInteractionsOutputs({
|
|
|
6953
6944
|
default: {
|
|
6954
6945
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
6955
6946
|
const call = step;
|
|
6956
|
-
const toolName = type === "mcp_server_tool_call" ?
|
|
6957
|
-
const input = JSON.stringify(
|
|
6947
|
+
const toolName = type === "mcp_server_tool_call" ? call.name ?? "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
6948
|
+
const input = JSON.stringify(call.arguments ?? {});
|
|
6958
6949
|
content.push({
|
|
6959
6950
|
type: "tool-call",
|
|
6960
6951
|
toolCallId: call.id || generateId4(),
|
|
@@ -6964,12 +6955,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
6964
6955
|
});
|
|
6965
6956
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
6966
6957
|
const result = step;
|
|
6967
|
-
const toolName = type === "mcp_server_tool_result" ?
|
|
6958
|
+
const toolName = type === "mcp_server_tool_result" ? result.name ?? "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
6968
6959
|
content.push({
|
|
6969
6960
|
type: "tool-result",
|
|
6970
6961
|
toolCallId: result.call_id || generateId4(),
|
|
6971
6962
|
toolName,
|
|
6972
|
-
result:
|
|
6963
|
+
result: result.result ?? null
|
|
6973
6964
|
});
|
|
6974
6965
|
const sources = builtinToolResultToSources({
|
|
6975
6966
|
block: step,
|
|
@@ -7022,9 +7013,9 @@ async function cancelGoogleInteraction({
|
|
|
7022
7013
|
});
|
|
7023
7014
|
try {
|
|
7024
7015
|
await response.text();
|
|
7025
|
-
} catch
|
|
7016
|
+
} catch {
|
|
7026
7017
|
}
|
|
7027
|
-
} catch
|
|
7018
|
+
} catch {
|
|
7028
7019
|
}
|
|
7029
7020
|
}
|
|
7030
7021
|
|
|
@@ -7057,7 +7048,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
7057
7048
|
const cancelOnServer = () => cancelGoogleInteraction({ baseURL, interactionId, headers, fetch: fetch2 });
|
|
7058
7049
|
try {
|
|
7059
7050
|
while (true) {
|
|
7060
|
-
if (abortSignal
|
|
7051
|
+
if (abortSignal?.aborted) {
|
|
7061
7052
|
await cancelOnServer();
|
|
7062
7053
|
throw new DOMException("Polling was aborted", "AbortError");
|
|
7063
7054
|
}
|
|
@@ -7100,9 +7091,8 @@ function prepareGoogleInteractionsTools({
|
|
|
7100
7091
|
tools,
|
|
7101
7092
|
toolChoice
|
|
7102
7093
|
}) {
|
|
7103
|
-
var _a2, _b, _c, _d;
|
|
7104
7094
|
const toolWarnings = [];
|
|
7105
|
-
const normalized =
|
|
7095
|
+
const normalized = tools?.length ? tools : void 0;
|
|
7106
7096
|
if (normalized == null) {
|
|
7107
7097
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
7108
7098
|
}
|
|
@@ -7112,13 +7102,13 @@ function prepareGoogleInteractionsTools({
|
|
|
7112
7102
|
interactionsTools.push({
|
|
7113
7103
|
type: "function",
|
|
7114
7104
|
name: tool.name,
|
|
7115
|
-
description:
|
|
7105
|
+
description: tool.description ?? "",
|
|
7116
7106
|
parameters: tool.inputSchema
|
|
7117
7107
|
});
|
|
7118
7108
|
continue;
|
|
7119
7109
|
}
|
|
7120
7110
|
if (tool.type === "provider") {
|
|
7121
|
-
const args =
|
|
7111
|
+
const args = tool.args ?? {};
|
|
7122
7112
|
switch (tool.id) {
|
|
7123
7113
|
case "google.google_search": {
|
|
7124
7114
|
const searchTypesArg = args.searchTypes;
|
|
@@ -7168,7 +7158,7 @@ function prepareGoogleInteractionsTools({
|
|
|
7168
7158
|
case "google.computer_use": {
|
|
7169
7159
|
interactionsTools.push({
|
|
7170
7160
|
type: "computer_use",
|
|
7171
|
-
environment:
|
|
7161
|
+
environment: args.environment ?? "browser",
|
|
7172
7162
|
...args.excludedPredefinedFunctions != null ? {
|
|
7173
7163
|
excludedPredefinedFunctions: args.excludedPredefinedFunctions
|
|
7174
7164
|
} : {}
|
|
@@ -7186,7 +7176,7 @@ function prepareGoogleInteractionsTools({
|
|
|
7186
7176
|
break;
|
|
7187
7177
|
}
|
|
7188
7178
|
case "google.retrieval": {
|
|
7189
|
-
const vertexAiSearchConfig =
|
|
7179
|
+
const vertexAiSearchConfig = args.vertexAiSearchConfig ?? void 0;
|
|
7190
7180
|
interactionsTools.push({
|
|
7191
7181
|
type: "retrieval",
|
|
7192
7182
|
...args.retrievalTypes != null ? {
|
|
@@ -7390,7 +7380,7 @@ function streamGoogleInteractionEvents({
|
|
|
7390
7380
|
if (abortSignal != null) {
|
|
7391
7381
|
abortSignal.removeEventListener("abort", upstreamAbortHandler);
|
|
7392
7382
|
}
|
|
7393
|
-
currentReader
|
|
7383
|
+
currentReader?.cancel().catch(() => {
|
|
7394
7384
|
});
|
|
7395
7385
|
currentReader = void 0;
|
|
7396
7386
|
if (effectiveSignal.aborted && !complete) {
|
|
@@ -7405,7 +7395,7 @@ function streamGoogleInteractionEvents({
|
|
|
7405
7395
|
},
|
|
7406
7396
|
cancel() {
|
|
7407
7397
|
internalAbort.abort();
|
|
7408
|
-
currentReader
|
|
7398
|
+
currentReader?.cancel().catch(() => {
|
|
7409
7399
|
});
|
|
7410
7400
|
currentReader = void 0;
|
|
7411
7401
|
}
|
|
@@ -7422,7 +7412,6 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7422
7412
|
}) {
|
|
7423
7413
|
return new ReadableStream({
|
|
7424
7414
|
start(controller) {
|
|
7425
|
-
var _a2, _b, _c;
|
|
7426
7415
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7427
7416
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7428
7417
|
let timestamp;
|
|
@@ -7436,19 +7425,19 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7436
7425
|
controller.enqueue({
|
|
7437
7426
|
type: "response-metadata",
|
|
7438
7427
|
...interactionId != null ? { id: interactionId } : {},
|
|
7439
|
-
modelId:
|
|
7428
|
+
modelId: response.model ?? void 0,
|
|
7440
7429
|
...timestamp ? { timestamp } : {}
|
|
7441
7430
|
});
|
|
7442
7431
|
if (includeRawChunks) {
|
|
7443
7432
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
7444
7433
|
}
|
|
7445
7434
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
7446
|
-
steps:
|
|
7435
|
+
steps: response.steps ?? null,
|
|
7447
7436
|
generateId: generateId4,
|
|
7448
7437
|
interactionId
|
|
7449
7438
|
});
|
|
7450
7439
|
let blockCounter = 0;
|
|
7451
|
-
const nextBlockId = () => `${interactionId
|
|
7440
|
+
const nextBlockId = () => `${interactionId ?? "agent"}:${blockCounter++}`;
|
|
7452
7441
|
for (const part of content) {
|
|
7453
7442
|
switch (part.type) {
|
|
7454
7443
|
case "text": {
|
|
@@ -7528,7 +7517,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7528
7517
|
break;
|
|
7529
7518
|
}
|
|
7530
7519
|
}
|
|
7531
|
-
const serviceTier =
|
|
7520
|
+
const serviceTier = response.service_tier ?? headerServiceTier;
|
|
7532
7521
|
const finishReason = {
|
|
7533
7522
|
unified: mapGoogleInteractionsFinishReason({
|
|
7534
7523
|
status: response.status,
|
|
@@ -7603,7 +7592,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7603
7592
|
};
|
|
7604
7593
|
}
|
|
7605
7594
|
async getArgs(options) {
|
|
7606
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
7607
7595
|
const warnings = [];
|
|
7608
7596
|
const googleOptions = await parseProviderOptions8({
|
|
7609
7597
|
provider: "google",
|
|
@@ -7638,7 +7626,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7638
7626
|
warnings.push(...prepared.toolWarnings);
|
|
7639
7627
|
}
|
|
7640
7628
|
const responseFormatEntries = [];
|
|
7641
|
-
if (
|
|
7629
|
+
if (options.responseFormat?.type === "json") {
|
|
7642
7630
|
if (isAgent) {
|
|
7643
7631
|
warnings.push({
|
|
7644
7632
|
type: "other",
|
|
@@ -7653,41 +7641,41 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7653
7641
|
responseFormatEntries.push(entry);
|
|
7654
7642
|
}
|
|
7655
7643
|
}
|
|
7656
|
-
if (
|
|
7644
|
+
if (googleOptions?.responseFormat != null) {
|
|
7657
7645
|
for (const entry of googleOptions.responseFormat) {
|
|
7658
7646
|
if (entry.type === "text") {
|
|
7659
7647
|
responseFormatEntries.push(
|
|
7660
7648
|
pruneUndefined({
|
|
7661
7649
|
type: "text",
|
|
7662
|
-
mime_type:
|
|
7663
|
-
schema:
|
|
7650
|
+
mime_type: entry.mimeType ?? void 0,
|
|
7651
|
+
schema: entry.schema ?? void 0
|
|
7664
7652
|
})
|
|
7665
7653
|
);
|
|
7666
7654
|
} else if (entry.type === "image") {
|
|
7667
7655
|
responseFormatEntries.push(
|
|
7668
7656
|
pruneUndefined({
|
|
7669
7657
|
type: "image",
|
|
7670
|
-
mime_type:
|
|
7671
|
-
aspect_ratio:
|
|
7672
|
-
image_size:
|
|
7658
|
+
mime_type: entry.mimeType ?? void 0,
|
|
7659
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
7660
|
+
image_size: entry.imageSize ?? void 0
|
|
7673
7661
|
})
|
|
7674
7662
|
);
|
|
7675
7663
|
} else if (entry.type === "audio") {
|
|
7676
7664
|
responseFormatEntries.push(
|
|
7677
7665
|
pruneUndefined({
|
|
7678
7666
|
type: "audio",
|
|
7679
|
-
mime_type:
|
|
7667
|
+
mime_type: entry.mimeType ?? void 0
|
|
7680
7668
|
})
|
|
7681
7669
|
);
|
|
7682
7670
|
} else if (entry.type === "video") {
|
|
7683
7671
|
responseFormatEntries.push(
|
|
7684
7672
|
pruneUndefined({
|
|
7685
7673
|
type: "video",
|
|
7686
|
-
aspect_ratio:
|
|
7687
|
-
resolution:
|
|
7688
|
-
duration:
|
|
7689
|
-
delivery:
|
|
7690
|
-
gcs_uri:
|
|
7674
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
7675
|
+
resolution: entry.resolution ?? void 0,
|
|
7676
|
+
duration: entry.duration ?? void 0,
|
|
7677
|
+
delivery: entry.delivery ?? void 0,
|
|
7678
|
+
gcs_uri: entry.gcsUri ?? void 0
|
|
7691
7679
|
})
|
|
7692
7680
|
);
|
|
7693
7681
|
}
|
|
@@ -7699,13 +7687,13 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7699
7687
|
warnings: convWarnings
|
|
7700
7688
|
} = convertToGoogleInteractionsInput({
|
|
7701
7689
|
prompt: options.prompt,
|
|
7702
|
-
previousInteractionId:
|
|
7703
|
-
store:
|
|
7704
|
-
mediaResolution:
|
|
7690
|
+
previousInteractionId: googleOptions?.previousInteractionId ?? void 0,
|
|
7691
|
+
store: googleOptions?.store ?? void 0,
|
|
7692
|
+
mediaResolution: googleOptions?.mediaResolution ?? void 0
|
|
7705
7693
|
});
|
|
7706
7694
|
warnings.push(...convWarnings);
|
|
7707
7695
|
let systemInstruction = convertedSystemInstruction;
|
|
7708
|
-
const optionSystemInstruction =
|
|
7696
|
+
const optionSystemInstruction = googleOptions?.systemInstruction ?? void 0;
|
|
7709
7697
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
7710
7698
|
warnings.push({
|
|
7711
7699
|
type: "other",
|
|
@@ -7730,12 +7718,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7730
7718
|
}
|
|
7731
7719
|
if (options.maxOutputTokens != null)
|
|
7732
7720
|
droppedFields.push("maxOutputTokens");
|
|
7733
|
-
if (
|
|
7721
|
+
if (googleOptions?.thinkingLevel != null)
|
|
7734
7722
|
droppedFields.push("thinkingLevel");
|
|
7735
|
-
if (
|
|
7723
|
+
if (googleOptions?.thinkingSummaries != null) {
|
|
7736
7724
|
droppedFields.push("thinkingSummaries");
|
|
7737
7725
|
}
|
|
7738
|
-
if (
|
|
7726
|
+
if (googleOptions?.imageConfig != null) droppedFields.push("imageConfig");
|
|
7739
7727
|
if (droppedFields.length > 0) {
|
|
7740
7728
|
warnings.push({
|
|
7741
7729
|
type: "other",
|
|
@@ -7745,17 +7733,17 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7745
7733
|
generationConfig = void 0;
|
|
7746
7734
|
} else {
|
|
7747
7735
|
generationConfig = pruneUndefined({
|
|
7748
|
-
temperature:
|
|
7749
|
-
top_p:
|
|
7750
|
-
top_k:
|
|
7751
|
-
seed:
|
|
7736
|
+
temperature: options.temperature ?? void 0,
|
|
7737
|
+
top_p: options.topP ?? void 0,
|
|
7738
|
+
top_k: options.topK ?? void 0,
|
|
7739
|
+
seed: options.seed ?? void 0,
|
|
7752
7740
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
7753
|
-
max_output_tokens:
|
|
7754
|
-
thinking_level:
|
|
7755
|
-
thinking_summaries:
|
|
7741
|
+
max_output_tokens: options.maxOutputTokens ?? void 0,
|
|
7742
|
+
thinking_level: googleOptions?.thinkingLevel ?? void 0,
|
|
7743
|
+
thinking_summaries: googleOptions?.thinkingSummaries ?? void 0,
|
|
7756
7744
|
tool_choice: toolChoiceForBody
|
|
7757
7745
|
});
|
|
7758
|
-
if (
|
|
7746
|
+
if (googleOptions?.imageConfig != null) {
|
|
7759
7747
|
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
7760
7748
|
(entry) => entry.type === "image"
|
|
7761
7749
|
);
|
|
@@ -7774,21 +7762,21 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7774
7762
|
}
|
|
7775
7763
|
}
|
|
7776
7764
|
let agentConfig;
|
|
7777
|
-
if (isAgent &&
|
|
7765
|
+
if (isAgent && googleOptions?.agentConfig != null) {
|
|
7778
7766
|
const agentConfigOptions = googleOptions.agentConfig;
|
|
7779
7767
|
if (agentConfigOptions.type === "deep-research") {
|
|
7780
7768
|
agentConfig = pruneUndefined({
|
|
7781
7769
|
type: "deep-research",
|
|
7782
|
-
thinking_summaries:
|
|
7783
|
-
visualization:
|
|
7784
|
-
collaborative_planning:
|
|
7770
|
+
thinking_summaries: agentConfigOptions.thinkingSummaries ?? void 0,
|
|
7771
|
+
visualization: agentConfigOptions.visualization ?? void 0,
|
|
7772
|
+
collaborative_planning: agentConfigOptions.collaborativePlanning ?? void 0
|
|
7785
7773
|
});
|
|
7786
7774
|
} else if (agentConfigOptions.type === "dynamic") {
|
|
7787
7775
|
agentConfig = { type: "dynamic" };
|
|
7788
7776
|
}
|
|
7789
7777
|
}
|
|
7790
7778
|
let environment;
|
|
7791
|
-
if (
|
|
7779
|
+
if (googleOptions?.environment != null) {
|
|
7792
7780
|
if (!isAgent) {
|
|
7793
7781
|
warnings.push({
|
|
7794
7782
|
type: "other",
|
|
@@ -7798,8 +7786,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7798
7786
|
environment = googleOptions.environment;
|
|
7799
7787
|
} else {
|
|
7800
7788
|
const environmentOptions = googleOptions.environment;
|
|
7801
|
-
const sources =
|
|
7802
|
-
var _a3;
|
|
7789
|
+
const sources = environmentOptions.sources?.map((source) => {
|
|
7803
7790
|
if (source.type === "inline") {
|
|
7804
7791
|
return {
|
|
7805
7792
|
type: "inline",
|
|
@@ -7810,7 +7797,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7810
7797
|
return pruneUndefined({
|
|
7811
7798
|
type: source.type,
|
|
7812
7799
|
source: source.source,
|
|
7813
|
-
target:
|
|
7800
|
+
target: source.target ?? void 0
|
|
7814
7801
|
});
|
|
7815
7802
|
});
|
|
7816
7803
|
let network;
|
|
@@ -7819,13 +7806,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7819
7806
|
} else if (environmentOptions.network != null) {
|
|
7820
7807
|
network = {
|
|
7821
7808
|
allowlist: environmentOptions.network.allowlist.map(
|
|
7822
|
-
(entry) => {
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
7827
|
-
});
|
|
7828
|
-
}
|
|
7809
|
+
(entry) => pruneUndefined({
|
|
7810
|
+
domain: entry.domain,
|
|
7811
|
+
transform: entry.transform ?? void 0
|
|
7812
|
+
})
|
|
7829
7813
|
)
|
|
7830
7814
|
};
|
|
7831
7815
|
}
|
|
@@ -7842,25 +7826,24 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7842
7826
|
system_instruction: systemInstruction,
|
|
7843
7827
|
tools: toolsForBody,
|
|
7844
7828
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
7845
|
-
response_modalities:
|
|
7846
|
-
previous_interaction_id:
|
|
7847
|
-
service_tier:
|
|
7848
|
-
store:
|
|
7829
|
+
response_modalities: googleOptions?.responseModalities != null ? googleOptions.responseModalities : void 0,
|
|
7830
|
+
previous_interaction_id: googleOptions?.previousInteractionId ?? void 0,
|
|
7831
|
+
service_tier: googleOptions?.serviceTier ?? void 0,
|
|
7832
|
+
store: googleOptions?.store ?? void 0,
|
|
7849
7833
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
7850
7834
|
agent_config: agentConfig,
|
|
7851
7835
|
environment,
|
|
7852
|
-
background:
|
|
7836
|
+
background: googleOptions?.background ?? void 0
|
|
7853
7837
|
});
|
|
7854
7838
|
return {
|
|
7855
7839
|
args,
|
|
7856
7840
|
warnings,
|
|
7857
7841
|
isAgent,
|
|
7858
|
-
isBackground:
|
|
7859
|
-
pollingTimeoutMs:
|
|
7842
|
+
isBackground: googleOptions?.background === true,
|
|
7843
|
+
pollingTimeoutMs: googleOptions?.pollingTimeoutMs ?? void 0
|
|
7860
7844
|
};
|
|
7861
7845
|
}
|
|
7862
7846
|
async doGenerate(options) {
|
|
7863
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
7864
7847
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
7865
7848
|
const url = `${this.config.baseURL}/interactions`;
|
|
7866
7849
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7894,12 +7877,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7894
7877
|
});
|
|
7895
7878
|
response = polled.response;
|
|
7896
7879
|
rawResponse = polled.rawResponse;
|
|
7897
|
-
responseHeaders =
|
|
7880
|
+
responseHeaders = polled.responseHeaders ?? responseHeaders;
|
|
7898
7881
|
}
|
|
7899
7882
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7900
7883
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
7901
|
-
steps:
|
|
7902
|
-
generateId:
|
|
7884
|
+
steps: response.steps ?? null,
|
|
7885
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
7903
7886
|
interactionId
|
|
7904
7887
|
});
|
|
7905
7888
|
const finishReason = {
|
|
@@ -7909,7 +7892,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7909
7892
|
}),
|
|
7910
7893
|
raw: response.status
|
|
7911
7894
|
};
|
|
7912
|
-
const serviceTier =
|
|
7895
|
+
const serviceTier = response.service_tier ?? responseHeaders?.["x-gemini-service-tier"] ?? void 0;
|
|
7913
7896
|
const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
|
|
7914
7897
|
response.usage
|
|
7915
7898
|
);
|
|
@@ -7939,12 +7922,11 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7939
7922
|
body: rawResponse,
|
|
7940
7923
|
...interactionId != null ? { id: interactionId } : {},
|
|
7941
7924
|
...timestamp ? { timestamp } : {},
|
|
7942
|
-
modelId:
|
|
7925
|
+
modelId: response.model ?? void 0
|
|
7943
7926
|
}
|
|
7944
7927
|
};
|
|
7945
7928
|
}
|
|
7946
7929
|
async doStream(options) {
|
|
7947
|
-
var _a2;
|
|
7948
7930
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
7949
7931
|
const url = `${this.config.baseURL}/interactions`;
|
|
7950
7932
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7973,10 +7955,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7973
7955
|
abortSignal: options.abortSignal,
|
|
7974
7956
|
fetch: this.config.fetch
|
|
7975
7957
|
});
|
|
7976
|
-
const headerServiceTier = responseHeaders
|
|
7958
|
+
const headerServiceTier = responseHeaders?.["x-gemini-service-tier"];
|
|
7977
7959
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
7978
7960
|
warnings,
|
|
7979
|
-
generateId:
|
|
7961
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
7980
7962
|
includeRawChunks: options.includeRawChunks,
|
|
7981
7963
|
serviceTier: headerServiceTier
|
|
7982
7964
|
});
|
|
@@ -8012,7 +7994,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8012
7994
|
options,
|
|
8013
7995
|
pollingTimeoutMs
|
|
8014
7996
|
}) {
|
|
8015
|
-
var _a2, _b;
|
|
8016
7997
|
const postResult = await postJsonToApi6({
|
|
8017
7998
|
url,
|
|
8018
7999
|
headers: mergedHeaders,
|
|
@@ -8031,12 +8012,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8031
8012
|
"google.interactions: background POST response did not include an interaction id; cannot stream the result."
|
|
8032
8013
|
);
|
|
8033
8014
|
}
|
|
8034
|
-
const headerServiceTier = postHeaders
|
|
8015
|
+
const headerServiceTier = postHeaders?.["x-gemini-service-tier"];
|
|
8035
8016
|
if (isTerminalStatus(postResponse.status)) {
|
|
8036
8017
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
8037
8018
|
response: postResponse,
|
|
8038
8019
|
warnings,
|
|
8039
|
-
generateId:
|
|
8020
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
8040
8021
|
includeRawChunks: options.includeRawChunks,
|
|
8041
8022
|
headerServiceTier
|
|
8042
8023
|
});
|
|
@@ -8056,7 +8037,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8056
8037
|
});
|
|
8057
8038
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
8058
8039
|
warnings,
|
|
8059
|
-
generateId:
|
|
8040
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
8060
8041
|
includeRawChunks: options.includeRawChunks,
|
|
8061
8042
|
serviceTier: headerServiceTier
|
|
8062
8043
|
});
|
|
@@ -8128,17 +8109,15 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8128
8109
|
this.turnClosed = false;
|
|
8129
8110
|
}
|
|
8130
8111
|
parseServerEvent(raw) {
|
|
8131
|
-
var _a2, _b;
|
|
8132
8112
|
const data = raw;
|
|
8133
8113
|
if (data.setupComplete != null) {
|
|
8134
8114
|
return { type: "session-created", raw };
|
|
8135
8115
|
}
|
|
8136
8116
|
if (data.toolCall != null) {
|
|
8137
8117
|
this.beginTurnIfClosed();
|
|
8138
|
-
const functionCalls =
|
|
8118
|
+
const functionCalls = data.toolCall.functionCalls ?? [];
|
|
8139
8119
|
return functionCalls.flatMap((functionCall) => {
|
|
8140
|
-
|
|
8141
|
-
const args = JSON.stringify((_a3 = functionCall.args) != null ? _a3 : {});
|
|
8120
|
+
const args = JSON.stringify(functionCall.args ?? {});
|
|
8142
8121
|
return [
|
|
8143
8122
|
{
|
|
8144
8123
|
type: "function-call-arguments-delta",
|
|
@@ -8184,7 +8163,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8184
8163
|
if (data.serverContent != null) {
|
|
8185
8164
|
return this.parseServerContent(data.serverContent, raw);
|
|
8186
8165
|
}
|
|
8187
|
-
if (
|
|
8166
|
+
if (data.inputTranscription?.text != null) {
|
|
8188
8167
|
return {
|
|
8189
8168
|
type: "input-transcription-completed",
|
|
8190
8169
|
itemId: `google-input-${this.turnCounter}`,
|
|
@@ -8195,7 +8174,6 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8195
8174
|
return { type: "custom", rawType: String(Object.keys(data)[0]), raw };
|
|
8196
8175
|
}
|
|
8197
8176
|
parseServerContent(serverContent, raw) {
|
|
8198
|
-
var _a2, _b, _c, _d;
|
|
8199
8177
|
const events = [];
|
|
8200
8178
|
if (serverContent.interrupted) {
|
|
8201
8179
|
events.push({
|
|
@@ -8203,10 +8181,10 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8203
8181
|
raw
|
|
8204
8182
|
});
|
|
8205
8183
|
}
|
|
8206
|
-
if (
|
|
8184
|
+
if (serverContent.modelTurn?.parts) {
|
|
8207
8185
|
this.beginTurnIfClosed();
|
|
8208
8186
|
for (const part of serverContent.modelTurn.parts) {
|
|
8209
|
-
if (
|
|
8187
|
+
if (part.inlineData?.data) {
|
|
8210
8188
|
this.hasAudio = true;
|
|
8211
8189
|
events.push({
|
|
8212
8190
|
type: "audio-delta",
|
|
@@ -8228,7 +8206,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8228
8206
|
}
|
|
8229
8207
|
}
|
|
8230
8208
|
}
|
|
8231
|
-
if (
|
|
8209
|
+
if (serverContent.outputTranscription?.text) {
|
|
8232
8210
|
this.hasTranscript = true;
|
|
8233
8211
|
events.push({
|
|
8234
8212
|
type: "audio-transcript-delta",
|
|
@@ -8238,7 +8216,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8238
8216
|
raw
|
|
8239
8217
|
});
|
|
8240
8218
|
}
|
|
8241
|
-
if (
|
|
8219
|
+
if (serverContent.inputTranscription?.text) {
|
|
8242
8220
|
events.push({
|
|
8243
8221
|
type: "input-transcription-completed",
|
|
8244
8222
|
itemId: `google-input-${this.turnCounter}`,
|
|
@@ -8306,10 +8284,9 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8306
8284
|
return events.length === 1 ? events[0] : events;
|
|
8307
8285
|
}
|
|
8308
8286
|
serializeClientEvent(event, modelId) {
|
|
8309
|
-
var _a2;
|
|
8310
8287
|
switch (event.type) {
|
|
8311
8288
|
case "session-update":
|
|
8312
|
-
if (
|
|
8289
|
+
if (event.config.inputAudioFormat?.rate != null) {
|
|
8313
8290
|
this.inputAudioRate = event.config.inputAudioFormat.rate;
|
|
8314
8291
|
}
|
|
8315
8292
|
return {
|
|
@@ -8378,26 +8355,24 @@ async function serializeFunctionCallOutput(item) {
|
|
|
8378
8355
|
};
|
|
8379
8356
|
}
|
|
8380
8357
|
function isThinkingLiveModel(modelId) {
|
|
8381
|
-
|
|
8382
|
-
const modelName = (_b = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
8358
|
+
const modelName = modelId.split("/").at(-1)?.toLowerCase() ?? "";
|
|
8383
8359
|
return /^gemini-\d+\.\d+-live\b.*thinking/.test(modelName);
|
|
8384
8360
|
}
|
|
8385
8361
|
function buildGoogleSessionConfig(config, modelId) {
|
|
8386
|
-
var _a2, _b;
|
|
8387
8362
|
const setup = {
|
|
8388
8363
|
model: getModelPath(modelId)
|
|
8389
8364
|
};
|
|
8390
|
-
const { google: google2, ...restProviderOptions } =
|
|
8365
|
+
const { google: google2, ...restProviderOptions } = config?.providerOptions ?? {};
|
|
8391
8366
|
const googleOptions = isRecord(google2) ? google2 : void 0;
|
|
8392
8367
|
const generationConfig = {};
|
|
8393
|
-
if (
|
|
8368
|
+
if (config?.outputModalities != null) {
|
|
8394
8369
|
generationConfig.responseModalities = config.outputModalities.map(
|
|
8395
8370
|
(m) => m.toUpperCase()
|
|
8396
8371
|
);
|
|
8397
8372
|
} else {
|
|
8398
8373
|
generationConfig.responseModalities = ["AUDIO"];
|
|
8399
8374
|
}
|
|
8400
|
-
if (
|
|
8375
|
+
if (config?.voice != null) {
|
|
8401
8376
|
generationConfig.speechConfig = {
|
|
8402
8377
|
voiceConfig: {
|
|
8403
8378
|
prebuiltVoiceConfig: {
|
|
@@ -8407,41 +8382,41 @@ function buildGoogleSessionConfig(config, modelId) {
|
|
|
8407
8382
|
};
|
|
8408
8383
|
}
|
|
8409
8384
|
setup.generationConfig = generationConfig;
|
|
8410
|
-
if (
|
|
8385
|
+
if (config?.instructions != null) {
|
|
8411
8386
|
setup.systemInstruction = {
|
|
8412
8387
|
parts: [{ text: config.instructions }]
|
|
8413
8388
|
};
|
|
8414
8389
|
}
|
|
8415
|
-
if (
|
|
8390
|
+
if (config?.tools != null && config.tools.length > 0) {
|
|
8416
8391
|
setup.tools = [
|
|
8417
8392
|
{
|
|
8418
8393
|
functionDeclarations: config.tools.map((tool) => ({
|
|
8419
8394
|
name: tool.name,
|
|
8420
8395
|
description: tool.description,
|
|
8421
8396
|
parametersJsonSchema: tool.parameters,
|
|
8422
|
-
...
|
|
8397
|
+
...googleOptions?.defaultToolBehavior != null ? { behavior: googleOptions.defaultToolBehavior } : {}
|
|
8423
8398
|
}))
|
|
8424
8399
|
}
|
|
8425
8400
|
];
|
|
8426
8401
|
}
|
|
8427
|
-
if (
|
|
8402
|
+
if (config?.inputAudioTranscription != null) {
|
|
8428
8403
|
setup.inputAudioTranscription = {};
|
|
8429
8404
|
}
|
|
8430
|
-
if (
|
|
8405
|
+
if (config?.outputAudioTranscription != null) {
|
|
8431
8406
|
setup.outputAudioTranscription = {};
|
|
8432
8407
|
}
|
|
8433
|
-
const thinkingConfig =
|
|
8408
|
+
const thinkingConfig = googleOptions?.thinkingConfig ?? (isThinkingLiveModel(modelId) ? { thinkingLevel: "low" } : void 0);
|
|
8434
8409
|
const applyThinkingConfig = () => {
|
|
8435
8410
|
if (thinkingConfig == null) return;
|
|
8436
8411
|
const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
|
|
8437
8412
|
setup.generationConfig = { ...target, thinkingConfig };
|
|
8438
8413
|
};
|
|
8439
|
-
if (
|
|
8414
|
+
if (config?.providerOptions == null) {
|
|
8440
8415
|
applyThinkingConfig();
|
|
8441
8416
|
return setup;
|
|
8442
8417
|
}
|
|
8443
8418
|
Object.assign(setup, restProviderOptions);
|
|
8444
|
-
if (
|
|
8419
|
+
if (googleOptions?.translationConfig != null) {
|
|
8445
8420
|
const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
|
|
8446
8421
|
setup.generationConfig = {
|
|
8447
8422
|
...target,
|
|
@@ -8471,8 +8446,7 @@ var GoogleRealtimeModel = class {
|
|
|
8471
8446
|
this.config = config;
|
|
8472
8447
|
}
|
|
8473
8448
|
async doCreateClientSecret(options) {
|
|
8474
|
-
|
|
8475
|
-
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
8449
|
+
const fetchFn = this.config.fetch ?? fetch;
|
|
8476
8450
|
const headers = this.config.headers();
|
|
8477
8451
|
const apiKey = headers["x-goog-api-key"];
|
|
8478
8452
|
if (!apiKey) {
|
|
@@ -8481,7 +8455,7 @@ var GoogleRealtimeModel = class {
|
|
|
8481
8455
|
);
|
|
8482
8456
|
}
|
|
8483
8457
|
const now = Date.now();
|
|
8484
|
-
const openWindowMs = (
|
|
8458
|
+
const openWindowMs = (options.expiresAfterSeconds ?? 60) * 1e3;
|
|
8485
8459
|
const newSessionExpireTime = new Date(now + openWindowMs).toISOString();
|
|
8486
8460
|
const expireTime = new Date(
|
|
8487
8461
|
now + openWindowMs + 30 * 60 * 1e3
|
|
@@ -8625,14 +8599,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8625
8599
|
});
|
|
8626
8600
|
}
|
|
8627
8601
|
async doGenerate(options) {
|
|
8628
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
8629
8602
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
8630
8603
|
throw new InvalidArgumentError3({
|
|
8631
8604
|
argument: "modelId",
|
|
8632
8605
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
8633
8606
|
});
|
|
8634
8607
|
}
|
|
8635
|
-
const currentDate =
|
|
8608
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
8636
8609
|
const warnings = [];
|
|
8637
8610
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8638
8611
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -8667,11 +8640,11 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8667
8640
|
});
|
|
8668
8641
|
let text = "";
|
|
8669
8642
|
const segments = [];
|
|
8670
|
-
for (const step of
|
|
8671
|
-
for (const content of
|
|
8643
|
+
for (const step of response.steps ?? []) {
|
|
8644
|
+
for (const content of step.content ?? []) {
|
|
8672
8645
|
if (content.type !== "text" || content.text == null) continue;
|
|
8673
8646
|
text += content.text;
|
|
8674
|
-
for (const annotation of
|
|
8647
|
+
for (const annotation of content.annotations ?? []) {
|
|
8675
8648
|
if (annotation.type !== "word_info") continue;
|
|
8676
8649
|
const startSecond = parseOffsetSeconds(annotation.start_offset);
|
|
8677
8650
|
const endSecond = parseOffsetSeconds(annotation.end_offset);
|
|
@@ -8702,14 +8675,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8702
8675
|
};
|
|
8703
8676
|
}
|
|
8704
8677
|
async doStream(options) {
|
|
8705
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
8706
8678
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
8707
8679
|
throw new InvalidArgumentError3({
|
|
8708
8680
|
argument: "modelId",
|
|
8709
8681
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
8710
8682
|
});
|
|
8711
8683
|
}
|
|
8712
|
-
const currentDate =
|
|
8684
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
8713
8685
|
const warnings = [];
|
|
8714
8686
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8715
8687
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -8735,7 +8707,7 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8735
8707
|
);
|
|
8736
8708
|
const setup = {
|
|
8737
8709
|
model: getModelPath(this.modelId),
|
|
8738
|
-
inputAudioTranscription:
|
|
8710
|
+
inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
|
|
8739
8711
|
};
|
|
8740
8712
|
return {
|
|
8741
8713
|
request: { body: setup },
|
|
@@ -8748,8 +8720,8 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8748
8720
|
url: getLiveWebSocketURL(this.config.baseURL, apiKey),
|
|
8749
8721
|
headers: webSocketHeaders,
|
|
8750
8722
|
setup,
|
|
8751
|
-
inputAudioRate:
|
|
8752
|
-
finishGraceMs:
|
|
8723
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
8724
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
|
|
8753
8725
|
warnings,
|
|
8754
8726
|
audio: options.audio,
|
|
8755
8727
|
abortSignal: options.abortSignal,
|
|
@@ -8813,7 +8785,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8813
8785
|
void audio.cancel().catch(() => {
|
|
8814
8786
|
});
|
|
8815
8787
|
}
|
|
8816
|
-
connection
|
|
8788
|
+
connection?.close(closeCode);
|
|
8817
8789
|
};
|
|
8818
8790
|
const finishWithError = (error) => {
|
|
8819
8791
|
if (finished) return;
|
|
@@ -8894,7 +8866,6 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8894
8866
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
8895
8867
|
},
|
|
8896
8868
|
onMessageText: async (text) => {
|
|
8897
|
-
var _a2, _b;
|
|
8898
8869
|
if (finished) return;
|
|
8899
8870
|
const parsed = await safeParseJSON2({ text });
|
|
8900
8871
|
if (!parsed.success) return;
|
|
@@ -8910,13 +8881,13 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8910
8881
|
}
|
|
8911
8882
|
if (message.error != null) {
|
|
8912
8883
|
finishWithError(
|
|
8913
|
-
new Error(
|
|
8884
|
+
new Error(message.error.message ?? "Google Live API error")
|
|
8914
8885
|
);
|
|
8915
8886
|
return;
|
|
8916
8887
|
}
|
|
8917
8888
|
const serverContent = message.serverContent;
|
|
8918
|
-
const interim = serverContent
|
|
8919
|
-
if (interim
|
|
8889
|
+
const interim = serverContent?.interimInputTranscription;
|
|
8890
|
+
if (interim?.text) {
|
|
8920
8891
|
schedulePendingFinish();
|
|
8921
8892
|
latestInterim = interim.text;
|
|
8922
8893
|
controller.enqueue({
|
|
@@ -8925,7 +8896,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8925
8896
|
text: interim.text
|
|
8926
8897
|
});
|
|
8927
8898
|
}
|
|
8928
|
-
const transcription =
|
|
8899
|
+
const transcription = serverContent?.inputTranscription ?? message.inputTranscription;
|
|
8929
8900
|
if (transcription != null) {
|
|
8930
8901
|
if (transcription.languageCode != null) {
|
|
8931
8902
|
language = transcription.languageCode;
|
|
@@ -8944,11 +8915,11 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8944
8915
|
completeSegment();
|
|
8945
8916
|
}
|
|
8946
8917
|
}
|
|
8947
|
-
if (serverContent
|
|
8918
|
+
if (serverContent?.turnComplete) {
|
|
8948
8919
|
completeSegment();
|
|
8949
8920
|
}
|
|
8950
|
-
const interactionStatus = serverContent
|
|
8951
|
-
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" ||
|
|
8921
|
+
const interactionStatus = serverContent?.interactionStatus;
|
|
8922
|
+
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) {
|
|
8952
8923
|
finish();
|
|
8953
8924
|
}
|
|
8954
8925
|
},
|
|
@@ -8963,7 +8934,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8963
8934
|
}
|
|
8964
8935
|
finishWithError(
|
|
8965
8936
|
new Error(
|
|
8966
|
-
`Google Live transcription WebSocket closed unexpectedly before finishing (code ${code
|
|
8937
|
+
`Google Live transcription WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
8967
8938
|
)
|
|
8968
8939
|
);
|
|
8969
8940
|
}
|
|
@@ -8997,7 +8968,6 @@ function buildAudioTranscriptionConfig(options) {
|
|
|
8997
8968
|
return Object.keys(config).length > 0 ? config : void 0;
|
|
8998
8969
|
}
|
|
8999
8970
|
function buildTranscriptionConfig(options) {
|
|
9000
|
-
var _a2;
|
|
9001
8971
|
if (options == null) return void 0;
|
|
9002
8972
|
const config = {};
|
|
9003
8973
|
if (options.languageCodes != null) {
|
|
@@ -9008,7 +8978,7 @@ function buildTranscriptionConfig(options) {
|
|
|
9008
8978
|
}
|
|
9009
8979
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
9010
8980
|
config.mode = {
|
|
9011
|
-
type: (
|
|
8981
|
+
type: (options.mode ?? "VERBATIM").toLowerCase(),
|
|
9012
8982
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
9013
8983
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
9014
8984
|
};
|
|
@@ -9116,14 +9086,13 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
9116
9086
|
return this.config.provider;
|
|
9117
9087
|
}
|
|
9118
9088
|
async doStream(options) {
|
|
9119
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
9120
9089
|
if (options.targetLanguage == null) {
|
|
9121
9090
|
throw new InvalidArgumentError4({
|
|
9122
9091
|
argument: "targetLanguage",
|
|
9123
9092
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
9124
9093
|
});
|
|
9125
9094
|
}
|
|
9126
|
-
const currentDate =
|
|
9095
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
9127
9096
|
const googleOptions = await parseProviderOptions10({
|
|
9128
9097
|
provider: "google",
|
|
9129
9098
|
providerOptions: options.providerOptions,
|
|
@@ -9178,8 +9147,8 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
9178
9147
|
url: getLiveWebSocketURL2(this.config.baseURL, apiKey),
|
|
9179
9148
|
headers: webSocketHeaders,
|
|
9180
9149
|
setup,
|
|
9181
|
-
inputAudioRate:
|
|
9182
|
-
finishGraceMs:
|
|
9150
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
9151
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs2,
|
|
9183
9152
|
warnings,
|
|
9184
9153
|
audio: options.audio,
|
|
9185
9154
|
abortSignal: options.abortSignal,
|
|
@@ -9250,7 +9219,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9250
9219
|
void audio.cancel().catch(() => {
|
|
9251
9220
|
});
|
|
9252
9221
|
}
|
|
9253
|
-
connection
|
|
9222
|
+
connection?.close(closeCode);
|
|
9254
9223
|
};
|
|
9255
9224
|
const finishWithError = (error) => {
|
|
9256
9225
|
if (finished) return;
|
|
@@ -9339,7 +9308,6 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9339
9308
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
9340
9309
|
},
|
|
9341
9310
|
onMessageText: async (text) => {
|
|
9342
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9343
9311
|
if (finished) return;
|
|
9344
9312
|
const parsed = await safeParseJSON3({ text });
|
|
9345
9313
|
if (!parsed.success) return;
|
|
@@ -9355,11 +9323,11 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9355
9323
|
}
|
|
9356
9324
|
if (message.error != null) {
|
|
9357
9325
|
finishWithError(
|
|
9358
|
-
new Error(
|
|
9326
|
+
new Error(message.error.message ?? "Google Live API error")
|
|
9359
9327
|
);
|
|
9360
9328
|
return;
|
|
9361
9329
|
}
|
|
9362
|
-
const inputTranscriptionText =
|
|
9330
|
+
const inputTranscriptionText = message.serverContent?.inputTranscription?.text ?? message.inputTranscription?.text;
|
|
9363
9331
|
if (inputTranscriptionText) {
|
|
9364
9332
|
onTurnActivity();
|
|
9365
9333
|
sourceTurnBuffer += inputTranscriptionText;
|
|
@@ -9373,8 +9341,8 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9373
9341
|
if (serverContent == null) {
|
|
9374
9342
|
return;
|
|
9375
9343
|
}
|
|
9376
|
-
for (const part of
|
|
9377
|
-
if (
|
|
9344
|
+
for (const part of serverContent.modelTurn?.parts ?? []) {
|
|
9345
|
+
if (part.inlineData?.data) {
|
|
9378
9346
|
controller.enqueue({
|
|
9379
9347
|
type: "audio",
|
|
9380
9348
|
id: itemId(),
|
|
@@ -9394,7 +9362,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9394
9362
|
}
|
|
9395
9363
|
}
|
|
9396
9364
|
}
|
|
9397
|
-
if (
|
|
9365
|
+
if (serverContent.outputTranscription?.text) {
|
|
9398
9366
|
onTurnActivity();
|
|
9399
9367
|
translationTurnBuffer += serverContent.outputTranscription.text;
|
|
9400
9368
|
controller.enqueue({
|
|
@@ -9423,7 +9391,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9423
9391
|
}
|
|
9424
9392
|
finishWithError(
|
|
9425
9393
|
new Error(
|
|
9426
|
-
`Google Live translation WebSocket closed unexpectedly before finishing (code ${code
|
|
9394
|
+
`Google Live translation WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
9427
9395
|
)
|
|
9428
9396
|
);
|
|
9429
9397
|
}
|
|
@@ -9437,17 +9405,16 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9437
9405
|
});
|
|
9438
9406
|
}
|
|
9439
9407
|
function accumulateGoogleLiveUsage(usage, usageMetadata) {
|
|
9440
|
-
|
|
9441
|
-
let
|
|
9442
|
-
|
|
9443
|
-
for (const detail of (_a2 = usageMetadata.promptTokensDetails) != null ? _a2 : []) {
|
|
9408
|
+
let inputAudioTokens = usage?.inputAudioTokens;
|
|
9409
|
+
let outputAudioTokens = usage?.outputAudioTokens;
|
|
9410
|
+
for (const detail of usageMetadata.promptTokensDetails ?? []) {
|
|
9444
9411
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9445
|
-
inputAudioTokens = (inputAudioTokens
|
|
9412
|
+
inputAudioTokens = (inputAudioTokens ?? 0) + detail.tokenCount;
|
|
9446
9413
|
}
|
|
9447
9414
|
}
|
|
9448
|
-
for (const detail of
|
|
9415
|
+
for (const detail of usageMetadata.responseTokensDetails ?? []) {
|
|
9449
9416
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9450
|
-
outputAudioTokens = (outputAudioTokens
|
|
9417
|
+
outputAudioTokens = (outputAudioTokens ?? 0) + detail.tokenCount;
|
|
9451
9418
|
}
|
|
9452
9419
|
}
|
|
9453
9420
|
if (inputAudioTokens == null && outputAudioTokens == null) {
|
|
@@ -9463,7 +9430,7 @@ function getPcm16SilenceDurationMs(audio) {
|
|
|
9463
9430
|
let bytes;
|
|
9464
9431
|
try {
|
|
9465
9432
|
bytes = convertBase64ToUint8Array2(audio);
|
|
9466
|
-
} catch
|
|
9433
|
+
} catch {
|
|
9467
9434
|
return void 0;
|
|
9468
9435
|
}
|
|
9469
9436
|
if (bytes.byteLength < 2) {
|
|
@@ -9489,7 +9456,7 @@ function buildGoogleLiveSpeechTranslationSetup({
|
|
|
9489
9456
|
responseModalities: ["AUDIO"],
|
|
9490
9457
|
translationConfig: {
|
|
9491
9458
|
targetLanguageCode: targetLanguage,
|
|
9492
|
-
...
|
|
9459
|
+
...providerOptions?.echoTargetLanguage != null ? { echoTargetLanguage: providerOptions.echoTargetLanguage } : {}
|
|
9493
9460
|
}
|
|
9494
9461
|
},
|
|
9495
9462
|
inputAudioTranscription: {},
|
|
@@ -9537,9 +9504,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
9537
9504
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
9538
9505
|
}
|
|
9539
9506
|
function createGoogle(options = {}) {
|
|
9540
|
-
|
|
9541
|
-
const
|
|
9542
|
-
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
9507
|
+
const baseURL = withoutTrailingSlash(options.baseURL) ?? DEFAULT_BASE_URL;
|
|
9508
|
+
const providerName = options.name ?? "google.generative-ai";
|
|
9543
9509
|
const getHeaders = () => withUserAgentSuffix2(
|
|
9544
9510
|
{
|
|
9545
9511
|
"x-goog-api-key": loadApiKey({
|
|
@@ -9571,7 +9537,7 @@ function createGoogle(options = {}) {
|
|
|
9571
9537
|
provider: providerName,
|
|
9572
9538
|
baseURL,
|
|
9573
9539
|
headers: getHeaders,
|
|
9574
|
-
generateId:
|
|
9540
|
+
generateId: options.generateId ?? generateId3,
|
|
9575
9541
|
fetch: options.fetch
|
|
9576
9542
|
};
|
|
9577
9543
|
const createChatModel = (modelId) => new GoogleLanguageModel(modelId, {
|
|
@@ -9603,16 +9569,13 @@ function createGoogle(options = {}) {
|
|
|
9603
9569
|
headers: getHeaders,
|
|
9604
9570
|
fetch: options.fetch
|
|
9605
9571
|
});
|
|
9606
|
-
const createVideoModel = (modelId) => {
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3
|
|
9614
|
-
});
|
|
9615
|
-
};
|
|
9572
|
+
const createVideoModel = (modelId) => new GoogleVideoModel(modelId, {
|
|
9573
|
+
provider: providerName,
|
|
9574
|
+
baseURL,
|
|
9575
|
+
headers: getHeaders,
|
|
9576
|
+
fetch: options.fetch,
|
|
9577
|
+
generateId: options.generateId ?? generateId3
|
|
9578
|
+
});
|
|
9616
9579
|
const createRealtimeModel = (modelId) => new GoogleRealtimeModel(modelId, {
|
|
9617
9580
|
provider: `${providerName}.realtime`,
|
|
9618
9581
|
baseURL,
|
|
@@ -9655,19 +9618,16 @@ function createGoogle(options = {}) {
|
|
|
9655
9618
|
}
|
|
9656
9619
|
}
|
|
9657
9620
|
);
|
|
9658
|
-
const createInteractionsModel = (modelIdOrAgent) =>
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
}
|
|
9669
|
-
);
|
|
9670
|
-
};
|
|
9621
|
+
const createInteractionsModel = (modelIdOrAgent) => new GoogleInteractionsLanguageModel(
|
|
9622
|
+
modelIdOrAgent,
|
|
9623
|
+
{
|
|
9624
|
+
provider: `${providerName}.interactions`,
|
|
9625
|
+
baseURL,
|
|
9626
|
+
headers: getHeaders,
|
|
9627
|
+
generateId: options.generateId ?? generateId3,
|
|
9628
|
+
fetch: options.fetch
|
|
9629
|
+
}
|
|
9630
|
+
);
|
|
9671
9631
|
const provider = function(modelId) {
|
|
9672
9632
|
if (new.target) {
|
|
9673
9633
|
throw new Error(
|