@ai-sdk/google 3.0.127 → 3.0.128
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 +9 -0
- package/dist/index.js +230 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -20
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +198 -105
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +118 -17
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +34 -12
- package/src/download-tool-result-files.ts +103 -0
- package/src/google-generative-ai-language-model.ts +22 -1
- package/src/google-generative-ai-prompt.ts +7 -3
package/dist/index.mjs
CHANGED
|
@@ -224,7 +224,7 @@ import {
|
|
|
224
224
|
} from "@ai-sdk/provider-utils";
|
|
225
225
|
|
|
226
226
|
// src/version.ts
|
|
227
|
-
var VERSION = true ? "3.0.
|
|
227
|
+
var VERSION = true ? "3.0.128" : "0.0.0-test";
|
|
228
228
|
|
|
229
229
|
// src/google-generative-ai-embedding-model.ts
|
|
230
230
|
import {
|
|
@@ -788,7 +788,11 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
788
788
|
import {
|
|
789
789
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
790
790
|
} from "@ai-sdk/provider";
|
|
791
|
-
import {
|
|
791
|
+
import {
|
|
792
|
+
convertToBase64 as convertToBase642,
|
|
793
|
+
isUrlSupported,
|
|
794
|
+
secureJsonParse
|
|
795
|
+
} from "@ai-sdk/provider-utils";
|
|
792
796
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
793
797
|
function getGoogleProviderOptions(providerOptions, providerOptionsName) {
|
|
794
798
|
const namespaces = [
|
|
@@ -817,19 +821,28 @@ function parseBase64DataUrl(value) {
|
|
|
817
821
|
data: match[2]
|
|
818
822
|
};
|
|
819
823
|
}
|
|
820
|
-
function convertUrlToolResultPart(url) {
|
|
824
|
+
function convertUrlToolResultPart(url, mediaType, supportedFunctionResponseUrls) {
|
|
821
825
|
const parsedDataUrl = parseBase64DataUrl(url);
|
|
822
|
-
if (parsedDataUrl
|
|
823
|
-
return
|
|
826
|
+
if (parsedDataUrl != null) {
|
|
827
|
+
return {
|
|
828
|
+
inlineData: {
|
|
829
|
+
mimeType: parsedDataUrl.mediaType,
|
|
830
|
+
data: parsedDataUrl.data
|
|
831
|
+
}
|
|
832
|
+
};
|
|
824
833
|
}
|
|
825
|
-
return {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
834
|
+
return mediaType != null && isUrlSupported({
|
|
835
|
+
url,
|
|
836
|
+
mediaType,
|
|
837
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
838
|
+
}) ? {
|
|
839
|
+
fileData: {
|
|
840
|
+
mimeType: mediaType,
|
|
841
|
+
fileUri: url
|
|
829
842
|
}
|
|
830
|
-
};
|
|
843
|
+
} : void 0;
|
|
831
844
|
}
|
|
832
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
845
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedFunctionResponseUrls = {}) {
|
|
833
846
|
const functionResponseParts = [];
|
|
834
847
|
const responseTextParts = [];
|
|
835
848
|
for (const contentPart of outputValue) {
|
|
@@ -851,7 +864,9 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
|
|
|
851
864
|
case "image-url":
|
|
852
865
|
case "file-url": {
|
|
853
866
|
const functionResponsePart = convertUrlToolResultPart(
|
|
854
|
-
contentPart.url
|
|
867
|
+
contentPart.url,
|
|
868
|
+
contentPart.mediaType,
|
|
869
|
+
supportedFunctionResponseUrls
|
|
855
870
|
);
|
|
856
871
|
if (functionResponsePart != null) {
|
|
857
872
|
functionResponseParts.push(functionResponsePart);
|
|
@@ -916,7 +931,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
916
931
|
}
|
|
917
932
|
}
|
|
918
933
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
919
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
934
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
920
935
|
const systemInstructionParts = [];
|
|
921
936
|
const contents = [];
|
|
922
937
|
let systemMessagesAllowed = true;
|
|
@@ -926,6 +941,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
926
941
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
927
942
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
928
943
|
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
944
|
+
const supportedFunctionResponseUrls = (_f = options == null ? void 0 : options.supportedFunctionResponseUrls) != null ? _f : {};
|
|
929
945
|
let sentinelInjected = false;
|
|
930
946
|
const missingSignatureToolNames = [];
|
|
931
947
|
const injectSkipSignature = (toolName) => {
|
|
@@ -1107,7 +1123,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1107
1123
|
part.toolName,
|
|
1108
1124
|
output.value,
|
|
1109
1125
|
part.toolCallId,
|
|
1110
|
-
includeFunctionCallIds
|
|
1126
|
+
includeFunctionCallIds,
|
|
1127
|
+
supportedFunctionResponseUrls
|
|
1111
1128
|
);
|
|
1112
1129
|
} else {
|
|
1113
1130
|
appendLegacyToolResultParts(
|
|
@@ -1125,7 +1142,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1125
1142
|
name: part.toolName,
|
|
1126
1143
|
response: {
|
|
1127
1144
|
name: part.toolName,
|
|
1128
|
-
content: output.type === "execution-denied" ? (
|
|
1145
|
+
content: output.type === "execution-denied" ? (_g = output.reason) != null ? _g : "Tool call execution denied." : output.value
|
|
1129
1146
|
}
|
|
1130
1147
|
}
|
|
1131
1148
|
});
|
|
@@ -1156,6 +1173,76 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1156
1173
|
};
|
|
1157
1174
|
}
|
|
1158
1175
|
|
|
1176
|
+
// src/download-tool-result-files.ts
|
|
1177
|
+
import {
|
|
1178
|
+
convertUint8ArrayToBase64,
|
|
1179
|
+
downloadBlob,
|
|
1180
|
+
isUrlSupported as isUrlSupported2
|
|
1181
|
+
} from "@ai-sdk/provider-utils";
|
|
1182
|
+
async function downloadToolResultFiles(prompt, {
|
|
1183
|
+
abortSignal,
|
|
1184
|
+
supportedUrls = {}
|
|
1185
|
+
}) {
|
|
1186
|
+
async function downloadOutput(output) {
|
|
1187
|
+
if (output.type !== "content") {
|
|
1188
|
+
return output;
|
|
1189
|
+
}
|
|
1190
|
+
return {
|
|
1191
|
+
...output,
|
|
1192
|
+
value: await Promise.all(
|
|
1193
|
+
output.value.map(async (part) => {
|
|
1194
|
+
var _a2;
|
|
1195
|
+
if (part.type !== "file-url" && part.type !== "image-url") {
|
|
1196
|
+
return part;
|
|
1197
|
+
}
|
|
1198
|
+
if (part.type === "file-url" && part.mediaType != null && isUrlSupported2({
|
|
1199
|
+
url: part.url,
|
|
1200
|
+
mediaType: part.mediaType,
|
|
1201
|
+
supportedUrls
|
|
1202
|
+
})) {
|
|
1203
|
+
return part;
|
|
1204
|
+
}
|
|
1205
|
+
const blob = await downloadBlob(part.url, { abortSignal });
|
|
1206
|
+
return {
|
|
1207
|
+
type: part.type === "file-url" ? "file-data" : "image-data",
|
|
1208
|
+
data: convertUint8ArrayToBase64(
|
|
1209
|
+
new Uint8Array(await blob.arrayBuffer())
|
|
1210
|
+
),
|
|
1211
|
+
mediaType: blob.type || (part.type === "file-url" ? (_a2 = part.mediaType) != null ? _a2 : "application/octet-stream" : "image/*"),
|
|
1212
|
+
providerOptions: part.providerOptions
|
|
1213
|
+
};
|
|
1214
|
+
})
|
|
1215
|
+
)
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
return Promise.all(
|
|
1219
|
+
prompt.map(async (message) => {
|
|
1220
|
+
switch (message.role) {
|
|
1221
|
+
case "assistant":
|
|
1222
|
+
return {
|
|
1223
|
+
...message,
|
|
1224
|
+
content: await Promise.all(
|
|
1225
|
+
message.content.map(
|
|
1226
|
+
async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
|
|
1227
|
+
)
|
|
1228
|
+
)
|
|
1229
|
+
};
|
|
1230
|
+
case "tool":
|
|
1231
|
+
return {
|
|
1232
|
+
...message,
|
|
1233
|
+
content: await Promise.all(
|
|
1234
|
+
message.content.map(
|
|
1235
|
+
async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
|
|
1236
|
+
)
|
|
1237
|
+
)
|
|
1238
|
+
};
|
|
1239
|
+
default:
|
|
1240
|
+
return message;
|
|
1241
|
+
}
|
|
1242
|
+
})
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1159
1246
|
// src/get-model-path.ts
|
|
1160
1247
|
function getModelPath(modelId) {
|
|
1161
1248
|
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
@@ -1904,6 +1991,13 @@ var configurableSafetySettingCategories = [
|
|
|
1904
1991
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1905
1992
|
];
|
|
1906
1993
|
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1994
|
+
var googleCloudStorageFunctionResponseUrls = {
|
|
1995
|
+
"image/png": [/^gs:\/\/.*$/],
|
|
1996
|
+
"image/jpeg": [/^gs:\/\/.*$/],
|
|
1997
|
+
"image/webp": [/^gs:\/\/.*$/],
|
|
1998
|
+
"application/pdf": [/^gs:\/\/.*$/],
|
|
1999
|
+
"text/plain": [/^gs:\/\/.*$/]
|
|
2000
|
+
};
|
|
1907
2001
|
var GoogleGenerativeAILanguageModel = class {
|
|
1908
2002
|
constructor(modelId, config) {
|
|
1909
2003
|
this.specificationVersion = "v3";
|
|
@@ -1932,7 +2026,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1932
2026
|
seed,
|
|
1933
2027
|
tools,
|
|
1934
2028
|
toolChoice,
|
|
1935
|
-
providerOptions
|
|
2029
|
+
providerOptions,
|
|
2030
|
+
abortSignal
|
|
1936
2031
|
}, { isStreaming = false } = {}) {
|
|
1937
2032
|
var _a2, _b, _c;
|
|
1938
2033
|
const warnings = [];
|
|
@@ -2021,15 +2116,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2021
2116
|
});
|
|
2022
2117
|
}
|
|
2023
2118
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
2119
|
+
const supportedFunctionResponseUrls = usesGemini3Features && isVertexProvider ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
2120
|
+
const promptWithDownloadedToolResultFiles = isVertexProvider ? await downloadToolResultFiles(prompt, {
|
|
2121
|
+
abortSignal,
|
|
2122
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
2123
|
+
}) : prompt;
|
|
2024
2124
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
2025
|
-
|
|
2125
|
+
promptWithDownloadedToolResultFiles,
|
|
2026
2126
|
{
|
|
2027
2127
|
isGemmaModel,
|
|
2028
2128
|
isGemini3Model: usesGemini3Features,
|
|
2029
2129
|
providerOptionsName,
|
|
2030
2130
|
supportsFunctionResponseParts: usesGemini3Features,
|
|
2031
2131
|
onWarning: (warning) => warnings.push(warning),
|
|
2032
|
-
includeFunctionCallIds: !isVertexProvider
|
|
2132
|
+
includeFunctionCallIds: !isVertexProvider,
|
|
2133
|
+
supportedFunctionResponseUrls
|
|
2033
2134
|
}
|
|
2034
2135
|
);
|
|
2035
2136
|
const {
|
|
@@ -3515,7 +3616,7 @@ import {
|
|
|
3515
3616
|
} from "@ai-sdk/provider";
|
|
3516
3617
|
import {
|
|
3517
3618
|
combineHeaders as combineHeaders5,
|
|
3518
|
-
convertUint8ArrayToBase64,
|
|
3619
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
3519
3620
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3520
3621
|
delay,
|
|
3521
3622
|
getFromApi,
|
|
@@ -3560,7 +3661,7 @@ function convertFileToGoogleImage(file, warnings) {
|
|
|
3560
3661
|
});
|
|
3561
3662
|
return void 0;
|
|
3562
3663
|
}
|
|
3563
|
-
const base64Data = typeof file.data === "string" ? file.data :
|
|
3664
|
+
const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase642(file.data);
|
|
3564
3665
|
return {
|
|
3565
3666
|
bytesBase64Encoded: base64Data,
|
|
3566
3667
|
mimeType: file.mediaType || "image/png"
|