@ai-sdk/amazon-bedrock 4.0.22 → 4.0.24
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 +15 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +33 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -368,6 +368,20 @@ import {
|
|
|
368
368
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
369
369
|
} from "@ai-sdk/provider";
|
|
370
370
|
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
371
|
+
|
|
372
|
+
// src/normalize-tool-call-id.ts
|
|
373
|
+
function isMistralModel(modelId) {
|
|
374
|
+
return modelId.includes("mistral.");
|
|
375
|
+
}
|
|
376
|
+
function normalizeToolCallId(toolCallId, isMistral) {
|
|
377
|
+
if (!isMistral) {
|
|
378
|
+
return toolCallId;
|
|
379
|
+
}
|
|
380
|
+
const alphanumericChars = toolCallId.replace(/[^a-zA-Z0-9]/g, "");
|
|
381
|
+
return alphanumericChars.slice(0, 9);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/convert-to-bedrock-chat-messages.ts
|
|
371
385
|
function getCachePoint(providerMetadata) {
|
|
372
386
|
var _a;
|
|
373
387
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
@@ -381,7 +395,7 @@ async function shouldEnableCitations(providerMetadata) {
|
|
|
381
395
|
});
|
|
382
396
|
return (_b = (_a = bedrockOptions == null ? void 0 : bedrockOptions.citations) == null ? void 0 : _a.enabled) != null ? _b : false;
|
|
383
397
|
}
|
|
384
|
-
async function convertToBedrockChatMessages(prompt) {
|
|
398
|
+
async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
385
399
|
var _a, _b;
|
|
386
400
|
const blocks = groupIntoBlocks(prompt);
|
|
387
401
|
let system = [];
|
|
@@ -518,7 +532,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
518
532
|
}
|
|
519
533
|
bedrockContent.push({
|
|
520
534
|
toolResult: {
|
|
521
|
-
toolUseId: part.toolCallId,
|
|
535
|
+
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
522
536
|
content: toolResultContent
|
|
523
537
|
}
|
|
524
538
|
});
|
|
@@ -605,7 +619,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
605
619
|
case "tool-call": {
|
|
606
620
|
bedrockContent.push({
|
|
607
621
|
toolUse: {
|
|
608
|
-
toolUseId: part.toolCallId,
|
|
622
|
+
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
609
623
|
name: part.toolName,
|
|
610
624
|
input: part.input
|
|
611
625
|
}
|
|
@@ -929,7 +943,11 @@ var BedrockChatLanguageModel = class {
|
|
|
929
943
|
});
|
|
930
944
|
}
|
|
931
945
|
}
|
|
932
|
-
const
|
|
946
|
+
const isMistral = isMistralModel(this.modelId);
|
|
947
|
+
const { system, messages } = await convertToBedrockChatMessages(
|
|
948
|
+
filteredPrompt,
|
|
949
|
+
isMistral
|
|
950
|
+
);
|
|
933
951
|
const {
|
|
934
952
|
reasoningConfig: _,
|
|
935
953
|
additionalModelRequestFields: __,
|
|
@@ -1026,9 +1044,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1026
1044
|
text: JSON.stringify(part.toolUse.input)
|
|
1027
1045
|
});
|
|
1028
1046
|
} else {
|
|
1047
|
+
const isMistral = isMistralModel(this.modelId);
|
|
1048
|
+
const rawToolCallId = (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId();
|
|
1029
1049
|
content.push({
|
|
1030
1050
|
type: "tool-call",
|
|
1031
|
-
toolCallId: (
|
|
1051
|
+
toolCallId: normalizeToolCallId(rawToolCallId, isMistral),
|
|
1032
1052
|
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
1033
1053
|
input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : {})
|
|
1034
1054
|
});
|
|
@@ -1072,6 +1092,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1072
1092
|
warnings,
|
|
1073
1093
|
usesJsonResponseTool
|
|
1074
1094
|
} = await this.getArgs(options);
|
|
1095
|
+
const isMistral = isMistralModel(this.modelId);
|
|
1075
1096
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
1076
1097
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1077
1098
|
url,
|
|
@@ -1275,9 +1296,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1275
1296
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1276
1297
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1277
1298
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
1299
|
+
const normalizedToolCallId = normalizeToolCallId(
|
|
1300
|
+
toolUse.toolUseId,
|
|
1301
|
+
isMistral
|
|
1302
|
+
);
|
|
1278
1303
|
contentBlocks[blockIndex] = {
|
|
1279
1304
|
type: "tool-call",
|
|
1280
|
-
toolCallId:
|
|
1305
|
+
toolCallId: normalizedToolCallId,
|
|
1281
1306
|
toolName: toolUse.name,
|
|
1282
1307
|
jsonText: "",
|
|
1283
1308
|
isJsonResponseTool
|
|
@@ -1285,7 +1310,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1285
1310
|
if (!isJsonResponseTool) {
|
|
1286
1311
|
controller.enqueue({
|
|
1287
1312
|
type: "tool-input-start",
|
|
1288
|
-
id:
|
|
1313
|
+
id: normalizedToolCallId,
|
|
1289
1314
|
toolName: toolUse.name
|
|
1290
1315
|
});
|
|
1291
1316
|
}
|
|
@@ -1773,7 +1798,7 @@ import {
|
|
|
1773
1798
|
import { AwsV4Signer } from "aws4fetch";
|
|
1774
1799
|
|
|
1775
1800
|
// src/version.ts
|
|
1776
|
-
var VERSION = true ? "4.0.
|
|
1801
|
+
var VERSION = true ? "4.0.24" : "0.0.0-test";
|
|
1777
1802
|
|
|
1778
1803
|
// src/bedrock-sigv4-fetch.ts
|
|
1779
1804
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|