@ai-sdk/amazon-bedrock 5.0.93 → 5.0.96
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 +33 -0
- package/README.md +3 -3
- package/dist/anthropic/index.js +24 -29
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.js +223 -187
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +23 -30
- package/dist/mantle/index.cjs.map +1 -1
- package/dist/mantle/index.js +23 -30
- package/dist/mantle/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +7 -7
- package/package.json +5 -5
- package/src/amazon-bedrock-chat-language-model.ts +29 -10
- package/src/amazon-bedrock-prepare-tools.ts +49 -12
- package/src/normalize-tool-call-id.ts +37 -4
package/dist/index.js
CHANGED
|
@@ -198,7 +198,6 @@ function createAmazonBedrockEventStreamDecoder(body, processEvent) {
|
|
|
198
198
|
return body.pipeThrough(
|
|
199
199
|
new TransformStream({
|
|
200
200
|
async transform(chunk, controller) {
|
|
201
|
-
var _a, _b, _c;
|
|
202
201
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
203
202
|
newBuffer.set(buffer);
|
|
204
203
|
newBuffer.set(chunk, buffer.length);
|
|
@@ -215,9 +214,9 @@ function createAmazonBedrockEventStreamDecoder(body, processEvent) {
|
|
|
215
214
|
const subView = buffer.subarray(0, totalLength);
|
|
216
215
|
const decoded = codec.decode(subView);
|
|
217
216
|
buffer = buffer.slice(totalLength);
|
|
218
|
-
const messageType =
|
|
219
|
-
const eventType =
|
|
220
|
-
const exceptionType =
|
|
217
|
+
const messageType = decoded.headers[":message-type"]?.value;
|
|
218
|
+
const eventType = decoded.headers[":event-type"]?.value;
|
|
219
|
+
const exceptionType = decoded.headers[":exception-type"]?.value;
|
|
221
220
|
const data = textDecoder.decode(decoded.body);
|
|
222
221
|
await processEvent(
|
|
223
222
|
{ messageType, eventType, exceptionType, data },
|
|
@@ -316,9 +315,9 @@ async function prepareTools({
|
|
|
316
315
|
modelId,
|
|
317
316
|
modelFamily,
|
|
318
317
|
reasoningBudgetTokens,
|
|
319
|
-
disableParallelToolUse
|
|
318
|
+
disableParallelToolUse,
|
|
319
|
+
rejectsForcedToolUse = false
|
|
320
320
|
}) {
|
|
321
|
-
var _a;
|
|
322
321
|
const toolWarnings = [];
|
|
323
322
|
const betas = /* @__PURE__ */ new Set();
|
|
324
323
|
if (tools == null || tools.length === 0) {
|
|
@@ -353,22 +352,25 @@ async function prepareTools({
|
|
|
353
352
|
modelFamily,
|
|
354
353
|
reasoningBudgetTokens
|
|
355
354
|
});
|
|
356
|
-
const
|
|
355
|
+
const providerTools = supportedTools.filter((t) => t.type === "provider");
|
|
357
356
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
357
|
+
const rejectsForcedToolChoice = isAnthropicModel2 && rejectsForcedToolUse && (toolChoice?.type === "required" || toolChoice?.type === "tool");
|
|
358
|
+
const providerToolsForRequest = rejectsForcedToolChoice && toolChoice.type === "tool" ? providerTools.filter((tool) => tool.name === toolChoice.toolName) : providerTools;
|
|
358
359
|
let additionalTools = void 0;
|
|
359
360
|
const amazonBedrockTools = [];
|
|
360
|
-
const usingAnthropicTools = isAnthropicModel2 &&
|
|
361
|
+
const usingAnthropicTools = isAnthropicModel2 && providerToolsForRequest.length > 0;
|
|
361
362
|
if (usingAnthropicTools) {
|
|
362
363
|
const {
|
|
363
364
|
toolChoice: preparedAnthropicToolChoice,
|
|
364
365
|
toolWarnings: anthropicToolWarnings,
|
|
365
366
|
betas: anthropicBetas
|
|
366
367
|
} = await prepareAnthropicTools({
|
|
367
|
-
tools:
|
|
368
|
+
tools: providerTools,
|
|
368
369
|
toolChoice,
|
|
369
370
|
disableParallelToolUse,
|
|
370
371
|
supportsStructuredOutput: false,
|
|
371
|
-
supportsStrictTools: false
|
|
372
|
+
supportsStrictTools: false,
|
|
373
|
+
rejectsForcedToolUse
|
|
372
374
|
});
|
|
373
375
|
toolWarnings.push(...anthropicToolWarnings);
|
|
374
376
|
anthropicBetas.forEach((beta) => betas.add(beta));
|
|
@@ -377,7 +379,7 @@ async function prepareTools({
|
|
|
377
379
|
tool_choice: preparedAnthropicToolChoice
|
|
378
380
|
};
|
|
379
381
|
}
|
|
380
|
-
for (const tool of
|
|
382
|
+
for (const tool of providerToolsForRequest) {
|
|
381
383
|
const toolFactory = Object.values(anthropicTools).find((factory) => {
|
|
382
384
|
const instance = factory({});
|
|
383
385
|
return instance.id === tool.id;
|
|
@@ -397,11 +399,28 @@ async function prepareTools({
|
|
|
397
399
|
}
|
|
398
400
|
}
|
|
399
401
|
} else {
|
|
400
|
-
for (const tool of
|
|
402
|
+
for (const tool of providerToolsForRequest) {
|
|
401
403
|
toolWarnings.push({ type: "unsupported", feature: `tool ${tool.id}` });
|
|
402
404
|
}
|
|
403
405
|
}
|
|
404
|
-
|
|
406
|
+
let preparedToolChoice = toolChoice;
|
|
407
|
+
if (!usingAnthropicTools && rejectsForcedToolChoice) {
|
|
408
|
+
if (toolChoice.type === "tool") {
|
|
409
|
+
toolWarnings.push({
|
|
410
|
+
type: "unsupported",
|
|
411
|
+
feature: "toolChoice",
|
|
412
|
+
details: `toolChoice 'tool' is not supported by this model because it rejects forced tool use. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
|
|
413
|
+
});
|
|
414
|
+
} else {
|
|
415
|
+
toolWarnings.push({
|
|
416
|
+
type: "unsupported",
|
|
417
|
+
feature: "toolChoice",
|
|
418
|
+
details: `toolChoice 'required' is not supported by this model because it rejects forced tool use. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made.`
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
preparedToolChoice = { type: "auto" };
|
|
422
|
+
}
|
|
423
|
+
const filteredFunctionTools = toolChoice?.type === "tool" ? functionTools.filter((t) => t.name === toolChoice.toolName) : functionTools;
|
|
405
424
|
const supportsStrictOnTools = supportsStrictTools(modelId);
|
|
406
425
|
for (const tool of filteredFunctionTools) {
|
|
407
426
|
const supportsStrictForTool = supportsStrictOnTools && (tool.strict !== true || isStrictToolSchemaCompatible(tool.inputSchema));
|
|
@@ -421,7 +440,7 @@ async function prepareTools({
|
|
|
421
440
|
amazonBedrockTools.push({
|
|
422
441
|
toolSpec: {
|
|
423
442
|
name: tool.name,
|
|
424
|
-
...
|
|
443
|
+
...tool.description?.trim() !== "" ? { description: tool.description } : {},
|
|
425
444
|
...tool.strict != null && supportsStrictForTool ? { strict: tool.strict } : {},
|
|
426
445
|
inputSchema: {
|
|
427
446
|
json: tool.inputSchema
|
|
@@ -429,18 +448,18 @@ async function prepareTools({
|
|
|
429
448
|
}
|
|
430
449
|
});
|
|
431
450
|
}
|
|
432
|
-
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && amazonBedrockTools.length > 0 &&
|
|
451
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && amazonBedrockTools.length > 0 && preparedToolChoice?.type !== "none") {
|
|
433
452
|
additionalTools = {
|
|
434
|
-
tool_choice:
|
|
453
|
+
tool_choice: preparedToolChoice?.type === "required" ? { type: "any", disable_parallel_tool_use: true } : preparedToolChoice?.type === "tool" ? {
|
|
435
454
|
type: "tool",
|
|
436
|
-
name:
|
|
455
|
+
name: preparedToolChoice.toolName,
|
|
437
456
|
disable_parallel_tool_use: true
|
|
438
457
|
} : { type: "auto", disable_parallel_tool_use: true }
|
|
439
458
|
};
|
|
440
459
|
}
|
|
441
460
|
let amazonBedrockToolChoice = void 0;
|
|
442
|
-
if (!usingAnthropicTools &&
|
|
443
|
-
const type =
|
|
461
|
+
if (!usingAnthropicTools && additionalTools?.tool_choice == null && amazonBedrockTools.length > 0 && preparedToolChoice) {
|
|
462
|
+
const type = preparedToolChoice.type;
|
|
444
463
|
switch (type) {
|
|
445
464
|
case "auto":
|
|
446
465
|
amazonBedrockToolChoice = { auto: {} };
|
|
@@ -453,7 +472,9 @@ async function prepareTools({
|
|
|
453
472
|
amazonBedrockToolChoice = void 0;
|
|
454
473
|
break;
|
|
455
474
|
case "tool":
|
|
456
|
-
amazonBedrockToolChoice = {
|
|
475
|
+
amazonBedrockToolChoice = {
|
|
476
|
+
tool: { name: preparedToolChoice.toolName }
|
|
477
|
+
};
|
|
457
478
|
break;
|
|
458
479
|
default: {
|
|
459
480
|
const _exhaustiveCheck = type;
|
|
@@ -521,14 +542,13 @@ function isStrictToolSchemaCompatible(schema) {
|
|
|
521
542
|
// src/convert-amazon-bedrock-usage.ts
|
|
522
543
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
523
544
|
function convertAmazonBedrockUsage(usage) {
|
|
524
|
-
var _a, _b;
|
|
525
545
|
if (usage == null) {
|
|
526
546
|
return createNullLanguageModelUsage();
|
|
527
547
|
}
|
|
528
548
|
const inputTokens = usage.inputTokens;
|
|
529
549
|
const outputTokens = usage.outputTokens;
|
|
530
|
-
const cacheReadTokens =
|
|
531
|
-
const cacheWriteTokens =
|
|
550
|
+
const cacheReadTokens = usage.cacheReadInputTokens ?? 0;
|
|
551
|
+
const cacheWriteTokens = usage.cacheWriteInputTokens ?? 0;
|
|
532
552
|
return {
|
|
533
553
|
inputTokens: {
|
|
534
554
|
total: inputTokens + cacheReadTokens + cacheWriteTokens,
|
|
@@ -574,14 +594,36 @@ function normalizeToolCallId(toolCallId, isMistral) {
|
|
|
574
594
|
if (!isMistral) {
|
|
575
595
|
return toolCallId;
|
|
576
596
|
}
|
|
577
|
-
|
|
578
|
-
|
|
597
|
+
if (/^[a-zA-Z0-9]{9}$/.test(toolCallId)) {
|
|
598
|
+
return toolCallId;
|
|
599
|
+
}
|
|
600
|
+
return convertToBase62Hash(toolCallId);
|
|
601
|
+
}
|
|
602
|
+
var base62Characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
603
|
+
var base62Length = BigInt(base62Characters.length);
|
|
604
|
+
var normalizedToolCallIdLength = 9;
|
|
605
|
+
var normalizedToolCallIdSpace = base62Length ** BigInt(normalizedToolCallIdLength);
|
|
606
|
+
var fnvOffsetBasis64 = BigInt("14695981039346656037");
|
|
607
|
+
var fnvPrime64 = BigInt("1099511628211");
|
|
608
|
+
var fnv64BitMask = BigInt("18446744073709551615");
|
|
609
|
+
function convertToBase62Hash(value) {
|
|
610
|
+
let hash = fnvOffsetBasis64;
|
|
611
|
+
for (let i = 0; i < value.length; i++) {
|
|
612
|
+
hash ^= BigInt(value.charCodeAt(i));
|
|
613
|
+
hash = hash * fnvPrime64 & fnv64BitMask;
|
|
614
|
+
}
|
|
615
|
+
let base62Value = hash % normalizedToolCallIdSpace;
|
|
616
|
+
let result = "";
|
|
617
|
+
for (let i = 0; i < normalizedToolCallIdLength; i++) {
|
|
618
|
+
result = base62Characters[Number(base62Value % base62Length)] + result;
|
|
619
|
+
base62Value /= base62Length;
|
|
620
|
+
}
|
|
621
|
+
return result;
|
|
579
622
|
}
|
|
580
623
|
|
|
581
624
|
// src/convert-to-amazon-bedrock-chat-messages.ts
|
|
582
625
|
function getCachePoint(providerMetadata) {
|
|
583
|
-
|
|
584
|
-
const cachePointConfig = (_c = (_a = providerMetadata == null ? void 0 : providerMetadata.amazonBedrock) == null ? void 0 : _a.cachePoint) != null ? _c : (_b = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _b.cachePoint;
|
|
626
|
+
const cachePointConfig = providerMetadata?.amazonBedrock?.cachePoint ?? providerMetadata?.bedrock?.cachePoint;
|
|
585
627
|
if (!cachePointConfig) {
|
|
586
628
|
return void 0;
|
|
587
629
|
}
|
|
@@ -618,44 +660,40 @@ function getAmazonBedrockMediaSource({
|
|
|
618
660
|
}
|
|
619
661
|
}
|
|
620
662
|
async function shouldEnableCitations(providerMetadata) {
|
|
621
|
-
|
|
622
|
-
const amazonBedrockOptions = (_a = await parseProviderOptions({
|
|
663
|
+
const amazonBedrockOptions = await parseProviderOptions({
|
|
623
664
|
provider: "amazonBedrock",
|
|
624
665
|
providerOptions: providerMetadata,
|
|
625
666
|
schema: amazonBedrockFilePartProviderOptions
|
|
626
|
-
})
|
|
667
|
+
}) ?? await parseProviderOptions({
|
|
627
668
|
provider: "bedrock",
|
|
628
669
|
providerOptions: providerMetadata,
|
|
629
670
|
schema: amazonBedrockFilePartProviderOptions
|
|
630
671
|
});
|
|
631
|
-
return
|
|
672
|
+
return amazonBedrockOptions?.citations?.enabled ?? false;
|
|
632
673
|
}
|
|
633
674
|
async function getTextPartGuardContentOptions(providerMetadata) {
|
|
634
|
-
|
|
635
|
-
return (_a = await parseProviderOptions({
|
|
675
|
+
return await parseProviderOptions({
|
|
636
676
|
provider: "amazonBedrock",
|
|
637
677
|
providerOptions: providerMetadata,
|
|
638
678
|
schema: amazonBedrockTextPartProviderOptions
|
|
639
|
-
})
|
|
679
|
+
}) ?? await parseProviderOptions({
|
|
640
680
|
provider: "bedrock",
|
|
641
681
|
providerOptions: providerMetadata,
|
|
642
682
|
schema: amazonBedrockTextPartProviderOptions
|
|
643
683
|
});
|
|
644
684
|
}
|
|
645
685
|
async function getImagePartGuardContentOptions(providerMetadata) {
|
|
646
|
-
|
|
647
|
-
return (_a = await parseProviderOptions({
|
|
686
|
+
return await parseProviderOptions({
|
|
648
687
|
provider: "amazonBedrock",
|
|
649
688
|
providerOptions: providerMetadata,
|
|
650
689
|
schema: amazonBedrockImagePartProviderOptions
|
|
651
|
-
})
|
|
690
|
+
}) ?? await parseProviderOptions({
|
|
652
691
|
provider: "bedrock",
|
|
653
692
|
providerOptions: providerMetadata,
|
|
654
693
|
schema: amazonBedrockImagePartProviderOptions
|
|
655
694
|
});
|
|
656
695
|
}
|
|
657
696
|
async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
658
|
-
var _a, _b;
|
|
659
697
|
const blocks = groupIntoBlocks(prompt);
|
|
660
698
|
let system = [];
|
|
661
699
|
const messages = [];
|
|
@@ -695,7 +733,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
695
733
|
const textOptions = await getTextPartGuardContentOptions(
|
|
696
734
|
part.providerOptions
|
|
697
735
|
);
|
|
698
|
-
if (textOptions
|
|
736
|
+
if (textOptions?.guardContent) {
|
|
699
737
|
amazonBedrockContent.push({
|
|
700
738
|
guardContent: {
|
|
701
739
|
text: {
|
|
@@ -795,7 +833,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
795
833
|
})
|
|
796
834
|
}
|
|
797
835
|
};
|
|
798
|
-
if (imageOptions
|
|
836
|
+
if (imageOptions?.guardContent) {
|
|
799
837
|
amazonBedrockContent.push({
|
|
800
838
|
guardContent: imageBlock
|
|
801
839
|
});
|
|
@@ -921,16 +959,16 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
921
959
|
break;
|
|
922
960
|
}
|
|
923
961
|
case "reasoning": {
|
|
924
|
-
const reasoningMetadata =
|
|
962
|
+
const reasoningMetadata = await parseProviderOptions({
|
|
925
963
|
provider: "amazonBedrock",
|
|
926
964
|
providerOptions: part.providerOptions,
|
|
927
965
|
schema: amazonBedrockReasoningMetadataSchema
|
|
928
|
-
})
|
|
966
|
+
}) ?? await parseProviderOptions({
|
|
929
967
|
provider: "bedrock",
|
|
930
968
|
providerOptions: part.providerOptions,
|
|
931
969
|
schema: amazonBedrockReasoningMetadataSchema
|
|
932
970
|
});
|
|
933
|
-
if (
|
|
971
|
+
if (reasoningMetadata?.signature != null) {
|
|
934
972
|
assistantContent.push({
|
|
935
973
|
reasoningContent: {
|
|
936
974
|
reasoningText: {
|
|
@@ -939,13 +977,13 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
939
977
|
}
|
|
940
978
|
}
|
|
941
979
|
});
|
|
942
|
-
} else if (
|
|
980
|
+
} else if (reasoningMetadata?.redactedContent != null) {
|
|
943
981
|
assistantContent.push({
|
|
944
982
|
reasoningContent: {
|
|
945
983
|
redactedContent: reasoningMetadata.redactedContent
|
|
946
984
|
}
|
|
947
985
|
});
|
|
948
|
-
} else if (
|
|
986
|
+
} else if (reasoningMetadata?.redactedData != null) {
|
|
949
987
|
assistantContent.push({
|
|
950
988
|
reasoningContent: {
|
|
951
989
|
redactedReasoning: {
|
|
@@ -986,7 +1024,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
986
1024
|
);
|
|
987
1025
|
}
|
|
988
1026
|
pushCachePoint(
|
|
989
|
-
|
|
1027
|
+
content[content.length - 1]?.type === "tool-result" ? toolResultContent : assistantContent,
|
|
990
1028
|
message.providerOptions
|
|
991
1029
|
);
|
|
992
1030
|
}
|
|
@@ -1004,7 +1042,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
1004
1042
|
}
|
|
1005
1043
|
function appendToUserMessage(messages, content) {
|
|
1006
1044
|
const lastMessage = messages[messages.length - 1];
|
|
1007
|
-
if (
|
|
1045
|
+
if (lastMessage?.role === "user" && lastMessage.content.some((block) => "toolResult" in block)) {
|
|
1008
1046
|
lastMessage.content.push(...content);
|
|
1009
1047
|
} else {
|
|
1010
1048
|
messages.push({ role: "user", content });
|
|
@@ -1014,7 +1052,6 @@ async function convertToolResultOutput({
|
|
|
1014
1052
|
output,
|
|
1015
1053
|
getDocumentName
|
|
1016
1054
|
}) {
|
|
1017
|
-
var _a;
|
|
1018
1055
|
switch (output.type) {
|
|
1019
1056
|
case "content": {
|
|
1020
1057
|
return Promise.all(
|
|
@@ -1086,7 +1123,7 @@ async function convertToolResultOutput({
|
|
|
1086
1123
|
case "error-text":
|
|
1087
1124
|
return [{ text: output.value }];
|
|
1088
1125
|
case "execution-denied":
|
|
1089
|
-
return [{ text:
|
|
1126
|
+
return [{ text: output.reason ?? "Tool call execution denied." }];
|
|
1090
1127
|
case "json":
|
|
1091
1128
|
case "error-json":
|
|
1092
1129
|
default:
|
|
@@ -1136,7 +1173,7 @@ function groupIntoBlocks(prompt) {
|
|
|
1136
1173
|
const { role } = message;
|
|
1137
1174
|
switch (role) {
|
|
1138
1175
|
case "system": {
|
|
1139
|
-
if (
|
|
1176
|
+
if (currentBlock?.type !== "system") {
|
|
1140
1177
|
currentBlock = { type: "system", messages: [] };
|
|
1141
1178
|
blocks.push(currentBlock);
|
|
1142
1179
|
}
|
|
@@ -1144,7 +1181,7 @@ function groupIntoBlocks(prompt) {
|
|
|
1144
1181
|
break;
|
|
1145
1182
|
}
|
|
1146
1183
|
case "assistant": {
|
|
1147
|
-
if (
|
|
1184
|
+
if (currentBlock?.type !== "assistant") {
|
|
1148
1185
|
currentBlock = { type: "assistant", messages: [] };
|
|
1149
1186
|
blocks.push(currentBlock);
|
|
1150
1187
|
}
|
|
@@ -1152,7 +1189,7 @@ function groupIntoBlocks(prompt) {
|
|
|
1152
1189
|
break;
|
|
1153
1190
|
}
|
|
1154
1191
|
case "user": {
|
|
1155
|
-
if (
|
|
1192
|
+
if (currentBlock?.type !== "user") {
|
|
1156
1193
|
currentBlock = { type: "user", messages: [] };
|
|
1157
1194
|
blocks.push(currentBlock);
|
|
1158
1195
|
}
|
|
@@ -1160,7 +1197,7 @@ function groupIntoBlocks(prompt) {
|
|
|
1160
1197
|
break;
|
|
1161
1198
|
}
|
|
1162
1199
|
case "tool": {
|
|
1163
|
-
if (
|
|
1200
|
+
if (currentBlock?.type !== "user") {
|
|
1164
1201
|
currentBlock = { type: "user", messages: [] };
|
|
1165
1202
|
blocks.push(currentBlock);
|
|
1166
1203
|
}
|
|
@@ -1248,16 +1285,15 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1248
1285
|
reasoning,
|
|
1249
1286
|
providerOptions
|
|
1250
1287
|
}) {
|
|
1251
|
-
|
|
1252
|
-
let amazonBedrockOptions = (_b = (_a = await parseProviderOptions2({
|
|
1288
|
+
let amazonBedrockOptions = await parseProviderOptions2({
|
|
1253
1289
|
provider: "amazonBedrock",
|
|
1254
1290
|
providerOptions,
|
|
1255
1291
|
schema: amazonBedrockLanguageModelChatOptions
|
|
1256
|
-
})
|
|
1292
|
+
}) ?? await parseProviderOptions2({
|
|
1257
1293
|
provider: "bedrock",
|
|
1258
1294
|
providerOptions,
|
|
1259
1295
|
schema: amazonBedrockLanguageModelChatOptions
|
|
1260
|
-
})
|
|
1296
|
+
}) ?? {};
|
|
1261
1297
|
const anthropicOptions = await parseProviderOptions2({
|
|
1262
1298
|
provider: "anthropic",
|
|
1263
1299
|
providerOptions,
|
|
@@ -1313,9 +1349,9 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1313
1349
|
topP = void 0;
|
|
1314
1350
|
}
|
|
1315
1351
|
}
|
|
1316
|
-
const openAIModelId =
|
|
1352
|
+
const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
|
|
1317
1353
|
const isOpenAIModel = openAIModelId != null;
|
|
1318
|
-
const isOpenAIGptOssModel =
|
|
1354
|
+
const isOpenAIGptOssModel = openAIModelId?.startsWith("openai.gpt-oss-") ?? false;
|
|
1319
1355
|
const shouldNormalizeTemperature = !isOpenAIModel || isOpenAIGptOssModel;
|
|
1320
1356
|
if (shouldNormalizeTemperature && temperature != null && temperature > 1) {
|
|
1321
1357
|
warnings.push({
|
|
@@ -1342,17 +1378,18 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1342
1378
|
const isAnthropicModel2 = isAnthropicModel({
|
|
1343
1379
|
modelId: this.modelId,
|
|
1344
1380
|
modelFamily: this.config.modelFamily,
|
|
1345
|
-
reasoningBudgetTokens:
|
|
1381
|
+
reasoningBudgetTokens: amazonBedrockOptions.reasoningConfig?.budgetTokens
|
|
1346
1382
|
});
|
|
1347
1383
|
amazonBedrockOptions = resolveAmazonBedrockReasoningConfig({
|
|
1348
1384
|
reasoning,
|
|
1349
1385
|
amazonBedrockOptions,
|
|
1350
1386
|
warnings,
|
|
1351
1387
|
isAnthropicModel: isAnthropicModel2,
|
|
1388
|
+
isOpenAIModel,
|
|
1352
1389
|
modelId: this.modelId
|
|
1353
1390
|
});
|
|
1354
|
-
const isThinkingEnabled =
|
|
1355
|
-
const structuredOutputMode =
|
|
1391
|
+
const isThinkingEnabled = amazonBedrockOptions.reasoningConfig?.type === "enabled" || amazonBedrockOptions.reasoningConfig?.type === "adaptive";
|
|
1392
|
+
const structuredOutputMode = amazonBedrockOptions.structuredOutputMode ?? anthropicOptions?.structuredOutputMode ?? "auto";
|
|
1356
1393
|
if (structuredOutputMode === "jsonTool") {
|
|
1357
1394
|
const additionalModelRequestFields = {
|
|
1358
1395
|
...amazonBedrockOptions.additionalModelRequestFields
|
|
@@ -1373,21 +1410,22 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1373
1410
|
}
|
|
1374
1411
|
}
|
|
1375
1412
|
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled || this.config.modelFamily === "anthropic");
|
|
1376
|
-
const useNativeStructuredOutput = isAnthropicModel2 &&
|
|
1377
|
-
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && isAnthropicModel2 &&
|
|
1378
|
-
const jsonResponseTool =
|
|
1413
|
+
const useNativeStructuredOutput = isAnthropicModel2 && responseFormat?.type === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
1414
|
+
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && isAnthropicModel2 && responseFormat?.type === "json" && responseFormat.schema != null && (rejectsForcedToolUse || structuredOutputMode !== "jsonTool" && !supportsStrictTools(this.modelId) && tools != null && tools.length > 0);
|
|
1415
|
+
const jsonResponseTool = responseFormat?.type === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1379
1416
|
type: "function",
|
|
1380
1417
|
name: "json",
|
|
1381
1418
|
description: "Respond with a JSON object.",
|
|
1382
1419
|
inputSchema: responseFormat.schema
|
|
1383
1420
|
} : void 0;
|
|
1384
1421
|
const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
|
|
1385
|
-
tools: jsonResponseTool ? [...tools
|
|
1422
|
+
tools: jsonResponseTool ? [...tools ?? [], jsonResponseTool] : tools,
|
|
1386
1423
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
1387
1424
|
modelId: this.modelId,
|
|
1388
1425
|
modelFamily: this.config.modelFamily,
|
|
1389
|
-
reasoningBudgetTokens:
|
|
1390
|
-
disableParallelToolUse: anthropicOptions
|
|
1426
|
+
reasoningBudgetTokens: amazonBedrockOptions.reasoningConfig?.budgetTokens,
|
|
1427
|
+
disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
|
|
1428
|
+
rejectsForcedToolUse
|
|
1391
1429
|
});
|
|
1392
1430
|
warnings.push(...toolWarnings);
|
|
1393
1431
|
if (additionalTools) {
|
|
@@ -1397,16 +1435,16 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1397
1435
|
};
|
|
1398
1436
|
}
|
|
1399
1437
|
if (betas.size > 0 || amazonBedrockOptions.anthropicBeta) {
|
|
1400
|
-
const existingBetas =
|
|
1438
|
+
const existingBetas = amazonBedrockOptions.anthropicBeta ?? [];
|
|
1401
1439
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1402
1440
|
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1403
1441
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1404
1442
|
anthropic_beta: mergedBetas
|
|
1405
1443
|
};
|
|
1406
1444
|
}
|
|
1407
|
-
const thinkingType =
|
|
1408
|
-
const thinkingBudget = thinkingType === "enabled" ?
|
|
1409
|
-
const thinkingDisplay = thinkingType === "adaptive" ?
|
|
1445
|
+
const thinkingType = amazonBedrockOptions.reasoningConfig?.type;
|
|
1446
|
+
const thinkingBudget = thinkingType === "enabled" ? amazonBedrockOptions.reasoningConfig?.budgetTokens : void 0;
|
|
1447
|
+
const thinkingDisplay = thinkingType === "adaptive" ? amazonBedrockOptions.reasoningConfig?.display : void 0;
|
|
1410
1448
|
const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingEnabled;
|
|
1411
1449
|
const inferenceConfig = {
|
|
1412
1450
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -1439,7 +1477,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1439
1477
|
};
|
|
1440
1478
|
}
|
|
1441
1479
|
} else if (!isAnthropicModel2) {
|
|
1442
|
-
if (
|
|
1480
|
+
if (amazonBedrockOptions.reasoningConfig?.budgetTokens != null) {
|
|
1443
1481
|
warnings.push({
|
|
1444
1482
|
type: "unsupported",
|
|
1445
1483
|
feature: "budgetTokens",
|
|
@@ -1454,13 +1492,13 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1454
1492
|
});
|
|
1455
1493
|
}
|
|
1456
1494
|
}
|
|
1457
|
-
const maxReasoningEffort =
|
|
1495
|
+
const maxReasoningEffort = amazonBedrockOptions.reasoningConfig?.maxReasoningEffort;
|
|
1458
1496
|
if (maxReasoningEffort != null) {
|
|
1459
1497
|
if (isAnthropicModel2) {
|
|
1460
1498
|
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1461
1499
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1462
1500
|
output_config: {
|
|
1463
|
-
...
|
|
1501
|
+
...amazonBedrockOptions.additionalModelRequestFields?.output_config,
|
|
1464
1502
|
effort: maxReasoningEffort
|
|
1465
1503
|
}
|
|
1466
1504
|
};
|
|
@@ -1471,7 +1509,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1471
1509
|
} : {
|
|
1472
1510
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1473
1511
|
reasoning: {
|
|
1474
|
-
...
|
|
1512
|
+
...amazonBedrockOptions.additionalModelRequestFields?.reasoning,
|
|
1475
1513
|
effort: maxReasoningEffort
|
|
1476
1514
|
}
|
|
1477
1515
|
};
|
|
@@ -1490,7 +1528,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1490
1528
|
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1491
1529
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1492
1530
|
output_config: {
|
|
1493
|
-
...
|
|
1531
|
+
...amazonBedrockOptions.additionalModelRequestFields?.output_config,
|
|
1494
1532
|
format: {
|
|
1495
1533
|
type: "json_schema",
|
|
1496
1534
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1535,7 +1573,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1535
1573
|
}
|
|
1536
1574
|
}
|
|
1537
1575
|
}
|
|
1538
|
-
const hasAnyTools = (
|
|
1576
|
+
const hasAnyTools = (toolConfig.tools?.length ?? 0) > 0 || additionalTools;
|
|
1539
1577
|
let filteredPrompt = prompt;
|
|
1540
1578
|
if (!hasAnyTools) {
|
|
1541
1579
|
const hasToolContent = prompt.some(
|
|
@@ -1579,7 +1617,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1579
1617
|
serviceTier: ___,
|
|
1580
1618
|
structuredOutputMode: ____,
|
|
1581
1619
|
...filteredAmazonBedrockOptions
|
|
1582
|
-
} =
|
|
1620
|
+
} = providerOptions?.amazonBedrock ?? providerOptions?.bedrock ?? {};
|
|
1583
1621
|
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1584
1622
|
return {
|
|
1585
1623
|
command: {
|
|
@@ -1615,7 +1653,6 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1615
1653
|
);
|
|
1616
1654
|
}
|
|
1617
1655
|
async doGenerate(options) {
|
|
1618
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1619
1656
|
const {
|
|
1620
1657
|
command: args,
|
|
1621
1658
|
warnings,
|
|
@@ -1629,10 +1666,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1629
1666
|
body: args,
|
|
1630
1667
|
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1631
1668
|
errorSchema: AmazonBedrockErrorSchema,
|
|
1632
|
-
errorToMessage: (error) => {
|
|
1633
|
-
var _a2;
|
|
1634
|
-
return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
|
|
1635
|
-
}
|
|
1669
|
+
errorToMessage: (error) => `${error.message ?? "Unknown error"}`
|
|
1636
1670
|
}),
|
|
1637
1671
|
successfulResponseHandler: createJsonResponseHandler(
|
|
1638
1672
|
AmazonBedrockResponseSchema
|
|
@@ -1644,13 +1678,13 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1644
1678
|
let isJsonResponseFromTool = false;
|
|
1645
1679
|
const jsonObjectTextExtractor = usesJsonInstruction ? new JsonObjectTextExtractor() : void 0;
|
|
1646
1680
|
for (const part of response.output.message.content) {
|
|
1647
|
-
const textParts = part.text != null ? [part.text] :
|
|
1681
|
+
const textParts = part.text != null ? [part.text] : part.citationsContent?.content?.flatMap(
|
|
1648
1682
|
(content2) => content2.text == null ? [] : [content2.text]
|
|
1649
|
-
)
|
|
1683
|
+
) ?? [];
|
|
1650
1684
|
for (const text of textParts) {
|
|
1651
1685
|
content.push({
|
|
1652
1686
|
type: "text",
|
|
1653
|
-
text:
|
|
1687
|
+
text: jsonObjectTextExtractor?.process(text) ?? text
|
|
1654
1688
|
});
|
|
1655
1689
|
}
|
|
1656
1690
|
if (part.reasoningContent) {
|
|
@@ -1671,7 +1705,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1671
1705
|
content.push(reasoning);
|
|
1672
1706
|
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
1673
1707
|
const redactedPayload = {
|
|
1674
|
-
redactedData:
|
|
1708
|
+
redactedData: part.reasoningContent.redactedReasoning.data ?? ""
|
|
1675
1709
|
};
|
|
1676
1710
|
content.push({
|
|
1677
1711
|
type: "reasoning",
|
|
@@ -1705,17 +1739,17 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1705
1739
|
});
|
|
1706
1740
|
} else {
|
|
1707
1741
|
const isMistral = isMistralModel(this.modelId);
|
|
1708
|
-
const rawToolCallId =
|
|
1742
|
+
const rawToolCallId = part.toolUse?.toolUseId || this.config.generateId();
|
|
1709
1743
|
content.push({
|
|
1710
1744
|
type: "tool-call",
|
|
1711
1745
|
toolCallId: normalizeToolCallId(rawToolCallId, isMistral),
|
|
1712
|
-
toolName:
|
|
1713
|
-
input: JSON.stringify(
|
|
1746
|
+
toolName: part.toolUse?.name ?? `tool-${this.config.generateId()}`,
|
|
1747
|
+
input: JSON.stringify(part.toolUse?.input ?? {})
|
|
1714
1748
|
});
|
|
1715
1749
|
}
|
|
1716
1750
|
}
|
|
1717
1751
|
}
|
|
1718
|
-
const stopSequence =
|
|
1752
|
+
const stopSequence = response.additionalModelResponseFields?.delta?.stop_sequence ?? null;
|
|
1719
1753
|
const providerMetadataPayload = response.trace || response.usage || response.performanceConfig || response.serviceTier || isJsonResponseFromTool || stopSequence ? {
|
|
1720
1754
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
1721
1755
|
...response.performanceConfig && {
|
|
@@ -1724,7 +1758,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1724
1758
|
...response.serviceTier && {
|
|
1725
1759
|
serviceTier: response.serviceTier
|
|
1726
1760
|
},
|
|
1727
|
-
...(
|
|
1761
|
+
...(response.usage?.cacheWriteInputTokens != null || response.usage?.cacheDetails != null) && {
|
|
1728
1762
|
usage: {
|
|
1729
1763
|
...response.usage.cacheWriteInputTokens != null && {
|
|
1730
1764
|
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
@@ -1748,12 +1782,12 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1748
1782
|
response.stopReason,
|
|
1749
1783
|
isJsonResponseFromTool
|
|
1750
1784
|
),
|
|
1751
|
-
raw:
|
|
1785
|
+
raw: response.stopReason ?? void 0
|
|
1752
1786
|
},
|
|
1753
1787
|
usage: convertAmazonBedrockUsage(response.usage),
|
|
1754
1788
|
response: {
|
|
1755
|
-
id:
|
|
1756
|
-
timestamp:
|
|
1789
|
+
id: responseHeaders?.["x-amzn-requestid"] ?? void 0,
|
|
1790
|
+
timestamp: responseHeaders?.["date"] != null ? new Date(responseHeaders["date"]) : void 0,
|
|
1757
1791
|
modelId: this.modelId,
|
|
1758
1792
|
headers: responseHeaders
|
|
1759
1793
|
},
|
|
@@ -1797,17 +1831,15 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1797
1831
|
stream: response.pipeThrough(
|
|
1798
1832
|
new TransformStream({
|
|
1799
1833
|
start(controller) {
|
|
1800
|
-
var _a;
|
|
1801
1834
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1802
1835
|
controller.enqueue({
|
|
1803
1836
|
type: "response-metadata",
|
|
1804
|
-
id:
|
|
1805
|
-
timestamp:
|
|
1837
|
+
id: responseHeaders?.["x-amzn-requestid"] ?? void 0,
|
|
1838
|
+
timestamp: responseHeaders?.["date"] != null ? new Date(responseHeaders["date"]) : void 0,
|
|
1806
1839
|
modelId
|
|
1807
1840
|
});
|
|
1808
1841
|
},
|
|
1809
1842
|
transform(chunk, controller) {
|
|
1810
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1811
1843
|
function enqueueError(type, amazonBedrockError) {
|
|
1812
1844
|
finishReason = { unified: "error", raw: void 0 };
|
|
1813
1845
|
controller.enqueue({
|
|
@@ -1863,20 +1895,20 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1863
1895
|
value.messageStop.stopReason,
|
|
1864
1896
|
isJsonResponseFromTool
|
|
1865
1897
|
),
|
|
1866
|
-
raw:
|
|
1898
|
+
raw: value.messageStop.stopReason ?? void 0
|
|
1867
1899
|
};
|
|
1868
|
-
stopSequence =
|
|
1900
|
+
stopSequence = value.messageStop.additionalModelResponseFields?.delta?.stop_sequence ?? null;
|
|
1869
1901
|
}
|
|
1870
1902
|
if (value.metadata) {
|
|
1871
1903
|
if (value.metadata.usage) {
|
|
1872
1904
|
usage = value.metadata.usage;
|
|
1873
1905
|
}
|
|
1874
|
-
const cacheUsage =
|
|
1906
|
+
const cacheUsage = value.metadata.usage?.cacheWriteInputTokens != null || value.metadata.usage?.cacheDetails != null ? {
|
|
1875
1907
|
usage: {
|
|
1876
|
-
...
|
|
1908
|
+
...value.metadata.usage?.cacheWriteInputTokens != null && {
|
|
1877
1909
|
cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
|
|
1878
1910
|
},
|
|
1879
|
-
...
|
|
1911
|
+
...value.metadata.usage?.cacheDetails != null && {
|
|
1880
1912
|
cacheDetails: value.metadata.usage.cacheDetails
|
|
1881
1913
|
}
|
|
1882
1914
|
}
|
|
@@ -1901,7 +1933,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1901
1933
|
};
|
|
1902
1934
|
}
|
|
1903
1935
|
}
|
|
1904
|
-
if (
|
|
1936
|
+
if (value.contentBlockStart?.contentBlockIndex != null && !value.contentBlockStart?.start?.toolUse) {
|
|
1905
1937
|
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
1906
1938
|
contentBlocks[blockIndex] = { type: "text" };
|
|
1907
1939
|
controller.enqueue({
|
|
@@ -1909,7 +1941,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1909
1941
|
id: String(blockIndex)
|
|
1910
1942
|
});
|
|
1911
1943
|
}
|
|
1912
|
-
if (
|
|
1944
|
+
if (value.contentBlockDelta?.delta && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
1913
1945
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1914
1946
|
if (contentBlocks[blockIndex] == null) {
|
|
1915
1947
|
contentBlocks[blockIndex] = { type: "text" };
|
|
@@ -1918,9 +1950,9 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1918
1950
|
id: String(blockIndex)
|
|
1919
1951
|
});
|
|
1920
1952
|
}
|
|
1921
|
-
const textDelta =
|
|
1953
|
+
const textDelta = jsonObjectTextExtractor?.process(
|
|
1922
1954
|
value.contentBlockDelta.delta.text
|
|
1923
|
-
)
|
|
1955
|
+
) ?? value.contentBlockDelta.delta.text;
|
|
1924
1956
|
if (textDelta.length > 0) {
|
|
1925
1957
|
controller.enqueue({
|
|
1926
1958
|
type: "text-delta",
|
|
@@ -1929,7 +1961,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1929
1961
|
});
|
|
1930
1962
|
}
|
|
1931
1963
|
}
|
|
1932
|
-
if (
|
|
1964
|
+
if (value.contentBlockStop?.contentBlockIndex != null) {
|
|
1933
1965
|
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
1934
1966
|
const contentBlock = contentBlocks[blockIndex];
|
|
1935
1967
|
if (contentBlock != null) {
|
|
@@ -1982,7 +2014,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1982
2014
|
delete contentBlocks[blockIndex];
|
|
1983
2015
|
}
|
|
1984
2016
|
}
|
|
1985
|
-
if (
|
|
2017
|
+
if (value.contentBlockDelta?.delta && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
1986
2018
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1987
2019
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
1988
2020
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
@@ -2052,12 +2084,12 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
2052
2084
|
}
|
|
2053
2085
|
const contentBlock = contentBlocks[blockIndex];
|
|
2054
2086
|
if (contentBlock.type === "reasoning") {
|
|
2055
|
-
contentBlock.redactedContent = (
|
|
2087
|
+
contentBlock.redactedContent = (contentBlock.redactedContent ?? "") + reasoningContent.redactedContent;
|
|
2056
2088
|
}
|
|
2057
2089
|
}
|
|
2058
2090
|
}
|
|
2059
2091
|
const contentBlockStart = value.contentBlockStart;
|
|
2060
|
-
if (
|
|
2092
|
+
if (contentBlockStart?.start?.toolUse != null) {
|
|
2061
2093
|
const toolUse = contentBlockStart.start.toolUse;
|
|
2062
2094
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
2063
2095
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -2081,11 +2113,11 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
2081
2113
|
}
|
|
2082
2114
|
}
|
|
2083
2115
|
const contentBlockDelta = value.contentBlockDelta;
|
|
2084
|
-
if (
|
|
2116
|
+
if (contentBlockDelta?.delta && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
2085
2117
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
2086
2118
|
const contentBlock = contentBlocks[blockIndex];
|
|
2087
|
-
if (
|
|
2088
|
-
const delta =
|
|
2119
|
+
if (contentBlock?.type === "tool-call") {
|
|
2120
|
+
const delta = contentBlockDelta.delta.toolUse.input ?? "";
|
|
2089
2121
|
if (!contentBlock.isJsonResponseTool) {
|
|
2090
2122
|
controller.enqueue({
|
|
2091
2123
|
type: "tool-input-delta",
|
|
@@ -2098,10 +2130,9 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
2098
2130
|
}
|
|
2099
2131
|
},
|
|
2100
2132
|
flush(controller) {
|
|
2101
|
-
var _a;
|
|
2102
2133
|
if (isJsonResponseFromTool || stopSequence != null) {
|
|
2103
2134
|
const updatePayload = {
|
|
2104
|
-
...
|
|
2135
|
+
...providerMetadata?.amazonBedrock ?? providerMetadata?.bedrock,
|
|
2105
2136
|
...isJsonResponseFromTool && {
|
|
2106
2137
|
isJsonResponseFromTool: true
|
|
2107
2138
|
},
|
|
@@ -2329,13 +2360,17 @@ function resolveAmazonBedrockReasoningConfig({
|
|
|
2329
2360
|
amazonBedrockOptions,
|
|
2330
2361
|
warnings,
|
|
2331
2362
|
isAnthropicModel: isAnthropicModel2,
|
|
2363
|
+
isOpenAIModel,
|
|
2332
2364
|
modelId
|
|
2333
2365
|
}) {
|
|
2334
|
-
var _a;
|
|
2335
2366
|
if (!isCustomReasoning(reasoning)) {
|
|
2336
2367
|
return amazonBedrockOptions;
|
|
2337
2368
|
}
|
|
2338
2369
|
const result = { ...amazonBedrockOptions };
|
|
2370
|
+
const hasPortableReasoning = reasoning !== "none";
|
|
2371
|
+
const hasExplicitReasoningConfig = amazonBedrockOptions.reasoningConfig != null;
|
|
2372
|
+
const isNovaReasoningModel = modelId.includes("amazon.nova-2-lite-v1:0");
|
|
2373
|
+
const supportsPortableReasoning = isOpenAIModel || isNovaReasoningModel;
|
|
2339
2374
|
if (isAnthropicModel2) {
|
|
2340
2375
|
const capabilities = getModelCapabilities(modelId);
|
|
2341
2376
|
if (reasoning === "none") {
|
|
@@ -2366,18 +2401,27 @@ function resolveAmazonBedrockReasoningConfig({
|
|
|
2366
2401
|
};
|
|
2367
2402
|
}
|
|
2368
2403
|
}
|
|
2369
|
-
} else if (
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2404
|
+
} else if (hasPortableReasoning) {
|
|
2405
|
+
if (supportsPortableReasoning || hasExplicitReasoningConfig) {
|
|
2406
|
+
const effort = mapReasoningToProviderEffort({
|
|
2407
|
+
reasoning,
|
|
2408
|
+
effortMap: amazonBedrockReasoningEffortMap,
|
|
2409
|
+
warnings
|
|
2410
|
+
});
|
|
2411
|
+
result.reasoningConfig = {
|
|
2412
|
+
...isNovaReasoningModel && { type: "enabled" },
|
|
2413
|
+
maxReasoningEffort: effort,
|
|
2414
|
+
...amazonBedrockOptions.reasoningConfig
|
|
2415
|
+
};
|
|
2416
|
+
} else {
|
|
2417
|
+
warnings.push({
|
|
2418
|
+
type: "unsupported",
|
|
2419
|
+
feature: "reasoning",
|
|
2420
|
+
details: "Portable reasoning is not supported for this model and will be ignored. If the model supports a provider-specific reasoning configuration, use providerOptions.amazonBedrock.reasoningConfig."
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2379
2423
|
}
|
|
2380
|
-
if (
|
|
2424
|
+
if (result.reasoningConfig?.type === "disabled") {
|
|
2381
2425
|
delete result.reasoningConfig.maxReasoningEffort;
|
|
2382
2426
|
delete result.reasoningConfig.budgetTokens;
|
|
2383
2427
|
}
|
|
@@ -2465,8 +2509,7 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2465
2509
|
return this.modelFamily === "cohere" ? 96 : 1;
|
|
2466
2510
|
}
|
|
2467
2511
|
get modelFamily() {
|
|
2468
|
-
|
|
2469
|
-
return (_a = this.config.modelFamily) != null ? _a : detectEmbeddingModelFamily(this.modelId);
|
|
2512
|
+
return this.config.modelFamily ?? detectEmbeddingModelFamily(this.modelId);
|
|
2470
2513
|
}
|
|
2471
2514
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
2472
2515
|
return serializeModelOptions2({
|
|
@@ -2487,7 +2530,6 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2487
2530
|
abortSignal,
|
|
2488
2531
|
providerOptions
|
|
2489
2532
|
}) {
|
|
2490
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2491
2533
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
2492
2534
|
throw new TooManyEmbeddingValuesForCallError({
|
|
2493
2535
|
provider: this.provider,
|
|
@@ -2496,30 +2538,30 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2496
2538
|
values
|
|
2497
2539
|
});
|
|
2498
2540
|
}
|
|
2499
|
-
const amazonBedrockOptions =
|
|
2541
|
+
const amazonBedrockOptions = await parseProviderOptions3({
|
|
2500
2542
|
provider: "amazonBedrock",
|
|
2501
2543
|
providerOptions,
|
|
2502
2544
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
2503
|
-
})
|
|
2545
|
+
}) ?? await parseProviderOptions3({
|
|
2504
2546
|
provider: "bedrock",
|
|
2505
2547
|
providerOptions,
|
|
2506
2548
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
2507
|
-
})
|
|
2549
|
+
}) ?? {};
|
|
2508
2550
|
const modelFamily = this.modelFamily;
|
|
2509
2551
|
const args = modelFamily === "nova" ? {
|
|
2510
2552
|
taskType: "SINGLE_EMBEDDING",
|
|
2511
2553
|
singleEmbeddingParams: {
|
|
2512
|
-
embeddingPurpose:
|
|
2513
|
-
embeddingDimension:
|
|
2554
|
+
embeddingPurpose: amazonBedrockOptions.embeddingPurpose ?? "GENERIC_INDEX",
|
|
2555
|
+
embeddingDimension: amazonBedrockOptions.embeddingDimension ?? 1024,
|
|
2514
2556
|
text: {
|
|
2515
|
-
truncationMode:
|
|
2557
|
+
truncationMode: amazonBedrockOptions.truncate ?? "END",
|
|
2516
2558
|
value: values[0]
|
|
2517
2559
|
}
|
|
2518
2560
|
}
|
|
2519
2561
|
} : modelFamily === "cohere" ? {
|
|
2520
2562
|
// Cohere embedding models on Bedrock require `input_type`.
|
|
2521
2563
|
// Without it, the service attempts other schema branches and rejects the request.
|
|
2522
|
-
input_type:
|
|
2564
|
+
input_type: amazonBedrockOptions.inputType ?? "search_query",
|
|
2523
2565
|
texts: values,
|
|
2524
2566
|
truncate: amazonBedrockOptions.truncate,
|
|
2525
2567
|
output_dimension: amazonBedrockOptions.outputDimension
|
|
@@ -2559,9 +2601,9 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2559
2601
|
embeddings = response.embeddings.float;
|
|
2560
2602
|
}
|
|
2561
2603
|
const headerTokenCount = Number(
|
|
2562
|
-
responseHeaders
|
|
2604
|
+
responseHeaders?.["x-amzn-bedrock-input-token-count"]
|
|
2563
2605
|
);
|
|
2564
|
-
const tokens = "inputTextTokenCount" in response ? response.inputTextTokenCount : "inputTokenCount" in response ?
|
|
2606
|
+
const tokens = "inputTextTokenCount" in response ? response.inputTextTokenCount : "inputTokenCount" in response ? response.inputTokenCount ?? 0 : headerTokenCount;
|
|
2565
2607
|
return {
|
|
2566
2608
|
embeddings,
|
|
2567
2609
|
usage: { tokens },
|
|
@@ -2679,8 +2721,7 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2679
2721
|
return new _AmazonBedrockImageModel(options.modelId, options.config);
|
|
2680
2722
|
}
|
|
2681
2723
|
get maxImagesPerCall() {
|
|
2682
|
-
|
|
2683
|
-
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
2724
|
+
return modelMaxImagesPerCall[this.modelId] ?? 1;
|
|
2684
2725
|
}
|
|
2685
2726
|
getUrl(modelId) {
|
|
2686
2727
|
const encodedModelId = encodeURIComponent(modelId);
|
|
@@ -2698,39 +2739,38 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2698
2739
|
files,
|
|
2699
2740
|
mask
|
|
2700
2741
|
}) {
|
|
2701
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2702
2742
|
const warnings = [];
|
|
2703
2743
|
const [width, height] = size ? size.split("x").map(Number) : [];
|
|
2704
2744
|
const hasFiles = files != null && files.length > 0;
|
|
2705
|
-
const amazonBedrockOptions =
|
|
2745
|
+
const amazonBedrockOptions = await parseProviderOptions4({
|
|
2706
2746
|
provider: "amazonBedrock",
|
|
2707
2747
|
providerOptions,
|
|
2708
2748
|
schema: amazonBedrockImageModelOptionsSchema
|
|
2709
|
-
})
|
|
2749
|
+
}) ?? await parseProviderOptions4({
|
|
2710
2750
|
provider: "bedrock",
|
|
2711
2751
|
providerOptions,
|
|
2712
2752
|
schema: amazonBedrockImageModelOptionsSchema
|
|
2713
|
-
})
|
|
2753
|
+
}) ?? {};
|
|
2714
2754
|
const imageGenerationConfig = {
|
|
2715
2755
|
...width ? { width } : {},
|
|
2716
2756
|
...height ? { height } : {},
|
|
2717
2757
|
...seed ? { seed } : {},
|
|
2718
2758
|
...n ? { numberOfImages: n } : {},
|
|
2719
|
-
...
|
|
2720
|
-
...
|
|
2759
|
+
...amazonBedrockOptions?.quality ? { quality: amazonBedrockOptions.quality } : {},
|
|
2760
|
+
...amazonBedrockOptions?.cfgScale ? { cfgScale: amazonBedrockOptions.cfgScale } : {}
|
|
2721
2761
|
};
|
|
2722
2762
|
let args;
|
|
2723
2763
|
if (hasFiles) {
|
|
2724
|
-
const hasMask =
|
|
2725
|
-
const hasMaskPrompt =
|
|
2726
|
-
const taskType =
|
|
2764
|
+
const hasMask = mask?.type != null;
|
|
2765
|
+
const hasMaskPrompt = amazonBedrockOptions?.maskPrompt != null;
|
|
2766
|
+
const taskType = amazonBedrockOptions?.taskType ?? (hasMask || hasMaskPrompt ? "INPAINTING" : "IMAGE_VARIATION");
|
|
2727
2767
|
const sourceImageBase64 = getBase64Data(files[0]);
|
|
2728
2768
|
switch (taskType) {
|
|
2729
2769
|
case "INPAINTING": {
|
|
2730
2770
|
const inPaintingParams = {
|
|
2731
2771
|
image: sourceImageBase64,
|
|
2732
2772
|
...prompt ? { text: prompt } : {},
|
|
2733
|
-
...
|
|
2773
|
+
...amazonBedrockOptions?.negativeText ? { negativeText: amazonBedrockOptions.negativeText } : {}
|
|
2734
2774
|
};
|
|
2735
2775
|
if (hasMask) {
|
|
2736
2776
|
inPaintingParams.maskImage = getBase64Data(mask);
|
|
@@ -2748,8 +2788,8 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2748
2788
|
const outPaintingParams = {
|
|
2749
2789
|
image: sourceImageBase64,
|
|
2750
2790
|
...prompt ? { text: prompt } : {},
|
|
2751
|
-
...
|
|
2752
|
-
...
|
|
2791
|
+
...amazonBedrockOptions?.negativeText ? { negativeText: amazonBedrockOptions.negativeText } : {},
|
|
2792
|
+
...amazonBedrockOptions?.outPaintingMode ? { outPaintingMode: amazonBedrockOptions.outPaintingMode } : {}
|
|
2753
2793
|
};
|
|
2754
2794
|
if (hasMask) {
|
|
2755
2795
|
outPaintingParams.maskImage = getBase64Data(mask);
|
|
@@ -2777,8 +2817,8 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2777
2817
|
const imageVariationParams = {
|
|
2778
2818
|
images,
|
|
2779
2819
|
...prompt ? { text: prompt } : {},
|
|
2780
|
-
...
|
|
2781
|
-
...
|
|
2820
|
+
...amazonBedrockOptions?.negativeText ? { negativeText: amazonBedrockOptions.negativeText } : {},
|
|
2821
|
+
...amazonBedrockOptions?.similarityStrength != null ? {
|
|
2782
2822
|
similarityStrength: amazonBedrockOptions.similarityStrength
|
|
2783
2823
|
} : {}
|
|
2784
2824
|
};
|
|
@@ -2797,10 +2837,10 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2797
2837
|
taskType: "TEXT_IMAGE",
|
|
2798
2838
|
textToImageParams: {
|
|
2799
2839
|
text: prompt,
|
|
2800
|
-
...
|
|
2840
|
+
...amazonBedrockOptions?.negativeText ? {
|
|
2801
2841
|
negativeText: amazonBedrockOptions.negativeText
|
|
2802
2842
|
} : {},
|
|
2803
|
-
...
|
|
2843
|
+
...amazonBedrockOptions?.style ? {
|
|
2804
2844
|
style: amazonBedrockOptions.style
|
|
2805
2845
|
} : {}
|
|
2806
2846
|
},
|
|
@@ -2814,7 +2854,7 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2814
2854
|
details: "This model does not support aspect ratio. Use `size` instead."
|
|
2815
2855
|
});
|
|
2816
2856
|
}
|
|
2817
|
-
const currentDate =
|
|
2857
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
2818
2858
|
const { value: response, responseHeaders } = await postJsonToApi3({
|
|
2819
2859
|
url: this.getUrl(this.modelId),
|
|
2820
2860
|
headers: await resolve3(
|
|
@@ -2832,7 +2872,7 @@ var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
|
2832
2872
|
fetch: this.config.fetch
|
|
2833
2873
|
});
|
|
2834
2874
|
if (response.status === "Request Moderated") {
|
|
2835
|
-
const moderationReasons =
|
|
2875
|
+
const moderationReasons = response.details?.["Moderation Reasons"];
|
|
2836
2876
|
const reasons = Array.isArray(moderationReasons) ? moderationReasons : ["Unknown"];
|
|
2837
2877
|
throw new Error(
|
|
2838
2878
|
`Amazon Bedrock request was moderated: ${reasons.join(", ")}`
|
|
@@ -2887,32 +2927,31 @@ import {
|
|
|
2887
2927
|
import { AwsV4Signer } from "aws4fetch";
|
|
2888
2928
|
|
|
2889
2929
|
// src/version.ts
|
|
2890
|
-
var VERSION = true ? "5.0.
|
|
2930
|
+
var VERSION = true ? "5.0.96" : "0.0.0-test";
|
|
2891
2931
|
|
|
2892
2932
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
2893
2933
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
2894
2934
|
return async (input, init) => {
|
|
2895
|
-
|
|
2896
|
-
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
2935
|
+
const effectiveFetch = fetch ?? globalThis.fetch;
|
|
2897
2936
|
const request = input instanceof Request ? input : void 0;
|
|
2898
2937
|
const originalHeaders = combineHeaders4(
|
|
2899
|
-
normalizeHeaders(request
|
|
2900
|
-
normalizeHeaders(init
|
|
2938
|
+
normalizeHeaders(request?.headers),
|
|
2939
|
+
normalizeHeaders(init?.headers)
|
|
2901
2940
|
);
|
|
2902
2941
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
2903
2942
|
originalHeaders,
|
|
2904
2943
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
2905
2944
|
getRuntimeEnvironmentUserAgent()
|
|
2906
2945
|
);
|
|
2907
|
-
let effectiveBody =
|
|
2946
|
+
let effectiveBody = init?.body ?? void 0;
|
|
2908
2947
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
2909
2948
|
try {
|
|
2910
2949
|
effectiveBody = await request.clone().text();
|
|
2911
|
-
} catch
|
|
2950
|
+
} catch {
|
|
2912
2951
|
}
|
|
2913
2952
|
}
|
|
2914
|
-
const effectiveMethod =
|
|
2915
|
-
if (
|
|
2953
|
+
const effectiveMethod = init?.method ?? request?.method;
|
|
2954
|
+
if (effectiveMethod?.toUpperCase() !== "POST" || !effectiveBody) {
|
|
2916
2955
|
return effectiveFetch(input, {
|
|
2917
2956
|
...init,
|
|
2918
2957
|
headers: headersWithUserAgent
|
|
@@ -2955,8 +2994,8 @@ function prepareBodyString(body) {
|
|
|
2955
2994
|
}
|
|
2956
2995
|
function createApiKeyFetchFunction(apiKey, fetch) {
|
|
2957
2996
|
return async (input, init) => {
|
|
2958
|
-
const effectiveFetch = fetch
|
|
2959
|
-
const originalHeaders = normalizeHeaders(init
|
|
2997
|
+
const effectiveFetch = fetch ?? globalThis.fetch;
|
|
2998
|
+
const originalHeaders = normalizeHeaders(init?.headers);
|
|
2960
2999
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
2961
3000
|
originalHeaders,
|
|
2962
3001
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
@@ -3032,12 +3071,11 @@ var AmazonBedrockRerankingModel = class {
|
|
|
3032
3071
|
abortSignal,
|
|
3033
3072
|
providerOptions
|
|
3034
3073
|
}) {
|
|
3035
|
-
|
|
3036
|
-
const amazonBedrockOptions = (_a = await parseProviderOptions5({
|
|
3074
|
+
const amazonBedrockOptions = await parseProviderOptions5({
|
|
3037
3075
|
provider: "amazonBedrock",
|
|
3038
3076
|
providerOptions,
|
|
3039
3077
|
schema: amazonBedrockRerankingModelOptionsSchema
|
|
3040
|
-
})
|
|
3078
|
+
}) ?? await parseProviderOptions5({
|
|
3041
3079
|
provider: "bedrock",
|
|
3042
3080
|
providerOptions,
|
|
3043
3081
|
schema: amazonBedrockRerankingModelOptionsSchema
|
|
@@ -3052,7 +3090,7 @@ var AmazonBedrockRerankingModel = class {
|
|
|
3052
3090
|
combineHeaders5(await resolve4(this.config.headers), headers)
|
|
3053
3091
|
),
|
|
3054
3092
|
body: {
|
|
3055
|
-
nextToken: amazonBedrockOptions
|
|
3093
|
+
nextToken: amazonBedrockOptions?.nextToken,
|
|
3056
3094
|
queries: [
|
|
3057
3095
|
{
|
|
3058
3096
|
textQuery: { text: query },
|
|
@@ -3063,7 +3101,7 @@ var AmazonBedrockRerankingModel = class {
|
|
|
3063
3101
|
bedrockRerankingConfiguration: {
|
|
3064
3102
|
modelConfiguration: {
|
|
3065
3103
|
modelArn: `arn:aws:bedrock:${this.config.region}::foundation-model/${this.modelId}`,
|
|
3066
|
-
additionalModelRequestFields: amazonBedrockOptions
|
|
3104
|
+
additionalModelRequestFields: amazonBedrockOptions?.additionalModelRequestFields
|
|
3067
3105
|
},
|
|
3068
3106
|
numberOfResults: topN
|
|
3069
3107
|
},
|
|
@@ -3116,23 +3154,22 @@ function resolveAmazonBedrockBaseURL({
|
|
|
3116
3154
|
service,
|
|
3117
3155
|
serviceEndpointUrlEnvironmentVariableName
|
|
3118
3156
|
}) {
|
|
3119
|
-
|
|
3120
|
-
const resolvedBaseURL = (_a = baseURL != null ? baseURL : loadOptionalSetting({
|
|
3157
|
+
const resolvedBaseURL = baseURL ?? loadOptionalSetting({
|
|
3121
3158
|
settingValue: void 0,
|
|
3122
3159
|
environmentVariableName: serviceEndpointUrlEnvironmentVariableName
|
|
3123
|
-
})
|
|
3160
|
+
}) ?? loadOptionalSetting({
|
|
3124
3161
|
settingValue: void 0,
|
|
3125
3162
|
environmentVariableName: "AWS_ENDPOINT_URL"
|
|
3126
3163
|
});
|
|
3127
3164
|
if (resolvedBaseURL != null) {
|
|
3128
|
-
return
|
|
3165
|
+
return withoutTrailingSlash(resolvedBaseURL) ?? resolvedBaseURL;
|
|
3129
3166
|
}
|
|
3130
3167
|
const region = getRegion();
|
|
3131
|
-
const dnsSuffix =
|
|
3168
|
+
const dnsSuffix = AWS_PARTITION_DNS_SUFFIXES.find(
|
|
3132
3169
|
({ regionPrefix }) => region.startsWith(regionPrefix)
|
|
3133
|
-
)
|
|
3170
|
+
)?.dnsSuffix ?? "amazonaws.com";
|
|
3134
3171
|
const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
|
|
3135
|
-
return
|
|
3172
|
+
return withoutTrailingSlash(generatedBaseURL) ?? generatedBaseURL;
|
|
3136
3173
|
}
|
|
3137
3174
|
|
|
3138
3175
|
// src/amazon-bedrock-provider.ts
|
|
@@ -3204,8 +3241,7 @@ Original error: ${errorMessage}`
|
|
|
3204
3241
|
}
|
|
3205
3242
|
}, options.fetch);
|
|
3206
3243
|
const getHeaders = () => {
|
|
3207
|
-
|
|
3208
|
-
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
3244
|
+
const baseHeaders = options.headers ?? {};
|
|
3209
3245
|
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
3210
3246
|
};
|
|
3211
3247
|
const getAmazonBedrockRuntimeBaseUrl = () => resolveAmazonBedrockBaseURL({
|