@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 4.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d5466df: fix(amazon-bedrock): normalize tool call IDs for Mistral models
|
|
8
|
+
|
|
9
|
+
Mistral models on Bedrock require tool call IDs to match exactly 9 alphanumeric characters. This fix normalizes Bedrock-generated tool call IDs when using Mistral models to prevent validation errors during multi-turn tool calling.
|
|
10
|
+
|
|
11
|
+
## 4.0.23
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [c10bd49]
|
|
16
|
+
- @ai-sdk/anthropic@3.0.18
|
|
17
|
+
|
|
3
18
|
## 4.0.22
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/anthropic/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "4.0.
|
|
38
|
+
var VERSION = true ? "4.0.24" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
package/dist/anthropic/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { AwsV4Signer } from "aws4fetch";
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = true ? "4.0.
|
|
27
|
+
var VERSION = true ? "4.0.24" : "0.0.0-test";
|
|
28
28
|
|
|
29
29
|
// src/bedrock-sigv4-fetch.ts
|
|
30
30
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
package/dist/index.js
CHANGED
|
@@ -372,6 +372,20 @@ function convertBedrockUsage(usage) {
|
|
|
372
372
|
// src/convert-to-bedrock-chat-messages.ts
|
|
373
373
|
var import_provider3 = require("@ai-sdk/provider");
|
|
374
374
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
375
|
+
|
|
376
|
+
// src/normalize-tool-call-id.ts
|
|
377
|
+
function isMistralModel(modelId) {
|
|
378
|
+
return modelId.includes("mistral.");
|
|
379
|
+
}
|
|
380
|
+
function normalizeToolCallId(toolCallId, isMistral) {
|
|
381
|
+
if (!isMistral) {
|
|
382
|
+
return toolCallId;
|
|
383
|
+
}
|
|
384
|
+
const alphanumericChars = toolCallId.replace(/[^a-zA-Z0-9]/g, "");
|
|
385
|
+
return alphanumericChars.slice(0, 9);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/convert-to-bedrock-chat-messages.ts
|
|
375
389
|
function getCachePoint(providerMetadata) {
|
|
376
390
|
var _a;
|
|
377
391
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
@@ -385,7 +399,7 @@ async function shouldEnableCitations(providerMetadata) {
|
|
|
385
399
|
});
|
|
386
400
|
return (_b = (_a = bedrockOptions == null ? void 0 : bedrockOptions.citations) == null ? void 0 : _a.enabled) != null ? _b : false;
|
|
387
401
|
}
|
|
388
|
-
async function convertToBedrockChatMessages(prompt) {
|
|
402
|
+
async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
389
403
|
var _a, _b;
|
|
390
404
|
const blocks = groupIntoBlocks(prompt);
|
|
391
405
|
let system = [];
|
|
@@ -522,7 +536,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
522
536
|
}
|
|
523
537
|
bedrockContent.push({
|
|
524
538
|
toolResult: {
|
|
525
|
-
toolUseId: part.toolCallId,
|
|
539
|
+
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
526
540
|
content: toolResultContent
|
|
527
541
|
}
|
|
528
542
|
});
|
|
@@ -609,7 +623,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
609
623
|
case "tool-call": {
|
|
610
624
|
bedrockContent.push({
|
|
611
625
|
toolUse: {
|
|
612
|
-
toolUseId: part.toolCallId,
|
|
626
|
+
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
613
627
|
name: part.toolName,
|
|
614
628
|
input: part.input
|
|
615
629
|
}
|
|
@@ -933,7 +947,11 @@ var BedrockChatLanguageModel = class {
|
|
|
933
947
|
});
|
|
934
948
|
}
|
|
935
949
|
}
|
|
936
|
-
const
|
|
950
|
+
const isMistral = isMistralModel(this.modelId);
|
|
951
|
+
const { system, messages } = await convertToBedrockChatMessages(
|
|
952
|
+
filteredPrompt,
|
|
953
|
+
isMistral
|
|
954
|
+
);
|
|
937
955
|
const {
|
|
938
956
|
reasoningConfig: _,
|
|
939
957
|
additionalModelRequestFields: __,
|
|
@@ -1030,9 +1048,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1030
1048
|
text: JSON.stringify(part.toolUse.input)
|
|
1031
1049
|
});
|
|
1032
1050
|
} else {
|
|
1051
|
+
const isMistral = isMistralModel(this.modelId);
|
|
1052
|
+
const rawToolCallId = (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId();
|
|
1033
1053
|
content.push({
|
|
1034
1054
|
type: "tool-call",
|
|
1035
|
-
toolCallId: (
|
|
1055
|
+
toolCallId: normalizeToolCallId(rawToolCallId, isMistral),
|
|
1036
1056
|
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
1037
1057
|
input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : {})
|
|
1038
1058
|
});
|
|
@@ -1076,6 +1096,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1076
1096
|
warnings,
|
|
1077
1097
|
usesJsonResponseTool
|
|
1078
1098
|
} = await this.getArgs(options);
|
|
1099
|
+
const isMistral = isMistralModel(this.modelId);
|
|
1079
1100
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
1080
1101
|
const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1081
1102
|
url,
|
|
@@ -1279,9 +1300,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1279
1300
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1280
1301
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1281
1302
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
1303
|
+
const normalizedToolCallId = normalizeToolCallId(
|
|
1304
|
+
toolUse.toolUseId,
|
|
1305
|
+
isMistral
|
|
1306
|
+
);
|
|
1282
1307
|
contentBlocks[blockIndex] = {
|
|
1283
1308
|
type: "tool-call",
|
|
1284
|
-
toolCallId:
|
|
1309
|
+
toolCallId: normalizedToolCallId,
|
|
1285
1310
|
toolName: toolUse.name,
|
|
1286
1311
|
jsonText: "",
|
|
1287
1312
|
isJsonResponseTool
|
|
@@ -1289,7 +1314,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1289
1314
|
if (!isJsonResponseTool) {
|
|
1290
1315
|
controller.enqueue({
|
|
1291
1316
|
type: "tool-input-start",
|
|
1292
|
-
id:
|
|
1317
|
+
id: normalizedToolCallId,
|
|
1293
1318
|
toolName: toolUse.name
|
|
1294
1319
|
});
|
|
1295
1320
|
}
|
|
@@ -1756,7 +1781,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
1756
1781
|
var import_aws4fetch = require("aws4fetch");
|
|
1757
1782
|
|
|
1758
1783
|
// src/version.ts
|
|
1759
|
-
var VERSION = true ? "4.0.
|
|
1784
|
+
var VERSION = true ? "4.0.24" : "0.0.0-test";
|
|
1760
1785
|
|
|
1761
1786
|
// src/bedrock-sigv4-fetch.ts
|
|
1762
1787
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|