@ai-sdk/amazon-bedrock 3.0.0-beta.1 → 3.0.0-beta.10
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 +65 -0
- package/README.md +75 -0
- package/dist/index.d.mts +28 -27
- package/dist/index.d.ts +28 -27
- package/dist/index.js +249 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
30
30
|
|
|
31
31
|
// src/bedrock-chat-language-model.ts
|
|
32
32
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
33
|
-
var
|
|
33
|
+
var import_v43 = require("zod/v4");
|
|
34
34
|
|
|
35
35
|
// src/bedrock-api-types.ts
|
|
36
36
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -48,27 +48,44 @@ var BEDROCK_STOP_REASONS = [
|
|
|
48
48
|
"tool-calls",
|
|
49
49
|
"tool_use"
|
|
50
50
|
];
|
|
51
|
+
var BEDROCK_IMAGE_MIME_TYPES = {
|
|
52
|
+
"image/jpeg": "jpeg",
|
|
53
|
+
"image/png": "png",
|
|
54
|
+
"image/gif": "gif",
|
|
55
|
+
"image/webp": "webp"
|
|
56
|
+
};
|
|
57
|
+
var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
58
|
+
"application/pdf": "pdf",
|
|
59
|
+
"text/csv": "csv",
|
|
60
|
+
"application/msword": "doc",
|
|
61
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
62
|
+
"application/vnd.ms-excel": "xls",
|
|
63
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
64
|
+
"text/html": "html",
|
|
65
|
+
"text/plain": "txt",
|
|
66
|
+
"text/markdown": "md"
|
|
67
|
+
};
|
|
51
68
|
|
|
52
69
|
// src/bedrock-chat-options.ts
|
|
53
|
-
var
|
|
54
|
-
var bedrockProviderOptions =
|
|
70
|
+
var import_v4 = require("zod/v4");
|
|
71
|
+
var bedrockProviderOptions = import_v4.z.object({
|
|
55
72
|
/**
|
|
56
73
|
* Additional inference parameters that the model supports,
|
|
57
74
|
* beyond the base set of inference parameters that Converse
|
|
58
75
|
* supports in the inferenceConfig field
|
|
59
76
|
*/
|
|
60
|
-
additionalModelRequestFields:
|
|
61
|
-
reasoningConfig:
|
|
62
|
-
type:
|
|
63
|
-
budgetTokens:
|
|
77
|
+
additionalModelRequestFields: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
|
|
78
|
+
reasoningConfig: import_v4.z.object({
|
|
79
|
+
type: import_v4.z.union([import_v4.z.literal("enabled"), import_v4.z.literal("disabled")]).optional(),
|
|
80
|
+
budgetTokens: import_v4.z.number().optional()
|
|
64
81
|
}).optional()
|
|
65
82
|
});
|
|
66
83
|
|
|
67
84
|
// src/bedrock-error.ts
|
|
68
|
-
var
|
|
69
|
-
var BedrockErrorSchema =
|
|
70
|
-
message:
|
|
71
|
-
type:
|
|
85
|
+
var import_v42 = require("zod/v4");
|
|
86
|
+
var BedrockErrorSchema = import_v42.z.object({
|
|
87
|
+
message: import_v42.z.string(),
|
|
88
|
+
type: import_v42.z.string().nullish()
|
|
72
89
|
});
|
|
73
90
|
|
|
74
91
|
// src/bedrock-event-stream-response-handler.ts
|
|
@@ -144,14 +161,29 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
144
161
|
|
|
145
162
|
// src/bedrock-prepare-tools.ts
|
|
146
163
|
var import_provider2 = require("@ai-sdk/provider");
|
|
164
|
+
function promptContainsToolContent(prompt) {
|
|
165
|
+
return prompt.some((message) => {
|
|
166
|
+
if ("content" in message && Array.isArray(message.content)) {
|
|
167
|
+
return message.content.some(
|
|
168
|
+
(part) => part.type === "tool-call" || part.type === "tool-result"
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
147
174
|
function prepareTools({
|
|
148
175
|
tools,
|
|
149
|
-
toolChoice
|
|
176
|
+
toolChoice,
|
|
177
|
+
prompt
|
|
150
178
|
}) {
|
|
151
179
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
180
|
+
const hasToolContent = promptContainsToolContent(prompt);
|
|
152
181
|
if (tools == null) {
|
|
153
182
|
return {
|
|
154
|
-
toolConfig: {
|
|
183
|
+
toolConfig: {
|
|
184
|
+
tools: hasToolContent ? [] : void 0,
|
|
185
|
+
toolChoice: void 0
|
|
186
|
+
},
|
|
155
187
|
toolWarnings: []
|
|
156
188
|
};
|
|
157
189
|
}
|
|
@@ -192,7 +224,10 @@ function prepareTools({
|
|
|
192
224
|
};
|
|
193
225
|
case "none":
|
|
194
226
|
return {
|
|
195
|
-
toolConfig: {
|
|
227
|
+
toolConfig: {
|
|
228
|
+
tools: hasToolContent ? [] : void 0,
|
|
229
|
+
toolChoice: void 0
|
|
230
|
+
},
|
|
196
231
|
toolWarnings
|
|
197
232
|
};
|
|
198
233
|
case "tool":
|
|
@@ -220,7 +255,6 @@ function getCachePoint(providerMetadata) {
|
|
|
220
255
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
221
256
|
}
|
|
222
257
|
async function convertToBedrockChatMessages(prompt) {
|
|
223
|
-
var _a, _b, _c, _d;
|
|
224
258
|
const blocks = groupIntoBlocks(prompt);
|
|
225
259
|
let system = [];
|
|
226
260
|
const messages = [];
|
|
@@ -267,19 +301,22 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
267
301
|
});
|
|
268
302
|
}
|
|
269
303
|
if (part.mediaType.startsWith("image/")) {
|
|
270
|
-
const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
|
|
271
304
|
bedrockContent.push({
|
|
272
305
|
image: {
|
|
273
|
-
format:
|
|
306
|
+
format: getBedrockImageFormat(part.mediaType),
|
|
274
307
|
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
275
308
|
}
|
|
276
309
|
});
|
|
277
310
|
} else {
|
|
311
|
+
if (!part.mediaType) {
|
|
312
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
313
|
+
functionality: "file without mime type",
|
|
314
|
+
message: "File mime type is required in user message part content"
|
|
315
|
+
});
|
|
316
|
+
}
|
|
278
317
|
bedrockContent.push({
|
|
279
318
|
document: {
|
|
280
|
-
format: (
|
|
281
|
-
"/"
|
|
282
|
-
)) == null ? void 0 : _d[1],
|
|
319
|
+
format: getBedrockDocumentFormat(part.mediaType),
|
|
283
320
|
name: generateDocumentName(),
|
|
284
321
|
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
285
322
|
}
|
|
@@ -307,12 +344,9 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
307
344
|
functionality: `media type: ${contentPart.mediaType}`
|
|
308
345
|
});
|
|
309
346
|
}
|
|
310
|
-
const format =
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
functionality: `media type: ${contentPart.mediaType}`
|
|
314
|
-
});
|
|
315
|
-
}
|
|
347
|
+
const format = getBedrockImageFormat(
|
|
348
|
+
contentPart.mediaType
|
|
349
|
+
);
|
|
316
350
|
return {
|
|
317
351
|
image: {
|
|
318
352
|
format,
|
|
@@ -445,8 +479,31 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
445
479
|
}
|
|
446
480
|
return { system, messages };
|
|
447
481
|
}
|
|
448
|
-
function
|
|
449
|
-
|
|
482
|
+
function getBedrockImageFormat(mimeType) {
|
|
483
|
+
if (!mimeType) {
|
|
484
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
485
|
+
functionality: "image without mime type",
|
|
486
|
+
message: "Image mime type is required in user message part content"
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
490
|
+
if (!format) {
|
|
491
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
492
|
+
functionality: `image mime type: ${mimeType}`,
|
|
493
|
+
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return format;
|
|
497
|
+
}
|
|
498
|
+
function getBedrockDocumentFormat(mimeType) {
|
|
499
|
+
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
500
|
+
if (!format) {
|
|
501
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
502
|
+
functionality: `file mime type: ${mimeType}`,
|
|
503
|
+
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
return format;
|
|
450
507
|
}
|
|
451
508
|
function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
|
|
452
509
|
return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
|
|
@@ -542,7 +599,7 @@ var BedrockChatLanguageModel = class {
|
|
|
542
599
|
toolChoice,
|
|
543
600
|
providerOptions
|
|
544
601
|
}) {
|
|
545
|
-
var _a, _b, _c, _d
|
|
602
|
+
var _a, _b, _c, _d;
|
|
546
603
|
const bedrockOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
547
604
|
provider: "bedrock",
|
|
548
605
|
providerOptions,
|
|
@@ -597,7 +654,7 @@ var BedrockChatLanguageModel = class {
|
|
|
597
654
|
}
|
|
598
655
|
bedrockOptions.additionalModelRequestFields = {
|
|
599
656
|
...bedrockOptions.additionalModelRequestFields,
|
|
600
|
-
|
|
657
|
+
thinking: {
|
|
601
658
|
type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
|
|
602
659
|
budget_tokens: thinkingBudget
|
|
603
660
|
}
|
|
@@ -619,7 +676,12 @@ var BedrockChatLanguageModel = class {
|
|
|
619
676
|
details: "topP is not supported when thinking is enabled"
|
|
620
677
|
});
|
|
621
678
|
}
|
|
622
|
-
const { toolConfig, toolWarnings } = prepareTools({
|
|
679
|
+
const { toolConfig, toolWarnings } = prepareTools({
|
|
680
|
+
tools,
|
|
681
|
+
toolChoice,
|
|
682
|
+
prompt
|
|
683
|
+
});
|
|
684
|
+
const { reasoningConfig: _, ...filteredBedrockOptions } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
623
685
|
return {
|
|
624
686
|
command: {
|
|
625
687
|
system,
|
|
@@ -628,8 +690,8 @@ var BedrockChatLanguageModel = class {
|
|
|
628
690
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
629
691
|
inferenceConfig
|
|
630
692
|
},
|
|
631
|
-
...
|
|
632
|
-
...
|
|
693
|
+
...filteredBedrockOptions,
|
|
694
|
+
...toolConfig.tools !== void 0 ? { toolConfig } : {}
|
|
633
695
|
},
|
|
634
696
|
warnings: [...warnings, ...toolWarnings]
|
|
635
697
|
};
|
|
@@ -958,104 +1020,104 @@ var BedrockChatLanguageModel = class {
|
|
|
958
1020
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
959
1021
|
}
|
|
960
1022
|
};
|
|
961
|
-
var BedrockStopReasonSchema =
|
|
962
|
-
|
|
963
|
-
|
|
1023
|
+
var BedrockStopReasonSchema = import_v43.z.union([
|
|
1024
|
+
import_v43.z.enum(BEDROCK_STOP_REASONS),
|
|
1025
|
+
import_v43.z.string()
|
|
964
1026
|
]);
|
|
965
|
-
var BedrockToolUseSchema =
|
|
966
|
-
toolUseId:
|
|
967
|
-
name:
|
|
968
|
-
input:
|
|
1027
|
+
var BedrockToolUseSchema = import_v43.z.object({
|
|
1028
|
+
toolUseId: import_v43.z.string(),
|
|
1029
|
+
name: import_v43.z.string(),
|
|
1030
|
+
input: import_v43.z.unknown()
|
|
969
1031
|
});
|
|
970
|
-
var BedrockReasoningTextSchema =
|
|
971
|
-
signature:
|
|
972
|
-
text:
|
|
1032
|
+
var BedrockReasoningTextSchema = import_v43.z.object({
|
|
1033
|
+
signature: import_v43.z.string().nullish(),
|
|
1034
|
+
text: import_v43.z.string()
|
|
973
1035
|
});
|
|
974
|
-
var BedrockRedactedReasoningSchema =
|
|
975
|
-
data:
|
|
1036
|
+
var BedrockRedactedReasoningSchema = import_v43.z.object({
|
|
1037
|
+
data: import_v43.z.string()
|
|
976
1038
|
});
|
|
977
|
-
var BedrockResponseSchema =
|
|
978
|
-
metrics:
|
|
979
|
-
latencyMs:
|
|
1039
|
+
var BedrockResponseSchema = import_v43.z.object({
|
|
1040
|
+
metrics: import_v43.z.object({
|
|
1041
|
+
latencyMs: import_v43.z.number()
|
|
980
1042
|
}).nullish(),
|
|
981
|
-
output:
|
|
982
|
-
message:
|
|
983
|
-
content:
|
|
984
|
-
|
|
985
|
-
text:
|
|
1043
|
+
output: import_v43.z.object({
|
|
1044
|
+
message: import_v43.z.object({
|
|
1045
|
+
content: import_v43.z.array(
|
|
1046
|
+
import_v43.z.object({
|
|
1047
|
+
text: import_v43.z.string().nullish(),
|
|
986
1048
|
toolUse: BedrockToolUseSchema.nullish(),
|
|
987
|
-
reasoningContent:
|
|
988
|
-
|
|
1049
|
+
reasoningContent: import_v43.z.union([
|
|
1050
|
+
import_v43.z.object({
|
|
989
1051
|
reasoningText: BedrockReasoningTextSchema
|
|
990
1052
|
}),
|
|
991
|
-
|
|
1053
|
+
import_v43.z.object({
|
|
992
1054
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
993
1055
|
})
|
|
994
1056
|
]).nullish()
|
|
995
1057
|
})
|
|
996
1058
|
),
|
|
997
|
-
role:
|
|
1059
|
+
role: import_v43.z.string()
|
|
998
1060
|
})
|
|
999
1061
|
}),
|
|
1000
1062
|
stopReason: BedrockStopReasonSchema,
|
|
1001
|
-
trace:
|
|
1002
|
-
usage:
|
|
1003
|
-
inputTokens:
|
|
1004
|
-
outputTokens:
|
|
1005
|
-
totalTokens:
|
|
1006
|
-
cacheReadInputTokens:
|
|
1007
|
-
cacheWriteInputTokens:
|
|
1063
|
+
trace: import_v43.z.unknown().nullish(),
|
|
1064
|
+
usage: import_v43.z.object({
|
|
1065
|
+
inputTokens: import_v43.z.number(),
|
|
1066
|
+
outputTokens: import_v43.z.number(),
|
|
1067
|
+
totalTokens: import_v43.z.number(),
|
|
1068
|
+
cacheReadInputTokens: import_v43.z.number().nullish(),
|
|
1069
|
+
cacheWriteInputTokens: import_v43.z.number().nullish()
|
|
1008
1070
|
})
|
|
1009
1071
|
});
|
|
1010
|
-
var BedrockStreamSchema =
|
|
1011
|
-
contentBlockDelta:
|
|
1012
|
-
contentBlockIndex:
|
|
1013
|
-
delta:
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
reasoningContent:
|
|
1072
|
+
var BedrockStreamSchema = import_v43.z.object({
|
|
1073
|
+
contentBlockDelta: import_v43.z.object({
|
|
1074
|
+
contentBlockIndex: import_v43.z.number(),
|
|
1075
|
+
delta: import_v43.z.union([
|
|
1076
|
+
import_v43.z.object({ text: import_v43.z.string() }),
|
|
1077
|
+
import_v43.z.object({ toolUse: import_v43.z.object({ input: import_v43.z.string() }) }),
|
|
1078
|
+
import_v43.z.object({
|
|
1079
|
+
reasoningContent: import_v43.z.object({ text: import_v43.z.string() })
|
|
1018
1080
|
}),
|
|
1019
|
-
|
|
1020
|
-
reasoningContent:
|
|
1021
|
-
signature:
|
|
1081
|
+
import_v43.z.object({
|
|
1082
|
+
reasoningContent: import_v43.z.object({
|
|
1083
|
+
signature: import_v43.z.string()
|
|
1022
1084
|
})
|
|
1023
1085
|
}),
|
|
1024
|
-
|
|
1025
|
-
reasoningContent:
|
|
1086
|
+
import_v43.z.object({
|
|
1087
|
+
reasoningContent: import_v43.z.object({ data: import_v43.z.string() })
|
|
1026
1088
|
})
|
|
1027
1089
|
]).nullish()
|
|
1028
1090
|
}).nullish(),
|
|
1029
|
-
contentBlockStart:
|
|
1030
|
-
contentBlockIndex:
|
|
1031
|
-
start:
|
|
1091
|
+
contentBlockStart: import_v43.z.object({
|
|
1092
|
+
contentBlockIndex: import_v43.z.number(),
|
|
1093
|
+
start: import_v43.z.object({
|
|
1032
1094
|
toolUse: BedrockToolUseSchema.nullish()
|
|
1033
1095
|
}).nullish()
|
|
1034
1096
|
}).nullish(),
|
|
1035
|
-
contentBlockStop:
|
|
1036
|
-
contentBlockIndex:
|
|
1097
|
+
contentBlockStop: import_v43.z.object({
|
|
1098
|
+
contentBlockIndex: import_v43.z.number()
|
|
1037
1099
|
}).nullish(),
|
|
1038
|
-
internalServerException:
|
|
1039
|
-
messageStop:
|
|
1040
|
-
additionalModelResponseFields:
|
|
1100
|
+
internalServerException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1101
|
+
messageStop: import_v43.z.object({
|
|
1102
|
+
additionalModelResponseFields: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1041
1103
|
stopReason: BedrockStopReasonSchema
|
|
1042
1104
|
}).nullish(),
|
|
1043
|
-
metadata:
|
|
1044
|
-
trace:
|
|
1045
|
-
usage:
|
|
1046
|
-
cacheReadInputTokens:
|
|
1047
|
-
cacheWriteInputTokens:
|
|
1048
|
-
inputTokens:
|
|
1049
|
-
outputTokens:
|
|
1105
|
+
metadata: import_v43.z.object({
|
|
1106
|
+
trace: import_v43.z.unknown().nullish(),
|
|
1107
|
+
usage: import_v43.z.object({
|
|
1108
|
+
cacheReadInputTokens: import_v43.z.number().nullish(),
|
|
1109
|
+
cacheWriteInputTokens: import_v43.z.number().nullish(),
|
|
1110
|
+
inputTokens: import_v43.z.number(),
|
|
1111
|
+
outputTokens: import_v43.z.number()
|
|
1050
1112
|
}).nullish()
|
|
1051
1113
|
}).nullish(),
|
|
1052
|
-
modelStreamErrorException:
|
|
1053
|
-
throttlingException:
|
|
1054
|
-
validationException:
|
|
1114
|
+
modelStreamErrorException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1115
|
+
throttlingException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1116
|
+
validationException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish()
|
|
1055
1117
|
});
|
|
1056
|
-
var bedrockReasoningMetadataSchema =
|
|
1057
|
-
signature:
|
|
1058
|
-
redactedData:
|
|
1118
|
+
var bedrockReasoningMetadataSchema = import_v43.z.object({
|
|
1119
|
+
signature: import_v43.z.string().optional(),
|
|
1120
|
+
redactedData: import_v43.z.string().optional()
|
|
1059
1121
|
});
|
|
1060
1122
|
|
|
1061
1123
|
// src/bedrock-embedding-model.ts
|
|
@@ -1063,22 +1125,22 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
1063
1125
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1064
1126
|
|
|
1065
1127
|
// src/bedrock-embedding-options.ts
|
|
1066
|
-
var
|
|
1067
|
-
var bedrockEmbeddingProviderOptions =
|
|
1128
|
+
var import_v44 = require("zod/v4");
|
|
1129
|
+
var bedrockEmbeddingProviderOptions = import_v44.z.object({
|
|
1068
1130
|
/**
|
|
1069
1131
|
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
1070
1132
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
1071
1133
|
*/
|
|
1072
|
-
dimensions:
|
|
1134
|
+
dimensions: import_v44.z.union([import_v44.z.literal(1024), import_v44.z.literal(512), import_v44.z.literal(256)]).optional(),
|
|
1073
1135
|
/**
|
|
1074
1136
|
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
1075
1137
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
1076
1138
|
*/
|
|
1077
|
-
normalize:
|
|
1139
|
+
normalize: import_v44.z.boolean().optional()
|
|
1078
1140
|
});
|
|
1079
1141
|
|
|
1080
1142
|
// src/bedrock-embedding-model.ts
|
|
1081
|
-
var
|
|
1143
|
+
var import_v45 = require("zod/v4");
|
|
1082
1144
|
var BedrockEmbeddingModel = class {
|
|
1083
1145
|
constructor(modelId, config) {
|
|
1084
1146
|
this.modelId = modelId;
|
|
@@ -1140,9 +1202,9 @@ var BedrockEmbeddingModel = class {
|
|
|
1140
1202
|
};
|
|
1141
1203
|
}
|
|
1142
1204
|
};
|
|
1143
|
-
var BedrockEmbeddingResponseSchema =
|
|
1144
|
-
embedding:
|
|
1145
|
-
inputTextTokenCount:
|
|
1205
|
+
var BedrockEmbeddingResponseSchema = import_v45.z.object({
|
|
1206
|
+
embedding: import_v45.z.array(import_v45.z.number()),
|
|
1207
|
+
inputTextTokenCount: import_v45.z.number()
|
|
1146
1208
|
});
|
|
1147
1209
|
|
|
1148
1210
|
// src/bedrock-image-model.ts
|
|
@@ -1154,7 +1216,7 @@ var modelMaxImagesPerCall = {
|
|
|
1154
1216
|
};
|
|
1155
1217
|
|
|
1156
1218
|
// src/bedrock-image-model.ts
|
|
1157
|
-
var
|
|
1219
|
+
var import_v46 = require("zod/v4");
|
|
1158
1220
|
var BedrockImageModel = class {
|
|
1159
1221
|
constructor(modelId, config) {
|
|
1160
1222
|
this.modelId = modelId;
|
|
@@ -1180,7 +1242,7 @@ var BedrockImageModel = class {
|
|
|
1180
1242
|
headers,
|
|
1181
1243
|
abortSignal
|
|
1182
1244
|
}) {
|
|
1183
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1245
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1184
1246
|
const warnings = [];
|
|
1185
1247
|
const [width, height] = size ? size.split("x").map(Number) : [];
|
|
1186
1248
|
const args = {
|
|
@@ -1189,6 +1251,9 @@ var BedrockImageModel = class {
|
|
|
1189
1251
|
text: prompt,
|
|
1190
1252
|
...((_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.negativeText) ? {
|
|
1191
1253
|
negativeText: providerOptions.bedrock.negativeText
|
|
1254
|
+
} : {},
|
|
1255
|
+
...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.style) ? {
|
|
1256
|
+
style: providerOptions.bedrock.style
|
|
1192
1257
|
} : {}
|
|
1193
1258
|
},
|
|
1194
1259
|
imageGenerationConfig: {
|
|
@@ -1196,8 +1261,8 @@ var BedrockImageModel = class {
|
|
|
1196
1261
|
...height ? { height } : {},
|
|
1197
1262
|
...seed ? { seed } : {},
|
|
1198
1263
|
...n ? { numberOfImages: n } : {},
|
|
1199
|
-
...((
|
|
1200
|
-
...((
|
|
1264
|
+
...((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.quality) ? { quality: providerOptions.bedrock.quality } : {},
|
|
1265
|
+
...((_d = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _d.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
|
|
1201
1266
|
}
|
|
1202
1267
|
};
|
|
1203
1268
|
if (aspectRatio != void 0) {
|
|
@@ -1207,7 +1272,7 @@ var BedrockImageModel = class {
|
|
|
1207
1272
|
details: "This model does not support aspect ratio. Use `size` instead."
|
|
1208
1273
|
});
|
|
1209
1274
|
}
|
|
1210
|
-
const currentDate = (
|
|
1275
|
+
const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
|
|
1211
1276
|
const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
1212
1277
|
url: this.getUrl(this.modelId),
|
|
1213
1278
|
headers: await (0, import_provider_utils5.resolve)(
|
|
@@ -1235,8 +1300,8 @@ var BedrockImageModel = class {
|
|
|
1235
1300
|
};
|
|
1236
1301
|
}
|
|
1237
1302
|
};
|
|
1238
|
-
var bedrockImageResponseSchema =
|
|
1239
|
-
images:
|
|
1303
|
+
var bedrockImageResponseSchema = import_v46.z.object({
|
|
1304
|
+
images: import_v46.z.array(import_v46.z.string())
|
|
1240
1305
|
});
|
|
1241
1306
|
|
|
1242
1307
|
// src/headers-utils.ts
|
|
@@ -1307,10 +1372,28 @@ function prepareBodyString(body) {
|
|
|
1307
1372
|
return JSON.stringify(body);
|
|
1308
1373
|
}
|
|
1309
1374
|
}
|
|
1375
|
+
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
1376
|
+
return async (input, init) => {
|
|
1377
|
+
const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
|
|
1378
|
+
return fetch(input, {
|
|
1379
|
+
...init,
|
|
1380
|
+
headers: (0, import_provider_utils6.removeUndefinedEntries)(
|
|
1381
|
+
(0, import_provider_utils6.combineHeaders)(originalHeaders, {
|
|
1382
|
+
Authorization: `Bearer ${apiKey}`
|
|
1383
|
+
})
|
|
1384
|
+
)
|
|
1385
|
+
});
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1310
1388
|
|
|
1311
1389
|
// src/bedrock-provider.ts
|
|
1312
1390
|
function createAmazonBedrock(options = {}) {
|
|
1313
|
-
const
|
|
1391
|
+
const rawApiKey = (0, import_provider_utils7.loadOptionalSetting)({
|
|
1392
|
+
settingValue: options.apiKey,
|
|
1393
|
+
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
1394
|
+
});
|
|
1395
|
+
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
1396
|
+
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
1314
1397
|
const region = (0, import_provider_utils7.loadSetting)({
|
|
1315
1398
|
settingValue: options.region,
|
|
1316
1399
|
settingName: "region",
|
|
@@ -1318,30 +1401,58 @@ function createAmazonBedrock(options = {}) {
|
|
|
1318
1401
|
description: "AWS region"
|
|
1319
1402
|
});
|
|
1320
1403
|
if (options.credentialProvider) {
|
|
1404
|
+
try {
|
|
1405
|
+
return {
|
|
1406
|
+
...await options.credentialProvider(),
|
|
1407
|
+
region
|
|
1408
|
+
};
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1411
|
+
throw new Error(
|
|
1412
|
+
`AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
try {
|
|
1321
1417
|
return {
|
|
1322
|
-
|
|
1323
|
-
|
|
1418
|
+
region,
|
|
1419
|
+
accessKeyId: (0, import_provider_utils7.loadSetting)({
|
|
1420
|
+
settingValue: options.accessKeyId,
|
|
1421
|
+
settingName: "accessKeyId",
|
|
1422
|
+
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1423
|
+
description: "AWS access key ID"
|
|
1424
|
+
}),
|
|
1425
|
+
secretAccessKey: (0, import_provider_utils7.loadSetting)({
|
|
1426
|
+
settingValue: options.secretAccessKey,
|
|
1427
|
+
settingName: "secretAccessKey",
|
|
1428
|
+
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1429
|
+
description: "AWS secret access key"
|
|
1430
|
+
}),
|
|
1431
|
+
sessionToken: (0, import_provider_utils7.loadOptionalSetting)({
|
|
1432
|
+
settingValue: options.sessionToken,
|
|
1433
|
+
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1434
|
+
})
|
|
1324
1435
|
};
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1438
|
+
if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
|
|
1439
|
+
throw new Error(
|
|
1440
|
+
`AWS SigV4 authentication requires AWS credentials. Please provide either:
|
|
1441
|
+
1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
|
|
1442
|
+
2. Provide accessKeyId and secretAccessKey in options
|
|
1443
|
+
3. Use a credentialProvider function
|
|
1444
|
+
4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option
|
|
1445
|
+
Original error: ${errorMessage}`
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
|
|
1449
|
+
throw new Error(
|
|
1450
|
+
`AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
|
|
1451
|
+
Original error: ${errorMessage}`
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
throw error;
|
|
1325
1455
|
}
|
|
1326
|
-
return {
|
|
1327
|
-
region,
|
|
1328
|
-
accessKeyId: (0, import_provider_utils7.loadSetting)({
|
|
1329
|
-
settingValue: options.accessKeyId,
|
|
1330
|
-
settingName: "accessKeyId",
|
|
1331
|
-
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1332
|
-
description: "AWS access key ID"
|
|
1333
|
-
}),
|
|
1334
|
-
secretAccessKey: (0, import_provider_utils7.loadSetting)({
|
|
1335
|
-
settingValue: options.secretAccessKey,
|
|
1336
|
-
settingName: "secretAccessKey",
|
|
1337
|
-
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1338
|
-
description: "AWS secret access key"
|
|
1339
|
-
}),
|
|
1340
|
-
sessionToken: (0, import_provider_utils7.loadOptionalSetting)({
|
|
1341
|
-
settingValue: options.sessionToken,
|
|
1342
|
-
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1343
|
-
})
|
|
1344
|
-
};
|
|
1345
1456
|
}, options.fetch);
|
|
1346
1457
|
const getBaseUrl = () => {
|
|
1347
1458
|
var _a, _b;
|
|
@@ -1359,7 +1470,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1359
1470
|
return new BedrockChatLanguageModel(modelId, {
|
|
1360
1471
|
baseUrl: getBaseUrl,
|
|
1361
1472
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1362
|
-
fetch:
|
|
1473
|
+
fetch: fetchFunction,
|
|
1363
1474
|
generateId: import_provider_utils7.generateId
|
|
1364
1475
|
});
|
|
1365
1476
|
};
|
|
@@ -1376,7 +1487,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1376
1487
|
return new BedrockEmbeddingModel(modelId, {
|
|
1377
1488
|
baseUrl: getBaseUrl,
|
|
1378
1489
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1379
|
-
fetch:
|
|
1490
|
+
fetch: fetchFunction
|
|
1380
1491
|
});
|
|
1381
1492
|
};
|
|
1382
1493
|
const createImageModel = (modelId) => {
|
|
@@ -1384,7 +1495,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1384
1495
|
return new BedrockImageModel(modelId, {
|
|
1385
1496
|
baseUrl: getBaseUrl,
|
|
1386
1497
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1387
|
-
fetch:
|
|
1498
|
+
fetch: fetchFunction
|
|
1388
1499
|
});
|
|
1389
1500
|
};
|
|
1390
1501
|
provider.languageModel = createChatModel;
|