@ai-sdk/amazon-bedrock 3.0.0-alpha.9 → 3.0.0-beta.2
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 +87 -0
- package/dist/index.d.mts +4 -27
- package/dist/index.d.ts +4 -27
- package/dist/index.js +223 -159
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
postJsonToApi,
|
|
16
16
|
resolve
|
|
17
17
|
} from "@ai-sdk/provider-utils";
|
|
18
|
-
import { z as z3 } from "zod";
|
|
18
|
+
import { z as z3 } from "zod/v4";
|
|
19
19
|
|
|
20
20
|
// src/bedrock-api-types.ts
|
|
21
21
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -35,14 +35,14 @@ var BEDROCK_STOP_REASONS = [
|
|
|
35
35
|
];
|
|
36
36
|
|
|
37
37
|
// src/bedrock-chat-options.ts
|
|
38
|
-
import { z } from "zod";
|
|
38
|
+
import { z } from "zod/v4";
|
|
39
39
|
var bedrockProviderOptions = z.object({
|
|
40
40
|
/**
|
|
41
41
|
* Additional inference parameters that the model supports,
|
|
42
42
|
* beyond the base set of inference parameters that Converse
|
|
43
43
|
* supports in the inferenceConfig field
|
|
44
44
|
*/
|
|
45
|
-
additionalModelRequestFields: z.record(z.any()).optional(),
|
|
45
|
+
additionalModelRequestFields: z.record(z.string(), z.any()).optional(),
|
|
46
46
|
reasoningConfig: z.object({
|
|
47
47
|
type: z.union([z.literal("enabled"), z.literal("disabled")]).optional(),
|
|
48
48
|
budgetTokens: z.number().optional()
|
|
@@ -50,7 +50,7 @@ var bedrockProviderOptions = z.object({
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
// src/bedrock-error.ts
|
|
53
|
-
import { z as z2 } from "zod";
|
|
53
|
+
import { z as z2 } from "zod/v4";
|
|
54
54
|
var BedrockErrorSchema = z2.object({
|
|
55
55
|
message: z2.string(),
|
|
56
56
|
type: z2.string().nullish()
|
|
@@ -157,7 +157,7 @@ function prepareTools({
|
|
|
157
157
|
name: tool.name,
|
|
158
158
|
description: tool.description,
|
|
159
159
|
inputSchema: {
|
|
160
|
-
json: tool.
|
|
160
|
+
json: tool.inputSchema
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
});
|
|
@@ -207,12 +207,7 @@ function prepareTools({
|
|
|
207
207
|
import {
|
|
208
208
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
209
209
|
} from "@ai-sdk/provider";
|
|
210
|
-
import {
|
|
211
|
-
convertToBase64,
|
|
212
|
-
createIdGenerator,
|
|
213
|
-
parseProviderOptions
|
|
214
|
-
} from "@ai-sdk/provider-utils";
|
|
215
|
-
var generateFileId = createIdGenerator({ prefix: "file", size: 16 });
|
|
210
|
+
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
216
211
|
function getCachePoint(providerMetadata) {
|
|
217
212
|
var _a;
|
|
218
213
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
@@ -222,6 +217,8 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
222
217
|
const blocks = groupIntoBlocks(prompt);
|
|
223
218
|
let system = [];
|
|
224
219
|
const messages = [];
|
|
220
|
+
let documentCounter = 0;
|
|
221
|
+
const generateDocumentName = () => `document-${++documentCounter}`;
|
|
225
222
|
for (let i = 0; i < blocks.length; i++) {
|
|
226
223
|
const block = blocks[i];
|
|
227
224
|
const isLastBlock = i === blocks.length - 1;
|
|
@@ -276,7 +273,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
276
273
|
format: (_d = (_c = part.mediaType) == null ? void 0 : _c.split(
|
|
277
274
|
"/"
|
|
278
275
|
)) == null ? void 0 : _d[1],
|
|
279
|
-
name:
|
|
276
|
+
name: generateDocumentName(),
|
|
280
277
|
source: { bytes: convertToBase64(part.data) }
|
|
281
278
|
}
|
|
282
279
|
});
|
|
@@ -288,36 +285,49 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
288
285
|
break;
|
|
289
286
|
}
|
|
290
287
|
case "tool": {
|
|
291
|
-
for (
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const format = part2.mediaType.split("/")[1];
|
|
306
|
-
if (!isBedrockImageFormat(format)) {
|
|
307
|
-
throw new Error(
|
|
308
|
-
`Unsupported image format: ${format}`
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
image: {
|
|
313
|
-
format,
|
|
314
|
-
source: {
|
|
315
|
-
bytes: part2.data
|
|
288
|
+
for (const part of content) {
|
|
289
|
+
let toolResultContent;
|
|
290
|
+
const output = part.output;
|
|
291
|
+
switch (output.type) {
|
|
292
|
+
case "content": {
|
|
293
|
+
toolResultContent = output.value.map((contentPart) => {
|
|
294
|
+
switch (contentPart.type) {
|
|
295
|
+
case "text":
|
|
296
|
+
return { text: contentPart.text };
|
|
297
|
+
case "media":
|
|
298
|
+
if (!contentPart.mediaType.startsWith("image/")) {
|
|
299
|
+
throw new UnsupportedFunctionalityError2({
|
|
300
|
+
functionality: `media type: ${contentPart.mediaType}`
|
|
301
|
+
});
|
|
316
302
|
}
|
|
317
|
-
|
|
318
|
-
|
|
303
|
+
const format = contentPart.mediaType.split("/")[1];
|
|
304
|
+
if (!isBedrockImageFormat(format)) {
|
|
305
|
+
throw new UnsupportedFunctionalityError2({
|
|
306
|
+
functionality: `media type: ${contentPart.mediaType}`
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
image: {
|
|
311
|
+
format,
|
|
312
|
+
source: { bytes: contentPart.data }
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
319
318
|
}
|
|
320
|
-
|
|
319
|
+
case "text":
|
|
320
|
+
case "error-text":
|
|
321
|
+
toolResultContent = [{ text: output.value }];
|
|
322
|
+
break;
|
|
323
|
+
case "json":
|
|
324
|
+
case "error-json":
|
|
325
|
+
default:
|
|
326
|
+
toolResultContent = [
|
|
327
|
+
{ text: JSON.stringify(output.value) }
|
|
328
|
+
];
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
321
331
|
bedrockContent.push({
|
|
322
332
|
toolResult: {
|
|
323
333
|
toolUseId: part.toolCallId,
|
|
@@ -406,7 +416,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
406
416
|
toolUse: {
|
|
407
417
|
toolUseId: part.toolCallId,
|
|
408
418
|
name: part.toolName,
|
|
409
|
-
input: part.
|
|
419
|
+
input: part.input
|
|
410
420
|
}
|
|
411
421
|
});
|
|
412
422
|
break;
|
|
@@ -675,10 +685,9 @@ var BedrockChatLanguageModel = class {
|
|
|
675
685
|
if (part.toolUse) {
|
|
676
686
|
content.push({
|
|
677
687
|
type: "tool-call",
|
|
678
|
-
toolCallType: "function",
|
|
679
688
|
toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
|
|
680
689
|
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
681
|
-
|
|
690
|
+
input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
|
|
682
691
|
});
|
|
683
692
|
}
|
|
684
693
|
}
|
|
@@ -736,7 +745,7 @@ var BedrockChatLanguageModel = class {
|
|
|
736
745
|
totalTokens: void 0
|
|
737
746
|
};
|
|
738
747
|
let providerMetadata = void 0;
|
|
739
|
-
const
|
|
748
|
+
const contentBlocks = {};
|
|
740
749
|
return {
|
|
741
750
|
stream: response.pipeThrough(
|
|
742
751
|
new TransformStream({
|
|
@@ -744,11 +753,14 @@ var BedrockChatLanguageModel = class {
|
|
|
744
753
|
controller.enqueue({ type: "stream-start", warnings });
|
|
745
754
|
},
|
|
746
755
|
transform(chunk, controller) {
|
|
747
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
756
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
748
757
|
function enqueueError(bedrockError) {
|
|
749
758
|
finishReason = "error";
|
|
750
759
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
751
760
|
}
|
|
761
|
+
if (options.includeRawChunks) {
|
|
762
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
763
|
+
}
|
|
752
764
|
if (!chunk.success) {
|
|
753
765
|
enqueueError(chunk.error);
|
|
754
766
|
return;
|
|
@@ -797,78 +809,126 @@ var BedrockChatLanguageModel = class {
|
|
|
797
809
|
};
|
|
798
810
|
}
|
|
799
811
|
}
|
|
800
|
-
if (((_j = value.
|
|
812
|
+
if (((_j = value.contentBlockStart) == null ? void 0 : _j.contentBlockIndex) != null && !((_l = (_k = value.contentBlockStart) == null ? void 0 : _k.start) == null ? void 0 : _l.toolUse)) {
|
|
813
|
+
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
814
|
+
contentBlocks[blockIndex] = { type: "text" };
|
|
815
|
+
controller.enqueue({
|
|
816
|
+
type: "text-start",
|
|
817
|
+
id: String(blockIndex)
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
if (((_m = value.contentBlockDelta) == null ? void 0 : _m.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
821
|
+
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
822
|
+
if (contentBlocks[blockIndex] == null) {
|
|
823
|
+
contentBlocks[blockIndex] = { type: "text" };
|
|
824
|
+
controller.enqueue({
|
|
825
|
+
type: "text-start",
|
|
826
|
+
id: String(blockIndex)
|
|
827
|
+
});
|
|
828
|
+
}
|
|
801
829
|
controller.enqueue({
|
|
802
|
-
type: "text",
|
|
803
|
-
|
|
830
|
+
type: "text-delta",
|
|
831
|
+
id: String(blockIndex),
|
|
832
|
+
delta: value.contentBlockDelta.delta.text
|
|
804
833
|
});
|
|
805
834
|
}
|
|
806
|
-
if (((
|
|
835
|
+
if (((_n = value.contentBlockStop) == null ? void 0 : _n.contentBlockIndex) != null) {
|
|
836
|
+
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
837
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
838
|
+
if (contentBlock != null) {
|
|
839
|
+
if (contentBlock.type === "reasoning") {
|
|
840
|
+
controller.enqueue({
|
|
841
|
+
type: "reasoning-end",
|
|
842
|
+
id: String(blockIndex)
|
|
843
|
+
});
|
|
844
|
+
} else if (contentBlock.type === "text") {
|
|
845
|
+
controller.enqueue({
|
|
846
|
+
type: "text-end",
|
|
847
|
+
id: String(blockIndex)
|
|
848
|
+
});
|
|
849
|
+
} else if (contentBlock.type === "tool-call") {
|
|
850
|
+
controller.enqueue({
|
|
851
|
+
type: "tool-input-end",
|
|
852
|
+
id: contentBlock.toolCallId
|
|
853
|
+
});
|
|
854
|
+
controller.enqueue({
|
|
855
|
+
type: "tool-call",
|
|
856
|
+
toolCallId: contentBlock.toolCallId,
|
|
857
|
+
toolName: contentBlock.toolName,
|
|
858
|
+
input: contentBlock.jsonText
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
delete contentBlocks[blockIndex];
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
if (((_o = value.contentBlockDelta) == null ? void 0 : _o.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
865
|
+
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
807
866
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
808
867
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
868
|
+
if (contentBlocks[blockIndex] == null) {
|
|
869
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
870
|
+
controller.enqueue({
|
|
871
|
+
type: "reasoning-start",
|
|
872
|
+
id: String(blockIndex)
|
|
873
|
+
});
|
|
874
|
+
}
|
|
809
875
|
controller.enqueue({
|
|
810
|
-
type: "reasoning",
|
|
811
|
-
|
|
876
|
+
type: "reasoning-delta",
|
|
877
|
+
id: String(blockIndex),
|
|
878
|
+
delta: reasoningContent.text
|
|
812
879
|
});
|
|
813
880
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
814
881
|
controller.enqueue({
|
|
815
|
-
type: "reasoning",
|
|
816
|
-
|
|
882
|
+
type: "reasoning-delta",
|
|
883
|
+
id: String(blockIndex),
|
|
884
|
+
delta: "",
|
|
817
885
|
providerMetadata: {
|
|
818
886
|
bedrock: {
|
|
819
887
|
signature: reasoningContent.signature
|
|
820
888
|
}
|
|
821
889
|
}
|
|
822
890
|
});
|
|
823
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
824
891
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
825
892
|
controller.enqueue({
|
|
826
|
-
type: "reasoning",
|
|
827
|
-
|
|
893
|
+
type: "reasoning-delta",
|
|
894
|
+
id: String(blockIndex),
|
|
895
|
+
delta: "",
|
|
828
896
|
providerMetadata: {
|
|
829
897
|
bedrock: {
|
|
830
898
|
redactedData: reasoningContent.data
|
|
831
899
|
}
|
|
832
900
|
}
|
|
833
901
|
});
|
|
834
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
835
902
|
}
|
|
836
903
|
}
|
|
837
904
|
const contentBlockStart = value.contentBlockStart;
|
|
838
|
-
if (((
|
|
905
|
+
if (((_p = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _p.toolUse) != null) {
|
|
839
906
|
const toolUse = contentBlockStart.start.toolUse;
|
|
840
|
-
|
|
907
|
+
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
908
|
+
contentBlocks[blockIndex] = {
|
|
909
|
+
type: "tool-call",
|
|
841
910
|
toolCallId: toolUse.toolUseId,
|
|
842
911
|
toolName: toolUse.name,
|
|
843
912
|
jsonText: ""
|
|
844
913
|
};
|
|
845
|
-
}
|
|
846
|
-
const contentBlockDelta = value.contentBlockDelta;
|
|
847
|
-
if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
848
|
-
const contentBlock = toolCallContentBlocks[contentBlockDelta.contentBlockIndex];
|
|
849
|
-
const delta = (_m = contentBlockDelta.delta.toolUse.input) != null ? _m : "";
|
|
850
914
|
controller.enqueue({
|
|
851
|
-
type: "tool-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
toolName: contentBlock.toolName,
|
|
855
|
-
argsTextDelta: delta
|
|
915
|
+
type: "tool-input-start",
|
|
916
|
+
id: toolUse.toolUseId,
|
|
917
|
+
toolName: toolUse.name
|
|
856
918
|
});
|
|
857
|
-
contentBlock.jsonText += delta;
|
|
858
919
|
}
|
|
859
|
-
const
|
|
860
|
-
if (
|
|
861
|
-
const
|
|
862
|
-
const contentBlock =
|
|
863
|
-
if (contentBlock
|
|
920
|
+
const contentBlockDelta = value.contentBlockDelta;
|
|
921
|
+
if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
922
|
+
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
923
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
924
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
925
|
+
const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
|
|
864
926
|
controller.enqueue({
|
|
865
|
-
type: "tool-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
toolName: contentBlock.toolName,
|
|
869
|
-
args: contentBlock.jsonText
|
|
927
|
+
type: "tool-input-delta",
|
|
928
|
+
id: contentBlock.toolCallId,
|
|
929
|
+
delta
|
|
870
930
|
});
|
|
871
|
-
|
|
931
|
+
contentBlock.jsonText += delta;
|
|
872
932
|
}
|
|
873
933
|
}
|
|
874
934
|
},
|
|
@@ -968,9 +1028,9 @@ var BedrockStreamSchema = z3.object({
|
|
|
968
1028
|
contentBlockStop: z3.object({
|
|
969
1029
|
contentBlockIndex: z3.number()
|
|
970
1030
|
}).nullish(),
|
|
971
|
-
internalServerException: z3.record(z3.unknown()).nullish(),
|
|
1031
|
+
internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
972
1032
|
messageStop: z3.object({
|
|
973
|
-
additionalModelResponseFields: z3.record(z3.unknown()).nullish(),
|
|
1033
|
+
additionalModelResponseFields: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
974
1034
|
stopReason: BedrockStopReasonSchema
|
|
975
1035
|
}).nullish(),
|
|
976
1036
|
metadata: z3.object({
|
|
@@ -982,9 +1042,9 @@ var BedrockStreamSchema = z3.object({
|
|
|
982
1042
|
outputTokens: z3.number()
|
|
983
1043
|
}).nullish()
|
|
984
1044
|
}).nullish(),
|
|
985
|
-
modelStreamErrorException: z3.record(z3.unknown()).nullish(),
|
|
986
|
-
throttlingException: z3.record(z3.unknown()).nullish(),
|
|
987
|
-
validationException: z3.record(z3.unknown()).nullish()
|
|
1045
|
+
modelStreamErrorException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1046
|
+
throttlingException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1047
|
+
validationException: z3.record(z3.string(), z3.unknown()).nullish()
|
|
988
1048
|
});
|
|
989
1049
|
var bedrockReasoningMetadataSchema = z3.object({
|
|
990
1050
|
signature: z3.string().optional(),
|
|
@@ -1005,7 +1065,7 @@ import {
|
|
|
1005
1065
|
} from "@ai-sdk/provider-utils";
|
|
1006
1066
|
|
|
1007
1067
|
// src/bedrock-embedding-options.ts
|
|
1008
|
-
import { z as z4 } from "zod";
|
|
1068
|
+
import { z as z4 } from "zod/v4";
|
|
1009
1069
|
var bedrockEmbeddingProviderOptions = z4.object({
|
|
1010
1070
|
/**
|
|
1011
1071
|
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
@@ -1020,7 +1080,7 @@ var bedrockEmbeddingProviderOptions = z4.object({
|
|
|
1020
1080
|
});
|
|
1021
1081
|
|
|
1022
1082
|
// src/bedrock-embedding-model.ts
|
|
1023
|
-
import { z as z5 } from "zod";
|
|
1083
|
+
import { z as z5 } from "zod/v4";
|
|
1024
1084
|
var BedrockEmbeddingModel = class {
|
|
1025
1085
|
constructor(modelId, config) {
|
|
1026
1086
|
this.modelId = modelId;
|
|
@@ -1102,7 +1162,7 @@ var modelMaxImagesPerCall = {
|
|
|
1102
1162
|
};
|
|
1103
1163
|
|
|
1104
1164
|
// src/bedrock-image-model.ts
|
|
1105
|
-
import { z as z6 } from "zod";
|
|
1165
|
+
import { z as z6 } from "zod/v4";
|
|
1106
1166
|
var BedrockImageModel = class {
|
|
1107
1167
|
constructor(modelId, config) {
|
|
1108
1168
|
this.modelId = modelId;
|