@ai-sdk/google 4.0.79 → 4.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/index.js +493 -519
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -0
- package/dist/internal/index.js +356 -342
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +14 -14
- package/package.json +3 -3
- package/src/convert-to-google-messages.ts +56 -10
- package/src/download-tool-result-files.ts +20 -2
- package/src/google-language-model.ts +16 -0
- package/src/google-prompt.ts +7 -3
- package/src/interactions/convert-to-google-interactions-input.ts +2 -2
- package/src/interactions/google-interactions-prompt.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { Experimental_EvaluationLanguageModel as EvaluationLanguageModel } from "@ai-sdk/provider-utils/experimental-evaluation";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "4.0.
|
|
11
|
+
var VERSION = true ? "4.0.82" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/google-embedding-model.ts
|
|
14
14
|
import {
|
|
@@ -126,8 +126,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
126
126
|
this.maxEmbeddingsPerCall = 100;
|
|
127
127
|
this.supportsParallelCalls = true;
|
|
128
128
|
this[_a] = ({ providerOptions, values, startIndex, endIndex }) => {
|
|
129
|
-
|
|
130
|
-
const multimodalContent = (_a2 = providerOptions == null ? void 0 : providerOptions.google) == null ? void 0 : _a2.content;
|
|
129
|
+
const multimodalContent = providerOptions?.google?.content;
|
|
131
130
|
if (!Array.isArray(multimodalContent)) {
|
|
132
131
|
return providerOptions;
|
|
133
132
|
}
|
|
@@ -138,7 +137,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
138
137
|
return {
|
|
139
138
|
...providerOptions,
|
|
140
139
|
google: {
|
|
141
|
-
...providerOptions
|
|
140
|
+
...providerOptions?.google,
|
|
142
141
|
content: multimodalContent.slice(startIndex, endIndex)
|
|
143
142
|
}
|
|
144
143
|
};
|
|
@@ -181,10 +180,10 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
181
180
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
182
181
|
headers
|
|
183
182
|
);
|
|
184
|
-
const multimodalContent = googleOptions
|
|
183
|
+
const multimodalContent = googleOptions?.content;
|
|
185
184
|
validateMultimodalContentLength({ multimodalContent, values });
|
|
186
185
|
if (values.length === 1) {
|
|
187
|
-
const valueParts = multimodalContent
|
|
186
|
+
const valueParts = multimodalContent?.[0];
|
|
188
187
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
189
188
|
const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
|
|
190
189
|
const {
|
|
@@ -199,8 +198,8 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
199
198
|
content: {
|
|
200
199
|
parts
|
|
201
200
|
},
|
|
202
|
-
outputDimensionality: googleOptions
|
|
203
|
-
taskType: googleOptions
|
|
201
|
+
outputDimensionality: googleOptions?.outputDimensionality,
|
|
202
|
+
taskType: googleOptions?.taskType
|
|
204
203
|
},
|
|
205
204
|
failedResponseHandler: googleFailedResponseHandler,
|
|
206
205
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -225,7 +224,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
225
224
|
headers: mergedHeaders,
|
|
226
225
|
body: {
|
|
227
226
|
requests: values.map((value, index) => {
|
|
228
|
-
const valueParts = multimodalContent
|
|
227
|
+
const valueParts = multimodalContent?.[index];
|
|
229
228
|
const textPart = value ? [{ text: value }] : [];
|
|
230
229
|
return {
|
|
231
230
|
model: `models/${this.modelId}`,
|
|
@@ -233,8 +232,8 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
233
232
|
role: "user",
|
|
234
233
|
parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
|
|
235
234
|
},
|
|
236
|
-
outputDimensionality: googleOptions
|
|
237
|
-
taskType: googleOptions
|
|
235
|
+
outputDimensionality: googleOptions?.outputDimensionality,
|
|
236
|
+
taskType: googleOptions?.taskType
|
|
238
237
|
};
|
|
239
238
|
})
|
|
240
239
|
},
|
|
@@ -332,15 +331,14 @@ import { z as z6 } from "zod/v4";
|
|
|
332
331
|
// src/convert-google-usage.ts
|
|
333
332
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
334
333
|
function convertGoogleUsage(usage) {
|
|
335
|
-
var _a2, _b, _c, _d, _e;
|
|
336
334
|
if (usage == null) {
|
|
337
335
|
return createNullLanguageModelUsage();
|
|
338
336
|
}
|
|
339
|
-
const promptTokens =
|
|
340
|
-
const candidatesTokens =
|
|
341
|
-
const toolUsePromptTokens =
|
|
342
|
-
const cachedContentTokens =
|
|
343
|
-
const thoughtsTokens =
|
|
337
|
+
const promptTokens = usage.promptTokenCount ?? 0;
|
|
338
|
+
const candidatesTokens = usage.candidatesTokenCount ?? 0;
|
|
339
|
+
const toolUsePromptTokens = usage.toolUsePromptTokenCount ?? 0;
|
|
340
|
+
const cachedContentTokens = usage.cachedContentTokenCount ?? 0;
|
|
341
|
+
const thoughtsTokens = usage.thoughtsTokenCount ?? 0;
|
|
344
342
|
const inputTokens = promptTokens + toolUsePromptTokens;
|
|
345
343
|
return {
|
|
346
344
|
inputTokens: {
|
|
@@ -366,6 +364,7 @@ import {
|
|
|
366
364
|
convertToBase64,
|
|
367
365
|
getTopLevelMediaType,
|
|
368
366
|
isFullMediaType,
|
|
367
|
+
isUrlSupported,
|
|
369
368
|
resolveFullMediaType,
|
|
370
369
|
resolveProviderReference,
|
|
371
370
|
secureJsonParse
|
|
@@ -413,7 +412,21 @@ function convertUrlToolResultPart(url) {
|
|
|
413
412
|
}
|
|
414
413
|
};
|
|
415
414
|
}
|
|
416
|
-
function
|
|
415
|
+
function containsJSONSchemaReference(value) {
|
|
416
|
+
if (Array.isArray(value)) {
|
|
417
|
+
return value.some(containsJSONSchemaReference);
|
|
418
|
+
}
|
|
419
|
+
if (typeof value !== "object" || value === null) {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
return Object.entries(value).some(
|
|
423
|
+
([key, nestedValue]) => key === "$ref" || containsJSONSchemaReference(nestedValue)
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
function serializeFunctionResponseContent(value) {
|
|
427
|
+
return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
|
|
428
|
+
}
|
|
429
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedUrls = {}) {
|
|
417
430
|
const functionResponseParts = [];
|
|
418
431
|
const responseTextParts = [];
|
|
419
432
|
for (const contentPart of outputValue) {
|
|
@@ -431,11 +444,22 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
|
|
|
431
444
|
}
|
|
432
445
|
});
|
|
433
446
|
} else if (contentPart.data.type === "url") {
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
if (
|
|
438
|
-
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
|
+
});
|
|
439
463
|
} else {
|
|
440
464
|
responseTextParts.push(JSON.stringify(contentPart));
|
|
441
465
|
}
|
|
@@ -503,17 +527,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
503
527
|
}
|
|
504
528
|
}
|
|
505
529
|
function convertToGoogleMessages(prompt, options) {
|
|
506
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
507
530
|
const systemInstructionParts = [];
|
|
508
531
|
const contents = [];
|
|
509
532
|
let systemMessagesAllowed = true;
|
|
510
|
-
const isGemmaModel =
|
|
511
|
-
const isGemini3Model =
|
|
512
|
-
const onWarning = options
|
|
513
|
-
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"];
|
|
514
537
|
const isVertexLike = !providerOptionsNames.includes("google");
|
|
515
|
-
const supportsFunctionResponseParts =
|
|
516
|
-
const includeFunctionCallIds =
|
|
538
|
+
const supportsFunctionResponseParts = options?.supportsFunctionResponseParts ?? true;
|
|
539
|
+
const includeFunctionCallIds = options?.includeFunctionCallIds ?? true;
|
|
540
|
+
const supportedFunctionResponseUrls = options?.supportedFunctionResponseUrls ?? {};
|
|
517
541
|
let sentinelInjected = false;
|
|
518
542
|
const missingSignatureToolNames = [];
|
|
519
543
|
const injectSkipSignature = (toolName) => {
|
|
@@ -522,15 +546,14 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
522
546
|
return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
523
547
|
};
|
|
524
548
|
const readProviderOpts = (part) => {
|
|
525
|
-
var _a3, _b2, _c2, _d2, _e2;
|
|
526
549
|
for (const name of providerOptionsNames) {
|
|
527
|
-
const v =
|
|
550
|
+
const v = part.providerOptions?.[name];
|
|
528
551
|
if (v != null) return v;
|
|
529
552
|
}
|
|
530
553
|
if (isVertexLike) {
|
|
531
|
-
return
|
|
554
|
+
return part.providerOptions?.google;
|
|
532
555
|
}
|
|
533
|
-
return
|
|
556
|
+
return part.providerOptions?.googleVertex ?? part.providerOptions?.vertex;
|
|
534
557
|
};
|
|
535
558
|
for (const { role, content } of prompt) {
|
|
536
559
|
switch (role) {
|
|
@@ -615,7 +638,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
615
638
|
role: "model",
|
|
616
639
|
parts: content.map((part) => {
|
|
617
640
|
const providerOpts = readProviderOpts(part);
|
|
618
|
-
const thoughtSignature =
|
|
641
|
+
const thoughtSignature = providerOpts?.thoughtSignature != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
619
642
|
switch (part.type) {
|
|
620
643
|
case "text": {
|
|
621
644
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -671,7 +694,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
671
694
|
provider: "google"
|
|
672
695
|
})
|
|
673
696
|
},
|
|
674
|
-
...
|
|
697
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
675
698
|
thoughtSignature
|
|
676
699
|
};
|
|
677
700
|
}
|
|
@@ -683,7 +706,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
683
706
|
new TextEncoder().encode(part.data.text)
|
|
684
707
|
)
|
|
685
708
|
},
|
|
686
|
-
...
|
|
709
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
687
710
|
thoughtSignature
|
|
688
711
|
};
|
|
689
712
|
}
|
|
@@ -693,7 +716,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
693
716
|
mimeType: part.mediaType,
|
|
694
717
|
data: convertToBase64(part.data.data)
|
|
695
718
|
},
|
|
696
|
-
...
|
|
719
|
+
...providerOpts?.thought === true ? { thought: true } : {},
|
|
697
720
|
thoughtSignature
|
|
698
721
|
};
|
|
699
722
|
}
|
|
@@ -708,8 +731,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
708
731
|
)
|
|
709
732
|
};
|
|
710
733
|
}
|
|
711
|
-
const serverToolCallId =
|
|
712
|
-
const serverToolType =
|
|
734
|
+
const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
735
|
+
const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
|
|
713
736
|
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
714
737
|
const shouldSkipMissingSignatureMitigation = (
|
|
715
738
|
// Gemini 3 returns a single signature for a parallel
|
|
@@ -718,7 +741,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
718
741
|
// model response legitimately have no signature.
|
|
719
742
|
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
720
743
|
);
|
|
721
|
-
const effectiveThoughtSignature = thoughtSignature
|
|
744
|
+
const effectiveThoughtSignature = thoughtSignature ?? (isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0);
|
|
722
745
|
if (!isServerToolCall && thoughtSignature != null) {
|
|
723
746
|
modelResponseHasSignedFunctionCall = true;
|
|
724
747
|
}
|
|
@@ -749,8 +772,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
749
772
|
)
|
|
750
773
|
};
|
|
751
774
|
}
|
|
752
|
-
const serverToolCallId =
|
|
753
|
-
const serverToolType =
|
|
775
|
+
const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
776
|
+
const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
|
|
754
777
|
if (serverToolCallId && serverToolType) {
|
|
755
778
|
return {
|
|
756
779
|
toolResponse: {
|
|
@@ -776,10 +799,10 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
776
799
|
continue;
|
|
777
800
|
}
|
|
778
801
|
const partProviderOpts = readProviderOpts(part);
|
|
779
|
-
const serverToolCallId =
|
|
780
|
-
const serverToolType =
|
|
802
|
+
const serverToolCallId = partProviderOpts?.serverToolCallId != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
803
|
+
const serverToolType = partProviderOpts?.serverToolType != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
781
804
|
if (serverToolCallId && serverToolType) {
|
|
782
|
-
const serverThoughtSignature =
|
|
805
|
+
const serverThoughtSignature = partProviderOpts?.thoughtSignature != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
783
806
|
if (contents.length > 0) {
|
|
784
807
|
const lastContent = contents[contents.length - 1];
|
|
785
808
|
if (lastContent.role === "model") {
|
|
@@ -803,7 +826,8 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
803
826
|
part.toolName,
|
|
804
827
|
output.value,
|
|
805
828
|
part.toolCallId,
|
|
806
|
-
includeFunctionCallIds
|
|
829
|
+
includeFunctionCallIds,
|
|
830
|
+
supportedFunctionResponseUrls
|
|
807
831
|
);
|
|
808
832
|
} else {
|
|
809
833
|
appendLegacyToolResultParts(
|
|
@@ -821,7 +845,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
821
845
|
name: part.toolName,
|
|
822
846
|
response: {
|
|
823
847
|
name: part.toolName,
|
|
824
|
-
content: output.type === "execution-denied" ?
|
|
848
|
+
content: output.type === "execution-denied" ? output.reason ?? "Tool call execution denied." : serializeFunctionResponseContent(output.value)
|
|
825
849
|
}
|
|
826
850
|
}
|
|
827
851
|
});
|
|
@@ -856,11 +880,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
856
880
|
import {
|
|
857
881
|
detectMediaType,
|
|
858
882
|
downloadBlob,
|
|
859
|
-
isFullMediaType as isFullMediaType2
|
|
883
|
+
isFullMediaType as isFullMediaType2,
|
|
884
|
+
isUrlSupported as isUrlSupported2
|
|
860
885
|
} from "@ai-sdk/provider-utils";
|
|
861
886
|
async function downloadToolResultFiles(prompt, {
|
|
862
887
|
abortSignal,
|
|
863
|
-
maxBytes
|
|
888
|
+
maxBytes,
|
|
889
|
+
supportedUrls = {}
|
|
864
890
|
}) {
|
|
865
891
|
const result = [];
|
|
866
892
|
for (const message of prompt) {
|
|
@@ -872,7 +898,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
872
898
|
...part,
|
|
873
899
|
output: await downloadToolResultOutput(part.output, {
|
|
874
900
|
abortSignal,
|
|
875
|
-
maxBytes
|
|
901
|
+
maxBytes,
|
|
902
|
+
supportedUrls
|
|
876
903
|
})
|
|
877
904
|
} : part
|
|
878
905
|
);
|
|
@@ -891,7 +918,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
891
918
|
...part,
|
|
892
919
|
output: await downloadToolResultOutput(part.output, {
|
|
893
920
|
abortSignal,
|
|
894
|
-
maxBytes
|
|
921
|
+
maxBytes,
|
|
922
|
+
supportedUrls
|
|
895
923
|
})
|
|
896
924
|
});
|
|
897
925
|
}
|
|
@@ -904,7 +932,8 @@ async function downloadToolResultFiles(prompt, {
|
|
|
904
932
|
}
|
|
905
933
|
async function downloadToolResultOutput(output, {
|
|
906
934
|
abortSignal,
|
|
907
|
-
maxBytes
|
|
935
|
+
maxBytes,
|
|
936
|
+
supportedUrls
|
|
908
937
|
}) {
|
|
909
938
|
if (output.type !== "content") {
|
|
910
939
|
return output;
|
|
@@ -915,6 +944,14 @@ async function downloadToolResultOutput(output, {
|
|
|
915
944
|
value.push(part);
|
|
916
945
|
continue;
|
|
917
946
|
}
|
|
947
|
+
if (isUrlSupported2({
|
|
948
|
+
url: part.data.url.toString(),
|
|
949
|
+
mediaType: part.mediaType,
|
|
950
|
+
supportedUrls
|
|
951
|
+
})) {
|
|
952
|
+
value.push(part);
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
918
955
|
const blob = await downloadBlob(part.data.url.toString(), {
|
|
919
956
|
abortSignal,
|
|
920
957
|
maxBytes
|
|
@@ -927,7 +964,7 @@ async function downloadToolResultOutput(output, {
|
|
|
927
964
|
value.push({
|
|
928
965
|
...part,
|
|
929
966
|
data: { type: "data", data },
|
|
930
|
-
mediaType: detectedMediaType
|
|
967
|
+
mediaType: detectedMediaType ?? (blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType)
|
|
931
968
|
});
|
|
932
969
|
}
|
|
933
970
|
return {
|
|
@@ -1196,7 +1233,7 @@ function prepareTools({
|
|
|
1196
1233
|
modelId,
|
|
1197
1234
|
isVertexProvider = false
|
|
1198
1235
|
}) {
|
|
1199
|
-
tools =
|
|
1236
|
+
tools = tools?.length ? tools : void 0;
|
|
1200
1237
|
const toolWarnings = [];
|
|
1201
1238
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1202
1239
|
if (tools == null) {
|
|
@@ -1425,10 +1462,9 @@ function prepareTools({
|
|
|
1425
1462
|
}
|
|
1426
1463
|
}
|
|
1427
1464
|
function prepareFunctionDeclaration(tool) {
|
|
1428
|
-
var _a2;
|
|
1429
1465
|
return {
|
|
1430
1466
|
name: tool.name,
|
|
1431
|
-
description:
|
|
1467
|
+
description: tool.description ?? "",
|
|
1432
1468
|
parametersJsonSchema: tool.inputSchema
|
|
1433
1469
|
};
|
|
1434
1470
|
}
|
|
@@ -1667,8 +1703,7 @@ function setNestedValue(obj, segments, value) {
|
|
|
1667
1703
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1668
1704
|
}
|
|
1669
1705
|
function resolvePartialArgValue(arg) {
|
|
1670
|
-
|
|
1671
|
-
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1706
|
+
const value = arg.stringValue ?? arg.numberValue ?? arg.boolValue;
|
|
1672
1707
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1673
1708
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1674
1709
|
}
|
|
@@ -1707,13 +1742,19 @@ var configurableSafetySettingCategories = [
|
|
|
1707
1742
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1708
1743
|
];
|
|
1709
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
|
+
};
|
|
1710
1752
|
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
1711
1753
|
constructor(modelId, config) {
|
|
1712
1754
|
this.specificationVersion = "v4";
|
|
1713
|
-
var _a2;
|
|
1714
1755
|
this.modelId = modelId;
|
|
1715
1756
|
this.config = config;
|
|
1716
|
-
this.generateId =
|
|
1757
|
+
this.generateId = config.generateId ?? generateId;
|
|
1717
1758
|
}
|
|
1718
1759
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
1719
1760
|
return serializeModelOptions2({
|
|
@@ -1728,8 +1769,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1728
1769
|
return this.config.provider;
|
|
1729
1770
|
}
|
|
1730
1771
|
get supportedUrls() {
|
|
1731
|
-
|
|
1732
|
-
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1772
|
+
return this.config.supportedUrls?.() ?? {};
|
|
1733
1773
|
}
|
|
1734
1774
|
static async prepareRequest({
|
|
1735
1775
|
modelId,
|
|
@@ -1753,7 +1793,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1753
1793
|
},
|
|
1754
1794
|
isStreaming = false
|
|
1755
1795
|
}) {
|
|
1756
|
-
var _a2, _b, _c;
|
|
1757
1796
|
const warnings = [];
|
|
1758
1797
|
const providerOptionsNames = config.provider.includes(
|
|
1759
1798
|
"vertex"
|
|
@@ -1775,33 +1814,33 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1775
1814
|
});
|
|
1776
1815
|
}
|
|
1777
1816
|
const isVertexProvider = config.provider.startsWith("google.vertex.");
|
|
1778
|
-
if (
|
|
1817
|
+
if (tools?.some(
|
|
1779
1818
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
1780
|
-
)
|
|
1819
|
+
) && !isVertexProvider) {
|
|
1781
1820
|
warnings.push({
|
|
1782
1821
|
type: "other",
|
|
1783
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}).`
|
|
1784
1823
|
});
|
|
1785
1824
|
}
|
|
1786
|
-
if (
|
|
1825
|
+
if (googleOptions?.streamFunctionCallArguments && !isVertexProvider) {
|
|
1787
1826
|
warnings.push({
|
|
1788
1827
|
type: "other",
|
|
1789
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`
|
|
1790
1829
|
});
|
|
1791
1830
|
}
|
|
1792
|
-
if (
|
|
1831
|
+
if (googleOptions?.serviceTier && isVertexProvider) {
|
|
1793
1832
|
warnings.push({
|
|
1794
1833
|
type: "other",
|
|
1795
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"
|
|
1796
1835
|
});
|
|
1797
1836
|
}
|
|
1798
|
-
if ((
|
|
1837
|
+
if ((googleOptions?.sharedRequestType || googleOptions?.requestType) && !isVertexProvider) {
|
|
1799
1838
|
warnings.push({
|
|
1800
1839
|
type: "other",
|
|
1801
1840
|
message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${config.provider}).`
|
|
1802
1841
|
});
|
|
1803
1842
|
}
|
|
1804
|
-
const vertexPaygoHeaders = isVertexProvider && (
|
|
1843
|
+
const vertexPaygoHeaders = isVertexProvider && (googleOptions?.sharedRequestType || googleOptions?.requestType) ? {
|
|
1805
1844
|
...googleOptions.sharedRequestType && {
|
|
1806
1845
|
"X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
|
|
1807
1846
|
},
|
|
@@ -1809,8 +1848,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1809
1848
|
"X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
|
|
1810
1849
|
}
|
|
1811
1850
|
} : void 0;
|
|
1812
|
-
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions
|
|
1813
|
-
let imageConfig = googleOptions
|
|
1851
|
+
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions?.serviceTier;
|
|
1852
|
+
let imageConfig = googleOptions?.imageConfig;
|
|
1814
1853
|
if (imageConfig != null && !isVertexProvider) {
|
|
1815
1854
|
const {
|
|
1816
1855
|
personGeneration,
|
|
@@ -1846,9 +1885,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1846
1885
|
});
|
|
1847
1886
|
}
|
|
1848
1887
|
const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1888
|
+
const supportedFunctionResponseUrls = usesGemini3Features && config.downloadToolResultFiles?.supportsGoogleCloudStorageUrls ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
1849
1889
|
const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
|
|
1850
1890
|
abortSignal,
|
|
1851
|
-
maxBytes: config.downloadToolResultFiles.maxBytes
|
|
1891
|
+
maxBytes: config.downloadToolResultFiles.maxBytes,
|
|
1892
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
1852
1893
|
}) : prompt;
|
|
1853
1894
|
const { contents, systemInstruction } = convertToGoogleMessages(
|
|
1854
1895
|
promptWithDownloadedToolResultFiles,
|
|
@@ -1858,7 +1899,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1858
1899
|
onWarning: (warning) => warnings.push(warning),
|
|
1859
1900
|
providerOptionsNames,
|
|
1860
1901
|
supportsFunctionResponseParts: usesGemini3Features,
|
|
1861
|
-
includeFunctionCallIds: !isVertexProvider
|
|
1902
|
+
includeFunctionCallIds: !isVertexProvider,
|
|
1903
|
+
supportedFunctionResponseUrls
|
|
1862
1904
|
}
|
|
1863
1905
|
);
|
|
1864
1906
|
const {
|
|
@@ -1882,22 +1924,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1882
1924
|
modelId,
|
|
1883
1925
|
warnings
|
|
1884
1926
|
});
|
|
1885
|
-
const thinkingConfig =
|
|
1886
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ?
|
|
1887
|
-
const safetyThreshold = googleOptions
|
|
1888
|
-
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) => ({
|
|
1889
1931
|
category,
|
|
1890
1932
|
threshold: safetyThreshold
|
|
1891
|
-
})) : void 0;
|
|
1892
|
-
const toolConfig = googleToolConfig || streamFunctionCallArguments ||
|
|
1933
|
+
})) : void 0);
|
|
1934
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || googleOptions?.retrievalConfig ? {
|
|
1893
1935
|
...googleToolConfig,
|
|
1894
1936
|
...streamFunctionCallArguments && {
|
|
1895
1937
|
functionCallingConfig: {
|
|
1896
|
-
...googleToolConfig
|
|
1938
|
+
...googleToolConfig?.functionCallingConfig,
|
|
1897
1939
|
streamFunctionCallArguments: true
|
|
1898
1940
|
}
|
|
1899
1941
|
},
|
|
1900
|
-
...
|
|
1942
|
+
...googleOptions?.retrievalConfig && {
|
|
1901
1943
|
retrievalConfig: googleOptions.retrievalConfig
|
|
1902
1944
|
}
|
|
1903
1945
|
} : void 0;
|
|
@@ -1914,18 +1956,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1914
1956
|
stopSequences,
|
|
1915
1957
|
seed,
|
|
1916
1958
|
// response format:
|
|
1917
|
-
responseMimeType:
|
|
1918
|
-
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
|
|
1919
1961
|
// responseJsonSchema, so this is needed as an escape hatch:
|
|
1920
1962
|
// TODO convert into provider option
|
|
1921
|
-
(
|
|
1922
|
-
...
|
|
1963
|
+
(googleOptions?.structuredOutputs ?? true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
|
|
1964
|
+
...googleOptions?.audioTimestamp && {
|
|
1923
1965
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1924
1966
|
},
|
|
1925
1967
|
// provider options:
|
|
1926
|
-
responseModalities: googleOptions
|
|
1968
|
+
responseModalities: googleOptions?.responseModalities,
|
|
1927
1969
|
thinkingConfig,
|
|
1928
|
-
...
|
|
1970
|
+
...googleOptions?.mediaResolution && {
|
|
1929
1971
|
mediaResolution: googleOptions.mediaResolution
|
|
1930
1972
|
},
|
|
1931
1973
|
...imageConfig && { imageConfig }
|
|
@@ -1935,8 +1977,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1935
1977
|
safetySettings,
|
|
1936
1978
|
tools: googleTools2,
|
|
1937
1979
|
toolConfig,
|
|
1938
|
-
cachedContent: googleOptions
|
|
1939
|
-
labels: googleOptions
|
|
1980
|
+
cachedContent: googleOptions?.cachedContent,
|
|
1981
|
+
labels: googleOptions?.labels,
|
|
1940
1982
|
serviceTier: bodyServiceTier
|
|
1941
1983
|
},
|
|
1942
1984
|
warnings: [...warnings, ...toolWarnings],
|
|
@@ -1960,30 +2002,29 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1960
2002
|
providerOptionsNames,
|
|
1961
2003
|
toolNameMapping
|
|
1962
2004
|
}) {
|
|
1963
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1964
2005
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1965
2006
|
providerOptionsNames.map((name) => [name, payload])
|
|
1966
2007
|
);
|
|
1967
|
-
const candidate =
|
|
1968
|
-
const promptBlockReason =
|
|
2008
|
+
const candidate = response.candidates?.[0];
|
|
2009
|
+
const promptBlockReason = response.promptFeedback?.blockReason;
|
|
1969
2010
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1970
2011
|
promptBlockReason
|
|
1971
2012
|
) ? promptBlockReason : void 0;
|
|
1972
|
-
const isPromptBlocked =
|
|
1973
|
-
const rawFinishReason =
|
|
2013
|
+
const isPromptBlocked = candidate?.finishReason == null && confirmedPromptBlockReason != null;
|
|
2014
|
+
const rawFinishReason = candidate?.finishReason ?? confirmedPromptBlockReason;
|
|
1974
2015
|
const content = [];
|
|
1975
|
-
const parts =
|
|
2016
|
+
const parts = candidate?.content?.parts ?? [];
|
|
1976
2017
|
const usageMetadata = response.usageMetadata;
|
|
1977
2018
|
let lastCodeExecutionToolCallId;
|
|
1978
2019
|
let lastServerToolCallId;
|
|
1979
2020
|
for (const part of parts) {
|
|
1980
|
-
if ("executableCode" in part &&
|
|
2021
|
+
if ("executableCode" in part && part.executableCode?.code) {
|
|
1981
2022
|
const toolCallId = config.generateId();
|
|
1982
2023
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1983
2024
|
content.push({
|
|
1984
2025
|
type: "tool-call",
|
|
1985
2026
|
toolCallId,
|
|
1986
|
-
toolName:
|
|
2027
|
+
toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
|
|
1987
2028
|
input: JSON.stringify(part.executableCode),
|
|
1988
2029
|
providerExecuted: true
|
|
1989
2030
|
});
|
|
@@ -1992,10 +2033,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1992
2033
|
type: "tool-result",
|
|
1993
2034
|
// Results correspond to the most recent executable code part.
|
|
1994
2035
|
toolCallId: lastCodeExecutionToolCallId,
|
|
1995
|
-
toolName:
|
|
2036
|
+
toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
|
|
1996
2037
|
result: {
|
|
1997
2038
|
outcome: part.codeExecutionResult.outcome,
|
|
1998
|
-
output:
|
|
2039
|
+
output: part.codeExecutionResult.output ?? ""
|
|
1999
2040
|
}
|
|
2000
2041
|
});
|
|
2001
2042
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2019,7 +2060,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2019
2060
|
type: "tool-call",
|
|
2020
2061
|
toolCallId: part.functionCall.id || config.generateId(),
|
|
2021
2062
|
toolName: part.functionCall.name,
|
|
2022
|
-
input: JSON.stringify(
|
|
2063
|
+
input: JSON.stringify(part.functionCall.args ?? {}),
|
|
2023
2064
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2024
2065
|
thoughtSignature: part.thoughtSignature
|
|
2025
2066
|
}) : void 0
|
|
@@ -2042,7 +2083,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2042
2083
|
type: "tool-call",
|
|
2043
2084
|
toolCallId,
|
|
2044
2085
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2045
|
-
input: JSON.stringify(
|
|
2086
|
+
input: JSON.stringify(part.toolCall.args ?? {}),
|
|
2046
2087
|
providerExecuted: true,
|
|
2047
2088
|
dynamic: true,
|
|
2048
2089
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -2060,7 +2101,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2060
2101
|
type: "tool-result",
|
|
2061
2102
|
toolCallId: responseToolCallId,
|
|
2062
2103
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2063
|
-
result:
|
|
2104
|
+
result: part.toolResponse.response ?? {},
|
|
2064
2105
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2065
2106
|
thoughtSignature: part.thoughtSignature,
|
|
2066
2107
|
serverToolCallId: responseToolCallId,
|
|
@@ -2073,10 +2114,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2073
2114
|
lastServerToolCallId = void 0;
|
|
2074
2115
|
}
|
|
2075
2116
|
}
|
|
2076
|
-
const sources =
|
|
2077
|
-
groundingMetadata: candidate
|
|
2117
|
+
const sources = extractSources({
|
|
2118
|
+
groundingMetadata: candidate?.groundingMetadata,
|
|
2078
2119
|
generateId: config.generateId
|
|
2079
|
-
})
|
|
2120
|
+
}) ?? [];
|
|
2080
2121
|
for (const source of sources) {
|
|
2081
2122
|
content.push(source);
|
|
2082
2123
|
}
|
|
@@ -2095,17 +2136,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2095
2136
|
usage: convertGoogleUsage(usageMetadata),
|
|
2096
2137
|
warnings,
|
|
2097
2138
|
providerMetadata: wrapProviderMetadata({
|
|
2098
|
-
promptFeedback:
|
|
2099
|
-
groundingMetadata:
|
|
2100
|
-
urlContextMetadata:
|
|
2101
|
-
safetyRatings:
|
|
2102
|
-
usageMetadata: usageMetadata
|
|
2103
|
-
finishMessage:
|
|
2104
|
-
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
|
|
2105
2146
|
}),
|
|
2106
2147
|
response: {
|
|
2107
2148
|
// TODO timestamp, model id
|
|
2108
|
-
id:
|
|
2149
|
+
id: response.responseId ?? void 0
|
|
2109
2150
|
}
|
|
2110
2151
|
};
|
|
2111
2152
|
}
|
|
@@ -2237,7 +2278,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2237
2278
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2238
2279
|
},
|
|
2239
2280
|
transform(chunk, controller) {
|
|
2240
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2241
2281
|
if (options.includeRawChunks) {
|
|
2242
2282
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2243
2283
|
}
|
|
@@ -2267,7 +2307,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2267
2307
|
};
|
|
2268
2308
|
}
|
|
2269
2309
|
}
|
|
2270
|
-
const candidate =
|
|
2310
|
+
const candidate = value.candidates?.[0];
|
|
2271
2311
|
if (candidate != null) {
|
|
2272
2312
|
if (candidate.groundingMetadata != null) {
|
|
2273
2313
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2299,9 +2339,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2299
2339
|
}
|
|
2300
2340
|
}
|
|
2301
2341
|
if (content != null) {
|
|
2302
|
-
const parts =
|
|
2342
|
+
const parts = content.parts ?? [];
|
|
2303
2343
|
for (const part of parts) {
|
|
2304
|
-
if ("executableCode" in part &&
|
|
2344
|
+
if ("executableCode" in part && part.executableCode?.code) {
|
|
2305
2345
|
const toolCallId = generateId4();
|
|
2306
2346
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2307
2347
|
controller.enqueue({
|
|
@@ -2320,7 +2360,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2320
2360
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2321
2361
|
result: {
|
|
2322
2362
|
outcome: part.codeExecutionResult.outcome,
|
|
2323
|
-
output:
|
|
2363
|
+
output: part.codeExecutionResult.output ?? ""
|
|
2324
2364
|
}
|
|
2325
2365
|
});
|
|
2326
2366
|
}
|
|
@@ -2420,7 +2460,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2420
2460
|
type: "tool-call",
|
|
2421
2461
|
toolCallId,
|
|
2422
2462
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2423
|
-
input: JSON.stringify(
|
|
2463
|
+
input: JSON.stringify(part.toolCall.args ?? {}),
|
|
2424
2464
|
providerExecuted: true,
|
|
2425
2465
|
dynamic: true,
|
|
2426
2466
|
providerMetadata: serverMeta
|
|
@@ -2436,7 +2476,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2436
2476
|
type: "tool-result",
|
|
2437
2477
|
toolCallId: responseToolCallId,
|
|
2438
2478
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2439
|
-
result:
|
|
2479
|
+
result: part.toolResponse.response ?? {},
|
|
2440
2480
|
providerMetadata: serverMeta
|
|
2441
2481
|
});
|
|
2442
2482
|
lastServerToolCallId = void 0;
|
|
@@ -2503,7 +2543,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2503
2543
|
} else if (isCompleteCall) {
|
|
2504
2544
|
const toolCallId = part.functionCall.id || generateId4();
|
|
2505
2545
|
const toolName = part.functionCall.name;
|
|
2506
|
-
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 ?? {});
|
|
2507
2547
|
controller.enqueue({
|
|
2508
2548
|
type: "tool-input-start",
|
|
2509
2549
|
id: toolCallId,
|
|
@@ -2565,7 +2605,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2565
2605
|
}
|
|
2566
2606
|
},
|
|
2567
2607
|
flush(controller) {
|
|
2568
|
-
var _a2;
|
|
2569
2608
|
if (currentTextBlockId !== null) {
|
|
2570
2609
|
controller.enqueue({
|
|
2571
2610
|
type: "text-end",
|
|
@@ -2587,9 +2626,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2587
2626
|
groundingMetadata: lastGroundingMetadata,
|
|
2588
2627
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2589
2628
|
safetyRatings: lastSafetyRatings,
|
|
2590
|
-
usageMetadata: usage
|
|
2629
|
+
usageMetadata: usage ?? null,
|
|
2591
2630
|
finishMessage: lastFinishMessage,
|
|
2592
|
-
serviceTier:
|
|
2631
|
+
serviceTier: usage?.serviceTier ?? null
|
|
2593
2632
|
})
|
|
2594
2633
|
});
|
|
2595
2634
|
}
|
|
@@ -2649,13 +2688,12 @@ function resolveGemini3ThinkingConfig({
|
|
|
2649
2688
|
return { thinkingLevel };
|
|
2650
2689
|
}
|
|
2651
2690
|
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2652
|
-
|
|
2653
|
-
const modelName = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase();
|
|
2691
|
+
const modelName = modelId.split("/").at(-1)?.toLowerCase();
|
|
2654
2692
|
if (modelName === "gemini-flash-latest") {
|
|
2655
2693
|
return "low";
|
|
2656
2694
|
}
|
|
2657
2695
|
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(
|
|
2658
|
-
modelName
|
|
2696
|
+
modelName ?? ""
|
|
2659
2697
|
);
|
|
2660
2698
|
if (versionMatch == null) {
|
|
2661
2699
|
return "minimal";
|
|
@@ -2688,8 +2726,7 @@ function extractSources({
|
|
|
2688
2726
|
groundingMetadata,
|
|
2689
2727
|
generateId: generateId4
|
|
2690
2728
|
}) {
|
|
2691
|
-
|
|
2692
|
-
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2729
|
+
if (!groundingMetadata?.groundingChunks) {
|
|
2693
2730
|
return void 0;
|
|
2694
2731
|
}
|
|
2695
2732
|
const sources = [];
|
|
@@ -2700,7 +2737,7 @@ function extractSources({
|
|
|
2700
2737
|
sourceType: "url",
|
|
2701
2738
|
id: generateId4(),
|
|
2702
2739
|
url: chunk.web.uri,
|
|
2703
|
-
title:
|
|
2740
|
+
title: chunk.web.title ?? void 0
|
|
2704
2741
|
});
|
|
2705
2742
|
} else if (chunk.image != null) {
|
|
2706
2743
|
sources.push({
|
|
@@ -2710,7 +2747,7 @@ function extractSources({
|
|
|
2710
2747
|
// Google requires attribution to the source URI, not the actual image URI.
|
|
2711
2748
|
// TODO: add another type in v7 to allow both the image and source URL to be included separately
|
|
2712
2749
|
url: chunk.image.sourceUri,
|
|
2713
|
-
title:
|
|
2750
|
+
title: chunk.image.title ?? void 0
|
|
2714
2751
|
});
|
|
2715
2752
|
} else if (chunk.retrievedContext != null) {
|
|
2716
2753
|
const uri = chunk.retrievedContext.uri;
|
|
@@ -2721,10 +2758,10 @@ function extractSources({
|
|
|
2721
2758
|
sourceType: "url",
|
|
2722
2759
|
id: generateId4(),
|
|
2723
2760
|
url: uri,
|
|
2724
|
-
title:
|
|
2761
|
+
title: chunk.retrievedContext.title ?? void 0
|
|
2725
2762
|
});
|
|
2726
2763
|
} else if (uri) {
|
|
2727
|
-
const title =
|
|
2764
|
+
const title = chunk.retrievedContext.title ?? "Unknown Document";
|
|
2728
2765
|
let mediaType = "application/octet-stream";
|
|
2729
2766
|
let filename = void 0;
|
|
2730
2767
|
if (uri.endsWith(".pdf")) {
|
|
@@ -2754,7 +2791,7 @@ function extractSources({
|
|
|
2754
2791
|
filename
|
|
2755
2792
|
});
|
|
2756
2793
|
} else if (fileSearchStore) {
|
|
2757
|
-
const title =
|
|
2794
|
+
const title = chunk.retrievedContext.title ?? "Unknown Document";
|
|
2758
2795
|
sources.push({
|
|
2759
2796
|
type: "source",
|
|
2760
2797
|
sourceType: "document",
|
|
@@ -2771,7 +2808,7 @@ function extractSources({
|
|
|
2771
2808
|
sourceType: "url",
|
|
2772
2809
|
id: generateId4(),
|
|
2773
2810
|
url: chunk.maps.uri,
|
|
2774
|
-
title:
|
|
2811
|
+
title: chunk.maps.title ?? void 0
|
|
2775
2812
|
});
|
|
2776
2813
|
}
|
|
2777
2814
|
}
|
|
@@ -3118,11 +3155,10 @@ var googleBatchResponsePreviewSchema = lazySchema8(
|
|
|
3118
3155
|
var GoogleBatch = class {
|
|
3119
3156
|
constructor(options) {
|
|
3120
3157
|
this.specificationVersion = "v4";
|
|
3121
|
-
var _a2;
|
|
3122
3158
|
this.provider = options.provider;
|
|
3123
3159
|
this.batchConfig = options.config;
|
|
3124
3160
|
this.supportedUrls = options.supportedUrls;
|
|
3125
|
-
this.batchGenerateId =
|
|
3161
|
+
this.batchGenerateId = options.config.generateId ?? generateId2;
|
|
3126
3162
|
}
|
|
3127
3163
|
async doStartBatch(options) {
|
|
3128
3164
|
assertSupportedBatchRequests(options.requests);
|
|
@@ -3317,7 +3353,6 @@ var GoogleBatch = class {
|
|
|
3317
3353
|
return {};
|
|
3318
3354
|
}
|
|
3319
3355
|
async doListBatches(options) {
|
|
3320
|
-
var _a2;
|
|
3321
3356
|
const url = new URL(`${this.batchConfig.baseURL}/batches`);
|
|
3322
3357
|
if (options.limit != null) {
|
|
3323
3358
|
url.searchParams.set("pageSize", String(options.limit));
|
|
@@ -3337,7 +3372,7 @@ var GoogleBatch = class {
|
|
|
3337
3372
|
validateUrl: false
|
|
3338
3373
|
});
|
|
3339
3374
|
return {
|
|
3340
|
-
batches: (
|
|
3375
|
+
batches: (page.operations ?? []).map((operation) => ({
|
|
3341
3376
|
batchId: operation.name,
|
|
3342
3377
|
...convertGoogleBatchStatus(operation)
|
|
3343
3378
|
})),
|
|
@@ -3345,7 +3380,6 @@ var GoogleBatch = class {
|
|
|
3345
3380
|
};
|
|
3346
3381
|
}
|
|
3347
3382
|
async doGetBatchResults(options) {
|
|
3348
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3349
3383
|
const operation = await this.retrieveBatch(options);
|
|
3350
3384
|
const batchStatus = convertGoogleBatchStatus(operation);
|
|
3351
3385
|
if (batchStatus.status === "pending") {
|
|
@@ -3354,7 +3388,7 @@ var GoogleBatch = class {
|
|
|
3354
3388
|
message: `Google batch "${options.batchId}" is not complete.`
|
|
3355
3389
|
});
|
|
3356
3390
|
}
|
|
3357
|
-
const inlinedResponses =
|
|
3391
|
+
const inlinedResponses = operation.metadata?.output?.inlinedResponses?.inlinedResponses ?? operation.response?.inlinedResponses?.inlinedResponses;
|
|
3358
3392
|
if (inlinedResponses != null) {
|
|
3359
3393
|
return convertAsyncIteratorToReadableStream(
|
|
3360
3394
|
this.iterateBatchResults(
|
|
@@ -3366,7 +3400,7 @@ var GoogleBatch = class {
|
|
|
3366
3400
|
)
|
|
3367
3401
|
);
|
|
3368
3402
|
}
|
|
3369
|
-
const responsesFile =
|
|
3403
|
+
const responsesFile = operation.metadata?.output?.responsesFile ?? operation.response?.responsesFile;
|
|
3370
3404
|
if (responsesFile == null) {
|
|
3371
3405
|
if (batchStatus.status === "completed") {
|
|
3372
3406
|
throw new InvalidResponseDataError({
|
|
@@ -3411,7 +3445,6 @@ var GoogleBatch = class {
|
|
|
3411
3445
|
return operation;
|
|
3412
3446
|
}
|
|
3413
3447
|
async *iterateBatchResults(results) {
|
|
3414
|
-
var _a2, _b, _c;
|
|
3415
3448
|
for await (const line of results) {
|
|
3416
3449
|
if (line.error != null) {
|
|
3417
3450
|
const error = convertGoogleRpcError(
|
|
@@ -3439,8 +3472,8 @@ var GoogleBatch = class {
|
|
|
3439
3472
|
schema: googleBatchResponsePreviewSchema
|
|
3440
3473
|
});
|
|
3441
3474
|
if (preview.success && (preview.value.candidates == null || preview.value.candidates.length === 0)) {
|
|
3442
|
-
const promptFeedback =
|
|
3443
|
-
const blockReason =
|
|
3475
|
+
const promptFeedback = preview.value.promptFeedback ?? void 0;
|
|
3476
|
+
const blockReason = promptFeedback?.blockReason ?? void 0;
|
|
3444
3477
|
yield {
|
|
3445
3478
|
type: "text",
|
|
3446
3479
|
id: line.key,
|
|
@@ -3454,7 +3487,7 @@ var GoogleBatch = class {
|
|
|
3454
3487
|
providerMetadata: {
|
|
3455
3488
|
google: {
|
|
3456
3489
|
promptFeedback: {
|
|
3457
|
-
blockReason:
|
|
3490
|
+
blockReason: promptFeedback.blockReason ?? null
|
|
3458
3491
|
}
|
|
3459
3492
|
}
|
|
3460
3493
|
}
|
|
@@ -3513,7 +3546,6 @@ var GoogleBatch = class {
|
|
|
3513
3546
|
}
|
|
3514
3547
|
}
|
|
3515
3548
|
async prepareImageRequest(request) {
|
|
3516
|
-
var _a2;
|
|
3517
3549
|
const { prompt, n, size, aspectRatio, seed, files, mask, providerOptions } = request.options;
|
|
3518
3550
|
const warnings = [];
|
|
3519
3551
|
if (mask != null) {
|
|
@@ -3535,7 +3567,7 @@ var GoogleBatch = class {
|
|
|
3535
3567
|
}
|
|
3536
3568
|
const userContent = [];
|
|
3537
3569
|
if (prompt != null) userContent.push({ type: "text", text: prompt });
|
|
3538
|
-
for (const file of files
|
|
3570
|
+
for (const file of files ?? []) {
|
|
3539
3571
|
userContent.push(
|
|
3540
3572
|
file.type === "url" ? {
|
|
3541
3573
|
type: "file",
|
|
@@ -3557,11 +3589,11 @@ var GoogleBatch = class {
|
|
|
3557
3589
|
responseModalities: _responseModalities,
|
|
3558
3590
|
imageConfig: userImageConfig,
|
|
3559
3591
|
...passthroughGoogleOptions
|
|
3560
|
-
} =
|
|
3592
|
+
} = await parseProviderOptions3({
|
|
3561
3593
|
provider: "google",
|
|
3562
3594
|
providerOptions,
|
|
3563
3595
|
schema: googleLanguageModelOptions
|
|
3564
|
-
})
|
|
3596
|
+
}) ?? {};
|
|
3565
3597
|
const preparedGoogleOptions = await parseProviderOptions3({
|
|
3566
3598
|
provider: "google",
|
|
3567
3599
|
providerOptions: {
|
|
@@ -3583,9 +3615,9 @@ var GoogleBatch = class {
|
|
|
3583
3615
|
prompt: [{ role: "user", content: userContent }],
|
|
3584
3616
|
seed,
|
|
3585
3617
|
providerOptions: {
|
|
3586
|
-
google: preparedGoogleOptions
|
|
3618
|
+
google: preparedGoogleOptions ?? { responseModalities: ["IMAGE"] }
|
|
3587
3619
|
},
|
|
3588
|
-
tools:
|
|
3620
|
+
tools: googleImageOptions?.googleSearch != null ? [
|
|
3589
3621
|
{
|
|
3590
3622
|
type: "provider",
|
|
3591
3623
|
id: "google.google_search",
|
|
@@ -3608,17 +3640,16 @@ var GoogleBatch = class {
|
|
|
3608
3640
|
}
|
|
3609
3641
|
};
|
|
3610
3642
|
function convertGoogleBatchStatus(operation) {
|
|
3611
|
-
|
|
3612
|
-
const rawStatus = (_b = (_a2 = operation.metadata) == null ? void 0 : _a2.state) != null ? _b : void 0;
|
|
3643
|
+
const rawStatus = operation.metadata?.state ?? void 0;
|
|
3613
3644
|
const requestCounts = convertGoogleRequestCounts(
|
|
3614
|
-
|
|
3645
|
+
operation.metadata?.batchStats
|
|
3615
3646
|
);
|
|
3616
|
-
const createdAt =
|
|
3647
|
+
const createdAt = operation.metadata?.createTime ?? void 0;
|
|
3617
3648
|
const error = operation.error != null ? convertGoogleRpcError(operation.error, "Google batch failed.") : void 0;
|
|
3618
3649
|
return {
|
|
3619
3650
|
status: mapGoogleBatchStatus({
|
|
3620
3651
|
rawStatus,
|
|
3621
|
-
done:
|
|
3652
|
+
done: operation.done ?? void 0,
|
|
3622
3653
|
hasError: error != null
|
|
3623
3654
|
}),
|
|
3624
3655
|
...rawStatus != null ? { rawStatus } : {},
|
|
@@ -3654,11 +3685,10 @@ function mapGoogleBatchStatus({
|
|
|
3654
3685
|
}
|
|
3655
3686
|
}
|
|
3656
3687
|
function convertGoogleRequestCounts(counts) {
|
|
3657
|
-
|
|
3658
|
-
const
|
|
3659
|
-
const
|
|
3660
|
-
const
|
|
3661
|
-
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);
|
|
3662
3692
|
return normalizeBatchRequestCounts({
|
|
3663
3693
|
total,
|
|
3664
3694
|
pending,
|
|
@@ -3671,9 +3701,8 @@ function parseCount(value) {
|
|
|
3671
3701
|
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
|
|
3672
3702
|
}
|
|
3673
3703
|
function convertGoogleRpcError(error, fallbackMessage) {
|
|
3674
|
-
var _a2;
|
|
3675
3704
|
return {
|
|
3676
|
-
message:
|
|
3705
|
+
message: error.message ?? fallbackMessage,
|
|
3677
3706
|
...error.status != null ? { type: error.status } : {},
|
|
3678
3707
|
...error.code != null ? { code: String(error.code) } : {}
|
|
3679
3708
|
};
|
|
@@ -3691,8 +3720,7 @@ var googleUploadUrlResponseHandler = async ({
|
|
|
3691
3720
|
return { value: uploadUrl };
|
|
3692
3721
|
};
|
|
3693
3722
|
function getGoogleBatchModelId(requests) {
|
|
3694
|
-
|
|
3695
|
-
const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
|
|
3723
|
+
const modelId = requests[0]?.modelId;
|
|
3696
3724
|
if (modelId == null) {
|
|
3697
3725
|
throw new InvalidArgumentError({
|
|
3698
3726
|
argument: "requests",
|
|
@@ -3710,12 +3738,11 @@ function getGoogleBatchModelId(requests) {
|
|
|
3710
3738
|
return modelId;
|
|
3711
3739
|
}
|
|
3712
3740
|
function convertGoogleImageBatchResult(result) {
|
|
3713
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
3714
3741
|
const images = result.content.flatMap(
|
|
3715
3742
|
(part) => part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data" ? [convertToBase642(part.data.data)] : []
|
|
3716
3743
|
);
|
|
3717
3744
|
if (images.length === 0) return void 0;
|
|
3718
|
-
const googleMetadata =
|
|
3745
|
+
const googleMetadata = result.providerMetadata?.google ?? {};
|
|
3719
3746
|
return {
|
|
3720
3747
|
images,
|
|
3721
3748
|
warnings: result.warnings,
|
|
@@ -3724,13 +3751,13 @@ function convertGoogleImageBatchResult(result) {
|
|
|
3724
3751
|
},
|
|
3725
3752
|
response: {
|
|
3726
3753
|
timestamp: /* @__PURE__ */ new Date(),
|
|
3727
|
-
modelId:
|
|
3728
|
-
headers:
|
|
3754
|
+
modelId: result.response?.modelId ?? "",
|
|
3755
|
+
headers: result.response?.headers
|
|
3729
3756
|
},
|
|
3730
3757
|
usage: {
|
|
3731
3758
|
inputTokens: result.usage.inputTokens.total,
|
|
3732
3759
|
outputTokens: result.usage.outputTokens.total,
|
|
3733
|
-
totalTokens: (
|
|
3760
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
3734
3761
|
}
|
|
3735
3762
|
};
|
|
3736
3763
|
}
|
|
@@ -3911,7 +3938,6 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3911
3938
|
return this.config.provider;
|
|
3912
3939
|
}
|
|
3913
3940
|
async doGenerate(options) {
|
|
3914
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3915
3941
|
if (!this.modelId.startsWith("gemini-")) {
|
|
3916
3942
|
throw new Error(
|
|
3917
3943
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -3978,13 +4004,13 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3978
4004
|
responseModalities: _strippedResponseModalities,
|
|
3979
4005
|
imageConfig: userImageConfig,
|
|
3980
4006
|
...passthroughGoogleOptions
|
|
3981
|
-
} =
|
|
4007
|
+
} = providerOptions?.google ?? {};
|
|
3982
4008
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
3983
4009
|
provider: this.config.provider,
|
|
3984
4010
|
baseURL: this.config.baseURL,
|
|
3985
|
-
headers:
|
|
4011
|
+
headers: this.config.headers ?? {},
|
|
3986
4012
|
fetch: this.config.fetch,
|
|
3987
|
-
generateId:
|
|
4013
|
+
generateId: this.config.generateId ?? defaultGenerateId
|
|
3988
4014
|
});
|
|
3989
4015
|
const result = await languageModel.doGenerate({
|
|
3990
4016
|
prompt: languageModelPrompt,
|
|
@@ -4001,7 +4027,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4001
4027
|
} : void 0
|
|
4002
4028
|
}
|
|
4003
4029
|
},
|
|
4004
|
-
tools:
|
|
4030
|
+
tools: googleImageOptions?.googleSearch != null ? [
|
|
4005
4031
|
{
|
|
4006
4032
|
type: "provider",
|
|
4007
4033
|
id: "google.google_search",
|
|
@@ -4012,14 +4038,14 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4012
4038
|
headers,
|
|
4013
4039
|
abortSignal
|
|
4014
4040
|
});
|
|
4015
|
-
const currentDate =
|
|
4041
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4016
4042
|
const images = [];
|
|
4017
4043
|
for (const part of result.content) {
|
|
4018
4044
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
4019
4045
|
images.push(convertToBase643(part.data.data));
|
|
4020
4046
|
}
|
|
4021
4047
|
}
|
|
4022
|
-
const languageModelGoogleMetadata =
|
|
4048
|
+
const languageModelGoogleMetadata = result.providerMetadata?.google ?? {};
|
|
4023
4049
|
return {
|
|
4024
4050
|
images,
|
|
4025
4051
|
...result.finishReason.unified === "content-filter" ? { isRetryable: false } : {},
|
|
@@ -4027,19 +4053,19 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
4027
4053
|
providerMetadata: {
|
|
4028
4054
|
google: {
|
|
4029
4055
|
...languageModelGoogleMetadata,
|
|
4030
|
-
finishReason:
|
|
4056
|
+
finishReason: result.finishReason.raw ?? null,
|
|
4031
4057
|
images: images.map(() => ({}))
|
|
4032
4058
|
}
|
|
4033
4059
|
},
|
|
4034
4060
|
response: {
|
|
4035
4061
|
timestamp: currentDate,
|
|
4036
4062
|
modelId: this.modelId,
|
|
4037
|
-
headers:
|
|
4063
|
+
headers: result.response?.headers
|
|
4038
4064
|
},
|
|
4039
4065
|
usage: result.usage ? {
|
|
4040
4066
|
inputTokens: result.usage.inputTokens.total,
|
|
4041
4067
|
outputTokens: result.usage.outputTokens.total,
|
|
4042
|
-
totalTokens: (
|
|
4068
|
+
totalTokens: (result.usage.inputTokens.total ?? 0) + (result.usage.outputTokens.total ?? 0)
|
|
4043
4069
|
} : void 0
|
|
4044
4070
|
};
|
|
4045
4071
|
}
|
|
@@ -4073,7 +4099,6 @@ var GoogleFiles = class {
|
|
|
4073
4099
|
return this.config.provider;
|
|
4074
4100
|
}
|
|
4075
4101
|
async uploadFile(options) {
|
|
4076
|
-
var _a2, _b, _c, _d;
|
|
4077
4102
|
const googleOptions = await parseProviderOptions5({
|
|
4078
4103
|
provider: "google",
|
|
4079
4104
|
providerOptions: options.providerOptions,
|
|
@@ -4083,14 +4108,14 @@ var GoogleFiles = class {
|
|
|
4083
4108
|
this.config.headers(),
|
|
4084
4109
|
options.headers
|
|
4085
4110
|
);
|
|
4086
|
-
const fetchFn =
|
|
4111
|
+
const fetchFn = this.config.fetch ?? globalThis.fetch;
|
|
4087
4112
|
const warnings = [];
|
|
4088
4113
|
if (options.filename != null) {
|
|
4089
4114
|
warnings.push({ type: "unsupported", feature: "filename" });
|
|
4090
4115
|
}
|
|
4091
4116
|
const fileBytes = convertInlineFileDataToUint8Array(options.data);
|
|
4092
4117
|
const mediaType = options.mediaType;
|
|
4093
|
-
const displayName = googleOptions
|
|
4118
|
+
const displayName = googleOptions?.displayName;
|
|
4094
4119
|
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|
|
4095
4120
|
const initResponse = await fetchFn(`${baseOrigin}/upload/v1beta/files`, {
|
|
4096
4121
|
method: "POST",
|
|
@@ -4141,8 +4166,8 @@ var GoogleFiles = class {
|
|
|
4141
4166
|
}
|
|
4142
4167
|
const uploadResult = await uploadResponse.json();
|
|
4143
4168
|
let file = uploadResult.file;
|
|
4144
|
-
const pollIntervalMs =
|
|
4145
|
-
const pollTimeoutMs =
|
|
4169
|
+
const pollIntervalMs = googleOptions?.pollIntervalMs ?? 2e3;
|
|
4170
|
+
const pollTimeoutMs = googleOptions?.pollTimeoutMs ?? 3e5;
|
|
4146
4171
|
const startTime = Date.now();
|
|
4147
4172
|
while (file.state === "PROCESSING") {
|
|
4148
4173
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
@@ -4176,7 +4201,7 @@ var GoogleFiles = class {
|
|
|
4176
4201
|
return {
|
|
4177
4202
|
warnings,
|
|
4178
4203
|
providerReference: { google: file.uri },
|
|
4179
|
-
mediaType:
|
|
4204
|
+
mediaType: file.mimeType ?? options.mediaType,
|
|
4180
4205
|
providerMetadata: {
|
|
4181
4206
|
google: {
|
|
4182
4207
|
name: file.name,
|
|
@@ -4264,16 +4289,13 @@ var googleVideoModelOptionsSchema = lazySchema15(
|
|
|
4264
4289
|
|
|
4265
4290
|
// src/google-video-model.ts
|
|
4266
4291
|
function getFirstFrameImage(options) {
|
|
4267
|
-
|
|
4268
|
-
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
4292
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
4269
4293
|
}
|
|
4270
4294
|
function resolveStartImage(options) {
|
|
4271
|
-
|
|
4272
|
-
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
4295
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
4273
4296
|
}
|
|
4274
4297
|
function getLastFrameImage(options) {
|
|
4275
|
-
|
|
4276
|
-
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
4298
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
4277
4299
|
}
|
|
4278
4300
|
function getInputReferences(options) {
|
|
4279
4301
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -4371,7 +4393,7 @@ var GoogleVideoModel = class {
|
|
|
4371
4393
|
const converted = convertInputReferenceImage(reference, warnings);
|
|
4372
4394
|
return converted != null ? [converted] : [];
|
|
4373
4395
|
});
|
|
4374
|
-
} else if (
|
|
4396
|
+
} else if (googleOptions?.referenceImages != null) {
|
|
4375
4397
|
instance.referenceImages = googleOptions.referenceImages.map(
|
|
4376
4398
|
(refImg) => convertProviderReferenceImage(refImg)
|
|
4377
4399
|
);
|
|
@@ -4419,9 +4441,8 @@ var GoogleVideoModel = class {
|
|
|
4419
4441
|
return { instances, parameters, warnings, googleOptions };
|
|
4420
4442
|
}
|
|
4421
4443
|
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
4422
|
-
var _a2, _b;
|
|
4423
4444
|
const response = finalOperation.response;
|
|
4424
|
-
if (!
|
|
4445
|
+
if (!response?.generateVideoResponse?.generatedSamples || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
4425
4446
|
throw new AISDKError2({
|
|
4426
4447
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
4427
4448
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -4430,9 +4451,9 @@ var GoogleVideoModel = class {
|
|
|
4430
4451
|
const videos = [];
|
|
4431
4452
|
const videoMetadata = [];
|
|
4432
4453
|
const resolvedHeaders = await resolve4(this.config.headers);
|
|
4433
|
-
const apiKey = resolvedHeaders
|
|
4454
|
+
const apiKey = resolvedHeaders?.["x-goog-api-key"];
|
|
4434
4455
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
4435
|
-
if (
|
|
4456
|
+
if (generatedSample.video?.uri) {
|
|
4436
4457
|
const urlWithAuth = apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
4437
4458
|
videos.push({
|
|
4438
4459
|
type: "url",
|
|
@@ -4467,8 +4488,7 @@ var GoogleVideoModel = class {
|
|
|
4467
4488
|
};
|
|
4468
4489
|
}
|
|
4469
4490
|
async doStart(options) {
|
|
4470
|
-
|
|
4471
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4491
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4472
4492
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
4473
4493
|
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
4474
4494
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -4505,8 +4525,7 @@ var GoogleVideoModel = class {
|
|
|
4505
4525
|
};
|
|
4506
4526
|
}
|
|
4507
4527
|
async doStatus(options) {
|
|
4508
|
-
|
|
4509
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4528
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4510
4529
|
const { operationName } = options.operation;
|
|
4511
4530
|
const { value: statusOperation, responseHeaders } = await getFromApi3({
|
|
4512
4531
|
url: `${this.config.baseURL}/${operationName}`,
|
|
@@ -4618,7 +4637,7 @@ function getGoogleSpeechInput({
|
|
|
4618
4637
|
voice,
|
|
4619
4638
|
providerOptions
|
|
4620
4639
|
}) {
|
|
4621
|
-
const google2 = providerOptions
|
|
4640
|
+
const google2 = providerOptions?.google;
|
|
4622
4641
|
const options = google2 != null && typeof google2 === "object" ? google2 : void 0;
|
|
4623
4642
|
const turns = options && "turns" in options ? options.turns : void 0;
|
|
4624
4643
|
const turnTexts = [];
|
|
@@ -4637,7 +4656,7 @@ function getGoogleSpeechInput({
|
|
|
4637
4656
|
const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
|
|
4638
4657
|
return {
|
|
4639
4658
|
text,
|
|
4640
|
-
usesCustomVoice:
|
|
4659
|
+
usesCustomVoice: voice?.startsWith("voice_") === true || voice?.startsWith("voicekey_") === true || speakers.some(
|
|
4641
4660
|
(speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
|
|
4642
4661
|
)
|
|
4643
4662
|
};
|
|
@@ -4726,7 +4745,6 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4726
4745
|
language,
|
|
4727
4746
|
providerOptions
|
|
4728
4747
|
}) {
|
|
4729
|
-
var _a2;
|
|
4730
4748
|
const warnings = [];
|
|
4731
4749
|
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
4732
4750
|
let googleOptions;
|
|
@@ -4759,7 +4777,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4759
4777
|
message: "Custom voices are not supported. Use a prebuilt voice instead."
|
|
4760
4778
|
});
|
|
4761
4779
|
}
|
|
4762
|
-
const multiSpeakerVoiceConfig = googleOptions
|
|
4780
|
+
const multiSpeakerVoiceConfig = googleOptions?.multiSpeakerVoiceConfig;
|
|
4763
4781
|
const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
|
|
4764
4782
|
let promptText = text;
|
|
4765
4783
|
if (instructions != null && !usesStructuredSpeech) {
|
|
@@ -4775,25 +4793,24 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4775
4793
|
}
|
|
4776
4794
|
let parts = [{ text: promptText }];
|
|
4777
4795
|
if (usesStructuredSpeech) {
|
|
4778
|
-
if (
|
|
4796
|
+
if (googleOptions?.turns && googleOptions.speechMetadata) {
|
|
4779
4797
|
throw new InvalidArgumentError2({
|
|
4780
4798
|
argument: "providerOptions",
|
|
4781
4799
|
message: "Set speechMetadata on each turn when using turns."
|
|
4782
4800
|
});
|
|
4783
4801
|
}
|
|
4784
|
-
if (
|
|
4802
|
+
if (googleOptions?.turns && text !== "") {
|
|
4785
4803
|
warnings.push({
|
|
4786
4804
|
type: "unsupported",
|
|
4787
4805
|
feature: "text",
|
|
4788
4806
|
details: "Google TTS turns replace the top-level text."
|
|
4789
4807
|
});
|
|
4790
4808
|
}
|
|
4791
|
-
parts = (
|
|
4792
|
-
{ text, speechMetadata: googleOptions
|
|
4809
|
+
parts = (googleOptions?.turns ?? [
|
|
4810
|
+
{ text, speechMetadata: googleOptions?.speechMetadata }
|
|
4793
4811
|
]).map((part) => {
|
|
4794
|
-
|
|
4795
|
-
const
|
|
4796
|
-
const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
|
|
4812
|
+
const style = part.speechMetadata?.style ?? instructions;
|
|
4813
|
+
const speaker = part.speechMetadata?.speaker;
|
|
4797
4814
|
if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
|
|
4798
4815
|
(config) => config.speaker === speaker
|
|
4799
4816
|
)) {
|
|
@@ -4807,7 +4824,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4807
4824
|
...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
|
|
4808
4825
|
};
|
|
4809
4826
|
});
|
|
4810
|
-
} else if (
|
|
4827
|
+
} else if (googleOptions?.turns || googleOptions?.speechMetadata) {
|
|
4811
4828
|
throw new InvalidArgumentError2({
|
|
4812
4829
|
argument: "providerOptions",
|
|
4813
4830
|
message: "Structured speech metadata and turns require Gemini 3.8 TTS."
|
|
@@ -4873,8 +4890,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4873
4890
|
};
|
|
4874
4891
|
}
|
|
4875
4892
|
async doGenerate(options) {
|
|
4876
|
-
|
|
4877
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4893
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4878
4894
|
const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
|
|
4879
4895
|
const {
|
|
4880
4896
|
value: response,
|
|
@@ -4896,11 +4912,11 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4896
4912
|
});
|
|
4897
4913
|
let base64Audio;
|
|
4898
4914
|
let mimeType;
|
|
4899
|
-
for (const candidate of
|
|
4900
|
-
for (const part of
|
|
4901
|
-
if (
|
|
4915
|
+
for (const candidate of response.candidates ?? []) {
|
|
4916
|
+
for (const part of candidate.content?.parts ?? []) {
|
|
4917
|
+
if (part.inlineData?.data) {
|
|
4902
4918
|
base64Audio = part.inlineData.data;
|
|
4903
|
-
mimeType =
|
|
4919
|
+
mimeType = part.inlineData.mimeType ?? void 0;
|
|
4904
4920
|
break;
|
|
4905
4921
|
}
|
|
4906
4922
|
}
|
|
@@ -4908,9 +4924,9 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4908
4924
|
break;
|
|
4909
4925
|
}
|
|
4910
4926
|
}
|
|
4911
|
-
const sampleRate =
|
|
4927
|
+
const sampleRate = parseSampleRate(mimeType) ?? DEFAULT_SAMPLE_RATE;
|
|
4912
4928
|
const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
|
|
4913
|
-
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType
|
|
4929
|
+
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType ?? "") || mimeType == null && !usesStructuredSpeech;
|
|
4914
4930
|
const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
|
|
4915
4931
|
if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
|
|
4916
4932
|
warnings.push({
|
|
@@ -4934,7 +4950,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4934
4950
|
providerMetadata: {
|
|
4935
4951
|
google: {
|
|
4936
4952
|
sampleRate,
|
|
4937
|
-
mimeType: mimeType
|
|
4953
|
+
mimeType: mimeType ?? null
|
|
4938
4954
|
}
|
|
4939
4955
|
}
|
|
4940
4956
|
};
|
|
@@ -5000,37 +5016,36 @@ import {
|
|
|
5000
5016
|
// src/interactions/convert-google-interactions-usage.ts
|
|
5001
5017
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
5002
5018
|
function convertGoogleInteractionsUsage(usage) {
|
|
5003
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5004
5019
|
if (usage == null) {
|
|
5005
5020
|
return createNullLanguageModelUsage2();
|
|
5006
5021
|
}
|
|
5007
|
-
const totalInput =
|
|
5008
|
-
const totalOutput =
|
|
5009
|
-
const totalThought =
|
|
5010
|
-
const totalCached =
|
|
5022
|
+
const totalInput = usage.total_input_tokens ?? 0;
|
|
5023
|
+
const totalOutput = usage.total_output_tokens ?? 0;
|
|
5024
|
+
const totalThought = usage.total_thought_tokens ?? 0;
|
|
5025
|
+
const totalCached = usage.total_cached_tokens ?? 0;
|
|
5011
5026
|
return {
|
|
5012
5027
|
inputTokens: {
|
|
5013
|
-
total:
|
|
5028
|
+
total: usage.total_input_tokens ?? void 0,
|
|
5014
5029
|
noCache: usage.total_input_tokens == null ? void 0 : totalInput - totalCached,
|
|
5015
|
-
cacheRead:
|
|
5030
|
+
cacheRead: usage.total_cached_tokens ?? void 0,
|
|
5016
5031
|
cacheWrite: void 0
|
|
5017
5032
|
},
|
|
5018
5033
|
outputTokens: {
|
|
5019
5034
|
total: usage.total_output_tokens == null && usage.total_thought_tokens == null ? void 0 : totalOutput + totalThought,
|
|
5020
|
-
text:
|
|
5021
|
-
reasoning:
|
|
5035
|
+
text: usage.total_output_tokens ?? void 0,
|
|
5036
|
+
reasoning: usage.total_thought_tokens ?? void 0
|
|
5022
5037
|
},
|
|
5023
5038
|
raw: usage
|
|
5024
5039
|
};
|
|
5025
5040
|
}
|
|
5026
5041
|
function getGoogleInteractionsOutputTokensByModality(usage) {
|
|
5027
|
-
const byModality = usage
|
|
5042
|
+
const byModality = usage?.output_tokens_by_modality;
|
|
5028
5043
|
if (byModality == null) {
|
|
5029
5044
|
return void 0;
|
|
5030
5045
|
}
|
|
5031
5046
|
const result = {};
|
|
5032
5047
|
for (const entry of byModality) {
|
|
5033
|
-
if (
|
|
5048
|
+
if (entry?.modality != null && entry.tokens != null) {
|
|
5034
5049
|
result[entry.modality] = entry.tokens;
|
|
5035
5050
|
}
|
|
5036
5051
|
}
|
|
@@ -5062,7 +5077,6 @@ function annotationToSource({
|
|
|
5062
5077
|
annotation,
|
|
5063
5078
|
generateId: generateId4
|
|
5064
5079
|
}) {
|
|
5065
|
-
var _a2, _b, _c, _d, _e;
|
|
5066
5080
|
switch (annotation.type) {
|
|
5067
5081
|
case "url_citation": {
|
|
5068
5082
|
const urlCitation = annotation;
|
|
@@ -5079,7 +5093,7 @@ function annotationToSource({
|
|
|
5079
5093
|
}
|
|
5080
5094
|
case "file_citation": {
|
|
5081
5095
|
const fileCitation = annotation;
|
|
5082
|
-
const uri =
|
|
5096
|
+
const uri = fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
|
|
5083
5097
|
if (uri == null || uri.length === 0) return void 0;
|
|
5084
5098
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
5085
5099
|
return {
|
|
@@ -5090,14 +5104,14 @@ function annotationToSource({
|
|
|
5090
5104
|
...fileCitation.file_name != null ? { title: fileCitation.file_name } : {}
|
|
5091
5105
|
};
|
|
5092
5106
|
}
|
|
5093
|
-
const filename =
|
|
5107
|
+
const filename = fileCitation.file_name ?? basename(uri);
|
|
5094
5108
|
const mediaType = inferDocMediaType(uri);
|
|
5095
5109
|
return {
|
|
5096
5110
|
type: "source",
|
|
5097
5111
|
sourceType: "document",
|
|
5098
5112
|
id: generateId4(),
|
|
5099
5113
|
mediaType,
|
|
5100
|
-
title:
|
|
5114
|
+
title: fileCitation.file_name ?? filename ?? uri,
|
|
5101
5115
|
...filename != null ? { filename } : {}
|
|
5102
5116
|
};
|
|
5103
5117
|
}
|
|
@@ -5122,13 +5136,12 @@ function builtinToolResultToSources({
|
|
|
5122
5136
|
block,
|
|
5123
5137
|
generateId: generateId4
|
|
5124
5138
|
}) {
|
|
5125
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5126
5139
|
const sources = [];
|
|
5127
5140
|
switch (block.type) {
|
|
5128
5141
|
case "url_context_result": {
|
|
5129
|
-
const result =
|
|
5142
|
+
const result = block.result ?? [];
|
|
5130
5143
|
for (const entry of result) {
|
|
5131
|
-
if (
|
|
5144
|
+
if (entry?.url == null || entry.url.length === 0) continue;
|
|
5132
5145
|
if (entry.status != null && entry.status !== "success") continue;
|
|
5133
5146
|
sources.push({
|
|
5134
5147
|
type: "source",
|
|
@@ -5140,9 +5153,9 @@ function builtinToolResultToSources({
|
|
|
5140
5153
|
break;
|
|
5141
5154
|
}
|
|
5142
5155
|
case "google_search_result": {
|
|
5143
|
-
const result =
|
|
5156
|
+
const result = block.result ?? [];
|
|
5144
5157
|
for (const entry of result) {
|
|
5145
|
-
const url = entry
|
|
5158
|
+
const url = entry?.url;
|
|
5146
5159
|
if (url == null || url.length === 0) continue;
|
|
5147
5160
|
sources.push({
|
|
5148
5161
|
type: "source",
|
|
@@ -5155,9 +5168,9 @@ function builtinToolResultToSources({
|
|
|
5155
5168
|
break;
|
|
5156
5169
|
}
|
|
5157
5170
|
case "google_maps_result": {
|
|
5158
|
-
const result =
|
|
5171
|
+
const result = block.result ?? [];
|
|
5159
5172
|
for (const entry of result) {
|
|
5160
|
-
for (const place of
|
|
5173
|
+
for (const place of entry.places ?? []) {
|
|
5161
5174
|
if (place.url == null || place.url.length === 0) continue;
|
|
5162
5175
|
sources.push({
|
|
5163
5176
|
type: "source",
|
|
@@ -5171,11 +5184,11 @@ function builtinToolResultToSources({
|
|
|
5171
5184
|
break;
|
|
5172
5185
|
}
|
|
5173
5186
|
case "file_search_result": {
|
|
5174
|
-
const result =
|
|
5187
|
+
const result = block.result ?? [];
|
|
5175
5188
|
for (const raw of result) {
|
|
5176
5189
|
if (raw == null || typeof raw !== "object") continue;
|
|
5177
5190
|
const entry = raw;
|
|
5178
|
-
const uri =
|
|
5191
|
+
const uri = entry.url ?? entry.document_uri ?? entry.file_name;
|
|
5179
5192
|
if (uri == null || uri.length === 0) continue;
|
|
5180
5193
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
5181
5194
|
sources.push({
|
|
@@ -5187,14 +5200,14 @@ function builtinToolResultToSources({
|
|
|
5187
5200
|
});
|
|
5188
5201
|
continue;
|
|
5189
5202
|
}
|
|
5190
|
-
const filename =
|
|
5203
|
+
const filename = entry.file_name ?? basename(uri);
|
|
5191
5204
|
const mediaType = inferDocMediaType(uri);
|
|
5192
5205
|
sources.push({
|
|
5193
5206
|
type: "source",
|
|
5194
5207
|
sourceType: "document",
|
|
5195
5208
|
id: generateId4(),
|
|
5196
5209
|
mediaType,
|
|
5197
|
-
title:
|
|
5210
|
+
title: entry.title ?? entry.file_name ?? filename ?? uri,
|
|
5198
5211
|
...filename != null ? { filename } : {}
|
|
5199
5212
|
});
|
|
5200
5213
|
}
|
|
@@ -5209,14 +5222,13 @@ function annotationsToSources({
|
|
|
5209
5222
|
annotations,
|
|
5210
5223
|
generateId: generateId4
|
|
5211
5224
|
}) {
|
|
5212
|
-
var _a2;
|
|
5213
5225
|
if (annotations == null) return [];
|
|
5214
5226
|
const seen = /* @__PURE__ */ new Set();
|
|
5215
5227
|
const sources = [];
|
|
5216
5228
|
for (const annotation of annotations) {
|
|
5217
5229
|
const source = annotationToSource({ annotation, generateId: generateId4 });
|
|
5218
5230
|
if (source == null) continue;
|
|
5219
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${
|
|
5231
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
5220
5232
|
if (seen.has(key)) continue;
|
|
5221
5233
|
seen.add(key);
|
|
5222
5234
|
sources.push(source);
|
|
@@ -5283,15 +5295,13 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5283
5295
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
5284
5296
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
5285
5297
|
function sourceKey(source) {
|
|
5286
|
-
|
|
5287
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5298
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
|
|
5288
5299
|
}
|
|
5289
5300
|
return new TransformStream({
|
|
5290
5301
|
start(controller) {
|
|
5291
5302
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5292
5303
|
},
|
|
5293
5304
|
transform(chunk, controller) {
|
|
5294
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5295
5305
|
if (includeRawChunks) {
|
|
5296
5306
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5297
5307
|
}
|
|
@@ -5306,8 +5316,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5306
5316
|
case "interaction.created": {
|
|
5307
5317
|
const event = value;
|
|
5308
5318
|
const interaction = event.interaction;
|
|
5309
|
-
interactionId =
|
|
5310
|
-
const created = interaction
|
|
5319
|
+
interactionId = interaction?.id != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
5320
|
+
const created = interaction?.created;
|
|
5311
5321
|
let timestamp;
|
|
5312
5322
|
if (typeof created === "string") {
|
|
5313
5323
|
const parsed = new Date(created);
|
|
@@ -5318,7 +5328,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5318
5328
|
controller.enqueue({
|
|
5319
5329
|
type: "response-metadata",
|
|
5320
5330
|
...interactionId != null ? { id: interactionId } : {},
|
|
5321
|
-
modelId: interaction
|
|
5331
|
+
modelId: interaction?.model,
|
|
5322
5332
|
...timestamp ? { timestamp } : {}
|
|
5323
5333
|
});
|
|
5324
5334
|
break;
|
|
@@ -5327,11 +5337,11 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5327
5337
|
const event = value;
|
|
5328
5338
|
const step = event.step;
|
|
5329
5339
|
const index = event.index;
|
|
5330
|
-
const blockId = `${interactionId
|
|
5331
|
-
const stepType = step
|
|
5340
|
+
const blockId = `${interactionId ?? "interaction"}:${index}`;
|
|
5341
|
+
const stepType = step?.type;
|
|
5332
5342
|
if (stepType === "model_output") {
|
|
5333
|
-
const initial =
|
|
5334
|
-
if (
|
|
5343
|
+
const initial = step?.content?.[0];
|
|
5344
|
+
if (initial?.type === "text") {
|
|
5335
5345
|
openBlocks.set(index, {
|
|
5336
5346
|
kind: "text",
|
|
5337
5347
|
id: blockId,
|
|
@@ -5348,7 +5358,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5348
5358
|
emittedSourceKeys.add(key);
|
|
5349
5359
|
controller.enqueue(source);
|
|
5350
5360
|
}
|
|
5351
|
-
} else if (
|
|
5361
|
+
} else if (initial?.type === "image") {
|
|
5352
5362
|
openBlocks.set(index, {
|
|
5353
5363
|
kind: "image",
|
|
5354
5364
|
id: blockId,
|
|
@@ -5363,16 +5373,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5363
5373
|
});
|
|
5364
5374
|
}
|
|
5365
5375
|
} else if (stepType === "thought") {
|
|
5366
|
-
const signature = step
|
|
5376
|
+
const signature = step?.signature;
|
|
5367
5377
|
openBlocks.set(index, {
|
|
5368
5378
|
kind: "reasoning",
|
|
5369
5379
|
id: blockId,
|
|
5370
5380
|
...signature != null ? { signature } : {}
|
|
5371
5381
|
});
|
|
5372
5382
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
5373
|
-
if (Array.isArray(step
|
|
5383
|
+
if (Array.isArray(step?.summary)) {
|
|
5374
5384
|
for (const item of step.summary) {
|
|
5375
|
-
if (
|
|
5385
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
5376
5386
|
controller.enqueue({
|
|
5377
5387
|
type: "reasoning-delta",
|
|
5378
5388
|
id: blockId,
|
|
@@ -5383,12 +5393,12 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5383
5393
|
}
|
|
5384
5394
|
} else if (stepType === "processing_call" || stepType === "processing_result") {
|
|
5385
5395
|
const google2 = {};
|
|
5386
|
-
if (
|
|
5396
|
+
if (step?.signature != null) google2.signature = step.signature;
|
|
5387
5397
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5388
5398
|
if (stepType === "processing_call") {
|
|
5389
|
-
google2.processingId =
|
|
5399
|
+
google2.processingId = step?.id || blockId;
|
|
5390
5400
|
} else {
|
|
5391
|
-
google2.processingCallId =
|
|
5401
|
+
google2.processingCallId = step?.call_id || blockId;
|
|
5392
5402
|
}
|
|
5393
5403
|
openBlocks.set(index, {
|
|
5394
5404
|
kind: "custom",
|
|
@@ -5397,8 +5407,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5397
5407
|
google: google2
|
|
5398
5408
|
});
|
|
5399
5409
|
} else if (stepType === "function_call") {
|
|
5400
|
-
const toolCallId =
|
|
5401
|
-
const toolName =
|
|
5410
|
+
const toolCallId = step?.id || blockId;
|
|
5411
|
+
const toolName = step?.name ?? "unknown";
|
|
5402
5412
|
hasFunctionCall = true;
|
|
5403
5413
|
const state = {
|
|
5404
5414
|
kind: "function_call",
|
|
@@ -5406,7 +5416,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5406
5416
|
toolCallId,
|
|
5407
5417
|
toolName,
|
|
5408
5418
|
argumentsAccum: "",
|
|
5409
|
-
...
|
|
5419
|
+
...step?.signature != null ? { signature: step.signature } : {}
|
|
5410
5420
|
};
|
|
5411
5421
|
openBlocks.set(index, state);
|
|
5412
5422
|
controller.enqueue({
|
|
@@ -5415,29 +5425,29 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5415
5425
|
toolName
|
|
5416
5426
|
});
|
|
5417
5427
|
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
5418
|
-
const toolName = stepType === "mcp_server_tool_call" ?
|
|
5419
|
-
const toolCallId =
|
|
5428
|
+
const toolName = stepType === "mcp_server_tool_call" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
5429
|
+
const toolCallId = step?.id || blockId;
|
|
5420
5430
|
const state = {
|
|
5421
5431
|
kind: "builtin_tool_call",
|
|
5422
5432
|
id: blockId,
|
|
5423
5433
|
blockType: stepType,
|
|
5424
5434
|
toolCallId,
|
|
5425
5435
|
toolName,
|
|
5426
|
-
arguments:
|
|
5436
|
+
arguments: step?.arguments ?? {},
|
|
5427
5437
|
callEmitted: false
|
|
5428
5438
|
};
|
|
5429
5439
|
openBlocks.set(index, state);
|
|
5430
5440
|
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
5431
|
-
const toolName = stepType === "mcp_server_tool_result" ?
|
|
5432
|
-
const callId =
|
|
5441
|
+
const toolName = stepType === "mcp_server_tool_result" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
5442
|
+
const callId = step?.call_id || blockId;
|
|
5433
5443
|
const state = {
|
|
5434
5444
|
kind: "builtin_tool_result",
|
|
5435
5445
|
id: blockId,
|
|
5436
5446
|
blockType: stepType,
|
|
5437
5447
|
callId,
|
|
5438
5448
|
toolName,
|
|
5439
|
-
result:
|
|
5440
|
-
...
|
|
5449
|
+
result: step?.result ?? null,
|
|
5450
|
+
...step?.is_error != null ? { isError: step.is_error } : {},
|
|
5441
5451
|
resultEmitted: false
|
|
5442
5452
|
};
|
|
5443
5453
|
openBlocks.set(index, state);
|
|
@@ -5450,7 +5460,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5450
5460
|
const event = value;
|
|
5451
5461
|
let open = openBlocks.get(event.index);
|
|
5452
5462
|
if (open == null) break;
|
|
5453
|
-
const dtype =
|
|
5463
|
+
const dtype = event.delta?.type;
|
|
5454
5464
|
if (open.kind === "pending_model_output") {
|
|
5455
5465
|
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
5456
5466
|
const promoted = {
|
|
@@ -5468,17 +5478,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5468
5478
|
const google2 = {};
|
|
5469
5479
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5470
5480
|
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
5471
|
-
if (
|
|
5481
|
+
if (imageDelta?.data != null && imageDelta.data.length > 0) {
|
|
5472
5482
|
controller.enqueue({
|
|
5473
5483
|
type: "file",
|
|
5474
|
-
mediaType:
|
|
5484
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
5475
5485
|
data: { type: "data", data: imageDelta.data },
|
|
5476
5486
|
...providerMetadata ? { providerMetadata } : {}
|
|
5477
5487
|
});
|
|
5478
|
-
} else if (
|
|
5488
|
+
} else if (imageDelta?.uri != null && imageDelta.uri.length > 0) {
|
|
5479
5489
|
controller.enqueue({
|
|
5480
5490
|
type: "file",
|
|
5481
|
-
mediaType:
|
|
5491
|
+
mediaType: imageDelta.mime_type ?? "image/png",
|
|
5482
5492
|
data: { type: "url", url: new URL(imageDelta.uri) },
|
|
5483
5493
|
...providerMetadata ? { providerMetadata } : {}
|
|
5484
5494
|
});
|
|
@@ -5494,17 +5504,17 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5494
5504
|
const google2 = {};
|
|
5495
5505
|
if (interactionId != null) google2.interactionId = interactionId;
|
|
5496
5506
|
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
5497
|
-
if (
|
|
5507
|
+
if (videoDelta?.data != null && videoDelta.data.length > 0) {
|
|
5498
5508
|
controller.enqueue({
|
|
5499
5509
|
type: "file",
|
|
5500
|
-
mediaType:
|
|
5510
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
5501
5511
|
data: { type: "data", data: videoDelta.data },
|
|
5502
5512
|
...providerMetadata ? { providerMetadata } : {}
|
|
5503
5513
|
});
|
|
5504
|
-
} else if (
|
|
5514
|
+
} else if (videoDelta?.uri != null && videoDelta.uri.length > 0) {
|
|
5505
5515
|
controller.enqueue({
|
|
5506
5516
|
type: "file",
|
|
5507
|
-
mediaType:
|
|
5517
|
+
mediaType: videoDelta.mime_type ?? "video/mp4",
|
|
5508
5518
|
data: { type: "url", url: new URL(videoDelta.uri) },
|
|
5509
5519
|
...providerMetadata ? { providerMetadata } : {}
|
|
5510
5520
|
});
|
|
@@ -5512,7 +5522,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5512
5522
|
break;
|
|
5513
5523
|
}
|
|
5514
5524
|
const delta = event.delta;
|
|
5515
|
-
if (open.kind === "custom" && (
|
|
5525
|
+
if (open.kind === "custom" && (delta?.type === "processing_call" || delta?.type === "processing_result")) {
|
|
5516
5526
|
if (delta.signature != null)
|
|
5517
5527
|
open.google.signature = delta.signature;
|
|
5518
5528
|
if (delta.type === "processing_call" && delta.id != null && delta.id.length > 0) {
|
|
@@ -5521,8 +5531,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5521
5531
|
if (delta.type === "processing_result" && delta.call_id != null && delta.call_id.length > 0) {
|
|
5522
5532
|
open.google.processingCallId = delta.call_id;
|
|
5523
5533
|
}
|
|
5524
|
-
} else if (open.kind === "text" &&
|
|
5525
|
-
const text =
|
|
5534
|
+
} else if (open.kind === "text" && delta?.type === "text") {
|
|
5535
|
+
const text = delta.text ?? "";
|
|
5526
5536
|
if (text.length > 0) {
|
|
5527
5537
|
controller.enqueue({
|
|
5528
5538
|
type: "text-delta",
|
|
@@ -5530,7 +5540,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5530
5540
|
delta: text
|
|
5531
5541
|
});
|
|
5532
5542
|
}
|
|
5533
|
-
} else if (open.kind === "text" && (
|
|
5543
|
+
} else if (open.kind === "text" && (delta?.type === "text_annotation" || delta?.type === "text_annotation_delta")) {
|
|
5534
5544
|
const sources = annotationsToSources({
|
|
5535
5545
|
annotations: delta.annotations,
|
|
5536
5546
|
generateId: generateId4
|
|
@@ -5542,27 +5552,27 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5542
5552
|
open.emittedSourceKeys.add(key);
|
|
5543
5553
|
controller.enqueue(source);
|
|
5544
5554
|
}
|
|
5545
|
-
} else if (open.kind === "image" &&
|
|
5555
|
+
} else if (open.kind === "image" && delta?.type === "image") {
|
|
5546
5556
|
if (delta.data != null) open.data = delta.data;
|
|
5547
5557
|
if (delta.mime_type != null) open.mimeType = delta.mime_type;
|
|
5548
5558
|
if (delta.uri != null) open.uri = delta.uri;
|
|
5549
5559
|
} else if (open.kind === "reasoning") {
|
|
5550
|
-
if (
|
|
5560
|
+
if (delta?.type === "thought_summary") {
|
|
5551
5561
|
const item = delta.content;
|
|
5552
|
-
if (
|
|
5562
|
+
if (item?.type === "text" && typeof item.text === "string") {
|
|
5553
5563
|
controller.enqueue({
|
|
5554
5564
|
type: "reasoning-delta",
|
|
5555
5565
|
id: open.id,
|
|
5556
5566
|
delta: item.text
|
|
5557
5567
|
});
|
|
5558
5568
|
}
|
|
5559
|
-
} else if (
|
|
5569
|
+
} else if (delta?.type === "thought_signature") {
|
|
5560
5570
|
const signature = delta.signature;
|
|
5561
5571
|
if (signature != null) {
|
|
5562
5572
|
open.signature = signature;
|
|
5563
5573
|
}
|
|
5564
5574
|
}
|
|
5565
|
-
} else if (open.kind === "function_call" &&
|
|
5575
|
+
} else if (open.kind === "function_call" && delta?.type === "arguments_delta") {
|
|
5566
5576
|
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
5567
5577
|
if (slice.length > 0) {
|
|
5568
5578
|
open.argumentsAccum += slice;
|
|
@@ -5579,7 +5589,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5579
5589
|
open.signature = delta.signature;
|
|
5580
5590
|
}
|
|
5581
5591
|
hasFunctionCall = true;
|
|
5582
|
-
} else if (open.kind === "builtin_tool_call" &&
|
|
5592
|
+
} else if (open.kind === "builtin_tool_call" && delta?.type === open.blockType) {
|
|
5583
5593
|
if (delta.id != null && delta.id.length > 0) {
|
|
5584
5594
|
open.toolCallId = delta.id;
|
|
5585
5595
|
}
|
|
@@ -5589,7 +5599,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5589
5599
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
5590
5600
|
open.toolName = delta.name;
|
|
5591
5601
|
}
|
|
5592
|
-
} else if (open.kind === "builtin_tool_result" &&
|
|
5602
|
+
} else if (open.kind === "builtin_tool_result" && delta?.type === open.blockType) {
|
|
5593
5603
|
if (delta.call_id != null && delta.call_id.length > 0) {
|
|
5594
5604
|
open.callId = delta.call_id;
|
|
5595
5605
|
}
|
|
@@ -5629,14 +5639,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5629
5639
|
if (open.data != null && open.data.length > 0) {
|
|
5630
5640
|
controller.enqueue({
|
|
5631
5641
|
type: "file",
|
|
5632
|
-
mediaType:
|
|
5642
|
+
mediaType: open.mimeType ?? "image/png",
|
|
5633
5643
|
data: { type: "data", data: open.data },
|
|
5634
5644
|
...providerMetadata ? { providerMetadata } : {}
|
|
5635
5645
|
});
|
|
5636
5646
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
5637
5647
|
controller.enqueue({
|
|
5638
5648
|
type: "file",
|
|
5639
|
-
mediaType:
|
|
5649
|
+
mediaType: open.mimeType ?? "image/png",
|
|
5640
5650
|
data: { type: "url", url: new URL(open.uri) },
|
|
5641
5651
|
...providerMetadata ? { providerMetadata } : {}
|
|
5642
5652
|
});
|
|
@@ -5669,7 +5679,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5669
5679
|
type: "tool-call",
|
|
5670
5680
|
toolCallId: open.toolCallId,
|
|
5671
5681
|
toolName: open.toolName,
|
|
5672
|
-
input: JSON.stringify(
|
|
5682
|
+
input: JSON.stringify(open.arguments ?? {}),
|
|
5673
5683
|
providerExecuted: true
|
|
5674
5684
|
});
|
|
5675
5685
|
open.callEmitted = true;
|
|
@@ -5678,7 +5688,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5678
5688
|
type: "tool-result",
|
|
5679
5689
|
toolCallId: open.callId,
|
|
5680
5690
|
toolName: open.toolName,
|
|
5681
|
-
result:
|
|
5691
|
+
result: open.result ?? null
|
|
5682
5692
|
});
|
|
5683
5693
|
open.resultEmitted = true;
|
|
5684
5694
|
const sources = builtinToolResultToSources({
|
|
@@ -5715,16 +5725,16 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5715
5725
|
case "interaction.completed": {
|
|
5716
5726
|
const event = value;
|
|
5717
5727
|
const interaction = event.interaction;
|
|
5718
|
-
if (
|
|
5728
|
+
if (interaction?.id != null && interaction.id.length > 0) {
|
|
5719
5729
|
interactionId = interaction.id;
|
|
5720
5730
|
}
|
|
5721
|
-
if (
|
|
5731
|
+
if (interaction?.status != null) {
|
|
5722
5732
|
finishStatus = interaction.status;
|
|
5723
5733
|
}
|
|
5724
|
-
if (
|
|
5734
|
+
if (interaction?.usage != null) {
|
|
5725
5735
|
usage = interaction.usage;
|
|
5726
5736
|
}
|
|
5727
|
-
if (
|
|
5737
|
+
if (interaction?.service_tier != null) {
|
|
5728
5738
|
serviceTier = interaction.service_tier;
|
|
5729
5739
|
}
|
|
5730
5740
|
break;
|
|
@@ -5735,9 +5745,9 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5735
5745
|
controller.enqueue({
|
|
5736
5746
|
type: "error",
|
|
5737
5747
|
error: createProviderStreamError({
|
|
5738
|
-
message:
|
|
5748
|
+
message: event.error?.message ?? "Unknown interaction error",
|
|
5739
5749
|
type: event.event_type,
|
|
5740
|
-
code:
|
|
5750
|
+
code: event.error?.code ?? void 0,
|
|
5741
5751
|
data: event
|
|
5742
5752
|
})
|
|
5743
5753
|
});
|
|
@@ -5788,7 +5798,6 @@ function convertToGoogleInteractionsInput({
|
|
|
5788
5798
|
store,
|
|
5789
5799
|
mediaResolution
|
|
5790
5800
|
}) {
|
|
5791
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5792
5801
|
const warnings = [];
|
|
5793
5802
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
5794
5803
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -5845,7 +5854,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5845
5854
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
5846
5855
|
} else if (part.type === "reasoning") {
|
|
5847
5856
|
flushModelOutput();
|
|
5848
|
-
const signature =
|
|
5857
|
+
const signature = part.providerOptions?.google?.signature;
|
|
5849
5858
|
steps.push({
|
|
5850
5859
|
type: "thought",
|
|
5851
5860
|
...signature != null ? { signature } : {},
|
|
@@ -5862,15 +5871,15 @@ function convertToGoogleInteractionsInput({
|
|
|
5862
5871
|
}
|
|
5863
5872
|
} else if (part.type === "custom") {
|
|
5864
5873
|
flushModelOutput();
|
|
5865
|
-
const google2 =
|
|
5866
|
-
const signature = typeof
|
|
5867
|
-
if (part.kind === "google.processing_call" && typeof
|
|
5874
|
+
const google2 = part.providerOptions?.google;
|
|
5875
|
+
const signature = typeof google2?.signature === "string" ? google2.signature : void 0;
|
|
5876
|
+
if (part.kind === "google.processing_call" && typeof google2?.processingId === "string") {
|
|
5868
5877
|
steps.push({
|
|
5869
5878
|
type: "processing_call",
|
|
5870
5879
|
id: google2.processingId,
|
|
5871
5880
|
...signature != null ? { signature } : {}
|
|
5872
5881
|
});
|
|
5873
|
-
} else if (part.kind === "google.processing_result" && typeof
|
|
5882
|
+
} else if (part.kind === "google.processing_result" && typeof google2?.processingCallId === "string") {
|
|
5874
5883
|
steps.push({
|
|
5875
5884
|
type: "processing_result",
|
|
5876
5885
|
call_id: google2.processingCallId,
|
|
@@ -5884,8 +5893,8 @@ function convertToGoogleInteractionsInput({
|
|
|
5884
5893
|
}
|
|
5885
5894
|
} else if (part.type === "tool-call") {
|
|
5886
5895
|
flushModelOutput();
|
|
5887
|
-
const signature =
|
|
5888
|
-
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) :
|
|
5896
|
+
const signature = part.providerOptions?.google?.signature;
|
|
5897
|
+
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : part.input ?? {};
|
|
5889
5898
|
steps.push({
|
|
5890
5899
|
type: "function_call",
|
|
5891
5900
|
id: part.toolCallId,
|
|
@@ -5917,7 +5926,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5917
5926
|
toolCallId: part.toolCallId,
|
|
5918
5927
|
toolName: part.toolName,
|
|
5919
5928
|
output: part.output,
|
|
5920
|
-
signature:
|
|
5929
|
+
signature: part.providerOptions?.google?.signature,
|
|
5921
5930
|
warnings
|
|
5922
5931
|
});
|
|
5923
5932
|
content.push(block);
|
|
@@ -6010,8 +6019,7 @@ function getVideoProcessingField({
|
|
|
6010
6019
|
part,
|
|
6011
6020
|
warnings
|
|
6012
6021
|
}) {
|
|
6013
|
-
|
|
6014
|
-
const processing = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.processing;
|
|
6022
|
+
const processing = part.providerOptions?.google?.processing;
|
|
6015
6023
|
if (processing == null) {
|
|
6016
6024
|
return {};
|
|
6017
6025
|
}
|
|
@@ -6023,8 +6031,8 @@ function getVideoProcessingField({
|
|
|
6023
6031
|
return {
|
|
6024
6032
|
processing: {
|
|
6025
6033
|
type: "static",
|
|
6026
|
-
...typeof config.startOffset === "number" ? { start_offset: config.startOffset } : {},
|
|
6027
|
-
...typeof config.endOffset === "number" ? { end_offset: config.endOffset } : {},
|
|
6034
|
+
...typeof config.startOffset === "number" ? { start_offset: `${config.startOffset}s` } : {},
|
|
6035
|
+
...typeof config.endOffset === "number" ? { end_offset: `${config.endOffset}s` } : {},
|
|
6028
6036
|
...typeof config.fps === "number" ? { fps: config.fps } : {}
|
|
6029
6037
|
}
|
|
6030
6038
|
};
|
|
@@ -6044,8 +6052,7 @@ function compactPromptForPreviousInteraction({
|
|
|
6044
6052
|
for (const message of prompt) {
|
|
6045
6053
|
if (message.role === "assistant") {
|
|
6046
6054
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
6047
|
-
|
|
6048
|
-
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
6055
|
+
const partInteractionId = part.providerOptions?.google?.interactionId;
|
|
6049
6056
|
return partInteractionId === previousInteractionId;
|
|
6050
6057
|
});
|
|
6051
6058
|
if (matchesLinkedInteraction) {
|
|
@@ -6086,7 +6093,7 @@ function safeParseToolArgs(input) {
|
|
|
6086
6093
|
return parsed;
|
|
6087
6094
|
}
|
|
6088
6095
|
return { value: parsed };
|
|
6089
|
-
} catch
|
|
6096
|
+
} catch {
|
|
6090
6097
|
return { value: input };
|
|
6091
6098
|
}
|
|
6092
6099
|
}
|
|
@@ -6097,7 +6104,6 @@ function convertToolResultPart({
|
|
|
6097
6104
|
signature,
|
|
6098
6105
|
warnings
|
|
6099
6106
|
}) {
|
|
6100
|
-
var _a2;
|
|
6101
6107
|
const base = {
|
|
6102
6108
|
type: "function_result",
|
|
6103
6109
|
call_id: toolCallId,
|
|
@@ -6117,7 +6123,7 @@ function convertToolResultPart({
|
|
|
6117
6123
|
return {
|
|
6118
6124
|
...base,
|
|
6119
6125
|
is_error: true,
|
|
6120
|
-
result:
|
|
6126
|
+
result: output.reason ?? "Tool execution denied by user."
|
|
6121
6127
|
};
|
|
6122
6128
|
case "content": {
|
|
6123
6129
|
const blocks = [];
|
|
@@ -6808,7 +6814,6 @@ function parseGoogleInteractionsOutputs({
|
|
|
6808
6814
|
generateId: generateId4,
|
|
6809
6815
|
interactionId
|
|
6810
6816
|
}) {
|
|
6811
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6812
6817
|
const content = [];
|
|
6813
6818
|
let hasFunctionCall = false;
|
|
6814
6819
|
if (steps == null) {
|
|
@@ -6823,12 +6828,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
6823
6828
|
break;
|
|
6824
6829
|
}
|
|
6825
6830
|
case "model_output": {
|
|
6826
|
-
const blocks =
|
|
6831
|
+
const blocks = step.content ?? [];
|
|
6827
6832
|
for (const block of blocks) {
|
|
6828
6833
|
if (block == null || typeof block !== "object") continue;
|
|
6829
6834
|
const blockType = block.type;
|
|
6830
6835
|
if (blockType === "text") {
|
|
6831
|
-
const text =
|
|
6836
|
+
const text = block.text ?? "";
|
|
6832
6837
|
const annotations = block.annotations;
|
|
6833
6838
|
content.push({
|
|
6834
6839
|
type: "text",
|
|
@@ -6844,14 +6849,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
6844
6849
|
if (image.data != null && image.data.length > 0) {
|
|
6845
6850
|
content.push({
|
|
6846
6851
|
type: "file",
|
|
6847
|
-
mediaType:
|
|
6852
|
+
mediaType: image.mime_type ?? "image/png",
|
|
6848
6853
|
data: { type: "data", data: image.data },
|
|
6849
6854
|
...googleProviderMetadata({ interactionId })
|
|
6850
6855
|
});
|
|
6851
6856
|
} else if (image.uri != null && image.uri.length > 0) {
|
|
6852
6857
|
content.push({
|
|
6853
6858
|
type: "file",
|
|
6854
|
-
mediaType:
|
|
6859
|
+
mediaType: image.mime_type ?? "image/png",
|
|
6855
6860
|
data: { type: "url", url: new URL(image.uri) },
|
|
6856
6861
|
...googleProviderMetadata({ interactionId })
|
|
6857
6862
|
});
|
|
@@ -6861,14 +6866,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
6861
6866
|
if (video.data != null && video.data.length > 0) {
|
|
6862
6867
|
content.push({
|
|
6863
6868
|
type: "file",
|
|
6864
|
-
mediaType:
|
|
6869
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
6865
6870
|
data: { type: "data", data: video.data },
|
|
6866
6871
|
...googleProviderMetadata({ interactionId })
|
|
6867
6872
|
});
|
|
6868
6873
|
} else if (video.uri != null && video.uri.length > 0) {
|
|
6869
6874
|
content.push({
|
|
6870
6875
|
type: "file",
|
|
6871
|
-
mediaType:
|
|
6876
|
+
mediaType: video.mime_type ?? "video/mp4",
|
|
6872
6877
|
data: { type: "url", url: new URL(video.uri) },
|
|
6873
6878
|
...googleProviderMetadata({ interactionId })
|
|
6874
6879
|
});
|
|
@@ -6881,7 +6886,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6881
6886
|
const thought = step;
|
|
6882
6887
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
6883
6888
|
const text = summary.filter(
|
|
6884
|
-
(item) =>
|
|
6889
|
+
(item) => item?.type === "text" && typeof item.text === "string"
|
|
6885
6890
|
).map((item) => item.text).join("\n");
|
|
6886
6891
|
content.push({
|
|
6887
6892
|
type: "reasoning",
|
|
@@ -6928,7 +6933,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6928
6933
|
type: "tool-call",
|
|
6929
6934
|
toolCallId: call.id,
|
|
6930
6935
|
toolName: call.name,
|
|
6931
|
-
input: JSON.stringify(
|
|
6936
|
+
input: JSON.stringify(call.arguments ?? {}),
|
|
6932
6937
|
...googleProviderMetadata({
|
|
6933
6938
|
signature: call.signature,
|
|
6934
6939
|
interactionId
|
|
@@ -6939,8 +6944,8 @@ function parseGoogleInteractionsOutputs({
|
|
|
6939
6944
|
default: {
|
|
6940
6945
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
6941
6946
|
const call = step;
|
|
6942
|
-
const toolName = type === "mcp_server_tool_call" ?
|
|
6943
|
-
const input = JSON.stringify(
|
|
6947
|
+
const toolName = type === "mcp_server_tool_call" ? call.name ?? "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
6948
|
+
const input = JSON.stringify(call.arguments ?? {});
|
|
6944
6949
|
content.push({
|
|
6945
6950
|
type: "tool-call",
|
|
6946
6951
|
toolCallId: call.id || generateId4(),
|
|
@@ -6950,12 +6955,12 @@ function parseGoogleInteractionsOutputs({
|
|
|
6950
6955
|
});
|
|
6951
6956
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
6952
6957
|
const result = step;
|
|
6953
|
-
const toolName = type === "mcp_server_tool_result" ?
|
|
6958
|
+
const toolName = type === "mcp_server_tool_result" ? result.name ?? "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
6954
6959
|
content.push({
|
|
6955
6960
|
type: "tool-result",
|
|
6956
6961
|
toolCallId: result.call_id || generateId4(),
|
|
6957
6962
|
toolName,
|
|
6958
|
-
result:
|
|
6963
|
+
result: result.result ?? null
|
|
6959
6964
|
});
|
|
6960
6965
|
const sources = builtinToolResultToSources({
|
|
6961
6966
|
block: step,
|
|
@@ -7008,9 +7013,9 @@ async function cancelGoogleInteraction({
|
|
|
7008
7013
|
});
|
|
7009
7014
|
try {
|
|
7010
7015
|
await response.text();
|
|
7011
|
-
} catch
|
|
7016
|
+
} catch {
|
|
7012
7017
|
}
|
|
7013
|
-
} catch
|
|
7018
|
+
} catch {
|
|
7014
7019
|
}
|
|
7015
7020
|
}
|
|
7016
7021
|
|
|
@@ -7043,7 +7048,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
7043
7048
|
const cancelOnServer = () => cancelGoogleInteraction({ baseURL, interactionId, headers, fetch: fetch2 });
|
|
7044
7049
|
try {
|
|
7045
7050
|
while (true) {
|
|
7046
|
-
if (abortSignal
|
|
7051
|
+
if (abortSignal?.aborted) {
|
|
7047
7052
|
await cancelOnServer();
|
|
7048
7053
|
throw new DOMException("Polling was aborted", "AbortError");
|
|
7049
7054
|
}
|
|
@@ -7086,9 +7091,8 @@ function prepareGoogleInteractionsTools({
|
|
|
7086
7091
|
tools,
|
|
7087
7092
|
toolChoice
|
|
7088
7093
|
}) {
|
|
7089
|
-
var _a2, _b, _c, _d;
|
|
7090
7094
|
const toolWarnings = [];
|
|
7091
|
-
const normalized =
|
|
7095
|
+
const normalized = tools?.length ? tools : void 0;
|
|
7092
7096
|
if (normalized == null) {
|
|
7093
7097
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
7094
7098
|
}
|
|
@@ -7098,13 +7102,13 @@ function prepareGoogleInteractionsTools({
|
|
|
7098
7102
|
interactionsTools.push({
|
|
7099
7103
|
type: "function",
|
|
7100
7104
|
name: tool.name,
|
|
7101
|
-
description:
|
|
7105
|
+
description: tool.description ?? "",
|
|
7102
7106
|
parameters: tool.inputSchema
|
|
7103
7107
|
});
|
|
7104
7108
|
continue;
|
|
7105
7109
|
}
|
|
7106
7110
|
if (tool.type === "provider") {
|
|
7107
|
-
const args =
|
|
7111
|
+
const args = tool.args ?? {};
|
|
7108
7112
|
switch (tool.id) {
|
|
7109
7113
|
case "google.google_search": {
|
|
7110
7114
|
const searchTypesArg = args.searchTypes;
|
|
@@ -7154,7 +7158,7 @@ function prepareGoogleInteractionsTools({
|
|
|
7154
7158
|
case "google.computer_use": {
|
|
7155
7159
|
interactionsTools.push({
|
|
7156
7160
|
type: "computer_use",
|
|
7157
|
-
environment:
|
|
7161
|
+
environment: args.environment ?? "browser",
|
|
7158
7162
|
...args.excludedPredefinedFunctions != null ? {
|
|
7159
7163
|
excludedPredefinedFunctions: args.excludedPredefinedFunctions
|
|
7160
7164
|
} : {}
|
|
@@ -7172,7 +7176,7 @@ function prepareGoogleInteractionsTools({
|
|
|
7172
7176
|
break;
|
|
7173
7177
|
}
|
|
7174
7178
|
case "google.retrieval": {
|
|
7175
|
-
const vertexAiSearchConfig =
|
|
7179
|
+
const vertexAiSearchConfig = args.vertexAiSearchConfig ?? void 0;
|
|
7176
7180
|
interactionsTools.push({
|
|
7177
7181
|
type: "retrieval",
|
|
7178
7182
|
...args.retrievalTypes != null ? {
|
|
@@ -7376,7 +7380,7 @@ function streamGoogleInteractionEvents({
|
|
|
7376
7380
|
if (abortSignal != null) {
|
|
7377
7381
|
abortSignal.removeEventListener("abort", upstreamAbortHandler);
|
|
7378
7382
|
}
|
|
7379
|
-
currentReader
|
|
7383
|
+
currentReader?.cancel().catch(() => {
|
|
7380
7384
|
});
|
|
7381
7385
|
currentReader = void 0;
|
|
7382
7386
|
if (effectiveSignal.aborted && !complete) {
|
|
@@ -7391,7 +7395,7 @@ function streamGoogleInteractionEvents({
|
|
|
7391
7395
|
},
|
|
7392
7396
|
cancel() {
|
|
7393
7397
|
internalAbort.abort();
|
|
7394
|
-
currentReader
|
|
7398
|
+
currentReader?.cancel().catch(() => {
|
|
7395
7399
|
});
|
|
7396
7400
|
currentReader = void 0;
|
|
7397
7401
|
}
|
|
@@ -7408,7 +7412,6 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7408
7412
|
}) {
|
|
7409
7413
|
return new ReadableStream({
|
|
7410
7414
|
start(controller) {
|
|
7411
|
-
var _a2, _b, _c;
|
|
7412
7415
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7413
7416
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7414
7417
|
let timestamp;
|
|
@@ -7422,19 +7425,19 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7422
7425
|
controller.enqueue({
|
|
7423
7426
|
type: "response-metadata",
|
|
7424
7427
|
...interactionId != null ? { id: interactionId } : {},
|
|
7425
|
-
modelId:
|
|
7428
|
+
modelId: response.model ?? void 0,
|
|
7426
7429
|
...timestamp ? { timestamp } : {}
|
|
7427
7430
|
});
|
|
7428
7431
|
if (includeRawChunks) {
|
|
7429
7432
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
7430
7433
|
}
|
|
7431
7434
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
7432
|
-
steps:
|
|
7435
|
+
steps: response.steps ?? null,
|
|
7433
7436
|
generateId: generateId4,
|
|
7434
7437
|
interactionId
|
|
7435
7438
|
});
|
|
7436
7439
|
let blockCounter = 0;
|
|
7437
|
-
const nextBlockId = () => `${interactionId
|
|
7440
|
+
const nextBlockId = () => `${interactionId ?? "agent"}:${blockCounter++}`;
|
|
7438
7441
|
for (const part of content) {
|
|
7439
7442
|
switch (part.type) {
|
|
7440
7443
|
case "text": {
|
|
@@ -7514,7 +7517,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7514
7517
|
break;
|
|
7515
7518
|
}
|
|
7516
7519
|
}
|
|
7517
|
-
const serviceTier =
|
|
7520
|
+
const serviceTier = response.service_tier ?? headerServiceTier;
|
|
7518
7521
|
const finishReason = {
|
|
7519
7522
|
unified: mapGoogleInteractionsFinishReason({
|
|
7520
7523
|
status: response.status,
|
|
@@ -7589,7 +7592,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7589
7592
|
};
|
|
7590
7593
|
}
|
|
7591
7594
|
async getArgs(options) {
|
|
7592
|
-
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;
|
|
7593
7595
|
const warnings = [];
|
|
7594
7596
|
const googleOptions = await parseProviderOptions8({
|
|
7595
7597
|
provider: "google",
|
|
@@ -7624,7 +7626,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7624
7626
|
warnings.push(...prepared.toolWarnings);
|
|
7625
7627
|
}
|
|
7626
7628
|
const responseFormatEntries = [];
|
|
7627
|
-
if (
|
|
7629
|
+
if (options.responseFormat?.type === "json") {
|
|
7628
7630
|
if (isAgent) {
|
|
7629
7631
|
warnings.push({
|
|
7630
7632
|
type: "other",
|
|
@@ -7639,41 +7641,41 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7639
7641
|
responseFormatEntries.push(entry);
|
|
7640
7642
|
}
|
|
7641
7643
|
}
|
|
7642
|
-
if (
|
|
7644
|
+
if (googleOptions?.responseFormat != null) {
|
|
7643
7645
|
for (const entry of googleOptions.responseFormat) {
|
|
7644
7646
|
if (entry.type === "text") {
|
|
7645
7647
|
responseFormatEntries.push(
|
|
7646
7648
|
pruneUndefined({
|
|
7647
7649
|
type: "text",
|
|
7648
|
-
mime_type:
|
|
7649
|
-
schema:
|
|
7650
|
+
mime_type: entry.mimeType ?? void 0,
|
|
7651
|
+
schema: entry.schema ?? void 0
|
|
7650
7652
|
})
|
|
7651
7653
|
);
|
|
7652
7654
|
} else if (entry.type === "image") {
|
|
7653
7655
|
responseFormatEntries.push(
|
|
7654
7656
|
pruneUndefined({
|
|
7655
7657
|
type: "image",
|
|
7656
|
-
mime_type:
|
|
7657
|
-
aspect_ratio:
|
|
7658
|
-
image_size:
|
|
7658
|
+
mime_type: entry.mimeType ?? void 0,
|
|
7659
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
7660
|
+
image_size: entry.imageSize ?? void 0
|
|
7659
7661
|
})
|
|
7660
7662
|
);
|
|
7661
7663
|
} else if (entry.type === "audio") {
|
|
7662
7664
|
responseFormatEntries.push(
|
|
7663
7665
|
pruneUndefined({
|
|
7664
7666
|
type: "audio",
|
|
7665
|
-
mime_type:
|
|
7667
|
+
mime_type: entry.mimeType ?? void 0
|
|
7666
7668
|
})
|
|
7667
7669
|
);
|
|
7668
7670
|
} else if (entry.type === "video") {
|
|
7669
7671
|
responseFormatEntries.push(
|
|
7670
7672
|
pruneUndefined({
|
|
7671
7673
|
type: "video",
|
|
7672
|
-
aspect_ratio:
|
|
7673
|
-
resolution:
|
|
7674
|
-
duration:
|
|
7675
|
-
delivery:
|
|
7676
|
-
gcs_uri:
|
|
7674
|
+
aspect_ratio: entry.aspectRatio ?? void 0,
|
|
7675
|
+
resolution: entry.resolution ?? void 0,
|
|
7676
|
+
duration: entry.duration ?? void 0,
|
|
7677
|
+
delivery: entry.delivery ?? void 0,
|
|
7678
|
+
gcs_uri: entry.gcsUri ?? void 0
|
|
7677
7679
|
})
|
|
7678
7680
|
);
|
|
7679
7681
|
}
|
|
@@ -7685,13 +7687,13 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7685
7687
|
warnings: convWarnings
|
|
7686
7688
|
} = convertToGoogleInteractionsInput({
|
|
7687
7689
|
prompt: options.prompt,
|
|
7688
|
-
previousInteractionId:
|
|
7689
|
-
store:
|
|
7690
|
-
mediaResolution:
|
|
7690
|
+
previousInteractionId: googleOptions?.previousInteractionId ?? void 0,
|
|
7691
|
+
store: googleOptions?.store ?? void 0,
|
|
7692
|
+
mediaResolution: googleOptions?.mediaResolution ?? void 0
|
|
7691
7693
|
});
|
|
7692
7694
|
warnings.push(...convWarnings);
|
|
7693
7695
|
let systemInstruction = convertedSystemInstruction;
|
|
7694
|
-
const optionSystemInstruction =
|
|
7696
|
+
const optionSystemInstruction = googleOptions?.systemInstruction ?? void 0;
|
|
7695
7697
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
7696
7698
|
warnings.push({
|
|
7697
7699
|
type: "other",
|
|
@@ -7716,12 +7718,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7716
7718
|
}
|
|
7717
7719
|
if (options.maxOutputTokens != null)
|
|
7718
7720
|
droppedFields.push("maxOutputTokens");
|
|
7719
|
-
if (
|
|
7721
|
+
if (googleOptions?.thinkingLevel != null)
|
|
7720
7722
|
droppedFields.push("thinkingLevel");
|
|
7721
|
-
if (
|
|
7723
|
+
if (googleOptions?.thinkingSummaries != null) {
|
|
7722
7724
|
droppedFields.push("thinkingSummaries");
|
|
7723
7725
|
}
|
|
7724
|
-
if (
|
|
7726
|
+
if (googleOptions?.imageConfig != null) droppedFields.push("imageConfig");
|
|
7725
7727
|
if (droppedFields.length > 0) {
|
|
7726
7728
|
warnings.push({
|
|
7727
7729
|
type: "other",
|
|
@@ -7731,17 +7733,17 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7731
7733
|
generationConfig = void 0;
|
|
7732
7734
|
} else {
|
|
7733
7735
|
generationConfig = pruneUndefined({
|
|
7734
|
-
temperature:
|
|
7735
|
-
top_p:
|
|
7736
|
-
top_k:
|
|
7737
|
-
seed:
|
|
7736
|
+
temperature: options.temperature ?? void 0,
|
|
7737
|
+
top_p: options.topP ?? void 0,
|
|
7738
|
+
top_k: options.topK ?? void 0,
|
|
7739
|
+
seed: options.seed ?? void 0,
|
|
7738
7740
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
7739
|
-
max_output_tokens:
|
|
7740
|
-
thinking_level:
|
|
7741
|
-
thinking_summaries:
|
|
7741
|
+
max_output_tokens: options.maxOutputTokens ?? void 0,
|
|
7742
|
+
thinking_level: googleOptions?.thinkingLevel ?? void 0,
|
|
7743
|
+
thinking_summaries: googleOptions?.thinkingSummaries ?? void 0,
|
|
7742
7744
|
tool_choice: toolChoiceForBody
|
|
7743
7745
|
});
|
|
7744
|
-
if (
|
|
7746
|
+
if (googleOptions?.imageConfig != null) {
|
|
7745
7747
|
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
7746
7748
|
(entry) => entry.type === "image"
|
|
7747
7749
|
);
|
|
@@ -7760,21 +7762,21 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7760
7762
|
}
|
|
7761
7763
|
}
|
|
7762
7764
|
let agentConfig;
|
|
7763
|
-
if (isAgent &&
|
|
7765
|
+
if (isAgent && googleOptions?.agentConfig != null) {
|
|
7764
7766
|
const agentConfigOptions = googleOptions.agentConfig;
|
|
7765
7767
|
if (agentConfigOptions.type === "deep-research") {
|
|
7766
7768
|
agentConfig = pruneUndefined({
|
|
7767
7769
|
type: "deep-research",
|
|
7768
|
-
thinking_summaries:
|
|
7769
|
-
visualization:
|
|
7770
|
-
collaborative_planning:
|
|
7770
|
+
thinking_summaries: agentConfigOptions.thinkingSummaries ?? void 0,
|
|
7771
|
+
visualization: agentConfigOptions.visualization ?? void 0,
|
|
7772
|
+
collaborative_planning: agentConfigOptions.collaborativePlanning ?? void 0
|
|
7771
7773
|
});
|
|
7772
7774
|
} else if (agentConfigOptions.type === "dynamic") {
|
|
7773
7775
|
agentConfig = { type: "dynamic" };
|
|
7774
7776
|
}
|
|
7775
7777
|
}
|
|
7776
7778
|
let environment;
|
|
7777
|
-
if (
|
|
7779
|
+
if (googleOptions?.environment != null) {
|
|
7778
7780
|
if (!isAgent) {
|
|
7779
7781
|
warnings.push({
|
|
7780
7782
|
type: "other",
|
|
@@ -7784,8 +7786,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7784
7786
|
environment = googleOptions.environment;
|
|
7785
7787
|
} else {
|
|
7786
7788
|
const environmentOptions = googleOptions.environment;
|
|
7787
|
-
const sources =
|
|
7788
|
-
var _a3;
|
|
7789
|
+
const sources = environmentOptions.sources?.map((source) => {
|
|
7789
7790
|
if (source.type === "inline") {
|
|
7790
7791
|
return {
|
|
7791
7792
|
type: "inline",
|
|
@@ -7796,7 +7797,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7796
7797
|
return pruneUndefined({
|
|
7797
7798
|
type: source.type,
|
|
7798
7799
|
source: source.source,
|
|
7799
|
-
target:
|
|
7800
|
+
target: source.target ?? void 0
|
|
7800
7801
|
});
|
|
7801
7802
|
});
|
|
7802
7803
|
let network;
|
|
@@ -7805,13 +7806,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7805
7806
|
} else if (environmentOptions.network != null) {
|
|
7806
7807
|
network = {
|
|
7807
7808
|
allowlist: environmentOptions.network.allowlist.map(
|
|
7808
|
-
(entry) => {
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
7813
|
-
});
|
|
7814
|
-
}
|
|
7809
|
+
(entry) => pruneUndefined({
|
|
7810
|
+
domain: entry.domain,
|
|
7811
|
+
transform: entry.transform ?? void 0
|
|
7812
|
+
})
|
|
7815
7813
|
)
|
|
7816
7814
|
};
|
|
7817
7815
|
}
|
|
@@ -7828,25 +7826,24 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7828
7826
|
system_instruction: systemInstruction,
|
|
7829
7827
|
tools: toolsForBody,
|
|
7830
7828
|
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
7831
|
-
response_modalities:
|
|
7832
|
-
previous_interaction_id:
|
|
7833
|
-
service_tier:
|
|
7834
|
-
store:
|
|
7829
|
+
response_modalities: googleOptions?.responseModalities != null ? googleOptions.responseModalities : void 0,
|
|
7830
|
+
previous_interaction_id: googleOptions?.previousInteractionId ?? void 0,
|
|
7831
|
+
service_tier: googleOptions?.serviceTier ?? void 0,
|
|
7832
|
+
store: googleOptions?.store ?? void 0,
|
|
7835
7833
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
7836
7834
|
agent_config: agentConfig,
|
|
7837
7835
|
environment,
|
|
7838
|
-
background:
|
|
7836
|
+
background: googleOptions?.background ?? void 0
|
|
7839
7837
|
});
|
|
7840
7838
|
return {
|
|
7841
7839
|
args,
|
|
7842
7840
|
warnings,
|
|
7843
7841
|
isAgent,
|
|
7844
|
-
isBackground:
|
|
7845
|
-
pollingTimeoutMs:
|
|
7842
|
+
isBackground: googleOptions?.background === true,
|
|
7843
|
+
pollingTimeoutMs: googleOptions?.pollingTimeoutMs ?? void 0
|
|
7846
7844
|
};
|
|
7847
7845
|
}
|
|
7848
7846
|
async doGenerate(options) {
|
|
7849
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
7850
7847
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
7851
7848
|
const url = `${this.config.baseURL}/interactions`;
|
|
7852
7849
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7880,12 +7877,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7880
7877
|
});
|
|
7881
7878
|
response = polled.response;
|
|
7882
7879
|
rawResponse = polled.rawResponse;
|
|
7883
|
-
responseHeaders =
|
|
7880
|
+
responseHeaders = polled.responseHeaders ?? responseHeaders;
|
|
7884
7881
|
}
|
|
7885
7882
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7886
7883
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
7887
|
-
steps:
|
|
7888
|
-
generateId:
|
|
7884
|
+
steps: response.steps ?? null,
|
|
7885
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
7889
7886
|
interactionId
|
|
7890
7887
|
});
|
|
7891
7888
|
const finishReason = {
|
|
@@ -7895,7 +7892,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7895
7892
|
}),
|
|
7896
7893
|
raw: response.status
|
|
7897
7894
|
};
|
|
7898
|
-
const serviceTier =
|
|
7895
|
+
const serviceTier = response.service_tier ?? responseHeaders?.["x-gemini-service-tier"] ?? void 0;
|
|
7899
7896
|
const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
|
|
7900
7897
|
response.usage
|
|
7901
7898
|
);
|
|
@@ -7925,12 +7922,11 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7925
7922
|
body: rawResponse,
|
|
7926
7923
|
...interactionId != null ? { id: interactionId } : {},
|
|
7927
7924
|
...timestamp ? { timestamp } : {},
|
|
7928
|
-
modelId:
|
|
7925
|
+
modelId: response.model ?? void 0
|
|
7929
7926
|
}
|
|
7930
7927
|
};
|
|
7931
7928
|
}
|
|
7932
7929
|
async doStream(options) {
|
|
7933
|
-
var _a2;
|
|
7934
7930
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
7935
7931
|
const url = `${this.config.baseURL}/interactions`;
|
|
7936
7932
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7959,10 +7955,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7959
7955
|
abortSignal: options.abortSignal,
|
|
7960
7956
|
fetch: this.config.fetch
|
|
7961
7957
|
});
|
|
7962
|
-
const headerServiceTier = responseHeaders
|
|
7958
|
+
const headerServiceTier = responseHeaders?.["x-gemini-service-tier"];
|
|
7963
7959
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
7964
7960
|
warnings,
|
|
7965
|
-
generateId:
|
|
7961
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
7966
7962
|
includeRawChunks: options.includeRawChunks,
|
|
7967
7963
|
serviceTier: headerServiceTier
|
|
7968
7964
|
});
|
|
@@ -7998,7 +7994,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7998
7994
|
options,
|
|
7999
7995
|
pollingTimeoutMs
|
|
8000
7996
|
}) {
|
|
8001
|
-
var _a2, _b;
|
|
8002
7997
|
const postResult = await postJsonToApi6({
|
|
8003
7998
|
url,
|
|
8004
7999
|
headers: mergedHeaders,
|
|
@@ -8017,12 +8012,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8017
8012
|
"google.interactions: background POST response did not include an interaction id; cannot stream the result."
|
|
8018
8013
|
);
|
|
8019
8014
|
}
|
|
8020
|
-
const headerServiceTier = postHeaders
|
|
8015
|
+
const headerServiceTier = postHeaders?.["x-gemini-service-tier"];
|
|
8021
8016
|
if (isTerminalStatus(postResponse.status)) {
|
|
8022
8017
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
8023
8018
|
response: postResponse,
|
|
8024
8019
|
warnings,
|
|
8025
|
-
generateId:
|
|
8020
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
8026
8021
|
includeRawChunks: options.includeRawChunks,
|
|
8027
8022
|
headerServiceTier
|
|
8028
8023
|
});
|
|
@@ -8042,7 +8037,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
8042
8037
|
});
|
|
8043
8038
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
8044
8039
|
warnings,
|
|
8045
|
-
generateId:
|
|
8040
|
+
generateId: this.config.generateId ?? defaultGenerateId2,
|
|
8046
8041
|
includeRawChunks: options.includeRawChunks,
|
|
8047
8042
|
serviceTier: headerServiceTier
|
|
8048
8043
|
});
|
|
@@ -8114,17 +8109,15 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8114
8109
|
this.turnClosed = false;
|
|
8115
8110
|
}
|
|
8116
8111
|
parseServerEvent(raw) {
|
|
8117
|
-
var _a2, _b;
|
|
8118
8112
|
const data = raw;
|
|
8119
8113
|
if (data.setupComplete != null) {
|
|
8120
8114
|
return { type: "session-created", raw };
|
|
8121
8115
|
}
|
|
8122
8116
|
if (data.toolCall != null) {
|
|
8123
8117
|
this.beginTurnIfClosed();
|
|
8124
|
-
const functionCalls =
|
|
8118
|
+
const functionCalls = data.toolCall.functionCalls ?? [];
|
|
8125
8119
|
return functionCalls.flatMap((functionCall) => {
|
|
8126
|
-
|
|
8127
|
-
const args = JSON.stringify((_a3 = functionCall.args) != null ? _a3 : {});
|
|
8120
|
+
const args = JSON.stringify(functionCall.args ?? {});
|
|
8128
8121
|
return [
|
|
8129
8122
|
{
|
|
8130
8123
|
type: "function-call-arguments-delta",
|
|
@@ -8170,7 +8163,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8170
8163
|
if (data.serverContent != null) {
|
|
8171
8164
|
return this.parseServerContent(data.serverContent, raw);
|
|
8172
8165
|
}
|
|
8173
|
-
if (
|
|
8166
|
+
if (data.inputTranscription?.text != null) {
|
|
8174
8167
|
return {
|
|
8175
8168
|
type: "input-transcription-completed",
|
|
8176
8169
|
itemId: `google-input-${this.turnCounter}`,
|
|
@@ -8181,7 +8174,6 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8181
8174
|
return { type: "custom", rawType: String(Object.keys(data)[0]), raw };
|
|
8182
8175
|
}
|
|
8183
8176
|
parseServerContent(serverContent, raw) {
|
|
8184
|
-
var _a2, _b, _c, _d;
|
|
8185
8177
|
const events = [];
|
|
8186
8178
|
if (serverContent.interrupted) {
|
|
8187
8179
|
events.push({
|
|
@@ -8189,10 +8181,10 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8189
8181
|
raw
|
|
8190
8182
|
});
|
|
8191
8183
|
}
|
|
8192
|
-
if (
|
|
8184
|
+
if (serverContent.modelTurn?.parts) {
|
|
8193
8185
|
this.beginTurnIfClosed();
|
|
8194
8186
|
for (const part of serverContent.modelTurn.parts) {
|
|
8195
|
-
if (
|
|
8187
|
+
if (part.inlineData?.data) {
|
|
8196
8188
|
this.hasAudio = true;
|
|
8197
8189
|
events.push({
|
|
8198
8190
|
type: "audio-delta",
|
|
@@ -8214,7 +8206,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8214
8206
|
}
|
|
8215
8207
|
}
|
|
8216
8208
|
}
|
|
8217
|
-
if (
|
|
8209
|
+
if (serverContent.outputTranscription?.text) {
|
|
8218
8210
|
this.hasTranscript = true;
|
|
8219
8211
|
events.push({
|
|
8220
8212
|
type: "audio-transcript-delta",
|
|
@@ -8224,7 +8216,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8224
8216
|
raw
|
|
8225
8217
|
});
|
|
8226
8218
|
}
|
|
8227
|
-
if (
|
|
8219
|
+
if (serverContent.inputTranscription?.text) {
|
|
8228
8220
|
events.push({
|
|
8229
8221
|
type: "input-transcription-completed",
|
|
8230
8222
|
itemId: `google-input-${this.turnCounter}`,
|
|
@@ -8292,10 +8284,9 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8292
8284
|
return events.length === 1 ? events[0] : events;
|
|
8293
8285
|
}
|
|
8294
8286
|
serializeClientEvent(event, modelId) {
|
|
8295
|
-
var _a2;
|
|
8296
8287
|
switch (event.type) {
|
|
8297
8288
|
case "session-update":
|
|
8298
|
-
if (
|
|
8289
|
+
if (event.config.inputAudioFormat?.rate != null) {
|
|
8299
8290
|
this.inputAudioRate = event.config.inputAudioFormat.rate;
|
|
8300
8291
|
}
|
|
8301
8292
|
return {
|
|
@@ -8364,26 +8355,24 @@ async function serializeFunctionCallOutput(item) {
|
|
|
8364
8355
|
};
|
|
8365
8356
|
}
|
|
8366
8357
|
function isThinkingLiveModel(modelId) {
|
|
8367
|
-
|
|
8368
|
-
const modelName = (_b = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
8358
|
+
const modelName = modelId.split("/").at(-1)?.toLowerCase() ?? "";
|
|
8369
8359
|
return /^gemini-\d+\.\d+-live\b.*thinking/.test(modelName);
|
|
8370
8360
|
}
|
|
8371
8361
|
function buildGoogleSessionConfig(config, modelId) {
|
|
8372
|
-
var _a2, _b;
|
|
8373
8362
|
const setup = {
|
|
8374
8363
|
model: getModelPath(modelId)
|
|
8375
8364
|
};
|
|
8376
|
-
const { google: google2, ...restProviderOptions } =
|
|
8365
|
+
const { google: google2, ...restProviderOptions } = config?.providerOptions ?? {};
|
|
8377
8366
|
const googleOptions = isRecord(google2) ? google2 : void 0;
|
|
8378
8367
|
const generationConfig = {};
|
|
8379
|
-
if (
|
|
8368
|
+
if (config?.outputModalities != null) {
|
|
8380
8369
|
generationConfig.responseModalities = config.outputModalities.map(
|
|
8381
8370
|
(m) => m.toUpperCase()
|
|
8382
8371
|
);
|
|
8383
8372
|
} else {
|
|
8384
8373
|
generationConfig.responseModalities = ["AUDIO"];
|
|
8385
8374
|
}
|
|
8386
|
-
if (
|
|
8375
|
+
if (config?.voice != null) {
|
|
8387
8376
|
generationConfig.speechConfig = {
|
|
8388
8377
|
voiceConfig: {
|
|
8389
8378
|
prebuiltVoiceConfig: {
|
|
@@ -8393,41 +8382,41 @@ function buildGoogleSessionConfig(config, modelId) {
|
|
|
8393
8382
|
};
|
|
8394
8383
|
}
|
|
8395
8384
|
setup.generationConfig = generationConfig;
|
|
8396
|
-
if (
|
|
8385
|
+
if (config?.instructions != null) {
|
|
8397
8386
|
setup.systemInstruction = {
|
|
8398
8387
|
parts: [{ text: config.instructions }]
|
|
8399
8388
|
};
|
|
8400
8389
|
}
|
|
8401
|
-
if (
|
|
8390
|
+
if (config?.tools != null && config.tools.length > 0) {
|
|
8402
8391
|
setup.tools = [
|
|
8403
8392
|
{
|
|
8404
8393
|
functionDeclarations: config.tools.map((tool) => ({
|
|
8405
8394
|
name: tool.name,
|
|
8406
8395
|
description: tool.description,
|
|
8407
8396
|
parametersJsonSchema: tool.parameters,
|
|
8408
|
-
...
|
|
8397
|
+
...googleOptions?.defaultToolBehavior != null ? { behavior: googleOptions.defaultToolBehavior } : {}
|
|
8409
8398
|
}))
|
|
8410
8399
|
}
|
|
8411
8400
|
];
|
|
8412
8401
|
}
|
|
8413
|
-
if (
|
|
8402
|
+
if (config?.inputAudioTranscription != null) {
|
|
8414
8403
|
setup.inputAudioTranscription = {};
|
|
8415
8404
|
}
|
|
8416
|
-
if (
|
|
8405
|
+
if (config?.outputAudioTranscription != null) {
|
|
8417
8406
|
setup.outputAudioTranscription = {};
|
|
8418
8407
|
}
|
|
8419
|
-
const thinkingConfig =
|
|
8408
|
+
const thinkingConfig = googleOptions?.thinkingConfig ?? (isThinkingLiveModel(modelId) ? { thinkingLevel: "low" } : void 0);
|
|
8420
8409
|
const applyThinkingConfig = () => {
|
|
8421
8410
|
if (thinkingConfig == null) return;
|
|
8422
8411
|
const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
|
|
8423
8412
|
setup.generationConfig = { ...target, thinkingConfig };
|
|
8424
8413
|
};
|
|
8425
|
-
if (
|
|
8414
|
+
if (config?.providerOptions == null) {
|
|
8426
8415
|
applyThinkingConfig();
|
|
8427
8416
|
return setup;
|
|
8428
8417
|
}
|
|
8429
8418
|
Object.assign(setup, restProviderOptions);
|
|
8430
|
-
if (
|
|
8419
|
+
if (googleOptions?.translationConfig != null) {
|
|
8431
8420
|
const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
|
|
8432
8421
|
setup.generationConfig = {
|
|
8433
8422
|
...target,
|
|
@@ -8457,8 +8446,7 @@ var GoogleRealtimeModel = class {
|
|
|
8457
8446
|
this.config = config;
|
|
8458
8447
|
}
|
|
8459
8448
|
async doCreateClientSecret(options) {
|
|
8460
|
-
|
|
8461
|
-
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
8449
|
+
const fetchFn = this.config.fetch ?? fetch;
|
|
8462
8450
|
const headers = this.config.headers();
|
|
8463
8451
|
const apiKey = headers["x-goog-api-key"];
|
|
8464
8452
|
if (!apiKey) {
|
|
@@ -8467,7 +8455,7 @@ var GoogleRealtimeModel = class {
|
|
|
8467
8455
|
);
|
|
8468
8456
|
}
|
|
8469
8457
|
const now = Date.now();
|
|
8470
|
-
const openWindowMs = (
|
|
8458
|
+
const openWindowMs = (options.expiresAfterSeconds ?? 60) * 1e3;
|
|
8471
8459
|
const newSessionExpireTime = new Date(now + openWindowMs).toISOString();
|
|
8472
8460
|
const expireTime = new Date(
|
|
8473
8461
|
now + openWindowMs + 30 * 60 * 1e3
|
|
@@ -8611,14 +8599,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8611
8599
|
});
|
|
8612
8600
|
}
|
|
8613
8601
|
async doGenerate(options) {
|
|
8614
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
8615
8602
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
8616
8603
|
throw new InvalidArgumentError3({
|
|
8617
8604
|
argument: "modelId",
|
|
8618
8605
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
8619
8606
|
});
|
|
8620
8607
|
}
|
|
8621
|
-
const currentDate =
|
|
8608
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
8622
8609
|
const warnings = [];
|
|
8623
8610
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8624
8611
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -8653,11 +8640,11 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8653
8640
|
});
|
|
8654
8641
|
let text = "";
|
|
8655
8642
|
const segments = [];
|
|
8656
|
-
for (const step of
|
|
8657
|
-
for (const content of
|
|
8643
|
+
for (const step of response.steps ?? []) {
|
|
8644
|
+
for (const content of step.content ?? []) {
|
|
8658
8645
|
if (content.type !== "text" || content.text == null) continue;
|
|
8659
8646
|
text += content.text;
|
|
8660
|
-
for (const annotation of
|
|
8647
|
+
for (const annotation of content.annotations ?? []) {
|
|
8661
8648
|
if (annotation.type !== "word_info") continue;
|
|
8662
8649
|
const startSecond = parseOffsetSeconds(annotation.start_offset);
|
|
8663
8650
|
const endSecond = parseOffsetSeconds(annotation.end_offset);
|
|
@@ -8688,14 +8675,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8688
8675
|
};
|
|
8689
8676
|
}
|
|
8690
8677
|
async doStream(options) {
|
|
8691
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
8692
8678
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
8693
8679
|
throw new InvalidArgumentError3({
|
|
8694
8680
|
argument: "modelId",
|
|
8695
8681
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
8696
8682
|
});
|
|
8697
8683
|
}
|
|
8698
|
-
const currentDate =
|
|
8684
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
8699
8685
|
const warnings = [];
|
|
8700
8686
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8701
8687
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -8721,7 +8707,7 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8721
8707
|
);
|
|
8722
8708
|
const setup = {
|
|
8723
8709
|
model: getModelPath(this.modelId),
|
|
8724
|
-
inputAudioTranscription:
|
|
8710
|
+
inputAudioTranscription: buildAudioTranscriptionConfig(googleOptions) ?? {}
|
|
8725
8711
|
};
|
|
8726
8712
|
return {
|
|
8727
8713
|
request: { body: setup },
|
|
@@ -8734,8 +8720,8 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8734
8720
|
url: getLiveWebSocketURL(this.config.baseURL, apiKey),
|
|
8735
8721
|
headers: webSocketHeaders,
|
|
8736
8722
|
setup,
|
|
8737
|
-
inputAudioRate:
|
|
8738
|
-
finishGraceMs:
|
|
8723
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
8724
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
|
|
8739
8725
|
warnings,
|
|
8740
8726
|
audio: options.audio,
|
|
8741
8727
|
abortSignal: options.abortSignal,
|
|
@@ -8799,7 +8785,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8799
8785
|
void audio.cancel().catch(() => {
|
|
8800
8786
|
});
|
|
8801
8787
|
}
|
|
8802
|
-
connection
|
|
8788
|
+
connection?.close(closeCode);
|
|
8803
8789
|
};
|
|
8804
8790
|
const finishWithError = (error) => {
|
|
8805
8791
|
if (finished) return;
|
|
@@ -8880,7 +8866,6 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8880
8866
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
8881
8867
|
},
|
|
8882
8868
|
onMessageText: async (text) => {
|
|
8883
|
-
var _a2, _b;
|
|
8884
8869
|
if (finished) return;
|
|
8885
8870
|
const parsed = await safeParseJSON2({ text });
|
|
8886
8871
|
if (!parsed.success) return;
|
|
@@ -8896,13 +8881,13 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8896
8881
|
}
|
|
8897
8882
|
if (message.error != null) {
|
|
8898
8883
|
finishWithError(
|
|
8899
|
-
new Error(
|
|
8884
|
+
new Error(message.error.message ?? "Google Live API error")
|
|
8900
8885
|
);
|
|
8901
8886
|
return;
|
|
8902
8887
|
}
|
|
8903
8888
|
const serverContent = message.serverContent;
|
|
8904
|
-
const interim = serverContent
|
|
8905
|
-
if (interim
|
|
8889
|
+
const interim = serverContent?.interimInputTranscription;
|
|
8890
|
+
if (interim?.text) {
|
|
8906
8891
|
schedulePendingFinish();
|
|
8907
8892
|
latestInterim = interim.text;
|
|
8908
8893
|
controller.enqueue({
|
|
@@ -8911,7 +8896,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8911
8896
|
text: interim.text
|
|
8912
8897
|
});
|
|
8913
8898
|
}
|
|
8914
|
-
const transcription =
|
|
8899
|
+
const transcription = serverContent?.inputTranscription ?? message.inputTranscription;
|
|
8915
8900
|
if (transcription != null) {
|
|
8916
8901
|
if (transcription.languageCode != null) {
|
|
8917
8902
|
language = transcription.languageCode;
|
|
@@ -8930,11 +8915,11 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8930
8915
|
completeSegment();
|
|
8931
8916
|
}
|
|
8932
8917
|
}
|
|
8933
|
-
if (serverContent
|
|
8918
|
+
if (serverContent?.turnComplete) {
|
|
8934
8919
|
completeSegment();
|
|
8935
8920
|
}
|
|
8936
|
-
const interactionStatus = serverContent
|
|
8937
|
-
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" ||
|
|
8921
|
+
const interactionStatus = serverContent?.interactionStatus;
|
|
8922
|
+
if (audioEnded && (interactionStatus === "IDLE" || interactionStatus === "REQUIRES_ACTION" || serverContent?.turnComplete === true && interactionStatus == null)) {
|
|
8938
8923
|
finish();
|
|
8939
8924
|
}
|
|
8940
8925
|
},
|
|
@@ -8949,7 +8934,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8949
8934
|
}
|
|
8950
8935
|
finishWithError(
|
|
8951
8936
|
new Error(
|
|
8952
|
-
`Google Live transcription WebSocket closed unexpectedly before finishing (code ${code
|
|
8937
|
+
`Google Live transcription WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
8953
8938
|
)
|
|
8954
8939
|
);
|
|
8955
8940
|
}
|
|
@@ -8983,7 +8968,6 @@ function buildAudioTranscriptionConfig(options) {
|
|
|
8983
8968
|
return Object.keys(config).length > 0 ? config : void 0;
|
|
8984
8969
|
}
|
|
8985
8970
|
function buildTranscriptionConfig(options) {
|
|
8986
|
-
var _a2;
|
|
8987
8971
|
if (options == null) return void 0;
|
|
8988
8972
|
const config = {};
|
|
8989
8973
|
if (options.languageCodes != null) {
|
|
@@ -8994,7 +8978,7 @@ function buildTranscriptionConfig(options) {
|
|
|
8994
8978
|
}
|
|
8995
8979
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
8996
8980
|
config.mode = {
|
|
8997
|
-
type: (
|
|
8981
|
+
type: (options.mode ?? "VERBATIM").toLowerCase(),
|
|
8998
8982
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
8999
8983
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
9000
8984
|
};
|
|
@@ -9102,14 +9086,13 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
9102
9086
|
return this.config.provider;
|
|
9103
9087
|
}
|
|
9104
9088
|
async doStream(options) {
|
|
9105
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
9106
9089
|
if (options.targetLanguage == null) {
|
|
9107
9090
|
throw new InvalidArgumentError4({
|
|
9108
9091
|
argument: "targetLanguage",
|
|
9109
9092
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
9110
9093
|
});
|
|
9111
9094
|
}
|
|
9112
|
-
const currentDate =
|
|
9095
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
9113
9096
|
const googleOptions = await parseProviderOptions10({
|
|
9114
9097
|
provider: "google",
|
|
9115
9098
|
providerOptions: options.providerOptions,
|
|
@@ -9164,8 +9147,8 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
9164
9147
|
url: getLiveWebSocketURL2(this.config.baseURL, apiKey),
|
|
9165
9148
|
headers: webSocketHeaders,
|
|
9166
9149
|
setup,
|
|
9167
|
-
inputAudioRate:
|
|
9168
|
-
finishGraceMs:
|
|
9150
|
+
inputAudioRate: options.inputAudioFormat.rate ?? 16e3,
|
|
9151
|
+
finishGraceMs: this.config._internal?.finishGraceMs ?? defaultFinishGraceMs2,
|
|
9169
9152
|
warnings,
|
|
9170
9153
|
audio: options.audio,
|
|
9171
9154
|
abortSignal: options.abortSignal,
|
|
@@ -9236,7 +9219,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9236
9219
|
void audio.cancel().catch(() => {
|
|
9237
9220
|
});
|
|
9238
9221
|
}
|
|
9239
|
-
connection
|
|
9222
|
+
connection?.close(closeCode);
|
|
9240
9223
|
};
|
|
9241
9224
|
const finishWithError = (error) => {
|
|
9242
9225
|
if (finished) return;
|
|
@@ -9325,7 +9308,6 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9325
9308
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
9326
9309
|
},
|
|
9327
9310
|
onMessageText: async (text) => {
|
|
9328
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9329
9311
|
if (finished) return;
|
|
9330
9312
|
const parsed = await safeParseJSON3({ text });
|
|
9331
9313
|
if (!parsed.success) return;
|
|
@@ -9341,11 +9323,11 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9341
9323
|
}
|
|
9342
9324
|
if (message.error != null) {
|
|
9343
9325
|
finishWithError(
|
|
9344
|
-
new Error(
|
|
9326
|
+
new Error(message.error.message ?? "Google Live API error")
|
|
9345
9327
|
);
|
|
9346
9328
|
return;
|
|
9347
9329
|
}
|
|
9348
|
-
const inputTranscriptionText =
|
|
9330
|
+
const inputTranscriptionText = message.serverContent?.inputTranscription?.text ?? message.inputTranscription?.text;
|
|
9349
9331
|
if (inputTranscriptionText) {
|
|
9350
9332
|
onTurnActivity();
|
|
9351
9333
|
sourceTurnBuffer += inputTranscriptionText;
|
|
@@ -9359,8 +9341,8 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9359
9341
|
if (serverContent == null) {
|
|
9360
9342
|
return;
|
|
9361
9343
|
}
|
|
9362
|
-
for (const part of
|
|
9363
|
-
if (
|
|
9344
|
+
for (const part of serverContent.modelTurn?.parts ?? []) {
|
|
9345
|
+
if (part.inlineData?.data) {
|
|
9364
9346
|
controller.enqueue({
|
|
9365
9347
|
type: "audio",
|
|
9366
9348
|
id: itemId(),
|
|
@@ -9380,7 +9362,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9380
9362
|
}
|
|
9381
9363
|
}
|
|
9382
9364
|
}
|
|
9383
|
-
if (
|
|
9365
|
+
if (serverContent.outputTranscription?.text) {
|
|
9384
9366
|
onTurnActivity();
|
|
9385
9367
|
translationTurnBuffer += serverContent.outputTranscription.text;
|
|
9386
9368
|
controller.enqueue({
|
|
@@ -9409,7 +9391,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9409
9391
|
}
|
|
9410
9392
|
finishWithError(
|
|
9411
9393
|
new Error(
|
|
9412
|
-
`Google Live translation WebSocket closed unexpectedly before finishing (code ${code
|
|
9394
|
+
`Google Live translation WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
9413
9395
|
)
|
|
9414
9396
|
);
|
|
9415
9397
|
}
|
|
@@ -9423,17 +9405,16 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9423
9405
|
});
|
|
9424
9406
|
}
|
|
9425
9407
|
function accumulateGoogleLiveUsage(usage, usageMetadata) {
|
|
9426
|
-
|
|
9427
|
-
let
|
|
9428
|
-
|
|
9429
|
-
for (const detail of (_a2 = usageMetadata.promptTokensDetails) != null ? _a2 : []) {
|
|
9408
|
+
let inputAudioTokens = usage?.inputAudioTokens;
|
|
9409
|
+
let outputAudioTokens = usage?.outputAudioTokens;
|
|
9410
|
+
for (const detail of usageMetadata.promptTokensDetails ?? []) {
|
|
9430
9411
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9431
|
-
inputAudioTokens = (inputAudioTokens
|
|
9412
|
+
inputAudioTokens = (inputAudioTokens ?? 0) + detail.tokenCount;
|
|
9432
9413
|
}
|
|
9433
9414
|
}
|
|
9434
|
-
for (const detail of
|
|
9415
|
+
for (const detail of usageMetadata.responseTokensDetails ?? []) {
|
|
9435
9416
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9436
|
-
outputAudioTokens = (outputAudioTokens
|
|
9417
|
+
outputAudioTokens = (outputAudioTokens ?? 0) + detail.tokenCount;
|
|
9437
9418
|
}
|
|
9438
9419
|
}
|
|
9439
9420
|
if (inputAudioTokens == null && outputAudioTokens == null) {
|
|
@@ -9449,7 +9430,7 @@ function getPcm16SilenceDurationMs(audio) {
|
|
|
9449
9430
|
let bytes;
|
|
9450
9431
|
try {
|
|
9451
9432
|
bytes = convertBase64ToUint8Array2(audio);
|
|
9452
|
-
} catch
|
|
9433
|
+
} catch {
|
|
9453
9434
|
return void 0;
|
|
9454
9435
|
}
|
|
9455
9436
|
if (bytes.byteLength < 2) {
|
|
@@ -9475,7 +9456,7 @@ function buildGoogleLiveSpeechTranslationSetup({
|
|
|
9475
9456
|
responseModalities: ["AUDIO"],
|
|
9476
9457
|
translationConfig: {
|
|
9477
9458
|
targetLanguageCode: targetLanguage,
|
|
9478
|
-
...
|
|
9459
|
+
...providerOptions?.echoTargetLanguage != null ? { echoTargetLanguage: providerOptions.echoTargetLanguage } : {}
|
|
9479
9460
|
}
|
|
9480
9461
|
},
|
|
9481
9462
|
inputAudioTranscription: {},
|
|
@@ -9523,9 +9504,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
9523
9504
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
9524
9505
|
}
|
|
9525
9506
|
function createGoogle(options = {}) {
|
|
9526
|
-
|
|
9527
|
-
const
|
|
9528
|
-
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
9507
|
+
const baseURL = withoutTrailingSlash(options.baseURL) ?? DEFAULT_BASE_URL;
|
|
9508
|
+
const providerName = options.name ?? "google.generative-ai";
|
|
9529
9509
|
const getHeaders = () => withUserAgentSuffix2(
|
|
9530
9510
|
{
|
|
9531
9511
|
"x-goog-api-key": loadApiKey({
|
|
@@ -9557,7 +9537,7 @@ function createGoogle(options = {}) {
|
|
|
9557
9537
|
provider: providerName,
|
|
9558
9538
|
baseURL,
|
|
9559
9539
|
headers: getHeaders,
|
|
9560
|
-
generateId:
|
|
9540
|
+
generateId: options.generateId ?? generateId3,
|
|
9561
9541
|
fetch: options.fetch
|
|
9562
9542
|
};
|
|
9563
9543
|
const createChatModel = (modelId) => new GoogleLanguageModel(modelId, {
|
|
@@ -9589,16 +9569,13 @@ function createGoogle(options = {}) {
|
|
|
9589
9569
|
headers: getHeaders,
|
|
9590
9570
|
fetch: options.fetch
|
|
9591
9571
|
});
|
|
9592
|
-
const createVideoModel = (modelId) => {
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3
|
|
9600
|
-
});
|
|
9601
|
-
};
|
|
9572
|
+
const createVideoModel = (modelId) => new GoogleVideoModel(modelId, {
|
|
9573
|
+
provider: providerName,
|
|
9574
|
+
baseURL,
|
|
9575
|
+
headers: getHeaders,
|
|
9576
|
+
fetch: options.fetch,
|
|
9577
|
+
generateId: options.generateId ?? generateId3
|
|
9578
|
+
});
|
|
9602
9579
|
const createRealtimeModel = (modelId) => new GoogleRealtimeModel(modelId, {
|
|
9603
9580
|
provider: `${providerName}.realtime`,
|
|
9604
9581
|
baseURL,
|
|
@@ -9641,19 +9618,16 @@ function createGoogle(options = {}) {
|
|
|
9641
9618
|
}
|
|
9642
9619
|
}
|
|
9643
9620
|
);
|
|
9644
|
-
const createInteractionsModel = (modelIdOrAgent) =>
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
}
|
|
9655
|
-
);
|
|
9656
|
-
};
|
|
9621
|
+
const createInteractionsModel = (modelIdOrAgent) => new GoogleInteractionsLanguageModel(
|
|
9622
|
+
modelIdOrAgent,
|
|
9623
|
+
{
|
|
9624
|
+
provider: `${providerName}.interactions`,
|
|
9625
|
+
baseURL,
|
|
9626
|
+
headers: getHeaders,
|
|
9627
|
+
generateId: options.generateId ?? generateId3,
|
|
9628
|
+
fetch: options.fetch
|
|
9629
|
+
}
|
|
9630
|
+
);
|
|
9657
9631
|
const provider = function(modelId) {
|
|
9658
9632
|
if (new.target) {
|
|
9659
9633
|
throw new Error(
|