@ai-sdk/google 4.0.80 → 4.0.83
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 +37 -0
- package/dist/index.js +492 -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 +4 -4
- package/src/convert-to-google-messages.ts +30 -9
- package/src/download-tool-result-files.ts +20 -2
- package/src/google-image-model.ts +16 -0
- 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/src/realtime/google-realtime-event-mapper.ts +16 -6
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.83" : "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
|
}
|
|
@@ -3899,6 +3912,11 @@ import {
|
|
|
3899
3912
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
3900
3913
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
|
|
3901
3914
|
} from "@ai-sdk/provider-utils";
|
|
3915
|
+
var googleImageModelsWithFileInputSupport = /* @__PURE__ */ new Set([
|
|
3916
|
+
"gemini-2.5-flash-image",
|
|
3917
|
+
"gemini-3-pro-image-preview",
|
|
3918
|
+
"gemini-3.1-flash-image-preview"
|
|
3919
|
+
]);
|
|
3902
3920
|
var GoogleImageModel = class _GoogleImageModel {
|
|
3903
3921
|
constructor(modelId, settings, config) {
|
|
3904
3922
|
this.modelId = modelId;
|
|
@@ -3921,11 +3939,16 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3921
3939
|
}
|
|
3922
3940
|
return 1;
|
|
3923
3941
|
}
|
|
3942
|
+
get supportsFileInputs() {
|
|
3943
|
+
return googleImageModelsWithFileInputSupport.has(this.modelId) ? true : void 0;
|
|
3944
|
+
}
|
|
3945
|
+
get supportsMaskInputs() {
|
|
3946
|
+
return this.supportsFileInputs === true ? false : void 0;
|
|
3947
|
+
}
|
|
3924
3948
|
get provider() {
|
|
3925
3949
|
return this.config.provider;
|
|
3926
3950
|
}
|
|
3927
3951
|
async doGenerate(options) {
|
|
3928
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3929
3952
|
if (!this.modelId.startsWith("gemini-")) {
|
|
3930
3953
|
throw new Error(
|
|
3931
3954
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -3992,13 +4015,13 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3992
4015
|
responseModalities: _strippedResponseModalities,
|
|
3993
4016
|
imageConfig: userImageConfig,
|
|
3994
4017
|
...passthroughGoogleOptions
|
|
3995
|
-
} =
|
|
4018
|
+
} = providerOptions?.google ?? {};
|
|
3996
4019
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
3997
4020
|
provider: this.config.provider,
|
|
3998
4021
|
baseURL: this.config.baseURL,
|
|
3999
|
-
headers:
|
|
4022
|
+
headers: this.config.headers ?? {},
|
|
4000
4023
|
fetch: this.config.fetch,
|
|
4001
|
-
generateId:
|
|
4024
|
+
generateId: this.config.generateId ?? defaultGenerateId
|
|
4002
4025
|
});
|
|
4003
4026
|
const result = await languageModel.doGenerate({
|
|
4004
4027
|
prompt: languageModelPrompt,
|
|
@@ -4015,7 +4038,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4015
4038
|
} : void 0
|
|
4016
4039
|
}
|
|
4017
4040
|
},
|
|
4018
|
-
tools:
|
|
4041
|
+
tools: googleImageOptions?.googleSearch != null ? [
|
|
4019
4042
|
{
|
|
4020
4043
|
type: "provider",
|
|
4021
4044
|
id: "google.google_search",
|
|
@@ -4026,14 +4049,14 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4026
4049
|
headers,
|
|
4027
4050
|
abortSignal
|
|
4028
4051
|
});
|
|
4029
|
-
const currentDate =
|
|
4052
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4030
4053
|
const images = [];
|
|
4031
4054
|
for (const part of result.content) {
|
|
4032
4055
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
4033
4056
|
images.push(convertToBase643(part.data.data));
|
|
4034
4057
|
}
|
|
4035
4058
|
}
|
|
4036
|
-
const languageModelGoogleMetadata =
|
|
4059
|
+
const languageModelGoogleMetadata = result.providerMetadata?.google ?? {};
|
|
4037
4060
|
return {
|
|
4038
4061
|
images,
|
|
4039
4062
|
...result.finishReason.unified === "content-filter" ? { isRetryable: false } : {},
|
|
@@ -4041,19 +4064,19 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4041
4064
|
providerMetadata: {
|
|
4042
4065
|
google: {
|
|
4043
4066
|
...languageModelGoogleMetadata,
|
|
4044
|
-
finishReason:
|
|
4067
|
+
finishReason: result.finishReason.raw ?? null,
|
|
4045
4068
|
images: images.map(() => ({}))
|
|
4046
4069
|
}
|
|
4047
4070
|
},
|
|
4048
4071
|
response: {
|
|
4049
4072
|
timestamp: currentDate,
|
|
4050
4073
|
modelId: this.modelId,
|
|
4051
|
-
headers:
|
|
4074
|
+
headers: result.response?.headers
|
|
4052
4075
|
},
|
|
4053
4076
|
usage: result.usage ? {
|
|
4054
4077
|
inputTokens: result.usage.inputTokens.total,
|
|
4055
4078
|
outputTokens: result.usage.outputTokens.total,
|
|
4056
|
-
totalTokens: (
|
|
4079
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
4057
4080
|
} : void 0
|
|
4058
4081
|
};
|
|
4059
4082
|
}
|
|
@@ -4087,7 +4110,6 @@ var GoogleFiles = class {
|
|
|
4087
4110
|
return this.config.provider;
|
|
4088
4111
|
}
|
|
4089
4112
|
async uploadFile(options) {
|
|
4090
|
-
var _a2, _b, _c, _d;
|
|
4091
4113
|
const googleOptions = await parseProviderOptions5({
|
|
4092
4114
|
provider: "google",
|
|
4093
4115
|
providerOptions: options.providerOptions,
|
|
@@ -4097,14 +4119,14 @@ var GoogleFiles = class {
|
|
|
4097
4119
|
this.config.headers(),
|
|
4098
4120
|
options.headers
|
|
4099
4121
|
);
|
|
4100
|
-
const fetchFn =
|
|
4122
|
+
const fetchFn = this.config.fetch ?? globalThis.fetch;
|
|
4101
4123
|
const warnings = [];
|
|
4102
4124
|
if (options.filename != null) {
|
|
4103
4125
|
warnings.push({ type: "unsupported", feature: "filename" });
|
|
4104
4126
|
}
|
|
4105
4127
|
const fileBytes = convertInlineFileDataToUint8Array(options.data);
|
|
4106
4128
|
const mediaType = options.mediaType;
|
|
4107
|
-
const displayName = googleOptions
|
|
4129
|
+
const displayName = googleOptions?.displayName;
|
|
4108
4130
|
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|
|
4109
4131
|
const initResponse = await fetchFn(`${baseOrigin}/upload/v1beta/files`, {
|
|
4110
4132
|
method: "POST",
|
|
@@ -4155,8 +4177,8 @@ var GoogleFiles = class {
|
|
|
4155
4177
|
}
|
|
4156
4178
|
const uploadResult = await uploadResponse.json();
|
|
4157
4179
|
let file = uploadResult.file;
|
|
4158
|
-
const pollIntervalMs =
|
|
4159
|
-
const pollTimeoutMs =
|
|
4180
|
+
const pollIntervalMs = googleOptions?.pollIntervalMs ?? 2e3;
|
|
4181
|
+
const pollTimeoutMs = googleOptions?.pollTimeoutMs ?? 3e5;
|
|
4160
4182
|
const startTime = Date.now();
|
|
4161
4183
|
while (file.state === "PROCESSING") {
|
|
4162
4184
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
@@ -4190,7 +4212,7 @@ var GoogleFiles = class {
|
|
|
4190
4212
|
return {
|
|
4191
4213
|
warnings,
|
|
4192
4214
|
providerReference: { google: file.uri },
|
|
4193
|
-
mediaType:
|
|
4215
|
+
mediaType: file.mimeType ?? options.mediaType,
|
|
4194
4216
|
providerMetadata: {
|
|
4195
4217
|
google: {
|
|
4196
4218
|
name: file.name,
|
|
@@ -4278,16 +4300,13 @@ var googleVideoModelOptionsSchema = lazySchema15(
|
|
|
4278
4300
|
|
|
4279
4301
|
// src/google-video-model.ts
|
|
4280
4302
|
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;
|
|
4303
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
4283
4304
|
}
|
|
4284
4305
|
function resolveStartImage(options) {
|
|
4285
|
-
|
|
4286
|
-
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
4306
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
4287
4307
|
}
|
|
4288
4308
|
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;
|
|
4309
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
4291
4310
|
}
|
|
4292
4311
|
function getInputReferences(options) {
|
|
4293
4312
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -4385,7 +4404,7 @@ var GoogleVideoModel = class {
|
|
|
4385
4404
|
const converted = convertInputReferenceImage(reference, warnings);
|
|
4386
4405
|
return converted != null ? [converted] : [];
|
|
4387
4406
|
});
|
|
4388
|
-
} else if (
|
|
4407
|
+
} else if (googleOptions?.referenceImages != null) {
|
|
4389
4408
|
instance.referenceImages = googleOptions.referenceImages.map(
|
|
4390
4409
|
(refImg) => convertProviderReferenceImage(refImg)
|
|
4391
4410
|
);
|
|
@@ -4433,9 +4452,8 @@ var GoogleVideoModel = class {
|
|
|
4433
4452
|
return { instances, parameters, warnings, googleOptions };
|
|
4434
4453
|
}
|
|
4435
4454
|
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
4436
|
-
var _a2, _b;
|
|
4437
4455
|
const response = finalOperation.response;
|
|
4438
|
-
if (!
|
|
4456
|
+
if (!response?.generateVideoResponse?.generatedSamples || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
4439
4457
|
throw new AISDKError2({
|
|
4440
4458
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
4441
4459
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -4444,9 +4462,9 @@ var GoogleVideoModel = class {
|
|
|
4444
4462
|
const videos = [];
|
|
4445
4463
|
const videoMetadata = [];
|
|
4446
4464
|
const resolvedHeaders = await resolve4(this.config.headers);
|
|
4447
|
-
const apiKey = resolvedHeaders
|
|
4465
|
+
const apiKey = resolvedHeaders?.["x-goog-api-key"];
|
|
4448
4466
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
4449
|
-
if (
|
|
4467
|
+
if (generatedSample.video?.uri) {
|
|
4450
4468
|
const urlWithAuth = apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
4451
4469
|
videos.push({
|
|
4452
4470
|
type: "url",
|
|
@@ -4481,8 +4499,7 @@ var GoogleVideoModel = class {
|
|
|
4481
4499
|
};
|
|
4482
4500
|
}
|
|
4483
4501
|
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();
|
|
4502
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4486
4503
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
4487
4504
|
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
4488
4505
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -4519,8 +4536,7 @@ var GoogleVideoModel = class {
|
|
|
4519
4536
|
};
|
|
4520
4537
|
}
|
|
4521
4538
|
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();
|
|
4539
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4524
4540
|
const { operationName } = options.operation;
|
|
4525
4541
|
const { value: statusOperation, responseHeaders } = await getFromApi3({
|
|
4526
4542
|
url: `${this.config.baseURL}/${operationName}`,
|
|
@@ -4632,7 +4648,7 @@ function getGoogleSpeechInput({
|
|
|
4632
4648
|
voice,
|
|
4633
4649
|
providerOptions
|
|
4634
4650
|
}) {
|
|
4635
|
-
const google2 = providerOptions
|
|
4651
|
+
const google2 = providerOptions?.google;
|
|
4636
4652
|
const options = google2 != null && typeof google2 === "object" ? google2 : void 0;
|
|
4637
4653
|
const turns = options && "turns" in options ? options.turns : void 0;
|
|
4638
4654
|
const turnTexts = [];
|
|
@@ -4651,7 +4667,7 @@ function getGoogleSpeechInput({
|
|
|
4651
4667
|
const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
|
|
4652
4668
|
return {
|
|
4653
4669
|
text,
|
|
4654
|
-
usesCustomVoice:
|
|
4670
|
+
usesCustomVoice: voice?.startsWith("voice_") === true || voice?.startsWith("voicekey_") === true || speakers.some(
|
|
4655
4671
|
(speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
|
|
4656
4672
|
)
|
|
4657
4673
|
};
|
|
@@ -4740,7 +4756,6 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4740
4756
|
language,
|
|
4741
4757
|
providerOptions
|
|
4742
4758
|
}) {
|
|
4743
|
-
var _a2;
|
|
4744
4759
|
const warnings = [];
|
|
4745
4760
|
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
4746
4761
|
let googleOptions;
|
|
@@ -4773,7 +4788,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4773
4788
|
message: "Custom voices are not supported. Use a prebuilt voice instead."
|
|
4774
4789
|
});
|
|
4775
4790
|
}
|
|
4776
|
-
const multiSpeakerVoiceConfig = googleOptions
|
|
4791
|
+
const multiSpeakerVoiceConfig = googleOptions?.multiSpeakerVoiceConfig;
|
|
4777
4792
|
const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
|
|
4778
4793
|
let promptText = text;
|
|
4779
4794
|
if (instructions != null && !usesStructuredSpeech) {
|
|
@@ -4789,25 +4804,24 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4789
4804
|
}
|
|
4790
4805
|
let parts = [{ text: promptText }];
|
|
4791
4806
|
if (usesStructuredSpeech) {
|
|
4792
|
-
if (
|
|
4807
|
+
if (googleOptions?.turns && googleOptions.speechMetadata) {
|
|
4793
4808
|
throw new InvalidArgumentError2({
|
|
4794
4809
|
argument: "providerOptions",
|
|
4795
4810
|
message: "Set speechMetadata on each turn when using turns."
|
|
4796
4811
|
});
|
|
4797
4812
|
}
|
|
4798
|
-
if (
|
|
4813
|
+
if (googleOptions?.turns && text !== "") {
|
|
4799
4814
|
warnings.push({
|
|
4800
4815
|
type: "unsupported",
|
|
4801
4816
|
feature: "text",
|
|
4802
4817
|
details: "Google TTS turns replace the top-level text."
|
|
4803
4818
|
});
|
|
4804
4819
|
}
|
|
4805
|
-
parts = (
|
|
4806
|
-
{ text, speechMetadata: googleOptions
|
|
4820
|
+
parts = (googleOptions?.turns ?? [
|
|
4821
|
+
{ text, speechMetadata: googleOptions?.speechMetadata }
|
|
4807
4822
|
]).map((part) => {
|
|
4808
|
-
|
|
4809
|
-
const
|
|
4810
|
-
const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
|
|
4823
|
+
const style = part.speechMetadata?.style ?? instructions;
|
|
4824
|
+
const speaker = part.speechMetadata?.speaker;
|
|
4811
4825
|
if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
|
|
4812
4826
|
(config) => config.speaker === speaker
|
|
4813
4827
|
)) {
|
|
@@ -4821,7 +4835,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4821
4835
|
...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
|
|
4822
4836
|
};
|
|
4823
4837
|
});
|
|
4824
|
-
} else if (
|
|
4838
|
+
} else if (googleOptions?.turns || googleOptions?.speechMetadata) {
|
|
4825
4839
|
throw new InvalidArgumentError2({
|
|
4826
4840
|
argument: "providerOptions",
|
|
4827
4841
|
message: "Structured speech metadata and turns require Gemini 3.8 TTS."
|
|
@@ -4887,8 +4901,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4887
4901
|
};
|
|
4888
4902
|
}
|
|
4889
4903
|
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();
|
|
4904
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4892
4905
|
const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
|
|
4893
4906
|
const {
|
|
4894
4907
|
value: response,
|
|
@@ -4910,11 +4923,11 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4910
4923
|
});
|
|
4911
4924
|
let base64Audio;
|
|
4912
4925
|
let mimeType;
|
|
4913
|
-
for (const candidate of
|
|
4914
|
-
for (const part of
|
|
4915
|
-
if (
|
|
4926
|
+
for (const candidate of response.candidates ?? []) {
|
|
4927
|
+
for (const part of candidate.content?.parts ?? []) {
|
|
4928
|
+
if (part.inlineData?.data) {
|
|
4916
4929
|
base64Audio = part.inlineData.data;
|
|
4917
|
-
mimeType =
|
|
4930
|
+
mimeType = part.inlineData.mimeType ?? void 0;
|
|
4918
4931
|
break;
|
|
4919
4932
|
}
|
|
4920
4933
|
}
|
|
@@ -4922,9 +4935,9 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4922
4935
|
break;
|
|
4923
4936
|
}
|
|
4924
4937
|
}
|
|
4925
|
-
const sampleRate =
|
|
4938
|
+
const sampleRate = parseSampleRate(mimeType) ?? DEFAULT_SAMPLE_RATE;
|
|
4926
4939
|
const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
|
|
4927
|
-
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType
|
|
4940
|
+
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType ?? "") || mimeType == null && !usesStructuredSpeech;
|
|
4928
4941
|
const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
|
|
4929
4942
|
if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
|
|
4930
4943
|
warnings.push({
|
|
@@ -4948,7 +4961,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4948
4961
|
providerMetadata: {
|
|
4949
4962
|
google: {
|
|
4950
4963
|
sampleRate,
|
|
4951
|
-
mimeType: mimeType
|
|
4964
|
+
mimeType: mimeType ?? null
|
|
4952
4965
|
}
|
|
4953
4966
|
}
|
|
4954
4967
|
};
|
|
@@ -5014,37 +5027,36 @@ import {
|
|
|
5014
5027
|
// src/interactions/convert-google-interactions-usage.ts
|
|
5015
5028
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
5016
5029
|
function convertGoogleInteractionsUsage(usage) {
|
|
5017
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5018
5030
|
if (usage == null) {
|
|
5019
5031
|
return createNullLanguageModelUsage2();
|
|
5020
5032
|
}
|
|
5021
|
-
const totalInput =
|
|
5022
|
-
const totalOutput =
|
|
5023
|
-
const totalThought =
|
|
5024
|
-
const totalCached =
|
|
5033
|
+
const totalInput = usage.total_input_tokens ?? 0;
|
|
5034
|
+
const totalOutput = usage.total_output_tokens ?? 0;
|
|
5035
|
+
const totalThought = usage.total_thought_tokens ?? 0;
|
|
5036
|
+
const totalCached = usage.total_cached_tokens ?? 0;
|
|
5025
5037
|
return {
|
|
5026
5038
|
inputTokens: {
|
|
5027
|
-
total:
|
|
5039
|
+
total: usage.total_input_tokens ?? void 0,
|
|
5028
5040
|
noCache: usage.total_input_tokens == null ? void 0 : totalInput - totalCached,
|
|
5029
|
-
cacheRead:
|
|
5041
|
+
cacheRead: usage.total_cached_tokens ?? void 0,
|
|
5030
5042
|
cacheWrite: void 0
|
|
5031
5043
|
},
|
|
5032
5044
|
outputTokens: {
|
|
5033
5045
|
total: usage.total_output_tokens == null && usage.total_thought_tokens == null ? void 0 : totalOutput + totalThought,
|
|
5034
|
-
text:
|
|
5035
|
-
reasoning:
|
|
5046
|
+
text: usage.total_output_tokens ?? void 0,
|
|
5047
|
+
reasoning: usage.total_thought_tokens ?? void 0
|
|
5036
5048
|
},
|
|
5037
5049
|
raw: usage
|
|
5038
5050
|
};
|
|
5039
5051
|
}
|
|
5040
5052
|
function getGoogleInteractionsOutputTokensByModality(usage) {
|
|
5041
|
-
const byModality = usage
|
|
5053
|
+
const byModality = usage?.output_tokens_by_modality;
|
|
5042
5054
|
if (byModality == null) {
|
|
5043
5055
|
return void 0;
|
|
5044
5056
|
}
|
|
5045
5057
|
const result = {};
|
|
5046
5058
|
for (const entry of byModality) {
|
|
5047
|
-
if (
|
|
5059
|
+
if (entry?.modality != null && entry.tokens != null) {
|
|
5048
5060
|
result[entry.modality] = entry.tokens;
|
|
5049
5061
|
}
|
|
5050
5062
|
}
|
|
@@ -5076,7 +5088,6 @@ function annotationToSource({
|
|
|
5076
5088
|
annotation,
|
|
5077
5089
|
generateId: generateId4
|
|
5078
5090
|
}) {
|
|
5079
|
-
var _a2, _b, _c, _d, _e;
|
|
5080
5091
|
switch (annotation.type) {
|
|
5081
5092
|
case "url_citation": {
|
|
5082
5093
|
const urlCitation = annotation;
|
|
@@ -5093,7 +5104,7 @@ function annotationToSource({
|
|
|
5093
5104
|
}
|
|
5094
5105
|
case "file_citation": {
|
|
5095
5106
|
const fileCitation = annotation;
|
|
5096
|
-
const uri =
|
|
5107
|
+
const uri = fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
|
|
5097
5108
|
if (uri == null || uri.length === 0) return void 0;
|
|
5098
5109
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
5099
5110
|
return {
|
|
@@ -5104,14 +5115,14 @@ function annotationToSource({
|
|
|
5104
5115
|
...fileCitation.file_name != null ? { title: fileCitation.file_name } : {}
|
|
5105
5116
|
};
|
|
5106
5117
|
}
|
|
5107
|
-
const filename =
|
|
5118
|
+
const filename = fileCitation.file_name ?? basename(uri);
|
|
5108
5119
|
const mediaType = inferDocMediaType(uri);
|
|
5109
5120
|
return {
|
|
5110
5121
|
type: "source",
|
|
5111
5122
|
sourceType: "document",
|
|
5112
5123
|
id: generateId4(),
|
|
5113
5124
|
mediaType,
|
|
5114
|
-
title:
|
|
5125
|
+
title: fileCitation.file_name ?? filename ?? uri,
|
|
5115
5126
|
...filename != null ? { filename } : {}
|
|
5116
5127
|
};
|
|
5117
5128
|
}
|
|
@@ -5136,13 +5147,12 @@ function builtinToolResultToSources({
|
|
|
5136
5147
|
block,
|
|
5137
5148
|
generateId: generateId4
|
|
5138
5149
|
}) {
|
|
5139
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5140
5150
|
const sources = [];
|
|
5141
5151
|
switch (block.type) {
|
|
5142
5152
|
case "url_context_result": {
|
|
5143
|
-
const result =
|
|
5153
|
+
const result = block.result ?? [];
|
|
5144
5154
|
for (const entry of result) {
|
|
5145
|
-
if (
|
|
5155
|
+
if (entry?.url == null || entry.url.length === 0) continue;
|
|
5146
5156
|
if (entry.status != null && entry.status !== "success") continue;
|
|
5147
5157
|
sources.push({
|
|
5148
5158
|
type: "source",
|
|
@@ -5154,9 +5164,9 @@ function builtinToolResultToSources({
|
|
|
5154
5164
|
break;
|
|
5155
5165
|
}
|
|
5156
5166
|
case "google_search_result": {
|
|
5157
|
-
const result =
|
|
5167
|
+
const result = block.result ?? [];
|
|
5158
5168
|
for (const entry of result) {
|
|
5159
|
-
const url = entry
|
|
5169
|
+
const url = entry?.url;
|
|
5160
5170
|
if (url == null || url.length === 0) continue;
|
|
5161
5171
|
sources.push({
|
|
5162
5172
|
type: "source",
|
|
@@ -5169,9 +5179,9 @@ function builtinToolResultToSources({
|
|
|
5169
5179
|
break;
|
|
5170
5180
|
}
|
|
5171
5181
|
case "google_maps_result": {
|
|
5172
|
-
const result =
|
|
5182
|
+
const result = block.result ?? [];
|
|
5173
5183
|
for (const entry of result) {
|
|
5174
|
-
for (const place of
|
|
5184
|
+
for (const place of entry.places ?? []) {
|
|
5175
5185
|
if (place.url == null || place.url.length === 0) continue;
|
|
5176
5186
|
sources.push({
|
|
5177
5187
|
type: "source",
|
|
@@ -5185,11 +5195,11 @@ function builtinToolResultToSources({
|
|
|
5185
5195
|
break;
|
|
5186
5196
|
}
|
|
5187
5197
|
case "file_search_result": {
|
|
5188
|
-
const result =
|
|
5198
|
+
const result = block.result ?? [];
|
|
5189
5199
|
for (const raw of result) {
|
|
5190
5200
|
if (raw == null || typeof raw !== "object") continue;
|
|
5191
5201
|
const entry = raw;
|
|
5192
|
-
const uri =
|
|
5202
|
+
const uri = entry.url ?? entry.document_uri ?? entry.file_name;
|
|
5193
5203
|
if (uri == null || uri.length === 0) continue;
|
|
5194
5204
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
5195
5205
|
sources.push({
|
|
@@ -5201,14 +5211,14 @@ function builtinToolResultToSources({
|
|
|
5201
5211
|
});
|
|
5202
5212
|
continue;
|
|
5203
5213
|
}
|
|
5204
|
-
const filename =
|
|
5214
|
+
const filename = entry.file_name ?? basename(uri);
|
|
5205
5215
|
const mediaType = inferDocMediaType(uri);
|
|
5206
5216
|
sources.push({
|
|
5207
5217
|
type: "source",
|
|
5208
5218
|
sourceType: "document",
|
|
5209
5219
|
id: generateId4(),
|
|
5210
5220
|
mediaType,
|
|
5211
|
-
title:
|
|
5221
|
+
title: entry.title ?? entry.file_name ?? filename ?? uri,
|
|
5212
5222
|
...filename != null ? { filename } : {}
|
|
5213
5223
|
});
|
|
5214
5224
|
}
|
|
@@ -5223,14 +5233,13 @@ function annotationsToSources({
|
|
|
5223
5233
|
annotations,
|
|
5224
5234
|
generateId: generateId4
|
|
5225
5235
|
}) {
|
|
5226
|
-
var _a2;
|
|
5227
5236
|
if (annotations == null) return [];
|
|
5228
5237
|
const seen = /* @__PURE__ */ new Set();
|
|
5229
5238
|
const sources = [];
|
|
5230
5239
|
for (const annotation of annotations) {
|
|
5231
5240
|
const source = annotationToSource({ annotation, generateId: generateId4 });
|
|
5232
5241
|
if (source == null) continue;
|
|
5233
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${
|
|
5242
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
5234
5243
|
if (seen.has(key)) continue;
|
|
5235
5244
|
seen.add(key);
|
|
5236
5245
|
sources.push(source);
|
|
@@ -5297,15 +5306,13 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5297
5306
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
5298
5307
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
5299
5308
|
function sourceKey(source) {
|
|
5300
|
-
|
|
5301
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5309
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
5302
5310
|
}
|
|
5303
5311
|
return new TransformStream({
|
|
5304
5312
|
start(controller) {
|
|
5305
5313
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5306
5314
|
},
|
|
5307
5315
|
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
5316
|
if (includeRawChunks) {
|
|
5310
5317
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5311
5318
|
}
|
|
@@ -5320,8 +5327,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5320
5327
|
case "interaction.created": {
|
|
5321
5328
|
const event = value;
|
|
5322
5329
|
const interaction = event.interaction;
|
|
5323
|
-
interactionId =
|
|
5324
|
-
const created = interaction
|
|
5330
|
+
interactionId = interaction?.id != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
5331
|
+
const created = interaction?.created;
|
|
5325
5332
|
let timestamp;
|
|
5326
5333
|
if (typeof created === "string") {
|
|
5327
5334
|
const parsed = new Date(created);
|
|
@@ -5332,7 +5339,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5332
5339
|
controller.enqueue({
|
|
5333
5340
|
type: "response-metadata",
|
|
5334
5341
|
...interactionId != null ? { id: interactionId } : {},
|
|
5335
|
-
modelId: interaction
|
|
5342
|
+
modelId: interaction?.model,
|
|
5336
5343
|
...timestamp ? { timestamp } : {}
|
|
5337
5344
|
});
|
|
5338
5345
|
break;
|
|
@@ -5341,11 +5348,11 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5341
5348
|
const event = value;
|
|
5342
5349
|
const step = event.step;
|
|
5343
5350
|
const index = event.index;
|
|
5344
|
-
const blockId = `${interactionId
|
|
5345
|
-
const stepType = step
|
|
5351
|
+
const blockId = `${interactionId ?? "interaction"}:${index}`;
|
|
5352
|
+
const stepType = step?.type;
|
|
5346
5353
|
if (stepType === "model_output") {
|
|
5347
|
-
const initial =
|
|
5348
|
-
if (
|
|
5354
|
+
const initial = step?.content?.[0];
|
|
5355
|
+
if (initial?.type === "text") {
|
|
5349
5356
|
openBlocks.set(index, {
|
|
5350
5357
|
kind: "text",
|
|
5351
5358
|
id: blockId,
|
|
@@ -5362,7 +5369,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5362
5369
|
emittedSourceKeys.add(key);
|
|
5363
5370
|
controller.enqueue(source);
|
|
5364
5371
|
}
|
|
5365
|
-
} else if (
|
|
5372
|
+
} else if (initial?.type === "image") {
|
|
5366
5373
|
openBlocks.set(index, {
|
|
5367
5374
|
kind: "image",
|
|
5368
5375
|
id: blockId,
|
|
@@ -5377,16 +5384,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5377
5384
|
});
|
|
5378
5385
|
}
|
|
5379
5386
|
} else if (stepType === "thought") {
|
|
5380
|
-
const signature = step
|
|
5387
|
+
const signature = step?.signature;
|
|
5381
5388
|
openBlocks.set(index, {
|
|
5382
5389
|
kind: "reasoning",
|
|
5383
5390
|
id: blockId,
|
|
5384
5391
|
...signature != null ? { signature } : {}
|
|
5385
5392
|
});
|
|
5386
5393
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
5387
|
-
if (Array.isArray(step
|
|
5394
|
+
if (Array.isArray(step?.summary)) {
|
|
5388
5395
|
for (const item of step.summary) {
|
|
5389
|
-
if (
|
|
5396
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
5390
5397
|
controller.enqueue({
|
|
5391
5398
|
type: "reasoning-delta",
|
|
5392
5399
|
id: blockId,
|
|
@@ -5397,12 +5404,12 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5397
5404
|
}
|
|
5398
5405
|
} else if (stepType === "processing_call" || stepType === "processing_result") {
|
|
5399
5406
|
const google2 = {};
|
|
5400
|
-
if (
|
|
5407
|
+
if (step?.signature != null) google2.signature = step.signature;
|
|
5401
5408
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5402
5409
|
if (stepType === "processing_call") {
|
|
5403
|
-
google2.processingId =
|
|
5410
|
+
google2.processingId = step?.id || blockId;
|
|
5404
5411
|
} else {
|
|
5405
|
-
google2.processingCallId =
|
|
5412
|
+
google2.processingCallId = step?.call_id || blockId;
|
|
5406
5413
|
}
|
|
5407
5414
|
openBlocks.set(index, {
|
|
5408
5415
|
kind: "custom",
|
|
@@ -5411,8 +5418,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5411
5418
|
google: google2
|
|
5412
5419
|
});
|
|
5413
5420
|
} else if (stepType === "function_call") {
|
|
5414
|
-
const toolCallId =
|
|
5415
|
-
const toolName =
|
|
5421
|
+
const toolCallId = step?.id || blockId;
|
|
5422
|
+
const toolName = step?.name ?? "unknown";
|
|
5416
5423
|
hasFunctionCall = true;
|
|
5417
5424
|
const state = {
|
|
5418
5425
|
kind: "function_call",
|
|
@@ -5420,7 +5427,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5420
5427
|
toolCallId,
|
|
5421
5428
|
toolName,
|
|
5422
5429
|
argumentsAccum: "",
|
|
5423
|
-
...
|
|
5430
|
+
...step?.signature != null ? { signature: step.signature } : {}
|
|
5424
5431
|
};
|
|
5425
5432
|
openBlocks.set(index, state);
|
|
5426
5433
|
controller.enqueue({
|
|
@@ -5429,29 +5436,29 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5429
5436
|
toolName
|
|
5430
5437
|
});
|
|
5431
5438
|
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
5432
|
-
const toolName = stepType === "mcp_server_tool_call" ?
|
|
5433
|
-
const toolCallId =
|
|
5439
|
+
const toolName = stepType === "mcp_server_tool_call" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
5440
|
+
const toolCallId = step?.id || blockId;
|
|
5434
5441
|
const state = {
|
|
5435
5442
|
kind: "builtin_tool_call",
|
|
5436
5443
|
id: blockId,
|
|
5437
5444
|
blockType: stepType,
|
|
5438
5445
|
toolCallId,
|
|
5439
5446
|
toolName,
|
|
5440
|
-
arguments:
|
|
5447
|
+
arguments: step?.arguments ?? {},
|
|
5441
5448
|
callEmitted: false
|
|
5442
5449
|
};
|
|
5443
5450
|
openBlocks.set(index, state);
|
|
5444
5451
|
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
5445
|
-
const toolName = stepType === "mcp_server_tool_result" ?
|
|
5446
|
-
const callId =
|
|
5452
|
+
const toolName = stepType === "mcp_server_tool_result" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
5453
|
+
const callId = step?.call_id || blockId;
|
|
5447
5454
|
const state = {
|
|
5448
5455
|
kind: "builtin_tool_result",
|
|
5449
5456
|
id: blockId,
|
|
5450
5457
|
blockType: stepType,
|
|
5451
5458
|
callId,
|
|
5452
5459
|
toolName,
|
|
5453
|
-
result:
|
|
5454
|
-
...
|
|
5460
|
+
result: step?.result ?? null,
|
|
5461
|
+
...step?.is_error != null ? { isError: step.is_error } : {},
|
|
5455
5462
|
resultEmitted: false
|
|
5456
5463
|
};
|
|
5457
5464
|
openBlocks.set(index, state);
|
|
@@ -5464,7 +5471,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5464
5471
|
const event = value;
|
|
5465
5472
|
let open = openBlocks.get(event.index);
|
|
5466
5473
|
if (open == null) break;
|
|
5467
|
-
const dtype =
|
|
5474
|
+
const dtype = event.delta?.type;
|
|
5468
5475
|
if (open.kind === "pending_model_output") {
|
|
5469
5476
|
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
5470
5477
|
const promoted = {
|
|
@@ -5482,17 +5489,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5482
5489
|
const google2 = {};
|
|
5483
5490
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5484
5491
|
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
5485
|
-
if (
|
|
5492
|
+
if (imageDelta?.data != null && imageDelta.data.length > 0) {
|
|
5486
5493
|
controller.enqueue({
|
|
5487
5494
|
type: "file",
|
|
5488
|
-
mediaType:
|
|
5495
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
5489
5496
|
data: { type: "data", data: imageDelta.data },
|
|
5490
5497
|
...providerMetadata ? { providerMetadata } : {}
|
|
5491
5498
|
});
|
|
5492
|
-
} else if (
|
|
5499
|
+
} else if (imageDelta?.uri != null && imageDelta.uri.length > 0) {
|
|
5493
5500
|
controller.enqueue({
|
|
5494
5501
|
type: "file",
|
|
5495
|
-
mediaType:
|
|
5502
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
5496
5503
|
data: { type: "url", url: new URL(imageDelta.uri) },
|
|
5497
5504
|
...providerMetadata ? { providerMetadata } : {}
|
|
5498
5505
|
});
|
|
@@ -5508,17 +5515,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5508
5515
|
const google2 = {};
|
|
5509
5516
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5510
5517
|
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
5511
|
-
if (
|
|
5518
|
+
if (videoDelta?.data != null && videoDelta.data.length > 0) {
|
|
5512
5519
|
controller.enqueue({
|
|
5513
5520
|
type: "file",
|
|
5514
|
-
mediaType:
|
|
5521
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
5515
5522
|
data: { type: "data", data: videoDelta.data },
|
|
5516
5523
|
...providerMetadata ? { providerMetadata } : {}
|
|
5517
5524
|
});
|
|
5518
|
-
} else if (
|
|
5525
|
+
} else if (videoDelta?.uri != null && videoDelta.uri.length > 0) {
|
|
5519
5526
|
controller.enqueue({
|
|
5520
5527
|
type: "file",
|
|
5521
|
-
mediaType:
|
|
5528
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
5522
5529
|
data: { type: "url", url: new URL(videoDelta.uri) },
|
|
5523
5530
|
...providerMetadata ? { providerMetadata } : {}
|
|
5524
5531
|
});
|
|
@@ -5526,7 +5533,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5526
5533
|
break;
|
|
5527
5534
|
}
|
|
5528
5535
|
const delta = event.delta;
|
|
5529
|
-
if (open.kind === "custom" && (
|
|
5536
|
+
if (open.kind === "custom" && (delta?.type === "processing_call" || delta?.type === "processing_result")) {
|
|
5530
5537
|
if (delta.signature != null)
|
|
5531
5538
|
open.google.signature = delta.signature;
|
|
5532
5539
|
if (delta.type === "processing_call" && delta.id != null && delta.id.length > 0) {
|
|
@@ -5535,8 +5542,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5535
5542
|
if (delta.type === "processing_result" && delta.call_id != null && delta.call_id.length > 0) {
|
|
5536
5543
|
open.google.processingCallId = delta.call_id;
|
|
5537
5544
|
}
|
|
5538
|
-
} else if (open.kind === "text" &&
|
|
5539
|
-
const text =
|
|
5545
|
+
} else if (open.kind === "text" && delta?.type === "text") {
|
|
5546
|
+
const text = delta.text ?? "";
|
|
5540
5547
|
if (text.length > 0) {
|
|
5541
5548
|
controller.enqueue({
|
|
5542
5549
|
type: "text-delta",
|
|
@@ -5544,7 +5551,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5544
5551
|
delta: text
|
|
5545
5552
|
});
|
|
5546
5553
|
}
|
|
5547
|
-
} else if (open.kind === "text" && (
|
|
5554
|
+
} else if (open.kind === "text" && (delta?.type === "text_annotation" || delta?.type === "text_annotation_delta")) {
|
|
5548
5555
|
const sources = annotationsToSources({
|
|
5549
5556
|
annotations: delta.annotations,
|
|
5550
5557
|
generateId: generateId4
|
|
@@ -5556,27 +5563,27 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5556
5563
|
open.emittedSourceKeys.add(key);
|
|
5557
5564
|
controller.enqueue(source);
|
|
5558
5565
|
}
|
|
5559
|
-
} else if (open.kind === "image" &&
|
|
5566
|
+
} else if (open.kind === "image" && delta?.type === "image") {
|
|
5560
5567
|
if (delta.data != null) open.data = delta.data;
|
|
5561
5568
|
if (delta.mime_type != null) open.mimeType = delta.mime_type;
|
|
5562
5569
|
if (delta.uri != null) open.uri = delta.uri;
|
|
5563
5570
|
} else if (open.kind === "reasoning") {
|
|
5564
|
-
if (
|
|
5571
|
+
if (delta?.type === "thought_summary") {
|
|
5565
5572
|
const item = delta.content;
|
|
5566
|
-
if (
|
|
5573
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
5567
5574
|
controller.enqueue({
|
|
5568
5575
|
type: "reasoning-delta",
|
|
5569
5576
|
id: open.id,
|
|
5570
5577
|
delta: item.text
|
|
5571
5578
|
});
|
|
5572
5579
|
}
|
|
5573
|
-
} else if (
|
|
5580
|
+
} else if (delta?.type === "thought_signature") {
|
|
5574
5581
|
const signature = delta.signature;
|
|
5575
5582
|
if (signature != null) {
|
|
5576
5583
|
open.signature = signature;
|
|
5577
5584
|
}
|
|
5578
5585
|
}
|
|
5579
|
-
} else if (open.kind === "function_call" &&
|
|
5586
|
+
} else if (open.kind === "function_call" && delta?.type === "arguments_delta") {
|
|
5580
5587
|
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
5581
5588
|
if (slice.length > 0) {
|
|
5582
5589
|
open.argumentsAccum += slice;
|
|
@@ -5593,7 +5600,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5593
5600
|
open.signature = delta.signature;
|
|
5594
5601
|
}
|
|
5595
5602
|
hasFunctionCall = true;
|
|
5596
|
-
} else if (open.kind === "builtin_tool_call" &&
|
|
5603
|
+
} else if (open.kind === "builtin_tool_call" && delta?.type === open.blockType) {
|
|
5597
5604
|
if (delta.id != null && delta.id.length > 0) {
|
|
5598
5605
|
open.toolCallId = delta.id;
|
|
5599
5606
|
}
|
|
@@ -5603,7 +5610,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5603
5610
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
5604
5611
|
open.toolName = delta.name;
|
|
5605
5612
|
}
|
|
5606
|
-
} else if (open.kind === "builtin_tool_result" &&
|
|
5613
|
+
} else if (open.kind === "builtin_tool_result" && delta?.type === open.blockType) {
|
|
5607
5614
|
if (delta.call_id != null && delta.call_id.length > 0) {
|
|
5608
5615
|
open.callId = delta.call_id;
|
|
5609
5616
|
}
|
|
@@ -5643,14 +5650,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5643
5650
|
if (open.data != null && open.data.length > 0) {
|
|
5644
5651
|
controller.enqueue({
|
|
5645
5652
|
type: "file",
|
|
5646
|
-
mediaType:
|
|
5653
|
+
mediaType: open.mimeType ?? "image/png",
|
|
5647
5654
|
data: { type: "data", data: open.data },
|
|
5648
5655
|
...providerMetadata ? { providerMetadata } : {}
|
|
5649
5656
|
});
|
|
5650
5657
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
5651
5658
|
controller.enqueue({
|
|
5652
5659
|
type: "file",
|
|
5653
|
-
mediaType:
|
|
5660
|
+
mediaType: open.mimeType ?? "image/png",
|
|
5654
5661
|
data: { type: "url", url: new URL(open.uri) },
|
|
5655
5662
|
...providerMetadata ? { providerMetadata } : {}
|
|
5656
5663
|
});
|
|
@@ -5683,7 +5690,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5683
5690
|
type: "tool-call",
|
|
5684
5691
|
toolCallId: open.toolCallId,
|
|
5685
5692
|
toolName: open.toolName,
|
|
5686
|
-
input: JSON.stringify(
|
|
5693
|
+
input: JSON.stringify(open.arguments ?? {}),
|
|
5687
5694
|
providerExecuted: true
|
|
5688
5695
|
});
|
|
5689
5696
|
open.callEmitted = true;
|
|
@@ -5692,7 +5699,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5692
5699
|
type: "tool-result",
|
|
5693
5700
|
toolCallId: open.callId,
|
|
5694
5701
|
toolName: open.toolName,
|
|
5695
|
-
result:
|
|
5702
|
+
result: open.result ?? null
|
|
5696
5703
|
});
|
|
5697
5704
|
open.resultEmitted = true;
|
|
5698
5705
|
const sources = builtinToolResultToSources({
|
|
@@ -5729,16 +5736,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5729
5736
|
case "interaction.completed": {
|
|
5730
5737
|
const event = value;
|
|
5731
5738
|
const interaction = event.interaction;
|
|
5732
|
-
if (
|
|
5739
|
+
if (interaction?.id != null && interaction.id.length > 0) {
|
|
5733
5740
|
interactionId = interaction.id;
|
|
5734
5741
|
}
|
|
5735
|
-
if (
|
|
5742
|
+
if (interaction?.status != null) {
|
|
5736
5743
|
finishStatus = interaction.status;
|
|
5737
5744
|
}
|
|
5738
|
-
if (
|
|
5745
|
+
if (interaction?.usage != null) {
|
|
5739
5746
|
usage = interaction.usage;
|
|
5740
5747
|
}
|
|
5741
|
-
if (
|
|
5748
|
+
if (interaction?.service_tier != null) {
|
|
5742
5749
|
serviceTier = interaction.service_tier;
|
|
5743
5750
|
}
|
|
5744
5751
|
break;
|
|
@@ -5749,9 +5756,9 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5749
5756
|
controller.enqueue({
|
|
5750
5757
|
type: "error",
|
|
5751
5758
|
error: createProviderStreamError({
|
|
5752
|
-
message:
|
|
5759
|
+
message: event.error?.message ?? "Unknown interaction error",
|
|
5753
5760
|
type: event.event_type,
|
|
5754
|
-
code:
|
|
5761
|
+
code: event.error?.code ?? void 0,
|
|
5755
5762
|
data: event
|
|
5756
5763
|
})
|
|
5757
5764
|
});
|
|
@@ -5802,7 +5809,6 @@ function convertToGoogleInteractionsInput({
|
|
|
5802
5809
|
store,
|
|
5803
5810
|
mediaResolution
|
|
5804
5811
|
}) {
|
|
5805
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5806
5812
|
const warnings = [];
|
|
5807
5813
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
5808
5814
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -5859,7 +5865,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5859
5865
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
5860
5866
|
} else if (part.type === "reasoning") {
|
|
5861
5867
|
flushModelOutput();
|
|
5862
|
-
const signature =
|
|
5868
|
+
const signature = part.providerOptions?.google?.signature;
|
|
5863
5869
|
steps.push({
|
|
5864
5870
|
type: "thought",
|
|
5865
5871
|
...signature != null ? { signature } : {},
|
|
@@ -5876,15 +5882,15 @@ function convertToGoogleInteractionsInput({
|
|
|
5876
5882
|
}
|
|
5877
5883
|
} else if (part.type === "custom") {
|
|
5878
5884
|
flushModelOutput();
|
|
5879
|
-
const google2 =
|
|
5880
|
-
const signature = typeof
|
|
5881
|
-
if (part.kind === "google.processing_call" && typeof
|
|
5885
|
+
const google2 = part.providerOptions?.google;
|
|
5886
|
+
const signature = typeof google2?.signature === "string" ? google2.signature : void 0;
|
|
5887
|
+
if (part.kind === "google.processing_call" && typeof google2?.processingId === "string") {
|
|
5882
5888
|
steps.push({
|
|
5883
5889
|
type: "processing_call",
|
|
5884
5890
|
id: google2.processingId,
|
|
5885
5891
|
...signature != null ? { signature } : {}
|
|
5886
5892
|
});
|
|
5887
|
-
} else if (part.kind === "google.processing_result" && typeof
|
|
5893
|
+
} else if (part.kind === "google.processing_result" && typeof google2?.processingCallId === "string") {
|
|
5888
5894
|
steps.push({
|
|
5889
5895
|
type: "processing_result",
|
|
5890
5896
|
call_id: google2.processingCallId,
|
|
@@ -5898,8 +5904,8 @@ function convertToGoogleInteractionsInput({
|
|
|
5898
5904
|
}
|
|
5899
5905
|
} else if (part.type === "tool-call") {
|
|
5900
5906
|
flushModelOutput();
|
|
5901
|
-
const signature =
|
|
5902
|
-
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) :
|
|
5907
|
+
const signature = part.providerOptions?.google?.signature;
|
|
5908
|
+
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : part.input ?? {};
|
|
5903
5909
|
steps.push({
|
|
5904
5910
|
type: "function_call",
|
|
5905
5911
|
id: part.toolCallId,
|
|
@@ -5931,7 +5937,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5931
5937
|
toolCallId: part.toolCallId,
|
|
5932
5938
|
toolName: part.toolName,
|
|
5933
5939
|
output: part.output,
|
|
5934
|
-
signature:
|
|
5940
|
+
signature: part.providerOptions?.google?.signature,
|
|
5935
5941
|
warnings
|
|
5936
5942
|
});
|
|
5937
5943
|
content.push(block);
|
|
@@ -6024,8 +6030,7 @@ function getVideoProcessingField({
|
|
|
6024
6030
|
part,
|
|
6025
6031
|
warnings
|
|
6026
6032
|
}) {
|
|
6027
|
-
|
|
6028
|
-
const processing = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.processing;
|
|
6033
|
+
const processing = part.providerOptions?.google?.processing;
|
|
6029
6034
|
if (processing == null) {
|
|
6030
6035
|
return {};
|
|
6031
6036
|
}
|
|
@@ -6037,8 +6042,8 @@ function getVideoProcessingField({
|
|
|
6037
6042
|
return {
|
|
6038
6043
|
processing: {
|
|
6039
6044
|
type: "static",
|
|
6040
|
-
...typeof config.startOffset === "number" ? { start_offset: config.startOffset } : {},
|
|
6041
|
-
...typeof config.endOffset === "number" ? { end_offset: config.endOffset } : {},
|
|
6045
|
+
...typeof config.startOffset === "number" ? { start_offset: `${config.startOffset}s` } : {},
|
|
6046
|
+
...typeof config.endOffset === "number" ? { end_offset: `${config.endOffset}s` } : {},
|
|
6042
6047
|
...typeof config.fps === "number" ? { fps: config.fps } : {}
|
|
6043
6048
|
}
|
|
6044
6049
|
};
|
|
@@ -6058,8 +6063,7 @@ function compactPromptForPreviousInteraction({
|
|
|
6058
6063
|
for (const message of prompt) {
|
|
6059
6064
|
if (message.role === "assistant") {
|
|
6060
6065
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
6061
|
-
|
|
6062
|
-
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
6066
|
+
const partInteractionId = part.providerOptions?.google?.interactionId;
|
|
6063
6067
|
return partInteractionId === previousInteractionId;
|
|
6064
6068
|
});
|
|
6065
6069
|
if (matchesLinkedInteraction) {
|
|
@@ -6100,7 +6104,7 @@ function safeParseToolArgs(input) {
|
|
|
6100
6104
|
return parsed;
|
|
6101
6105
|
}
|
|
6102
6106
|
return { value: parsed };
|
|
6103
|
-
} catch
|
|
6107
|
+
} catch {
|
|
6104
6108
|
return { value: input };
|
|
6105
6109
|
}
|
|
6106
6110
|
}
|
|
@@ -6111,7 +6115,6 @@ function convertToolResultPart({
|
|
|
6111
6115
|
signature,
|
|
6112
6116
|
warnings
|
|
6113
6117
|
}) {
|
|
6114
|
-
var _a2;
|
|
6115
6118
|
const base = {
|
|
6116
6119
|
type: "function_result",
|
|
6117
6120
|
call_id: toolCallId,
|
|
@@ -6131,7 +6134,7 @@ function convertToolResultPart({
|
|
|
6131
6134
|
return {
|
|
6132
6135
|
...base,
|
|
6133
6136
|
is_error: true,
|
|
6134
|
-
result:
|
|
6137
|
+
result: output.reason ?? "Tool execution denied by user."
|
|
6135
6138
|
};
|
|
6136
6139
|
case "content": {
|
|
6137
6140
|
const blocks = [];
|
|
@@ -6822,7 +6825,6 @@ function parseGoogleInteractionsOutputs({
|
|
|
6822
6825
|
generateId: generateId4,
|
|
6823
6826
|
interactionId
|
|
6824
6827
|
}) {
|
|
6825
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6826
6828
|
const content = [];
|
|
6827
6829
|
let hasFunctionCall = false;
|
|
6828
6830
|
if (steps == null) {
|
|
@@ -6837,12 +6839,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
6837
6839
|
break;
|
|
6838
6840
|
}
|
|
6839
6841
|
case "model_output": {
|
|
6840
|
-
const blocks =
|
|
6842
|
+
const blocks = step.content ?? [];
|
|
6841
6843
|
for (const block of blocks) {
|
|
6842
6844
|
if (block == null || typeof block !== "object") continue;
|
|
6843
6845
|
const blockType = block.type;
|
|
6844
6846
|
if (blockType === "text") {
|
|
6845
|
-
const text =
|
|
6847
|
+
const text = block.text ?? "";
|
|
6846
6848
|
const annotations = block.annotations;
|
|
6847
6849
|
content.push({
|
|
6848
6850
|
type: "text",
|
|
@@ -6858,14 +6860,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
6858
6860
|
if (image.data != null && image.data.length > 0) {
|
|
6859
6861
|
content.push({
|
|
6860
6862
|
type: "file",
|
|
6861
|
-
mediaType:
|
|
6863
|
+
mediaType: image.mime_type ?? "image/png",
|
|
6862
6864
|
data: { type: "data", data: image.data },
|
|
6863
6865
|
...googleProviderMetadata({ interactionId })
|
|
6864
6866
|
});
|
|
6865
6867
|
} else if (image.uri != null && image.uri.length > 0) {
|
|
6866
6868
|
content.push({
|
|
6867
6869
|
type: "file",
|
|
6868
|
-
mediaType:
|
|
6870
|
+
mediaType: image.mime_type ?? "image/png",
|
|
6869
6871
|
data: { type: "url", url: new URL(image.uri) },
|
|
6870
6872
|
...googleProviderMetadata({ interactionId })
|
|
6871
6873
|
});
|
|
@@ -6875,14 +6877,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
6875
6877
|
if (video.data != null && video.data.length > 0) {
|
|
6876
6878
|
content.push({
|
|
6877
6879
|
type: "file",
|
|
6878
|
-
mediaType:
|
|
6880
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
6879
6881
|
data: { type: "data", data: video.data },
|
|
6880
6882
|
...googleProviderMetadata({ interactionId })
|
|
6881
6883
|
});
|
|
6882
6884
|
} else if (video.uri != null && video.uri.length > 0) {
|
|
6883
6885
|
content.push({
|
|
6884
6886
|
type: "file",
|
|
6885
|
-
mediaType:
|
|
6887
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
6886
6888
|
data: { type: "url", url: new URL(video.uri) },
|
|
6887
6889
|
...googleProviderMetadata({ interactionId })
|
|
6888
6890
|
});
|
|
@@ -6895,7 +6897,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6895
6897
|
const thought = step;
|
|
6896
6898
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
6897
6899
|
const text = summary.filter(
|
|
6898
|
-
(item) =>
|
|
6900
|
+
(item) => item?.type === "text" && typeof item.text === "string"
|
|
6899
6901
|
).map((item) => item.text).join("\n");
|
|
6900
6902
|
content.push({
|
|
6901
6903
|
type: "reasoning",
|
|
@@ -6942,7 +6944,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6942
6944
|
type: "tool-call",
|
|
6943
6945
|
toolCallId: call.id,
|
|
6944
6946
|
toolName: call.name,
|
|
6945
|
-
input: JSON.stringify(
|
|
6947
|
+
input: JSON.stringify(call.arguments ?? {}),
|
|
6946
6948
|
...googleProviderMetadata({
|
|
6947
6949
|
signature: call.signature,
|
|
6948
6950
|
interactionId
|
|
@@ -6953,8 +6955,8 @@ function parseGoogleInteractionsOutputs({
|
|
|
6953
6955
|
default: {
|
|
6954
6956
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
6955
6957
|
const call = step;
|
|
6956
|
-
const toolName = type === "mcp_server_tool_call" ?
|
|
6957
|
-
const input = JSON.stringify(
|
|
6958
|
+
const toolName = type === "mcp_server_tool_call" ? call.name ?? "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
6959
|
+
const input = JSON.stringify(call.arguments ?? {});
|
|
6958
6960
|
content.push({
|
|
6959
6961
|
type: "tool-call",
|
|
6960
6962
|
toolCallId: call.id || generateId4(),
|
|
@@ -6964,12 +6966,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
6964
6966
|
});
|
|
6965
6967
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
6966
6968
|
const result = step;
|
|
6967
|
-
const toolName = type === "mcp_server_tool_result" ?
|
|
6969
|
+
const toolName = type === "mcp_server_tool_result" ? result.name ?? "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
6968
6970
|
content.push({
|
|
6969
6971
|
type: "tool-result",
|
|
6970
6972
|
toolCallId: result.call_id || generateId4(),
|
|
6971
6973
|
toolName,
|
|
6972
|
-
result:
|
|
6974
|
+
result: result.result ?? null
|
|
6973
6975
|
});
|
|
6974
6976
|
const sources = builtinToolResultToSources({
|
|
6975
6977
|
block: step,
|
|
@@ -7022,9 +7024,9 @@ async function cancelGoogleInteraction({
|
|
|
7022
7024
|
});
|
|
7023
7025
|
try {
|
|
7024
7026
|
await response.text();
|
|
7025
|
-
} catch
|
|
7027
|
+
} catch {
|
|
7026
7028
|
}
|
|
7027
|
-
} catch
|
|
7029
|
+
} catch {
|
|
7028
7030
|
}
|
|
7029
7031
|
}
|
|
7030
7032
|
|
|
@@ -7057,7 +7059,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
7057
7059
|
const cancelOnServer = () => cancelGoogleInteraction({ baseURL, interactionId, headers, fetch: fetch2 });
|
|
7058
7060
|
try {
|
|
7059
7061
|
while (true) {
|
|
7060
|
-
if (abortSignal
|
|
7062
|
+
if (abortSignal?.aborted) {
|
|
7061
7063
|
await cancelOnServer();
|
|
7062
7064
|
throw new DOMException("Polling was aborted", "AbortError");
|
|
7063
7065
|
}
|
|
@@ -7100,9 +7102,8 @@ function prepareGoogleInteractionsTools({
|
|
|
7100
7102
|
tools,
|
|
7101
7103
|
toolChoice
|
|
7102
7104
|
}) {
|
|
7103
|
-
var _a2, _b, _c, _d;
|
|
7104
7105
|
const toolWarnings = [];
|
|
7105
|
-
const normalized =
|
|
7106
|
+
const normalized = tools?.length ? tools : void 0;
|
|
7106
7107
|
if (normalized == null) {
|
|
7107
7108
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
7108
7109
|
}
|
|
@@ -7112,13 +7113,13 @@ function prepareGoogleInteractionsTools({
|
|
|
7112
7113
|
interactionsTools.push({
|
|
7113
7114
|
type: "function",
|
|
7114
7115
|
name: tool.name,
|
|
7115
|
-
description:
|
|
7116
|
+
description: tool.description ?? "",
|
|
7116
7117
|
parameters: tool.inputSchema
|
|
7117
7118
|
});
|
|
7118
7119
|
continue;
|
|
7119
7120
|
}
|
|
7120
7121
|
if (tool.type === "provider") {
|
|
7121
|
-
const args =
|
|
7122
|
+
const args = tool.args ?? {};
|
|
7122
7123
|
switch (tool.id) {
|
|
7123
7124
|
case "google.google_search": {
|
|
7124
7125
|
const searchTypesArg = args.searchTypes;
|
|
@@ -7168,7 +7169,7 @@ function prepareGoogleInteractionsTools({
|
|
|
7168
7169
|
case "google.computer_use": {
|
|
7169
7170
|
interactionsTools.push({
|
|
7170
7171
|
type: "computer_use",
|
|
7171
|
-
environment:
|
|
7172
|
+
environment: args.environment ?? "browser",
|
|
7172
7173
|
...args.excludedPredefinedFunctions != null ? {
|
|
7173
7174
|
excludedPredefinedFunctions: args.excludedPredefinedFunctions
|
|
7174
7175
|
} : {}
|
|
@@ -7186,7 +7187,7 @@ function prepareGoogleInteractionsTools({
|
|
|
7186
7187
|
break;
|
|
7187
7188
|
}
|
|
7188
7189
|
case "google.retrieval": {
|
|
7189
|
-
const vertexAiSearchConfig =
|
|
7190
|
+
const vertexAiSearchConfig = args.vertexAiSearchConfig ?? void 0;
|
|
7190
7191
|
interactionsTools.push({
|
|
7191
7192
|
type: "retrieval",
|
|
7192
7193
|
...args.retrievalTypes != null ? {
|
|
@@ -7390,7 +7391,7 @@ function streamGoogleInteractionEvents({
|
|
|
7390
7391
|
if (abortSignal != null) {
|
|
7391
7392
|
abortSignal.removeEventListener("abort", upstreamAbortHandler);
|
|
7392
7393
|
}
|
|
7393
|
-
currentReader
|
|
7394
|
+
currentReader?.cancel().catch(() => {
|
|
7394
7395
|
});
|
|
7395
7396
|
currentReader = void 0;
|
|
7396
7397
|
if (effectiveSignal.aborted && !complete) {
|
|
@@ -7405,7 +7406,7 @@ function streamGoogleInteractionEvents({
|
|
|
7405
7406
|
},
|
|
7406
7407
|
cancel() {
|
|
7407
7408
|
internalAbort.abort();
|
|
7408
|
-
currentReader
|
|
7409
|
+
currentReader?.cancel().catch(() => {
|
|
7409
7410
|
});
|
|
7410
7411
|
currentReader = void 0;
|
|
7411
7412
|
}
|
|
@@ -7422,7 +7423,6 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7422
7423
|
}) {
|
|
7423
7424
|
return new ReadableStream({
|
|
7424
7425
|
start(controller) {
|
|
7425
|
-
var _a2, _b, _c;
|
|
7426
7426
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7427
7427
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7428
7428
|
let timestamp;
|
|
@@ -7436,19 +7436,19 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7436
7436
|
controller.enqueue({
|
|
7437
7437
|
type: "response-metadata",
|
|
7438
7438
|
...interactionId != null ? { id: interactionId } : {},
|
|
7439
|
-
modelId:
|
|
7439
|
+
modelId: response.model ?? void 0,
|
|
7440
7440
|
...timestamp ? { timestamp } : {}
|
|
7441
7441
|
});
|
|
7442
7442
|
if (includeRawChunks) {
|
|
7443
7443
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
7444
7444
|
}
|
|
7445
7445
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
7446
|
-
steps:
|
|
7446
|
+
steps: response.steps ?? null,
|
|
7447
7447
|
generateId: generateId4,
|
|
7448
7448
|
interactionId
|
|
7449
7449
|
});
|
|
7450
7450
|
let blockCounter = 0;
|
|
7451
|
-
const nextBlockId = () => `${interactionId
|
|
7451
|
+
const nextBlockId = () => `${interactionId ?? "agent"}:${blockCounter++}`;
|
|
7452
7452
|
for (const part of content) {
|
|
7453
7453
|
switch (part.type) {
|
|
7454
7454
|
case "text": {
|
|
@@ -7528,7 +7528,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7528
7528
|
break;
|
|
7529
7529
|
}
|
|
7530
7530
|
}
|
|
7531
|
-
const serviceTier =
|
|
7531
|
+
const serviceTier = response.service_tier ?? headerServiceTier;
|
|
7532
7532
|
const finishReason = {
|
|
7533
7533
|
unified: mapGoogleInteractionsFinishReason({
|
|
7534
7534
|
status: response.status,
|
|
@@ -7603,7 +7603,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7603
7603
|
};
|
|
7604
7604
|
}
|
|
7605
7605
|
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
7606
|
const warnings = [];
|
|
7608
7607
|
const googleOptions = await parseProviderOptions8({
|
|
7609
7608
|
provider: "google",
|
|
@@ -7638,7 +7637,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7638
7637
|
warnings.push(...prepared.toolWarnings);
|
|
7639
7638
|
}
|
|
7640
7639
|
const responseFormatEntries = [];
|
|
7641
|
-
if (
|
|
7640
|
+
if (options.responseFormat?.type === "json") {
|
|
7642
7641
|
if (isAgent) {
|
|
7643
7642
|
warnings.push({
|
|
7644
7643
|
type: "other",
|
|
@@ -7653,41 +7652,41 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7653
7652
|
responseFormatEntries.push(entry);
|
|
7654
7653
|
}
|
|
7655
7654
|
}
|
|
7656
|
-
if (
|
|
7655
|
+
if (googleOptions?.responseFormat != null) {
|
|
7657
7656
|
for (const entry of googleOptions.responseFormat) {
|
|
7658
7657
|
if (entry.type === "text") {
|
|
7659
7658
|
responseFormatEntries.push(
|
|
7660
7659
|
pruneUndefined({
|
|
7661
7660
|
type: "text",
|
|
7662
|
-
mime_type:
|
|
7663
|
-
schema:
|
|
7661
|
+
mime_type: entry.mimeType ?? void 0,
|
|
7662
|
+
schema: entry.schema ?? void 0
|
|
7664
7663
|
})
|
|
7665
7664
|
);
|
|
7666
7665
|
} else if (entry.type === "image") {
|
|
7667
7666
|
responseFormatEntries.push(
|
|
7668
7667
|
pruneUndefined({
|
|
7669
7668
|
type: "image",
|
|
7670
|
-
mime_type:
|
|
7671
|
-
aspect_ratio:
|
|
7672
|
-
image_size:
|
|
7669
|
+
mime_type: entry.mimeType ?? void 0,
|
|
7670
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
7671
|
+
image_size: entry.imageSize ?? void 0
|
|
7673
7672
|
})
|
|
7674
7673
|
);
|
|
7675
7674
|
} else if (entry.type === "audio") {
|
|
7676
7675
|
responseFormatEntries.push(
|
|
7677
7676
|
pruneUndefined({
|
|
7678
7677
|
type: "audio",
|
|
7679
|
-
mime_type:
|
|
7678
|
+
mime_type: entry.mimeType ?? void 0
|
|
7680
7679
|
})
|
|
7681
7680
|
);
|
|
7682
7681
|
} else if (entry.type === "video") {
|
|
7683
7682
|
responseFormatEntries.push(
|
|
7684
7683
|
pruneUndefined({
|
|
7685
7684
|
type: "video",
|
|
7686
|
-
aspect_ratio:
|
|
7687
|
-
resolution:
|
|
7688
|
-
duration:
|
|
7689
|
-
delivery:
|
|
7690
|
-
gcs_uri:
|
|
7685
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
7686
|
+
resolution: entry.resolution ?? void 0,
|
|
7687
|
+
duration: entry.duration ?? void 0,
|
|
7688
|
+
delivery: entry.delivery ?? void 0,
|
|
7689
|
+
gcs_uri: entry.gcsUri ?? void 0
|
|
7691
7690
|
})
|
|
7692
7691
|
);
|
|
7693
7692
|
}
|
|
@@ -7699,13 +7698,13 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7699
7698
|
warnings: convWarnings
|
|
7700
7699
|
} = convertToGoogleInteractionsInput({
|
|
7701
7700
|
prompt: options.prompt,
|
|
7702
|
-
previousInteractionId:
|
|
7703
|
-
store:
|
|
7704
|
-
mediaResolution:
|
|
7701
|
+
previousInteractionId: googleOptions?.previousInteractionId ?? void 0,
|
|
7702
|
+
store: googleOptions?.store ?? void 0,
|
|
7703
|
+
mediaResolution: googleOptions?.mediaResolution ?? void 0
|
|
7705
7704
|
});
|
|
7706
7705
|
warnings.push(...convWarnings);
|
|
7707
7706
|
let systemInstruction = convertedSystemInstruction;
|
|
7708
|
-
const optionSystemInstruction =
|
|
7707
|
+
const optionSystemInstruction = googleOptions?.systemInstruction ?? void 0;
|
|
7709
7708
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
7710
7709
|
warnings.push({
|
|
7711
7710
|
type: "other",
|
|
@@ -7730,12 +7729,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7730
7729
|
}
|
|
7731
7730
|
if (options.maxOutputTokens != null)
|
|
7732
7731
|
droppedFields.push("maxOutputTokens");
|
|
7733
|
-
if (
|
|
7732
|
+
if (googleOptions?.thinkingLevel != null)
|
|
7734
7733
|
droppedFields.push("thinkingLevel");
|
|
7735
|
-
if (
|
|
7734
|
+
if (googleOptions?.thinkingSummaries != null) {
|
|
7736
7735
|
droppedFields.push("thinkingSummaries");
|
|
7737
7736
|
}
|
|
7738
|
-
if (
|
|
7737
|
+
if (googleOptions?.imageConfig != null) droppedFields.push("imageConfig");
|
|
7739
7738
|
if (droppedFields.length > 0) {
|
|
7740
7739
|
warnings.push({
|
|
7741
7740
|
type: "other",
|
|
@@ -7745,17 +7744,17 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7745
7744
|
generationConfig = void 0;
|
|
7746
7745
|
} else {
|
|
7747
7746
|
generationConfig = pruneUndefined({
|
|
7748
|
-
temperature:
|
|
7749
|
-
top_p:
|
|
7750
|
-
top_k:
|
|
7751
|
-
seed:
|
|
7747
|
+
temperature: options.temperature ?? void 0,
|
|
7748
|
+
top_p: options.topP ?? void 0,
|
|
7749
|
+
top_k: options.topK ?? void 0,
|
|
7750
|
+
seed: options.seed ?? void 0,
|
|
7752
7751
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
7753
|
-
max_output_tokens:
|
|
7754
|
-
thinking_level:
|
|
7755
|
-
thinking_summaries:
|
|
7752
|
+
max_output_tokens: options.maxOutputTokens ?? void 0,
|
|
7753
|
+
thinking_level: googleOptions?.thinkingLevel ?? void 0,
|
|
7754
|
+
thinking_summaries: googleOptions?.thinkingSummaries ?? void 0,
|
|
7756
7755
|
tool_choice: toolChoiceForBody
|
|
7757
7756
|
});
|
|
7758
|
-
if (
|
|
7757
|
+
if (googleOptions?.imageConfig != null) {
|
|
7759
7758
|
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
7760
7759
|
(entry) => entry.type === "image"
|
|
7761
7760
|
);
|
|
@@ -7774,21 +7773,21 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7774
7773
|
}
|
|
7775
7774
|
}
|
|
7776
7775
|
let agentConfig;
|
|
7777
|
-
if (isAgent &&
|
|
7776
|
+
if (isAgent && googleOptions?.agentConfig != null) {
|
|
7778
7777
|
const agentConfigOptions = googleOptions.agentConfig;
|
|
7779
7778
|
if (agentConfigOptions.type === "deep-research") {
|
|
7780
7779
|
agentConfig = pruneUndefined({
|
|
7781
7780
|
type: "deep-research",
|
|
7782
|
-
thinking_summaries:
|
|
7783
|
-
visualization:
|
|
7784
|
-
collaborative_planning:
|
|
7781
|
+
thinking_summaries: agentConfigOptions.thinkingSummaries ?? void 0,
|
|
7782
|
+
visualization: agentConfigOptions.visualization ?? void 0,
|
|
7783
|
+
collaborative_planning: agentConfigOptions.collaborativePlanning ?? void 0
|
|
7785
7784
|
});
|
|
7786
7785
|
} else if (agentConfigOptions.type === "dynamic") {
|
|
7787
7786
|
agentConfig = { type: "dynamic" };
|
|
7788
7787
|
}
|
|
7789
7788
|
}
|
|
7790
7789
|
let environment;
|
|
7791
|
-
if (
|
|
7790
|
+
if (googleOptions?.environment != null) {
|
|
7792
7791
|
if (!isAgent) {
|
|
7793
7792
|
warnings.push({
|
|
7794
7793
|
type: "other",
|
|
@@ -7798,8 +7797,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7798
7797
|
environment = googleOptions.environment;
|
|
7799
7798
|
} else {
|
|
7800
7799
|
const environmentOptions = googleOptions.environment;
|
|
7801
|
-
const sources =
|
|
7802
|
-
var _a3;
|
|
7800
|
+
const sources = environmentOptions.sources?.map((source) => {
|
|
7803
7801
|
if (source.type === "inline") {
|
|
7804
7802
|
return {
|
|
7805
7803
|
type: "inline",
|
|
@@ -7810,7 +7808,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7810
7808
|
return pruneUndefined({
|
|
7811
7809
|
type: source.type,
|
|
7812
7810
|
source: source.source,
|
|
7813
|
-
target:
|
|
7811
|
+
target: source.target ?? void 0
|
|
7814
7812
|
});
|
|
7815
7813
|
});
|
|
7816
7814
|
let network;
|
|
@@ -7819,13 +7817,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7819
7817
|
} else if (environmentOptions.network != null) {
|
|
7820
7818
|
network = {
|
|
7821
7819
|
allowlist: environmentOptions.network.allowlist.map(
|
|
7822
|
-
(entry) => {
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
7827
|
-
});
|
|
7828
|
-
}
|
|
7820
|
+
(entry) => pruneUndefined({
|
|
7821
|
+
domain: entry.domain,
|
|
7822
|
+
transform: entry.transform ?? void 0
|
|
7823
|
+
})
|
|
7829
7824
|
)
|
|
7830
7825
|
};
|
|
7831
7826
|
}
|
|
@@ -7842,25 +7837,24 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7842
7837
|
system_instruction: systemInstruction,
|
|
7843
7838
|
tools: toolsForBody,
|
|
7844
7839
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
7845
|
-
response_modalities:
|
|
7846
|
-
previous_interaction_id:
|
|
7847
|
-
service_tier:
|
|
7848
|
-
store:
|
|
7840
|
+
response_modalities: googleOptions?.responseModalities != null ? googleOptions.responseModalities : void 0,
|
|
7841
|
+
previous_interaction_id: googleOptions?.previousInteractionId ?? void 0,
|
|
7842
|
+
service_tier: googleOptions?.serviceTier ?? void 0,
|
|
7843
|
+
store: googleOptions?.store ?? void 0,
|
|
7849
7844
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
7850
7845
|
agent_config: agentConfig,
|
|
7851
7846
|
environment,
|
|
7852
|
-
background:
|
|
7847
|
+
background: googleOptions?.background ?? void 0
|
|
7853
7848
|
});
|
|
7854
7849
|
return {
|
|
7855
7850
|
args,
|
|
7856
7851
|
warnings,
|
|
7857
7852
|
isAgent,
|
|
7858
|
-
isBackground:
|
|
7859
|
-
pollingTimeoutMs:
|
|
7853
|
+
isBackground: googleOptions?.background === true,
|
|
7854
|
+
pollingTimeoutMs: googleOptions?.pollingTimeoutMs ?? void 0
|
|
7860
7855
|
};
|
|
7861
7856
|
}
|
|
7862
7857
|
async doGenerate(options) {
|
|
7863
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
7864
7858
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
7865
7859
|
const url = `${this.config.baseURL}/interactions`;
|
|
7866
7860
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7894,12 +7888,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7894
7888
|
});
|
|
7895
7889
|
response = polled.response;
|
|
7896
7890
|
rawResponse = polled.rawResponse;
|
|
7897
|
-
responseHeaders =
|
|
7891
|
+
responseHeaders = polled.responseHeaders ?? responseHeaders;
|
|
7898
7892
|
}
|
|
7899
7893
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7900
7894
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
7901
|
-
steps:
|
|
7902
|
-
generateId:
|
|
7895
|
+
steps: response.steps ?? null,
|
|
7896
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
7903
7897
|
interactionId
|
|
7904
7898
|
});
|
|
7905
7899
|
const finishReason = {
|
|
@@ -7909,7 +7903,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7909
7903
|
}),
|
|
7910
7904
|
raw: response.status
|
|
7911
7905
|
};
|
|
7912
|
-
const serviceTier =
|
|
7906
|
+
const serviceTier = response.service_tier ?? responseHeaders?.["x-gemini-service-tier"] ?? void 0;
|
|
7913
7907
|
const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
|
|
7914
7908
|
response.usage
|
|
7915
7909
|
);
|
|
@@ -7939,12 +7933,11 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7939
7933
|
body: rawResponse,
|
|
7940
7934
|
...interactionId != null ? { id: interactionId } : {},
|
|
7941
7935
|
...timestamp ? { timestamp } : {},
|
|
7942
|
-
modelId:
|
|
7936
|
+
modelId: response.model ?? void 0
|
|
7943
7937
|
}
|
|
7944
7938
|
};
|
|
7945
7939
|
}
|
|
7946
7940
|
async doStream(options) {
|
|
7947
|
-
var _a2;
|
|
7948
7941
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
7949
7942
|
const url = `${this.config.baseURL}/interactions`;
|
|
7950
7943
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7973,10 +7966,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7973
7966
|
abortSignal: options.abortSignal,
|
|
7974
7967
|
fetch: this.config.fetch
|
|
7975
7968
|
});
|
|
7976
|
-
const headerServiceTier = responseHeaders
|
|
7969
|
+
const headerServiceTier = responseHeaders?.["x-gemini-service-tier"];
|
|
7977
7970
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
7978
7971
|
warnings,
|
|
7979
|
-
generateId:
|
|
7972
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
7980
7973
|
includeRawChunks: options.includeRawChunks,
|
|
7981
7974
|
serviceTier: headerServiceTier
|
|
7982
7975
|
});
|
|
@@ -8012,7 +8005,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8012
8005
|
options,
|
|
8013
8006
|
pollingTimeoutMs
|
|
8014
8007
|
}) {
|
|
8015
|
-
var _a2, _b;
|
|
8016
8008
|
const postResult = await postJsonToApi6({
|
|
8017
8009
|
url,
|
|
8018
8010
|
headers: mergedHeaders,
|
|
@@ -8031,12 +8023,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8031
8023
|
"google.interactions: background POST response did not include an interaction id; cannot stream the result."
|
|
8032
8024
|
);
|
|
8033
8025
|
}
|
|
8034
|
-
const headerServiceTier = postHeaders
|
|
8026
|
+
const headerServiceTier = postHeaders?.["x-gemini-service-tier"];
|
|
8035
8027
|
if (isTerminalStatus(postResponse.status)) {
|
|
8036
8028
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
8037
8029
|
response: postResponse,
|
|
8038
8030
|
warnings,
|
|
8039
|
-
generateId:
|
|
8031
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
8040
8032
|
includeRawChunks: options.includeRawChunks,
|
|
8041
8033
|
headerServiceTier
|
|
8042
8034
|
});
|
|
@@ -8056,7 +8048,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8056
8048
|
});
|
|
8057
8049
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
8058
8050
|
warnings,
|
|
8059
|
-
generateId:
|
|
8051
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
8060
8052
|
includeRawChunks: options.includeRawChunks,
|
|
8061
8053
|
serviceTier: headerServiceTier
|
|
8062
8054
|
});
|
|
@@ -8128,17 +8120,15 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8128
8120
|
this.turnClosed = false;
|
|
8129
8121
|
}
|
|
8130
8122
|
parseServerEvent(raw) {
|
|
8131
|
-
var _a2, _b;
|
|
8132
8123
|
const data = raw;
|
|
8133
8124
|
if (data.setupComplete != null) {
|
|
8134
8125
|
return { type: "session-created", raw };
|
|
8135
8126
|
}
|
|
8136
8127
|
if (data.toolCall != null) {
|
|
8137
8128
|
this.beginTurnIfClosed();
|
|
8138
|
-
const functionCalls =
|
|
8129
|
+
const functionCalls = data.toolCall.functionCalls ?? [];
|
|
8139
8130
|
return functionCalls.flatMap((functionCall) => {
|
|
8140
|
-
|
|
8141
|
-
const args = JSON.stringify((_a3 = functionCall.args) != null ? _a3 : {});
|
|
8131
|
+
const args = JSON.stringify(functionCall.args ?? {});
|
|
8142
8132
|
return [
|
|
8143
8133
|
{
|
|
8144
8134
|
type: "function-call-arguments-delta",
|
|
@@ -8184,7 +8174,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8184
8174
|
if (data.serverContent != null) {
|
|
8185
8175
|
return this.parseServerContent(data.serverContent, raw);
|
|
8186
8176
|
}
|
|
8187
|
-
if (
|
|
8177
|
+
if (data.inputTranscription?.text != null) {
|
|
8188
8178
|
return {
|
|
8189
8179
|
type: "input-transcription-completed",
|
|
8190
8180
|
itemId: `google-input-${this.turnCounter}`,
|
|
@@ -8195,7 +8185,6 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8195
8185
|
return { type: "custom", rawType: String(Object.keys(data)[0]), raw };
|
|
8196
8186
|
}
|
|
8197
8187
|
parseServerContent(serverContent, raw) {
|
|
8198
|
-
var _a2, _b, _c, _d;
|
|
8199
8188
|
const events = [];
|
|
8200
8189
|
if (serverContent.interrupted) {
|
|
8201
8190
|
events.push({
|
|
@@ -8203,10 +8192,10 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8203
8192
|
raw
|
|
8204
8193
|
});
|
|
8205
8194
|
}
|
|
8206
|
-
if (
|
|
8195
|
+
if (serverContent.modelTurn?.parts) {
|
|
8207
8196
|
this.beginTurnIfClosed();
|
|
8208
8197
|
for (const part of serverContent.modelTurn.parts) {
|
|
8209
|
-
if (
|
|
8198
|
+
if (part.inlineData?.data) {
|
|
8210
8199
|
this.hasAudio = true;
|
|
8211
8200
|
events.push({
|
|
8212
8201
|
type: "audio-delta",
|
|
@@ -8228,7 +8217,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8228
8217
|
}
|
|
8229
8218
|
}
|
|
8230
8219
|
}
|
|
8231
|
-
if (
|
|
8220
|
+
if (serverContent.outputTranscription?.text) {
|
|
8232
8221
|
this.hasTranscript = true;
|
|
8233
8222
|
events.push({
|
|
8234
8223
|
type: "audio-transcript-delta",
|
|
@@ -8238,7 +8227,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8238
8227
|
raw
|
|
8239
8228
|
});
|
|
8240
8229
|
}
|
|
8241
|
-
if (
|
|
8230
|
+
if (serverContent.inputTranscription?.text) {
|
|
8242
8231
|
events.push({
|
|
8243
8232
|
type: "input-transcription-completed",
|
|
8244
8233
|
itemId: `google-input-${this.turnCounter}`,
|
|
@@ -8306,10 +8295,9 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8306
8295
|
return events.length === 1 ? events[0] : events;
|
|
8307
8296
|
}
|
|
8308
8297
|
serializeClientEvent(event, modelId) {
|
|
8309
|
-
var _a2;
|
|
8310
8298
|
switch (event.type) {
|
|
8311
8299
|
case "session-update":
|
|
8312
|
-
if (
|
|
8300
|
+
if (event.config.inputAudioFormat?.rate != null) {
|
|
8313
8301
|
this.inputAudioRate = event.config.inputAudioFormat.rate;
|
|
8314
8302
|
}
|
|
8315
8303
|
return {
|
|
@@ -8378,26 +8366,24 @@ async function serializeFunctionCallOutput(item) {
|
|
|
8378
8366
|
};
|
|
8379
8367
|
}
|
|
8380
8368
|
function isThinkingLiveModel(modelId) {
|
|
8381
|
-
|
|
8382
|
-
const modelName = (_b = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
8369
|
+
const modelName = modelId.split("/").at(-1)?.toLowerCase() ?? "";
|
|
8383
8370
|
return /^gemini-\d+\.\d+-live\b.*thinking/.test(modelName);
|
|
8384
8371
|
}
|
|
8385
8372
|
function buildGoogleSessionConfig(config, modelId) {
|
|
8386
|
-
var _a2, _b;
|
|
8387
8373
|
const setup = {
|
|
8388
8374
|
model: getModelPath(modelId)
|
|
8389
8375
|
};
|
|
8390
|
-
const { google: google2, ...restProviderOptions } =
|
|
8376
|
+
const { google: google2, ...restProviderOptions } = config?.providerOptions ?? {};
|
|
8391
8377
|
const googleOptions = isRecord(google2) ? google2 : void 0;
|
|
8392
8378
|
const generationConfig = {};
|
|
8393
|
-
if (
|
|
8379
|
+
if (config?.outputModalities != null) {
|
|
8394
8380
|
generationConfig.responseModalities = config.outputModalities.map(
|
|
8395
8381
|
(m) => m.toUpperCase()
|
|
8396
8382
|
);
|
|
8397
8383
|
} else {
|
|
8398
8384
|
generationConfig.responseModalities = ["AUDIO"];
|
|
8399
8385
|
}
|
|
8400
|
-
if (
|
|
8386
|
+
if (config?.voice != null) {
|
|
8401
8387
|
generationConfig.speechConfig = {
|
|
8402
8388
|
voiceConfig: {
|
|
8403
8389
|
prebuiltVoiceConfig: {
|
|
@@ -8407,41 +8393,43 @@ function buildGoogleSessionConfig(config, modelId) {
|
|
|
8407
8393
|
};
|
|
8408
8394
|
}
|
|
8409
8395
|
setup.generationConfig = generationConfig;
|
|
8410
|
-
if (
|
|
8396
|
+
if (config?.instructions != null) {
|
|
8411
8397
|
setup.systemInstruction = {
|
|
8412
8398
|
parts: [{ text: config.instructions }]
|
|
8413
8399
|
};
|
|
8414
8400
|
}
|
|
8415
|
-
if (
|
|
8401
|
+
if (config?.tools != null && config.tools.length > 0) {
|
|
8416
8402
|
setup.tools = [
|
|
8417
8403
|
{
|
|
8418
8404
|
functionDeclarations: config.tools.map((tool) => ({
|
|
8419
8405
|
name: tool.name,
|
|
8420
8406
|
description: tool.description,
|
|
8421
8407
|
parametersJsonSchema: tool.parameters,
|
|
8422
|
-
...
|
|
8408
|
+
...googleOptions?.defaultToolBehavior != null ? { behavior: googleOptions.defaultToolBehavior } : {}
|
|
8423
8409
|
}))
|
|
8424
8410
|
}
|
|
8425
8411
|
];
|
|
8426
8412
|
}
|
|
8427
|
-
if (
|
|
8413
|
+
if (config?.inputAudioTranscription != null) {
|
|
8428
8414
|
setup.inputAudioTranscription = {};
|
|
8429
8415
|
}
|
|
8430
|
-
if (
|
|
8416
|
+
if (config?.outputAudioTranscription != null) {
|
|
8431
8417
|
setup.outputAudioTranscription = {};
|
|
8432
8418
|
}
|
|
8433
|
-
const
|
|
8419
|
+
const rawGenerationConfig = restProviderOptions.generationConfig;
|
|
8420
|
+
const explicitThinkingConfig = googleOptions?.thinkingConfig ?? (isRecord(rawGenerationConfig) && isRecord(rawGenerationConfig.thinkingConfig) ? rawGenerationConfig.thinkingConfig : void 0);
|
|
8421
|
+
const thinkingConfig = isThinkingLiveModel(modelId) && explicitThinkingConfig?.thinkingLevel == null && explicitThinkingConfig?.thinkingBudget == null ? { ...explicitThinkingConfig, thinkingLevel: "low" } : googleOptions?.thinkingConfig;
|
|
8434
8422
|
const applyThinkingConfig = () => {
|
|
8435
8423
|
if (thinkingConfig == null) return;
|
|
8436
8424
|
const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
|
|
8437
8425
|
setup.generationConfig = { ...target, thinkingConfig };
|
|
8438
8426
|
};
|
|
8439
|
-
if (
|
|
8427
|
+
if (config?.providerOptions == null) {
|
|
8440
8428
|
applyThinkingConfig();
|
|
8441
8429
|
return setup;
|
|
8442
8430
|
}
|
|
8443
8431
|
Object.assign(setup, restProviderOptions);
|
|
8444
|
-
if (
|
|
8432
|
+
if (googleOptions?.translationConfig != null) {
|
|
8445
8433
|
const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
|
|
8446
8434
|
setup.generationConfig = {
|
|
8447
8435
|
...target,
|
|
@@ -8471,8 +8459,7 @@ var GoogleRealtimeModel = class {
|
|
|
8471
8459
|
this.config = config;
|
|
8472
8460
|
}
|
|
8473
8461
|
async doCreateClientSecret(options) {
|
|
8474
|
-
|
|
8475
|
-
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
8462
|
+
const fetchFn = this.config.fetch ?? fetch;
|
|
8476
8463
|
const headers = this.config.headers();
|
|
8477
8464
|
const apiKey = headers["x-goog-api-key"];
|
|
8478
8465
|
if (!apiKey) {
|
|
@@ -8481,7 +8468,7 @@ var GoogleRealtimeModel = class {
|
|
|
8481
8468
|
);
|
|
8482
8469
|
}
|
|
8483
8470
|
const now = Date.now();
|
|
8484
|
-
const openWindowMs = (
|
|
8471
|
+
const openWindowMs = (options.expiresAfterSeconds ?? 60) * 1e3;
|
|
8485
8472
|
const newSessionExpireTime = new Date(now + openWindowMs).toISOString();
|
|
8486
8473
|
const expireTime = new Date(
|
|
8487
8474
|
now + openWindowMs + 30 * 60 * 1e3
|
|
@@ -8625,14 +8612,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8625
8612
|
});
|
|
8626
8613
|
}
|
|
8627
8614
|
async doGenerate(options) {
|
|
8628
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
8629
8615
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
8630
8616
|
throw new InvalidArgumentError3({
|
|
8631
8617
|
argument: "modelId",
|
|
8632
8618
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
8633
8619
|
});
|
|
8634
8620
|
}
|
|
8635
|
-
const currentDate =
|
|
8621
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
8636
8622
|
const warnings = [];
|
|
8637
8623
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8638
8624
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -8667,11 +8653,11 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8667
8653
|
});
|
|
8668
8654
|
let text = "";
|
|
8669
8655
|
const segments = [];
|
|
8670
|
-
for (const step of
|
|
8671
|
-
for (const content of
|
|
8656
|
+
for (const step of response.steps ?? []) {
|
|
8657
|
+
for (const content of step.content ?? []) {
|
|
8672
8658
|
if (content.type !== "text" || content.text == null) continue;
|
|
8673
8659
|
text += content.text;
|
|
8674
|
-
for (const annotation of
|
|
8660
|
+
for (const annotation of content.annotations ?? []) {
|
|
8675
8661
|
if (annotation.type !== "word_info") continue;
|
|
8676
8662
|
const startSecond = parseOffsetSeconds(annotation.start_offset);
|
|
8677
8663
|
const endSecond = parseOffsetSeconds(annotation.end_offset);
|
|
@@ -8702,14 +8688,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8702
8688
|
};
|
|
8703
8689
|
}
|
|
8704
8690
|
async doStream(options) {
|
|
8705
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
8706
8691
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
8707
8692
|
throw new InvalidArgumentError3({
|
|
8708
8693
|
argument: "modelId",
|
|
8709
8694
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
8710
8695
|
});
|
|
8711
8696
|
}
|
|
8712
|
-
const currentDate =
|
|
8697
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
8713
8698
|
const warnings = [];
|
|
8714
8699
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8715
8700
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -8735,7 +8720,7 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8735
8720
|
);
|
|
8736
8721
|
const setup = {
|
|
8737
8722
|
model: getModelPath(this.modelId),
|
|
8738
|
-
inputAudioTranscription:
|
|
8723
|
+
inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
|
|
8739
8724
|
};
|
|
8740
8725
|
return {
|
|
8741
8726
|
request: { body: setup },
|
|
@@ -8748,8 +8733,8 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8748
8733
|
url: getLiveWebSocketURL(this.config.baseURL, apiKey),
|
|
8749
8734
|
headers: webSocketHeaders,
|
|
8750
8735
|
setup,
|
|
8751
|
-
inputAudioRate:
|
|
8752
|
-
finishGraceMs:
|
|
8736
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
8737
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
|
|
8753
8738
|
warnings,
|
|
8754
8739
|
audio: options.audio,
|
|
8755
8740
|
abortSignal: options.abortSignal,
|
|
@@ -8813,7 +8798,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8813
8798
|
void audio.cancel().catch(() => {
|
|
8814
8799
|
});
|
|
8815
8800
|
}
|
|
8816
|
-
connection
|
|
8801
|
+
connection?.close(closeCode);
|
|
8817
8802
|
};
|
|
8818
8803
|
const finishWithError = (error) => {
|
|
8819
8804
|
if (finished) return;
|
|
@@ -8894,7 +8879,6 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8894
8879
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
8895
8880
|
},
|
|
8896
8881
|
onMessageText: async (text) => {
|
|
8897
|
-
var _a2, _b;
|
|
8898
8882
|
if (finished) return;
|
|
8899
8883
|
const parsed = await safeParseJSON2({ text });
|
|
8900
8884
|
if (!parsed.success) return;
|
|
@@ -8910,13 +8894,13 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8910
8894
|
}
|
|
8911
8895
|
if (message.error != null) {
|
|
8912
8896
|
finishWithError(
|
|
8913
|
-
new Error(
|
|
8897
|
+
new Error(message.error.message ?? "Google Live API error")
|
|
8914
8898
|
);
|
|
8915
8899
|
return;
|
|
8916
8900
|
}
|
|
8917
8901
|
const serverContent = message.serverContent;
|
|
8918
|
-
const interim = serverContent
|
|
8919
|
-
if (interim
|
|
8902
|
+
const interim = serverContent?.interimInputTranscription;
|
|
8903
|
+
if (interim?.text) {
|
|
8920
8904
|
schedulePendingFinish();
|
|
8921
8905
|
latestInterim = interim.text;
|
|
8922
8906
|
controller.enqueue({
|
|
@@ -8925,7 +8909,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8925
8909
|
text: interim.text
|
|
8926
8910
|
});
|
|
8927
8911
|
}
|
|
8928
|
-
const transcription =
|
|
8912
|
+
const transcription = serverContent?.inputTranscription ?? message.inputTranscription;
|
|
8929
8913
|
if (transcription != null) {
|
|
8930
8914
|
if (transcription.languageCode != null) {
|
|
8931
8915
|
language = transcription.languageCode;
|
|
@@ -8944,11 +8928,11 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8944
8928
|
completeSegment();
|
|
8945
8929
|
}
|
|
8946
8930
|
}
|
|
8947
|
-
if (serverContent
|
|
8931
|
+
if (serverContent?.turnComplete) {
|
|
8948
8932
|
completeSegment();
|
|
8949
8933
|
}
|
|
8950
|
-
const interactionStatus = serverContent
|
|
8951
|
-
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" ||
|
|
8934
|
+
const interactionStatus = serverContent?.interactionStatus;
|
|
8935
|
+
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) {
|
|
8952
8936
|
finish();
|
|
8953
8937
|
}
|
|
8954
8938
|
},
|
|
@@ -8963,7 +8947,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8963
8947
|
}
|
|
8964
8948
|
finishWithError(
|
|
8965
8949
|
new Error(
|
|
8966
|
-
`Google Live transcription WebSocket closed unexpectedly before finishing (code ${code
|
|
8950
|
+
`Google Live transcription WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
8967
8951
|
)
|
|
8968
8952
|
);
|
|
8969
8953
|
}
|
|
@@ -8997,7 +8981,6 @@ function buildAudioTranscriptionConfig(options) {
|
|
|
8997
8981
|
return Object.keys(config).length > 0 ? config : void 0;
|
|
8998
8982
|
}
|
|
8999
8983
|
function buildTranscriptionConfig(options) {
|
|
9000
|
-
var _a2;
|
|
9001
8984
|
if (options == null) return void 0;
|
|
9002
8985
|
const config = {};
|
|
9003
8986
|
if (options.languageCodes != null) {
|
|
@@ -9008,7 +8991,7 @@ function buildTranscriptionConfig(options) {
|
|
|
9008
8991
|
}
|
|
9009
8992
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
9010
8993
|
config.mode = {
|
|
9011
|
-
type: (
|
|
8994
|
+
type: (options.mode ?? "VERBATIM").toLowerCase(),
|
|
9012
8995
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
9013
8996
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
9014
8997
|
};
|
|
@@ -9116,14 +9099,13 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
9116
9099
|
return this.config.provider;
|
|
9117
9100
|
}
|
|
9118
9101
|
async doStream(options) {
|
|
9119
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
9120
9102
|
if (options.targetLanguage == null) {
|
|
9121
9103
|
throw new InvalidArgumentError4({
|
|
9122
9104
|
argument: "targetLanguage",
|
|
9123
9105
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
9124
9106
|
});
|
|
9125
9107
|
}
|
|
9126
|
-
const currentDate =
|
|
9108
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
9127
9109
|
const googleOptions = await parseProviderOptions10({
|
|
9128
9110
|
provider: "google",
|
|
9129
9111
|
providerOptions: options.providerOptions,
|
|
@@ -9178,8 +9160,8 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
9178
9160
|
url: getLiveWebSocketURL2(this.config.baseURL, apiKey),
|
|
9179
9161
|
headers: webSocketHeaders,
|
|
9180
9162
|
setup,
|
|
9181
|
-
inputAudioRate:
|
|
9182
|
-
finishGraceMs:
|
|
9163
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
9164
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs2,
|
|
9183
9165
|
warnings,
|
|
9184
9166
|
audio: options.audio,
|
|
9185
9167
|
abortSignal: options.abortSignal,
|
|
@@ -9250,7 +9232,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9250
9232
|
void audio.cancel().catch(() => {
|
|
9251
9233
|
});
|
|
9252
9234
|
}
|
|
9253
|
-
connection
|
|
9235
|
+
connection?.close(closeCode);
|
|
9254
9236
|
};
|
|
9255
9237
|
const finishWithError = (error) => {
|
|
9256
9238
|
if (finished) return;
|
|
@@ -9339,7 +9321,6 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9339
9321
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
9340
9322
|
},
|
|
9341
9323
|
onMessageText: async (text) => {
|
|
9342
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9343
9324
|
if (finished) return;
|
|
9344
9325
|
const parsed = await safeParseJSON3({ text });
|
|
9345
9326
|
if (!parsed.success) return;
|
|
@@ -9355,11 +9336,11 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9355
9336
|
}
|
|
9356
9337
|
if (message.error != null) {
|
|
9357
9338
|
finishWithError(
|
|
9358
|
-
new Error(
|
|
9339
|
+
new Error(message.error.message ?? "Google Live API error")
|
|
9359
9340
|
);
|
|
9360
9341
|
return;
|
|
9361
9342
|
}
|
|
9362
|
-
const inputTranscriptionText =
|
|
9343
|
+
const inputTranscriptionText = message.serverContent?.inputTranscription?.text ?? message.inputTranscription?.text;
|
|
9363
9344
|
if (inputTranscriptionText) {
|
|
9364
9345
|
onTurnActivity();
|
|
9365
9346
|
sourceTurnBuffer += inputTranscriptionText;
|
|
@@ -9373,8 +9354,8 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9373
9354
|
if (serverContent == null) {
|
|
9374
9355
|
return;
|
|
9375
9356
|
}
|
|
9376
|
-
for (const part of
|
|
9377
|
-
if (
|
|
9357
|
+
for (const part of serverContent.modelTurn?.parts ?? []) {
|
|
9358
|
+
if (part.inlineData?.data) {
|
|
9378
9359
|
controller.enqueue({
|
|
9379
9360
|
type: "audio",
|
|
9380
9361
|
id: itemId(),
|
|
@@ -9394,7 +9375,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9394
9375
|
}
|
|
9395
9376
|
}
|
|
9396
9377
|
}
|
|
9397
|
-
if (
|
|
9378
|
+
if (serverContent.outputTranscription?.text) {
|
|
9398
9379
|
onTurnActivity();
|
|
9399
9380
|
translationTurnBuffer += serverContent.outputTranscription.text;
|
|
9400
9381
|
controller.enqueue({
|
|
@@ -9423,7 +9404,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9423
9404
|
}
|
|
9424
9405
|
finishWithError(
|
|
9425
9406
|
new Error(
|
|
9426
|
-
`Google Live translation WebSocket closed unexpectedly before finishing (code ${code
|
|
9407
|
+
`Google Live translation WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
9427
9408
|
)
|
|
9428
9409
|
);
|
|
9429
9410
|
}
|
|
@@ -9437,17 +9418,16 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9437
9418
|
});
|
|
9438
9419
|
}
|
|
9439
9420
|
function accumulateGoogleLiveUsage(usage, usageMetadata) {
|
|
9440
|
-
|
|
9441
|
-
let
|
|
9442
|
-
|
|
9443
|
-
for (const detail of (_a2 = usageMetadata.promptTokensDetails) != null ? _a2 : []) {
|
|
9421
|
+
let inputAudioTokens = usage?.inputAudioTokens;
|
|
9422
|
+
let outputAudioTokens = usage?.outputAudioTokens;
|
|
9423
|
+
for (const detail of usageMetadata.promptTokensDetails ?? []) {
|
|
9444
9424
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9445
|
-
inputAudioTokens = (inputAudioTokens
|
|
9425
|
+
inputAudioTokens = (inputAudioTokens ?? 0) + detail.tokenCount;
|
|
9446
9426
|
}
|
|
9447
9427
|
}
|
|
9448
|
-
for (const detail of
|
|
9428
|
+
for (const detail of usageMetadata.responseTokensDetails ?? []) {
|
|
9449
9429
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9450
|
-
outputAudioTokens = (outputAudioTokens
|
|
9430
|
+
outputAudioTokens = (outputAudioTokens ?? 0) + detail.tokenCount;
|
|
9451
9431
|
}
|
|
9452
9432
|
}
|
|
9453
9433
|
if (inputAudioTokens == null && outputAudioTokens == null) {
|
|
@@ -9463,7 +9443,7 @@ function getPcm16SilenceDurationMs(audio) {
|
|
|
9463
9443
|
let bytes;
|
|
9464
9444
|
try {
|
|
9465
9445
|
bytes = convertBase64ToUint8Array2(audio);
|
|
9466
|
-
} catch
|
|
9446
|
+
} catch {
|
|
9467
9447
|
return void 0;
|
|
9468
9448
|
}
|
|
9469
9449
|
if (bytes.byteLength < 2) {
|
|
@@ -9489,7 +9469,7 @@ function buildGoogleLiveSpeechTranslationSetup({
|
|
|
9489
9469
|
responseModalities: ["AUDIO"],
|
|
9490
9470
|
translationConfig: {
|
|
9491
9471
|
targetLanguageCode: targetLanguage,
|
|
9492
|
-
...
|
|
9472
|
+
...providerOptions?.echoTargetLanguage != null ? { echoTargetLanguage: providerOptions.echoTargetLanguage } : {}
|
|
9493
9473
|
}
|
|
9494
9474
|
},
|
|
9495
9475
|
inputAudioTranscription: {},
|
|
@@ -9537,9 +9517,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
9537
9517
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
9538
9518
|
}
|
|
9539
9519
|
function createGoogle(options = {}) {
|
|
9540
|
-
|
|
9541
|
-
const
|
|
9542
|
-
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
9520
|
+
const baseURL = withoutTrailingSlash(options.baseURL) ?? DEFAULT_BASE_URL;
|
|
9521
|
+
const providerName = options.name ?? "google.generative-ai";
|
|
9543
9522
|
const getHeaders = () => withUserAgentSuffix2(
|
|
9544
9523
|
{
|
|
9545
9524
|
"x-goog-api-key": loadApiKey({
|
|
@@ -9571,7 +9550,7 @@ function createGoogle(options = {}) {
|
|
|
9571
9550
|
provider: providerName,
|
|
9572
9551
|
baseURL,
|
|
9573
9552
|
headers: getHeaders,
|
|
9574
|
-
generateId:
|
|
9553
|
+
generateId: options.generateId ?? generateId3,
|
|
9575
9554
|
fetch: options.fetch
|
|
9576
9555
|
};
|
|
9577
9556
|
const createChatModel = (modelId) => new GoogleLanguageModel(modelId, {
|
|
@@ -9603,16 +9582,13 @@ function createGoogle(options = {}) {
|
|
|
9603
9582
|
headers: getHeaders,
|
|
9604
9583
|
fetch: options.fetch
|
|
9605
9584
|
});
|
|
9606
|
-
const createVideoModel = (modelId) => {
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3
|
|
9614
|
-
});
|
|
9615
|
-
};
|
|
9585
|
+
const createVideoModel = (modelId) => new GoogleVideoModel(modelId, {
|
|
9586
|
+
provider: providerName,
|
|
9587
|
+
baseURL,
|
|
9588
|
+
headers: getHeaders,
|
|
9589
|
+
fetch: options.fetch,
|
|
9590
|
+
generateId: options.generateId ?? generateId3
|
|
9591
|
+
});
|
|
9616
9592
|
const createRealtimeModel = (modelId) => new GoogleRealtimeModel(modelId, {
|
|
9617
9593
|
provider: `${providerName}.realtime`,
|
|
9618
9594
|
baseURL,
|
|
@@ -9655,19 +9631,16 @@ function createGoogle(options = {}) {
|
|
|
9655
9631
|
}
|
|
9656
9632
|
}
|
|
9657
9633
|
);
|
|
9658
|
-
const createInteractionsModel = (modelIdOrAgent) =>
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
}
|
|
9669
|
-
);
|
|
9670
|
-
};
|
|
9634
|
+
const createInteractionsModel = (modelIdOrAgent) => new GoogleInteractionsLanguageModel(
|
|
9635
|
+
modelIdOrAgent,
|
|
9636
|
+
{
|
|
9637
|
+
provider: `${providerName}.interactions`,
|
|
9638
|
+
baseURL,
|
|
9639
|
+
headers: getHeaders,
|
|
9640
|
+
generateId: options.generateId ?? generateId3,
|
|
9641
|
+
fetch: options.fetch
|
|
9642
|
+
}
|
|
9643
|
+
);
|
|
9671
9644
|
const provider = function(modelId) {
|
|
9672
9645
|
if (new.target) {
|
|
9673
9646
|
throw new Error(
|