@ai-sdk/amazon-bedrock 5.0.0-beta.4 → 5.0.0-beta.41
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 +321 -4
- package/README.md +2 -0
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +88 -69
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +493 -307
- package/dist/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +49 -6
- package/package.json +10 -12
- package/src/anthropic/bedrock-anthropic-fetch.ts +26 -0
- package/src/anthropic/bedrock-anthropic-options.ts +2 -0
- package/src/anthropic/bedrock-anthropic-provider.ts +11 -1
- package/src/bedrock-api-types.ts +3 -0
- package/src/bedrock-chat-language-model.ts +139 -6
- package/src/bedrock-chat-options.ts +16 -1
- package/src/bedrock-embedding-model.ts +22 -2
- package/src/bedrock-image-model.ts +22 -2
- package/src/convert-to-bedrock-chat-messages.ts +46 -34
- package/dist/anthropic/index.d.mts +0 -91
- package/dist/anthropic/index.mjs +0 -397
- package/dist/anthropic/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -194
- package/dist/index.mjs +0 -2329
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
bedrock: () => bedrock,
|
|
25
|
-
createAmazonBedrock: () => createAmazonBedrock
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/bedrock-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
3
|
+
import {
|
|
4
|
+
generateId,
|
|
5
|
+
loadOptionalSetting,
|
|
6
|
+
loadSetting,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix as withUserAgentSuffix2
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
32
10
|
|
|
33
11
|
// src/bedrock-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import {
|
|
13
|
+
combineHeaders,
|
|
14
|
+
createJsonErrorResponseHandler,
|
|
15
|
+
createJsonResponseHandler,
|
|
16
|
+
isCustomReasoning,
|
|
17
|
+
mapReasoningToProviderBudget,
|
|
18
|
+
mapReasoningToProviderEffort,
|
|
19
|
+
parseProviderOptions as parseProviderOptions2,
|
|
20
|
+
postJsonToApi,
|
|
21
|
+
resolve,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
25
|
+
} from "@ai-sdk/provider-utils";
|
|
26
|
+
import { getModelCapabilities } from "@ai-sdk/anthropic/internal";
|
|
27
|
+
import { z as z3 } from "zod/v4";
|
|
36
28
|
|
|
37
29
|
// src/bedrock-api-types.ts
|
|
38
30
|
var BEDROCK_STOP_REASONS = [
|
|
@@ -66,57 +58,72 @@ var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
|
66
58
|
};
|
|
67
59
|
|
|
68
60
|
// src/bedrock-chat-options.ts
|
|
69
|
-
|
|
70
|
-
var bedrockFilePartProviderOptions =
|
|
61
|
+
import { z } from "zod/v4";
|
|
62
|
+
var bedrockFilePartProviderOptions = z.object({
|
|
71
63
|
/**
|
|
72
64
|
* Citation configuration for this document.
|
|
73
65
|
* When enabled, this document will generate citations in the response.
|
|
74
66
|
*/
|
|
75
|
-
citations:
|
|
67
|
+
citations: z.object({
|
|
76
68
|
/**
|
|
77
69
|
* Enable citations for this document
|
|
78
70
|
*/
|
|
79
|
-
enabled:
|
|
71
|
+
enabled: z.boolean()
|
|
80
72
|
}).optional()
|
|
81
73
|
});
|
|
82
|
-
var amazonBedrockLanguageModelOptions =
|
|
74
|
+
var amazonBedrockLanguageModelOptions = z.object({
|
|
83
75
|
/**
|
|
84
76
|
* Additional inference parameters that the model supports,
|
|
85
77
|
* beyond the base set of inference parameters that Converse
|
|
86
78
|
* supports in the inferenceConfig field
|
|
87
79
|
*/
|
|
88
|
-
additionalModelRequestFields:
|
|
89
|
-
reasoningConfig:
|
|
90
|
-
type:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
additionalModelRequestFields: z.record(z.string(), z.any()).optional(),
|
|
81
|
+
reasoningConfig: z.object({
|
|
82
|
+
type: z.union([
|
|
83
|
+
z.literal("enabled"),
|
|
84
|
+
z.literal("disabled"),
|
|
85
|
+
z.literal("adaptive")
|
|
94
86
|
]).optional(),
|
|
95
|
-
budgetTokens:
|
|
96
|
-
maxReasoningEffort:
|
|
87
|
+
budgetTokens: z.number().optional(),
|
|
88
|
+
maxReasoningEffort: z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
89
|
+
display: z.enum(["omitted", "summarized"]).optional()
|
|
97
90
|
}).optional(),
|
|
98
91
|
/**
|
|
99
92
|
* Anthropic beta features to enable
|
|
100
93
|
*/
|
|
101
|
-
anthropicBeta:
|
|
94
|
+
anthropicBeta: z.array(z.string()).optional(),
|
|
95
|
+
/**
|
|
96
|
+
* Service tier for the request.
|
|
97
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
|
|
98
|
+
*
|
|
99
|
+
* - 'reserved': Uses provisioned throughput capacity
|
|
100
|
+
* - 'priority': Prioritizes low-latency inference when capacity is available
|
|
101
|
+
* - 'default': Standard on-demand tier
|
|
102
|
+
* - 'flex': Lower-cost tier for flexible latency workloads
|
|
103
|
+
*/
|
|
104
|
+
serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
102
105
|
});
|
|
103
106
|
|
|
104
107
|
// src/bedrock-error.ts
|
|
105
|
-
|
|
106
|
-
var BedrockErrorSchema =
|
|
107
|
-
message:
|
|
108
|
-
type:
|
|
108
|
+
import { z as z2 } from "zod/v4";
|
|
109
|
+
var BedrockErrorSchema = z2.object({
|
|
110
|
+
message: z2.string(),
|
|
111
|
+
type: z2.string().nullish()
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
// src/bedrock-event-stream-response-handler.ts
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
import { EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
116
|
+
import {
|
|
117
|
+
safeParseJSON,
|
|
118
|
+
extractResponseHeaders,
|
|
119
|
+
safeValidateTypes
|
|
120
|
+
} from "@ai-sdk/provider-utils";
|
|
114
121
|
|
|
115
122
|
// src/bedrock-event-stream-decoder.ts
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
124
|
+
import { toUtf8, fromUtf8 } from "@smithy/util-utf8";
|
|
118
125
|
function createBedrockEventStreamDecoder(body, processEvent) {
|
|
119
|
-
const codec = new
|
|
126
|
+
const codec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
120
127
|
let buffer = new Uint8Array(0);
|
|
121
128
|
const textDecoder = new TextDecoder();
|
|
122
129
|
return body.pipeThrough(
|
|
@@ -155,9 +162,9 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
155
162
|
|
|
156
163
|
// src/bedrock-event-stream-response-handler.ts
|
|
157
164
|
var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
158
|
-
const responseHeaders =
|
|
165
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
159
166
|
if (response.body == null) {
|
|
160
|
-
throw new
|
|
167
|
+
throw new EmptyResponseBodyError({});
|
|
161
168
|
}
|
|
162
169
|
return {
|
|
163
170
|
responseHeaders,
|
|
@@ -165,7 +172,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
165
172
|
response.body,
|
|
166
173
|
async (event, controller) => {
|
|
167
174
|
if (event.messageType === "event") {
|
|
168
|
-
const parsedDataResult = await
|
|
175
|
+
const parsedDataResult = await safeParseJSON({ text: event.data });
|
|
169
176
|
if (!parsedDataResult.success) {
|
|
170
177
|
controller.enqueue(parsedDataResult);
|
|
171
178
|
return;
|
|
@@ -174,7 +181,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
174
181
|
const wrappedData = {
|
|
175
182
|
[event.eventType]: parsedDataResult.value
|
|
176
183
|
};
|
|
177
|
-
const validatedWrappedData = await
|
|
184
|
+
const validatedWrappedData = await safeValidateTypes({
|
|
178
185
|
value: wrappedData,
|
|
179
186
|
schema: chunkSchema
|
|
180
187
|
});
|
|
@@ -194,9 +201,14 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
194
201
|
};
|
|
195
202
|
|
|
196
203
|
// src/bedrock-prepare-tools.ts
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
import {
|
|
205
|
+
UnsupportedFunctionalityError
|
|
206
|
+
} from "@ai-sdk/provider";
|
|
207
|
+
import { asSchema } from "@ai-sdk/provider-utils";
|
|
208
|
+
import {
|
|
209
|
+
anthropicTools,
|
|
210
|
+
prepareTools as prepareAnthropicTools
|
|
211
|
+
} from "@ai-sdk/anthropic/internal";
|
|
200
212
|
async function prepareTools({
|
|
201
213
|
tools,
|
|
202
214
|
toolChoice,
|
|
@@ -243,7 +255,7 @@ async function prepareTools({
|
|
|
243
255
|
toolChoice: preparedAnthropicToolChoice,
|
|
244
256
|
toolWarnings: anthropicToolWarnings,
|
|
245
257
|
betas: anthropicBetas
|
|
246
|
-
} = await (
|
|
258
|
+
} = await prepareAnthropicTools({
|
|
247
259
|
tools: ProviderTools,
|
|
248
260
|
toolChoice,
|
|
249
261
|
supportsStructuredOutput: false,
|
|
@@ -257,7 +269,7 @@ async function prepareTools({
|
|
|
257
269
|
};
|
|
258
270
|
}
|
|
259
271
|
for (const tool of ProviderTools) {
|
|
260
|
-
const toolFactory = Object.values(
|
|
272
|
+
const toolFactory = Object.values(anthropicTools).find((factory) => {
|
|
261
273
|
const instance = factory({});
|
|
262
274
|
return instance.id === tool.id;
|
|
263
275
|
});
|
|
@@ -267,7 +279,7 @@ async function prepareTools({
|
|
|
267
279
|
toolSpec: {
|
|
268
280
|
name: tool.name,
|
|
269
281
|
inputSchema: {
|
|
270
|
-
json: await
|
|
282
|
+
json: await asSchema(fullToolDefinition.inputSchema).jsonSchema
|
|
271
283
|
}
|
|
272
284
|
}
|
|
273
285
|
});
|
|
@@ -312,7 +324,7 @@ async function prepareTools({
|
|
|
312
324
|
break;
|
|
313
325
|
default: {
|
|
314
326
|
const _exhaustiveCheck = type;
|
|
315
|
-
throw new
|
|
327
|
+
throw new UnsupportedFunctionalityError({
|
|
316
328
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
317
329
|
});
|
|
318
330
|
}
|
|
@@ -367,8 +379,15 @@ function convertBedrockUsage(usage) {
|
|
|
367
379
|
}
|
|
368
380
|
|
|
369
381
|
// src/convert-to-bedrock-chat-messages.ts
|
|
370
|
-
|
|
371
|
-
|
|
382
|
+
import {
|
|
383
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
384
|
+
} from "@ai-sdk/provider";
|
|
385
|
+
import {
|
|
386
|
+
convertToBase64,
|
|
387
|
+
isProviderReference,
|
|
388
|
+
parseProviderOptions,
|
|
389
|
+
stripFileExtension
|
|
390
|
+
} from "@ai-sdk/provider-utils";
|
|
372
391
|
|
|
373
392
|
// src/normalize-tool-call-id.ts
|
|
374
393
|
function isMistralModel(modelId) {
|
|
@@ -393,7 +412,7 @@ function getCachePoint(providerMetadata) {
|
|
|
393
412
|
}
|
|
394
413
|
async function shouldEnableCitations(providerMetadata) {
|
|
395
414
|
var _a, _b;
|
|
396
|
-
const bedrockOptions = await
|
|
415
|
+
const bedrockOptions = await parseProviderOptions({
|
|
397
416
|
provider: "bedrock",
|
|
398
417
|
providerOptions: providerMetadata,
|
|
399
418
|
schema: bedrockFilePartProviderOptions
|
|
@@ -414,7 +433,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
414
433
|
switch (type) {
|
|
415
434
|
case "system": {
|
|
416
435
|
if (messages.length > 0) {
|
|
417
|
-
throw new
|
|
436
|
+
throw new UnsupportedFunctionalityError2({
|
|
418
437
|
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
419
438
|
});
|
|
420
439
|
}
|
|
@@ -443,8 +462,13 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
443
462
|
break;
|
|
444
463
|
}
|
|
445
464
|
case "file": {
|
|
465
|
+
if (isProviderReference(part.data)) {
|
|
466
|
+
throw new UnsupportedFunctionalityError2({
|
|
467
|
+
functionality: "file parts with provider references"
|
|
468
|
+
});
|
|
469
|
+
}
|
|
446
470
|
if (part.data instanceof URL) {
|
|
447
|
-
throw new
|
|
471
|
+
throw new UnsupportedFunctionalityError2({
|
|
448
472
|
functionality: "File URL data"
|
|
449
473
|
});
|
|
450
474
|
}
|
|
@@ -452,12 +476,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
452
476
|
bedrockContent.push({
|
|
453
477
|
image: {
|
|
454
478
|
format: getBedrockImageFormat(part.mediaType),
|
|
455
|
-
source: { bytes:
|
|
479
|
+
source: { bytes: convertToBase64(part.data) }
|
|
456
480
|
}
|
|
457
481
|
});
|
|
458
482
|
} else {
|
|
459
483
|
if (!part.mediaType) {
|
|
460
|
-
throw new
|
|
484
|
+
throw new UnsupportedFunctionalityError2({
|
|
461
485
|
functionality: "file without mime type",
|
|
462
486
|
message: "File mime type is required in user message part content"
|
|
463
487
|
});
|
|
@@ -468,8 +492,8 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
468
492
|
bedrockContent.push({
|
|
469
493
|
document: {
|
|
470
494
|
format: getBedrockDocumentFormat(part.mediaType),
|
|
471
|
-
name: part.filename ?
|
|
472
|
-
source: { bytes:
|
|
495
|
+
name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
|
|
496
|
+
source: { bytes: convertToBase64(part.data) },
|
|
473
497
|
...enableCitations && {
|
|
474
498
|
citations: { enabled: true }
|
|
475
499
|
}
|
|
@@ -495,9 +519,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
495
519
|
switch (contentPart.type) {
|
|
496
520
|
case "text":
|
|
497
521
|
return { text: contentPart.text };
|
|
498
|
-
case "
|
|
522
|
+
case "file-data":
|
|
499
523
|
if (!contentPart.mediaType.startsWith("image/")) {
|
|
500
|
-
throw new
|
|
524
|
+
throw new UnsupportedFunctionalityError2({
|
|
501
525
|
functionality: `media type: ${contentPart.mediaType}`
|
|
502
526
|
});
|
|
503
527
|
}
|
|
@@ -511,7 +535,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
511
535
|
}
|
|
512
536
|
};
|
|
513
537
|
default: {
|
|
514
|
-
throw new
|
|
538
|
+
throw new UnsupportedFunctionalityError2({
|
|
515
539
|
functionality: `unsupported tool content part type: ${contentPart.type}`
|
|
516
540
|
});
|
|
517
541
|
}
|
|
@@ -564,12 +588,15 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
564
588
|
const message = block.messages[j];
|
|
565
589
|
const isLastMessage = j === block.messages.length - 1;
|
|
566
590
|
const { content } = message;
|
|
591
|
+
const hasReasoningBlocks = content.some(
|
|
592
|
+
(part) => part.type === "reasoning"
|
|
593
|
+
);
|
|
567
594
|
for (let k = 0; k < content.length; k++) {
|
|
568
595
|
const part = content[k];
|
|
569
596
|
const isLastContentPart = k === content.length - 1;
|
|
570
597
|
switch (part.type) {
|
|
571
598
|
case "text": {
|
|
572
|
-
if (!part.text.trim()) {
|
|
599
|
+
if (!part.text.trim() && !hasReasoningBlocks) {
|
|
573
600
|
break;
|
|
574
601
|
}
|
|
575
602
|
bedrockContent.push({
|
|
@@ -588,38 +615,41 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
588
615
|
break;
|
|
589
616
|
}
|
|
590
617
|
case "reasoning": {
|
|
591
|
-
const reasoningMetadata = await
|
|
618
|
+
const reasoningMetadata = await parseProviderOptions({
|
|
592
619
|
provider: "bedrock",
|
|
593
620
|
providerOptions: part.providerOptions,
|
|
594
621
|
schema: bedrockReasoningMetadataSchema
|
|
595
622
|
});
|
|
596
|
-
if (reasoningMetadata != null) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
// because Bedrock does not allow trailing whitespace
|
|
603
|
-
// in pre-filled assistant responses
|
|
604
|
-
text: trimIfLast(
|
|
605
|
-
isLastBlock,
|
|
606
|
-
isLastMessage,
|
|
607
|
-
isLastContentPart,
|
|
608
|
-
part.text
|
|
609
|
-
),
|
|
610
|
-
signature: reasoningMetadata.signature
|
|
611
|
-
}
|
|
623
|
+
if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
|
|
624
|
+
bedrockContent.push({
|
|
625
|
+
reasoningContent: {
|
|
626
|
+
reasoningText: {
|
|
627
|
+
text: part.text,
|
|
628
|
+
signature: reasoningMetadata.signature
|
|
612
629
|
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
633
|
+
bedrockContent.push({
|
|
634
|
+
reasoningContent: {
|
|
635
|
+
redactedReasoning: {
|
|
636
|
+
data: reasoningMetadata.redactedData
|
|
620
637
|
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
} else {
|
|
641
|
+
bedrockContent.push({
|
|
642
|
+
reasoningContent: {
|
|
643
|
+
reasoningText: {
|
|
644
|
+
text: trimIfLast(
|
|
645
|
+
isLastBlock,
|
|
646
|
+
isLastMessage,
|
|
647
|
+
isLastContentPart,
|
|
648
|
+
part.text
|
|
649
|
+
)
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
});
|
|
623
653
|
}
|
|
624
654
|
break;
|
|
625
655
|
}
|
|
@@ -653,14 +683,14 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
653
683
|
}
|
|
654
684
|
function getBedrockImageFormat(mimeType) {
|
|
655
685
|
if (!mimeType) {
|
|
656
|
-
throw new
|
|
686
|
+
throw new UnsupportedFunctionalityError2({
|
|
657
687
|
functionality: "image without mime type",
|
|
658
688
|
message: "Image mime type is required in user message part content"
|
|
659
689
|
});
|
|
660
690
|
}
|
|
661
691
|
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
662
692
|
if (!format) {
|
|
663
|
-
throw new
|
|
693
|
+
throw new UnsupportedFunctionalityError2({
|
|
664
694
|
functionality: `image mime type: ${mimeType}`,
|
|
665
695
|
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
666
696
|
});
|
|
@@ -670,7 +700,7 @@ function getBedrockImageFormat(mimeType) {
|
|
|
670
700
|
function getBedrockDocumentFormat(mimeType) {
|
|
671
701
|
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
672
702
|
if (!format) {
|
|
673
|
-
throw new
|
|
703
|
+
throw new UnsupportedFunctionalityError2({
|
|
674
704
|
functionality: `file mime type: ${mimeType}`,
|
|
675
705
|
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
676
706
|
});
|
|
@@ -746,7 +776,7 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
746
776
|
}
|
|
747
777
|
|
|
748
778
|
// src/bedrock-chat-language-model.ts
|
|
749
|
-
var BedrockChatLanguageModel = class {
|
|
779
|
+
var BedrockChatLanguageModel = class _BedrockChatLanguageModel {
|
|
750
780
|
constructor(modelId, config) {
|
|
751
781
|
this.modelId = modelId;
|
|
752
782
|
this.config = config;
|
|
@@ -756,6 +786,15 @@ var BedrockChatLanguageModel = class {
|
|
|
756
786
|
// no supported urls for bedrock
|
|
757
787
|
};
|
|
758
788
|
}
|
|
789
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
790
|
+
return serializeModelOptions({
|
|
791
|
+
modelId: model.modelId,
|
|
792
|
+
config: model.config
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
796
|
+
return new _BedrockChatLanguageModel(options.modelId, options.config);
|
|
797
|
+
}
|
|
759
798
|
async getArgs({
|
|
760
799
|
prompt,
|
|
761
800
|
maxOutputTokens,
|
|
@@ -769,10 +808,11 @@ var BedrockChatLanguageModel = class {
|
|
|
769
808
|
seed,
|
|
770
809
|
tools,
|
|
771
810
|
toolChoice,
|
|
811
|
+
reasoning,
|
|
772
812
|
providerOptions
|
|
773
813
|
}) {
|
|
774
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
775
|
-
|
|
814
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
815
|
+
let bedrockOptions = (_a = await parseProviderOptions2({
|
|
776
816
|
provider: "bedrock",
|
|
777
817
|
providerOptions,
|
|
778
818
|
schema: amazonBedrockLanguageModelOptions
|
|
@@ -819,8 +859,17 @@ var BedrockChatLanguageModel = class {
|
|
|
819
859
|
});
|
|
820
860
|
}
|
|
821
861
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
862
|
+
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
863
|
+
bedrockOptions = resolveBedrockReasoningConfig({
|
|
864
|
+
reasoning,
|
|
865
|
+
bedrockOptions,
|
|
866
|
+
warnings,
|
|
867
|
+
isAnthropicModel,
|
|
868
|
+
modelId: this.modelId
|
|
869
|
+
});
|
|
822
870
|
const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
|
|
823
|
-
const
|
|
871
|
+
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
872
|
+
const useNativeStructuredOutput = isAnthropicModel && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
824
873
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
825
874
|
type: "function",
|
|
826
875
|
name: "json",
|
|
@@ -849,6 +898,7 @@ var BedrockChatLanguageModel = class {
|
|
|
849
898
|
}
|
|
850
899
|
const thinkingType = (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type;
|
|
851
900
|
const thinkingBudget = thinkingType === "enabled" ? (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.budgetTokens : void 0;
|
|
901
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.display : void 0;
|
|
852
902
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
853
903
|
const inferenceConfig = {
|
|
854
904
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -875,12 +925,13 @@ var BedrockChatLanguageModel = class {
|
|
|
875
925
|
bedrockOptions.additionalModelRequestFields = {
|
|
876
926
|
...bedrockOptions.additionalModelRequestFields,
|
|
877
927
|
thinking: {
|
|
878
|
-
type: "adaptive"
|
|
928
|
+
type: "adaptive",
|
|
929
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
879
930
|
}
|
|
880
931
|
};
|
|
881
932
|
}
|
|
882
933
|
} else if (!isAnthropicModel) {
|
|
883
|
-
if (((
|
|
934
|
+
if (((_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.budgetTokens) != null) {
|
|
884
935
|
warnings.push({
|
|
885
936
|
type: "unsupported",
|
|
886
937
|
feature: "budgetTokens",
|
|
@@ -895,14 +946,13 @@ var BedrockChatLanguageModel = class {
|
|
|
895
946
|
});
|
|
896
947
|
}
|
|
897
948
|
}
|
|
898
|
-
const maxReasoningEffort = (
|
|
899
|
-
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
949
|
+
const maxReasoningEffort = (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.maxReasoningEffort;
|
|
900
950
|
if (maxReasoningEffort != null) {
|
|
901
951
|
if (isAnthropicModel) {
|
|
902
952
|
bedrockOptions.additionalModelRequestFields = {
|
|
903
953
|
...bedrockOptions.additionalModelRequestFields,
|
|
904
954
|
output_config: {
|
|
905
|
-
...(
|
|
955
|
+
...(_j = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _j.output_config,
|
|
906
956
|
effort: maxReasoningEffort
|
|
907
957
|
}
|
|
908
958
|
};
|
|
@@ -926,7 +976,7 @@ var BedrockChatLanguageModel = class {
|
|
|
926
976
|
bedrockOptions.additionalModelRequestFields = {
|
|
927
977
|
...bedrockOptions.additionalModelRequestFields,
|
|
928
978
|
output_config: {
|
|
929
|
-
...(
|
|
979
|
+
...(_k = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _k.output_config,
|
|
930
980
|
format: {
|
|
931
981
|
type: "json_schema",
|
|
932
982
|
schema: responseFormat.schema
|
|
@@ -958,7 +1008,7 @@ var BedrockChatLanguageModel = class {
|
|
|
958
1008
|
details: "topK is not supported when thinking is enabled"
|
|
959
1009
|
});
|
|
960
1010
|
}
|
|
961
|
-
const hasAnyTools = ((
|
|
1011
|
+
const hasAnyTools = ((_m = (_l = toolConfig.tools) == null ? void 0 : _l.length) != null ? _m : 0) > 0 || additionalTools;
|
|
962
1012
|
let filteredPrompt = prompt;
|
|
963
1013
|
if (!hasAnyTools) {
|
|
964
1014
|
const hasToolContent = prompt.some(
|
|
@@ -992,6 +1042,7 @@ var BedrockChatLanguageModel = class {
|
|
|
992
1042
|
const {
|
|
993
1043
|
reasoningConfig: _,
|
|
994
1044
|
additionalModelRequestFields: __,
|
|
1045
|
+
serviceTier: ___,
|
|
995
1046
|
...filteredBedrockOptions
|
|
996
1047
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
997
1048
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -1006,6 +1057,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1006
1057
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
1007
1058
|
inferenceConfig
|
|
1008
1059
|
},
|
|
1060
|
+
...bedrockOptions.serviceTier != null && {
|
|
1061
|
+
serviceTier: {
|
|
1062
|
+
type: bedrockOptions.serviceTier
|
|
1063
|
+
}
|
|
1064
|
+
},
|
|
1009
1065
|
...filteredBedrockOptions,
|
|
1010
1066
|
...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
|
|
1011
1067
|
},
|
|
@@ -1017,7 +1073,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1017
1073
|
async getHeaders({
|
|
1018
1074
|
headers
|
|
1019
1075
|
}) {
|
|
1020
|
-
return
|
|
1076
|
+
return combineHeaders(
|
|
1077
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
1078
|
+
headers
|
|
1079
|
+
);
|
|
1021
1080
|
}
|
|
1022
1081
|
async doGenerate(options) {
|
|
1023
1082
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
@@ -1027,18 +1086,18 @@ var BedrockChatLanguageModel = class {
|
|
|
1027
1086
|
usesJsonResponseTool
|
|
1028
1087
|
} = await this.getArgs(options);
|
|
1029
1088
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
1030
|
-
const { value: response, responseHeaders } = await
|
|
1089
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1031
1090
|
url,
|
|
1032
1091
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1033
1092
|
body: args,
|
|
1034
|
-
failedResponseHandler:
|
|
1093
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
1035
1094
|
errorSchema: BedrockErrorSchema,
|
|
1036
1095
|
errorToMessage: (error) => {
|
|
1037
1096
|
var _a2;
|
|
1038
1097
|
return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
|
|
1039
1098
|
}
|
|
1040
1099
|
}),
|
|
1041
|
-
successfulResponseHandler:
|
|
1100
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1042
1101
|
BedrockResponseSchema
|
|
1043
1102
|
),
|
|
1044
1103
|
abortSignal: options.abortSignal,
|
|
@@ -1047,7 +1106,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1047
1106
|
const content = [];
|
|
1048
1107
|
let isJsonResponseFromTool = false;
|
|
1049
1108
|
for (const part of response.output.message.content) {
|
|
1050
|
-
if (part.text) {
|
|
1109
|
+
if (part.text != null) {
|
|
1051
1110
|
content.push({ type: "text", text: part.text });
|
|
1052
1111
|
}
|
|
1053
1112
|
if (part.reasoningContent) {
|
|
@@ -1149,11 +1208,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1149
1208
|
const modelId = this.modelId;
|
|
1150
1209
|
const isMistral = isMistralModel(modelId);
|
|
1151
1210
|
const url = `${this.getUrl(modelId)}/converse-stream`;
|
|
1152
|
-
const { value: response, responseHeaders } = await
|
|
1211
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1153
1212
|
url,
|
|
1154
1213
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1155
1214
|
body: args,
|
|
1156
|
-
failedResponseHandler:
|
|
1215
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
1157
1216
|
errorSchema: BedrockErrorSchema,
|
|
1158
1217
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1159
1218
|
}),
|
|
@@ -1341,6 +1400,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1341
1400
|
delta: reasoningContent.text
|
|
1342
1401
|
});
|
|
1343
1402
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
1403
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1404
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1405
|
+
controller.enqueue({
|
|
1406
|
+
type: "reasoning-start",
|
|
1407
|
+
id: String(blockIndex)
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1344
1410
|
controller.enqueue({
|
|
1345
1411
|
type: "reasoning-delta",
|
|
1346
1412
|
id: String(blockIndex),
|
|
@@ -1352,6 +1418,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1352
1418
|
}
|
|
1353
1419
|
});
|
|
1354
1420
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
1421
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1422
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1423
|
+
controller.enqueue({
|
|
1424
|
+
type: "reasoning-start",
|
|
1425
|
+
id: String(blockIndex)
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1355
1428
|
controller.enqueue({
|
|
1356
1429
|
type: "reasoning-delta",
|
|
1357
1430
|
id: String(blockIndex),
|
|
@@ -1444,146 +1517,214 @@ var BedrockChatLanguageModel = class {
|
|
|
1444
1517
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
1445
1518
|
}
|
|
1446
1519
|
};
|
|
1447
|
-
var BedrockStopReasonSchema =
|
|
1448
|
-
|
|
1449
|
-
|
|
1520
|
+
var BedrockStopReasonSchema = z3.union([
|
|
1521
|
+
z3.enum(BEDROCK_STOP_REASONS),
|
|
1522
|
+
z3.string()
|
|
1450
1523
|
]);
|
|
1451
|
-
var BedrockAdditionalModelResponseFieldsSchema =
|
|
1452
|
-
delta:
|
|
1453
|
-
stop_sequence:
|
|
1524
|
+
var BedrockAdditionalModelResponseFieldsSchema = z3.object({
|
|
1525
|
+
delta: z3.object({
|
|
1526
|
+
stop_sequence: z3.string().nullish()
|
|
1454
1527
|
}).nullish()
|
|
1455
|
-
}).catchall(
|
|
1456
|
-
var BedrockToolUseSchema =
|
|
1457
|
-
toolUseId:
|
|
1458
|
-
name:
|
|
1459
|
-
input:
|
|
1528
|
+
}).catchall(z3.unknown());
|
|
1529
|
+
var BedrockToolUseSchema = z3.object({
|
|
1530
|
+
toolUseId: z3.string(),
|
|
1531
|
+
name: z3.string(),
|
|
1532
|
+
input: z3.unknown()
|
|
1460
1533
|
});
|
|
1461
|
-
var BedrockReasoningTextSchema =
|
|
1462
|
-
signature:
|
|
1463
|
-
text:
|
|
1534
|
+
var BedrockReasoningTextSchema = z3.object({
|
|
1535
|
+
signature: z3.string().nullish(),
|
|
1536
|
+
text: z3.string()
|
|
1464
1537
|
});
|
|
1465
|
-
var BedrockRedactedReasoningSchema =
|
|
1466
|
-
data:
|
|
1538
|
+
var BedrockRedactedReasoningSchema = z3.object({
|
|
1539
|
+
data: z3.string()
|
|
1467
1540
|
});
|
|
1468
|
-
var BedrockResponseSchema =
|
|
1469
|
-
metrics:
|
|
1470
|
-
latencyMs:
|
|
1541
|
+
var BedrockResponseSchema = z3.object({
|
|
1542
|
+
metrics: z3.object({
|
|
1543
|
+
latencyMs: z3.number()
|
|
1471
1544
|
}).nullish(),
|
|
1472
|
-
output:
|
|
1473
|
-
message:
|
|
1474
|
-
content:
|
|
1475
|
-
|
|
1476
|
-
text:
|
|
1545
|
+
output: z3.object({
|
|
1546
|
+
message: z3.object({
|
|
1547
|
+
content: z3.array(
|
|
1548
|
+
z3.object({
|
|
1549
|
+
text: z3.string().nullish(),
|
|
1477
1550
|
toolUse: BedrockToolUseSchema.nullish(),
|
|
1478
|
-
reasoningContent:
|
|
1479
|
-
|
|
1551
|
+
reasoningContent: z3.union([
|
|
1552
|
+
z3.object({
|
|
1480
1553
|
reasoningText: BedrockReasoningTextSchema
|
|
1481
1554
|
}),
|
|
1482
|
-
|
|
1555
|
+
z3.object({
|
|
1483
1556
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
1484
1557
|
})
|
|
1485
1558
|
]).nullish()
|
|
1486
1559
|
})
|
|
1487
1560
|
),
|
|
1488
|
-
role:
|
|
1561
|
+
role: z3.string()
|
|
1489
1562
|
})
|
|
1490
1563
|
}),
|
|
1491
1564
|
stopReason: BedrockStopReasonSchema,
|
|
1492
1565
|
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1493
|
-
trace:
|
|
1494
|
-
performanceConfig:
|
|
1495
|
-
serviceTier:
|
|
1496
|
-
usage:
|
|
1497
|
-
inputTokens:
|
|
1498
|
-
outputTokens:
|
|
1499
|
-
totalTokens:
|
|
1500
|
-
cacheReadInputTokens:
|
|
1501
|
-
cacheWriteInputTokens:
|
|
1502
|
-
cacheDetails:
|
|
1566
|
+
trace: z3.unknown().nullish(),
|
|
1567
|
+
performanceConfig: z3.object({ latency: z3.string() }).nullish(),
|
|
1568
|
+
serviceTier: z3.object({ type: z3.string() }).nullish(),
|
|
1569
|
+
usage: z3.object({
|
|
1570
|
+
inputTokens: z3.number(),
|
|
1571
|
+
outputTokens: z3.number(),
|
|
1572
|
+
totalTokens: z3.number(),
|
|
1573
|
+
cacheReadInputTokens: z3.number().nullish(),
|
|
1574
|
+
cacheWriteInputTokens: z3.number().nullish(),
|
|
1575
|
+
cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish()
|
|
1503
1576
|
})
|
|
1504
1577
|
});
|
|
1505
|
-
var BedrockStreamSchema =
|
|
1506
|
-
contentBlockDelta:
|
|
1507
|
-
contentBlockIndex:
|
|
1508
|
-
delta:
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
reasoningContent:
|
|
1578
|
+
var BedrockStreamSchema = z3.object({
|
|
1579
|
+
contentBlockDelta: z3.object({
|
|
1580
|
+
contentBlockIndex: z3.number(),
|
|
1581
|
+
delta: z3.union([
|
|
1582
|
+
z3.object({ text: z3.string() }),
|
|
1583
|
+
z3.object({ toolUse: z3.object({ input: z3.string() }) }),
|
|
1584
|
+
z3.object({
|
|
1585
|
+
reasoningContent: z3.object({ text: z3.string() })
|
|
1513
1586
|
}),
|
|
1514
|
-
|
|
1515
|
-
reasoningContent:
|
|
1516
|
-
signature:
|
|
1587
|
+
z3.object({
|
|
1588
|
+
reasoningContent: z3.object({
|
|
1589
|
+
signature: z3.string()
|
|
1517
1590
|
})
|
|
1518
1591
|
}),
|
|
1519
|
-
|
|
1520
|
-
reasoningContent:
|
|
1592
|
+
z3.object({
|
|
1593
|
+
reasoningContent: z3.object({ data: z3.string() })
|
|
1521
1594
|
})
|
|
1522
1595
|
]).nullish()
|
|
1523
1596
|
}).nullish(),
|
|
1524
|
-
contentBlockStart:
|
|
1525
|
-
contentBlockIndex:
|
|
1526
|
-
start:
|
|
1597
|
+
contentBlockStart: z3.object({
|
|
1598
|
+
contentBlockIndex: z3.number(),
|
|
1599
|
+
start: z3.object({
|
|
1527
1600
|
toolUse: BedrockToolUseSchema.nullish()
|
|
1528
1601
|
}).nullish()
|
|
1529
1602
|
}).nullish(),
|
|
1530
|
-
contentBlockStop:
|
|
1531
|
-
contentBlockIndex:
|
|
1603
|
+
contentBlockStop: z3.object({
|
|
1604
|
+
contentBlockIndex: z3.number()
|
|
1532
1605
|
}).nullish(),
|
|
1533
|
-
internalServerException:
|
|
1534
|
-
messageStop:
|
|
1606
|
+
internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1607
|
+
messageStop: z3.object({
|
|
1535
1608
|
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1536
1609
|
stopReason: BedrockStopReasonSchema
|
|
1537
1610
|
}).nullish(),
|
|
1538
|
-
metadata:
|
|
1539
|
-
trace:
|
|
1540
|
-
performanceConfig:
|
|
1541
|
-
serviceTier:
|
|
1542
|
-
usage:
|
|
1543
|
-
cacheReadInputTokens:
|
|
1544
|
-
cacheWriteInputTokens:
|
|
1545
|
-
cacheDetails:
|
|
1546
|
-
inputTokens:
|
|
1547
|
-
outputTokens:
|
|
1611
|
+
metadata: z3.object({
|
|
1612
|
+
trace: z3.unknown().nullish(),
|
|
1613
|
+
performanceConfig: z3.object({ latency: z3.string() }).nullish(),
|
|
1614
|
+
serviceTier: z3.object({ type: z3.string() }).nullish(),
|
|
1615
|
+
usage: z3.object({
|
|
1616
|
+
cacheReadInputTokens: z3.number().nullish(),
|
|
1617
|
+
cacheWriteInputTokens: z3.number().nullish(),
|
|
1618
|
+
cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish(),
|
|
1619
|
+
inputTokens: z3.number(),
|
|
1620
|
+
outputTokens: z3.number()
|
|
1548
1621
|
}).nullish()
|
|
1549
1622
|
}).nullish(),
|
|
1550
|
-
modelStreamErrorException:
|
|
1551
|
-
throttlingException:
|
|
1552
|
-
validationException:
|
|
1623
|
+
modelStreamErrorException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1624
|
+
throttlingException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1625
|
+
validationException: z3.record(z3.string(), z3.unknown()).nullish()
|
|
1553
1626
|
});
|
|
1554
|
-
var bedrockReasoningMetadataSchema =
|
|
1555
|
-
signature:
|
|
1556
|
-
redactedData:
|
|
1627
|
+
var bedrockReasoningMetadataSchema = z3.object({
|
|
1628
|
+
signature: z3.string().optional(),
|
|
1629
|
+
redactedData: z3.string().optional()
|
|
1557
1630
|
});
|
|
1631
|
+
var bedrockReasoningEffortMap = {
|
|
1632
|
+
minimal: "low",
|
|
1633
|
+
low: "low",
|
|
1634
|
+
medium: "medium",
|
|
1635
|
+
high: "high",
|
|
1636
|
+
xhigh: "max"
|
|
1637
|
+
};
|
|
1638
|
+
function resolveBedrockReasoningConfig({
|
|
1639
|
+
reasoning,
|
|
1640
|
+
bedrockOptions,
|
|
1641
|
+
warnings,
|
|
1642
|
+
isAnthropicModel,
|
|
1643
|
+
modelId
|
|
1644
|
+
}) {
|
|
1645
|
+
if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
|
|
1646
|
+
return bedrockOptions;
|
|
1647
|
+
}
|
|
1648
|
+
const result = { ...bedrockOptions };
|
|
1649
|
+
if (isAnthropicModel) {
|
|
1650
|
+
const capabilities = getModelCapabilities(modelId);
|
|
1651
|
+
if (reasoning === "none") {
|
|
1652
|
+
result.reasoningConfig = { type: "disabled" };
|
|
1653
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1654
|
+
const effort = mapReasoningToProviderEffort({
|
|
1655
|
+
reasoning,
|
|
1656
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1657
|
+
warnings
|
|
1658
|
+
});
|
|
1659
|
+
result.reasoningConfig = {
|
|
1660
|
+
type: "adaptive",
|
|
1661
|
+
maxReasoningEffort: effort
|
|
1662
|
+
};
|
|
1663
|
+
} else {
|
|
1664
|
+
const budgetTokens = mapReasoningToProviderBudget({
|
|
1665
|
+
reasoning,
|
|
1666
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1667
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1668
|
+
warnings
|
|
1669
|
+
});
|
|
1670
|
+
if (budgetTokens != null) {
|
|
1671
|
+
result.reasoningConfig = {
|
|
1672
|
+
type: "enabled",
|
|
1673
|
+
budgetTokens
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
} else if (reasoning !== "none") {
|
|
1678
|
+
const effort = mapReasoningToProviderEffort({
|
|
1679
|
+
reasoning,
|
|
1680
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1681
|
+
warnings
|
|
1682
|
+
});
|
|
1683
|
+
result.reasoningConfig = { maxReasoningEffort: effort };
|
|
1684
|
+
}
|
|
1685
|
+
return result;
|
|
1686
|
+
}
|
|
1558
1687
|
|
|
1559
1688
|
// src/bedrock-embedding-model.ts
|
|
1560
|
-
|
|
1561
|
-
|
|
1689
|
+
import {
|
|
1690
|
+
TooManyEmbeddingValuesForCallError
|
|
1691
|
+
} from "@ai-sdk/provider";
|
|
1692
|
+
import {
|
|
1693
|
+
combineHeaders as combineHeaders2,
|
|
1694
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1695
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1696
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1697
|
+
postJsonToApi as postJsonToApi2,
|
|
1698
|
+
resolve as resolve2,
|
|
1699
|
+
serializeModelOptions as serializeModelOptions2,
|
|
1700
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
1701
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
1702
|
+
} from "@ai-sdk/provider-utils";
|
|
1562
1703
|
|
|
1563
1704
|
// src/bedrock-embedding-options.ts
|
|
1564
|
-
|
|
1565
|
-
var amazonBedrockEmbeddingModelOptionsSchema =
|
|
1705
|
+
import { z as z4 } from "zod/v4";
|
|
1706
|
+
var amazonBedrockEmbeddingModelOptionsSchema = z4.object({
|
|
1566
1707
|
/**
|
|
1567
1708
|
* The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
1568
1709
|
* Only supported in amazon.titan-embed-text-v2:0.
|
|
1569
1710
|
*/
|
|
1570
|
-
dimensions:
|
|
1711
|
+
dimensions: z4.union([z4.literal(1024), z4.literal(512), z4.literal(256)]).optional(),
|
|
1571
1712
|
/**
|
|
1572
1713
|
* Flag indicating whether or not to normalize the output embeddings. Defaults to true.
|
|
1573
1714
|
* Only supported in amazon.titan-embed-text-v2:0.
|
|
1574
1715
|
*/
|
|
1575
|
-
normalize:
|
|
1716
|
+
normalize: z4.boolean().optional(),
|
|
1576
1717
|
/**
|
|
1577
1718
|
* The number of dimensions for Nova embedding models (defaults to 1024).
|
|
1578
1719
|
* Supported values: 256, 384, 1024, 3072.
|
|
1579
1720
|
* Only supported in amazon.nova-* embedding models.
|
|
1580
1721
|
*/
|
|
1581
|
-
embeddingDimension:
|
|
1722
|
+
embeddingDimension: z4.union([z4.literal(256), z4.literal(384), z4.literal(1024), z4.literal(3072)]).optional(),
|
|
1582
1723
|
/**
|
|
1583
1724
|
* The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
|
|
1584
1725
|
* Only supported in amazon.nova-* embedding models.
|
|
1585
1726
|
*/
|
|
1586
|
-
embeddingPurpose:
|
|
1727
|
+
embeddingPurpose: z4.enum([
|
|
1587
1728
|
"GENERIC_INDEX",
|
|
1588
1729
|
"TEXT_RETRIEVAL",
|
|
1589
1730
|
"IMAGE_RETRIEVAL",
|
|
@@ -1599,22 +1740,22 @@ var amazonBedrockEmbeddingModelOptionsSchema = import_v44.z.object({
|
|
|
1599
1740
|
* Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
1600
1741
|
* If not set, the provider defaults to `search_query`.
|
|
1601
1742
|
*/
|
|
1602
|
-
inputType:
|
|
1743
|
+
inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
1603
1744
|
/**
|
|
1604
1745
|
* Truncation behavior when input exceeds the model's context length.
|
|
1605
1746
|
* Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
|
|
1606
1747
|
*/
|
|
1607
|
-
truncate:
|
|
1748
|
+
truncate: z4.enum(["NONE", "START", "END"]).optional(),
|
|
1608
1749
|
/**
|
|
1609
1750
|
* The number of dimensions the resulting output embeddings should have (defaults to 1536).
|
|
1610
1751
|
* Only supported in cohere.embed-v4:0 and newer Cohere embedding models.
|
|
1611
1752
|
*/
|
|
1612
|
-
outputDimension:
|
|
1753
|
+
outputDimension: z4.union([z4.literal(256), z4.literal(512), z4.literal(1024), z4.literal(1536)]).optional()
|
|
1613
1754
|
});
|
|
1614
1755
|
|
|
1615
1756
|
// src/bedrock-embedding-model.ts
|
|
1616
|
-
|
|
1617
|
-
var BedrockEmbeddingModel = class {
|
|
1757
|
+
import { z as z5 } from "zod/v4";
|
|
1758
|
+
var BedrockEmbeddingModel = class _BedrockEmbeddingModel {
|
|
1618
1759
|
constructor(modelId, config) {
|
|
1619
1760
|
this.modelId = modelId;
|
|
1620
1761
|
this.config = config;
|
|
@@ -1623,6 +1764,15 @@ var BedrockEmbeddingModel = class {
|
|
|
1623
1764
|
this.maxEmbeddingsPerCall = 1;
|
|
1624
1765
|
this.supportsParallelCalls = true;
|
|
1625
1766
|
}
|
|
1767
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
1768
|
+
return serializeModelOptions2({
|
|
1769
|
+
modelId: model.modelId,
|
|
1770
|
+
config: model.config
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
1774
|
+
return new _BedrockEmbeddingModel(options.modelId, options.config);
|
|
1775
|
+
}
|
|
1626
1776
|
getUrl(modelId) {
|
|
1627
1777
|
const encodedModelId = encodeURIComponent(modelId);
|
|
1628
1778
|
return `${this.config.baseUrl()}/model/${encodedModelId}/invoke`;
|
|
@@ -1635,14 +1785,14 @@ var BedrockEmbeddingModel = class {
|
|
|
1635
1785
|
}) {
|
|
1636
1786
|
var _a, _b, _c, _d, _e, _f;
|
|
1637
1787
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1638
|
-
throw new
|
|
1788
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
1639
1789
|
provider: this.provider,
|
|
1640
1790
|
modelId: this.modelId,
|
|
1641
1791
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1642
1792
|
values
|
|
1643
1793
|
});
|
|
1644
1794
|
}
|
|
1645
|
-
const bedrockOptions = (_a = await (
|
|
1795
|
+
const bedrockOptions = (_a = await parseProviderOptions3({
|
|
1646
1796
|
provider: "bedrock",
|
|
1647
1797
|
providerOptions,
|
|
1648
1798
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
@@ -1672,17 +1822,20 @@ var BedrockEmbeddingModel = class {
|
|
|
1672
1822
|
normalize: bedrockOptions.normalize
|
|
1673
1823
|
};
|
|
1674
1824
|
const url = this.getUrl(this.modelId);
|
|
1675
|
-
const { value: response } = await (
|
|
1825
|
+
const { value: response } = await postJsonToApi2({
|
|
1676
1826
|
url,
|
|
1677
|
-
headers: await (
|
|
1678
|
-
(
|
|
1827
|
+
headers: await resolve2(
|
|
1828
|
+
combineHeaders2(
|
|
1829
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
1830
|
+
headers
|
|
1831
|
+
)
|
|
1679
1832
|
),
|
|
1680
1833
|
body: args,
|
|
1681
|
-
failedResponseHandler: (
|
|
1834
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1682
1835
|
errorSchema: BedrockErrorSchema,
|
|
1683
1836
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1684
1837
|
}),
|
|
1685
|
-
successfulResponseHandler: (
|
|
1838
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
1686
1839
|
BedrockEmbeddingResponseSchema
|
|
1687
1840
|
),
|
|
1688
1841
|
fetch: this.config.fetch,
|
|
@@ -1709,36 +1862,46 @@ var BedrockEmbeddingModel = class {
|
|
|
1709
1862
|
};
|
|
1710
1863
|
}
|
|
1711
1864
|
};
|
|
1712
|
-
var BedrockEmbeddingResponseSchema =
|
|
1865
|
+
var BedrockEmbeddingResponseSchema = z5.union([
|
|
1713
1866
|
// Titan-style response
|
|
1714
|
-
|
|
1715
|
-
embedding:
|
|
1716
|
-
inputTextTokenCount:
|
|
1867
|
+
z5.object({
|
|
1868
|
+
embedding: z5.array(z5.number()),
|
|
1869
|
+
inputTextTokenCount: z5.number()
|
|
1717
1870
|
}),
|
|
1718
1871
|
// Nova-style response
|
|
1719
|
-
|
|
1720
|
-
embeddings:
|
|
1721
|
-
|
|
1722
|
-
embeddingType:
|
|
1723
|
-
embedding:
|
|
1872
|
+
z5.object({
|
|
1873
|
+
embeddings: z5.array(
|
|
1874
|
+
z5.object({
|
|
1875
|
+
embeddingType: z5.string(),
|
|
1876
|
+
embedding: z5.array(z5.number())
|
|
1724
1877
|
})
|
|
1725
1878
|
),
|
|
1726
|
-
inputTokenCount:
|
|
1879
|
+
inputTokenCount: z5.number().optional()
|
|
1727
1880
|
}),
|
|
1728
1881
|
// Cohere v3-style response
|
|
1729
|
-
|
|
1730
|
-
embeddings:
|
|
1882
|
+
z5.object({
|
|
1883
|
+
embeddings: z5.array(z5.array(z5.number()))
|
|
1731
1884
|
}),
|
|
1732
1885
|
// Cohere v4-style response
|
|
1733
|
-
|
|
1734
|
-
embeddings:
|
|
1735
|
-
float:
|
|
1886
|
+
z5.object({
|
|
1887
|
+
embeddings: z5.object({
|
|
1888
|
+
float: z5.array(z5.array(z5.number()))
|
|
1736
1889
|
})
|
|
1737
1890
|
})
|
|
1738
1891
|
]);
|
|
1739
1892
|
|
|
1740
1893
|
// src/bedrock-image-model.ts
|
|
1741
|
-
|
|
1894
|
+
import {
|
|
1895
|
+
combineHeaders as combineHeaders3,
|
|
1896
|
+
convertUint8ArrayToBase64,
|
|
1897
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
1898
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1899
|
+
postJsonToApi as postJsonToApi3,
|
|
1900
|
+
resolve as resolve3,
|
|
1901
|
+
serializeModelOptions as serializeModelOptions3,
|
|
1902
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
1903
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
|
|
1904
|
+
} from "@ai-sdk/provider-utils";
|
|
1742
1905
|
|
|
1743
1906
|
// src/bedrock-image-settings.ts
|
|
1744
1907
|
var modelMaxImagesPerCall = {
|
|
@@ -1746,14 +1909,23 @@ var modelMaxImagesPerCall = {
|
|
|
1746
1909
|
};
|
|
1747
1910
|
|
|
1748
1911
|
// src/bedrock-image-model.ts
|
|
1749
|
-
|
|
1750
|
-
var BedrockImageModel = class {
|
|
1912
|
+
import { z as z6 } from "zod/v4";
|
|
1913
|
+
var BedrockImageModel = class _BedrockImageModel {
|
|
1751
1914
|
constructor(modelId, config) {
|
|
1752
1915
|
this.modelId = modelId;
|
|
1753
1916
|
this.config = config;
|
|
1754
1917
|
this.specificationVersion = "v4";
|
|
1755
1918
|
this.provider = "amazon-bedrock";
|
|
1756
1919
|
}
|
|
1920
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
1921
|
+
return serializeModelOptions3({
|
|
1922
|
+
modelId: model.modelId,
|
|
1923
|
+
config: model.config
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
1927
|
+
return new _BedrockImageModel(options.modelId, options.config);
|
|
1928
|
+
}
|
|
1757
1929
|
get maxImagesPerCall() {
|
|
1758
1930
|
var _a;
|
|
1759
1931
|
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
@@ -1882,17 +2054,20 @@ var BedrockImageModel = class {
|
|
|
1882
2054
|
});
|
|
1883
2055
|
}
|
|
1884
2056
|
const currentDate = (_o = (_n = (_m = this.config._internal) == null ? void 0 : _m.currentDate) == null ? void 0 : _n.call(_m)) != null ? _o : /* @__PURE__ */ new Date();
|
|
1885
|
-
const { value: response, responseHeaders } = await (
|
|
2057
|
+
const { value: response, responseHeaders } = await postJsonToApi3({
|
|
1886
2058
|
url: this.getUrl(this.modelId),
|
|
1887
|
-
headers: await (
|
|
1888
|
-
(
|
|
2059
|
+
headers: await resolve3(
|
|
2060
|
+
combineHeaders3(
|
|
2061
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
2062
|
+
headers
|
|
2063
|
+
)
|
|
1889
2064
|
),
|
|
1890
2065
|
body: args,
|
|
1891
|
-
failedResponseHandler: (
|
|
2066
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
1892
2067
|
errorSchema: BedrockErrorSchema,
|
|
1893
2068
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1894
2069
|
}),
|
|
1895
|
-
successfulResponseHandler: (
|
|
2070
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1896
2071
|
bedrockImageResponseSchema
|
|
1897
2072
|
),
|
|
1898
2073
|
abortSignal,
|
|
@@ -1928,42 +2103,47 @@ function getBase64Data(file) {
|
|
|
1928
2103
|
);
|
|
1929
2104
|
}
|
|
1930
2105
|
if (file.data instanceof Uint8Array) {
|
|
1931
|
-
return
|
|
2106
|
+
return convertUint8ArrayToBase64(file.data);
|
|
1932
2107
|
}
|
|
1933
2108
|
return file.data;
|
|
1934
2109
|
}
|
|
1935
|
-
var bedrockImageResponseSchema =
|
|
2110
|
+
var bedrockImageResponseSchema = z6.object({
|
|
1936
2111
|
// Normal successful response
|
|
1937
|
-
images:
|
|
2112
|
+
images: z6.array(z6.string()).optional(),
|
|
1938
2113
|
// Moderation response fields
|
|
1939
|
-
id:
|
|
1940
|
-
status:
|
|
1941
|
-
result:
|
|
1942
|
-
progress:
|
|
1943
|
-
details:
|
|
1944
|
-
preview:
|
|
2114
|
+
id: z6.string().optional(),
|
|
2115
|
+
status: z6.string().optional(),
|
|
2116
|
+
result: z6.unknown().optional(),
|
|
2117
|
+
progress: z6.unknown().optional(),
|
|
2118
|
+
details: z6.record(z6.string(), z6.unknown()).optional(),
|
|
2119
|
+
preview: z6.unknown().optional()
|
|
1945
2120
|
});
|
|
1946
2121
|
|
|
1947
2122
|
// src/bedrock-sigv4-fetch.ts
|
|
1948
|
-
|
|
1949
|
-
|
|
2123
|
+
import {
|
|
2124
|
+
combineHeaders as combineHeaders4,
|
|
2125
|
+
normalizeHeaders,
|
|
2126
|
+
withUserAgentSuffix,
|
|
2127
|
+
getRuntimeEnvironmentUserAgent
|
|
2128
|
+
} from "@ai-sdk/provider-utils";
|
|
2129
|
+
import { AwsV4Signer } from "aws4fetch";
|
|
1950
2130
|
|
|
1951
2131
|
// src/version.ts
|
|
1952
|
-
var VERSION = true ? "5.0.0-beta.
|
|
2132
|
+
var VERSION = true ? "5.0.0-beta.41" : "0.0.0-test";
|
|
1953
2133
|
|
|
1954
2134
|
// src/bedrock-sigv4-fetch.ts
|
|
1955
2135
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
1956
2136
|
return async (input, init) => {
|
|
1957
2137
|
var _a, _b;
|
|
1958
2138
|
const request = input instanceof Request ? input : void 0;
|
|
1959
|
-
const originalHeaders = (
|
|
1960
|
-
|
|
1961
|
-
|
|
2139
|
+
const originalHeaders = combineHeaders4(
|
|
2140
|
+
normalizeHeaders(request == null ? void 0 : request.headers),
|
|
2141
|
+
normalizeHeaders(init == null ? void 0 : init.headers)
|
|
1962
2142
|
);
|
|
1963
|
-
const headersWithUserAgent =
|
|
2143
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
1964
2144
|
originalHeaders,
|
|
1965
2145
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1966
|
-
|
|
2146
|
+
getRuntimeEnvironmentUserAgent()
|
|
1967
2147
|
);
|
|
1968
2148
|
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
1969
2149
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
@@ -1982,7 +2162,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1982
2162
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
1983
2163
|
const body = prepareBodyString(effectiveBody);
|
|
1984
2164
|
const credentials = await getCredentials();
|
|
1985
|
-
const signer = new
|
|
2165
|
+
const signer = new AwsV4Signer({
|
|
1986
2166
|
url,
|
|
1987
2167
|
method: "POST",
|
|
1988
2168
|
headers: Object.entries(headersWithUserAgent),
|
|
@@ -1994,8 +2174,8 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1994
2174
|
service: "bedrock"
|
|
1995
2175
|
});
|
|
1996
2176
|
const signingResult = await signer.sign();
|
|
1997
|
-
const signedHeaders =
|
|
1998
|
-
const combinedHeaders = (
|
|
2177
|
+
const signedHeaders = normalizeHeaders(signingResult.headers);
|
|
2178
|
+
const combinedHeaders = combineHeaders4(headersWithUserAgent, signedHeaders);
|
|
1999
2179
|
return fetch(input, {
|
|
2000
2180
|
...init,
|
|
2001
2181
|
body,
|
|
@@ -2016,13 +2196,13 @@ function prepareBodyString(body) {
|
|
|
2016
2196
|
}
|
|
2017
2197
|
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
2018
2198
|
return async (input, init) => {
|
|
2019
|
-
const originalHeaders =
|
|
2020
|
-
const headersWithUserAgent =
|
|
2199
|
+
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
2200
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
2021
2201
|
originalHeaders,
|
|
2022
2202
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
2023
|
-
|
|
2203
|
+
getRuntimeEnvironmentUserAgent()
|
|
2024
2204
|
);
|
|
2025
|
-
const finalHeaders = (
|
|
2205
|
+
const finalHeaders = combineHeaders4(headersWithUserAgent, {
|
|
2026
2206
|
Authorization: `Bearer ${apiKey}`
|
|
2027
2207
|
});
|
|
2028
2208
|
return fetch(input, {
|
|
@@ -2033,39 +2213,46 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
|
2033
2213
|
}
|
|
2034
2214
|
|
|
2035
2215
|
// src/reranking/bedrock-reranking-model.ts
|
|
2036
|
-
|
|
2216
|
+
import {
|
|
2217
|
+
combineHeaders as combineHeaders5,
|
|
2218
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
2219
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2220
|
+
parseProviderOptions as parseProviderOptions4,
|
|
2221
|
+
postJsonToApi as postJsonToApi4,
|
|
2222
|
+
resolve as resolve4
|
|
2223
|
+
} from "@ai-sdk/provider-utils";
|
|
2037
2224
|
|
|
2038
2225
|
// src/reranking/bedrock-reranking-api.ts
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
var bedrockRerankingResponseSchema =
|
|
2042
|
-
() =>
|
|
2043
|
-
|
|
2044
|
-
results:
|
|
2045
|
-
|
|
2046
|
-
index:
|
|
2047
|
-
relevanceScore:
|
|
2226
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
2227
|
+
import { z as z7 } from "zod/v4";
|
|
2228
|
+
var bedrockRerankingResponseSchema = lazySchema(
|
|
2229
|
+
() => zodSchema(
|
|
2230
|
+
z7.object({
|
|
2231
|
+
results: z7.array(
|
|
2232
|
+
z7.object({
|
|
2233
|
+
index: z7.number(),
|
|
2234
|
+
relevanceScore: z7.number()
|
|
2048
2235
|
})
|
|
2049
2236
|
),
|
|
2050
|
-
nextToken:
|
|
2237
|
+
nextToken: z7.string().optional()
|
|
2051
2238
|
})
|
|
2052
2239
|
)
|
|
2053
2240
|
);
|
|
2054
2241
|
|
|
2055
2242
|
// src/reranking/bedrock-reranking-options.ts
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
var amazonBedrockRerankingModelOptionsSchema = (
|
|
2059
|
-
() => (
|
|
2060
|
-
|
|
2243
|
+
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
2244
|
+
import { z as z8 } from "zod/v4";
|
|
2245
|
+
var amazonBedrockRerankingModelOptionsSchema = lazySchema2(
|
|
2246
|
+
() => zodSchema2(
|
|
2247
|
+
z8.object({
|
|
2061
2248
|
/**
|
|
2062
2249
|
* If the total number of results was greater than could fit in a response, a token is returned in the nextToken field. You can enter that token in this field to return the next batch of results.
|
|
2063
2250
|
*/
|
|
2064
|
-
nextToken:
|
|
2251
|
+
nextToken: z8.string().optional(),
|
|
2065
2252
|
/**
|
|
2066
2253
|
* Additional model request fields to pass to the model.
|
|
2067
2254
|
*/
|
|
2068
|
-
additionalModelRequestFields:
|
|
2255
|
+
additionalModelRequestFields: z8.record(z8.string(), z8.any()).optional()
|
|
2069
2256
|
})
|
|
2070
2257
|
)
|
|
2071
2258
|
);
|
|
@@ -2086,7 +2273,7 @@ var BedrockRerankingModel = class {
|
|
|
2086
2273
|
abortSignal,
|
|
2087
2274
|
providerOptions
|
|
2088
2275
|
}) {
|
|
2089
|
-
const bedrockOptions = await (
|
|
2276
|
+
const bedrockOptions = await parseProviderOptions4({
|
|
2090
2277
|
provider: "bedrock",
|
|
2091
2278
|
providerOptions,
|
|
2092
2279
|
schema: amazonBedrockRerankingModelOptionsSchema
|
|
@@ -2095,10 +2282,10 @@ var BedrockRerankingModel = class {
|
|
|
2095
2282
|
value: response,
|
|
2096
2283
|
responseHeaders,
|
|
2097
2284
|
rawValue
|
|
2098
|
-
} = await (
|
|
2285
|
+
} = await postJsonToApi4({
|
|
2099
2286
|
url: `${this.config.baseUrl()}/rerank`,
|
|
2100
|
-
headers: await (
|
|
2101
|
-
(
|
|
2287
|
+
headers: await resolve4(
|
|
2288
|
+
combineHeaders5(await resolve4(this.config.headers), headers)
|
|
2102
2289
|
),
|
|
2103
2290
|
body: {
|
|
2104
2291
|
nextToken: bedrockOptions == null ? void 0 : bedrockOptions.nextToken,
|
|
@@ -2129,11 +2316,11 @@ var BedrockRerankingModel = class {
|
|
|
2129
2316
|
}
|
|
2130
2317
|
}))
|
|
2131
2318
|
},
|
|
2132
|
-
failedResponseHandler: (
|
|
2319
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
2133
2320
|
errorSchema: BedrockErrorSchema,
|
|
2134
2321
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
2135
2322
|
}),
|
|
2136
|
-
successfulResponseHandler: (
|
|
2323
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2137
2324
|
bedrockRerankingResponseSchema
|
|
2138
2325
|
),
|
|
2139
2326
|
fetch: this.config.fetch,
|
|
@@ -2151,13 +2338,13 @@ var BedrockRerankingModel = class {
|
|
|
2151
2338
|
|
|
2152
2339
|
// src/bedrock-provider.ts
|
|
2153
2340
|
function createAmazonBedrock(options = {}) {
|
|
2154
|
-
const rawApiKey =
|
|
2341
|
+
const rawApiKey = loadOptionalSetting({
|
|
2155
2342
|
settingValue: options.apiKey,
|
|
2156
2343
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
2157
2344
|
});
|
|
2158
2345
|
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
2159
2346
|
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
2160
|
-
const region =
|
|
2347
|
+
const region = loadSetting({
|
|
2161
2348
|
settingValue: options.region,
|
|
2162
2349
|
settingName: "region",
|
|
2163
2350
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2179,19 +2366,19 @@ function createAmazonBedrock(options = {}) {
|
|
|
2179
2366
|
try {
|
|
2180
2367
|
return {
|
|
2181
2368
|
region,
|
|
2182
|
-
accessKeyId:
|
|
2369
|
+
accessKeyId: loadSetting({
|
|
2183
2370
|
settingValue: options.accessKeyId,
|
|
2184
2371
|
settingName: "accessKeyId",
|
|
2185
2372
|
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
2186
2373
|
description: "AWS access key ID"
|
|
2187
2374
|
}),
|
|
2188
|
-
secretAccessKey:
|
|
2375
|
+
secretAccessKey: loadSetting({
|
|
2189
2376
|
settingValue: options.secretAccessKey,
|
|
2190
2377
|
settingName: "secretAccessKey",
|
|
2191
2378
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
2192
2379
|
description: "AWS secret access key"
|
|
2193
2380
|
}),
|
|
2194
|
-
sessionToken:
|
|
2381
|
+
sessionToken: loadOptionalSetting({
|
|
2195
2382
|
settingValue: options.sessionToken,
|
|
2196
2383
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
2197
2384
|
})
|
|
@@ -2220,12 +2407,12 @@ Original error: ${errorMessage}`
|
|
|
2220
2407
|
const getHeaders = () => {
|
|
2221
2408
|
var _a;
|
|
2222
2409
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2223
|
-
return (
|
|
2410
|
+
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2224
2411
|
};
|
|
2225
2412
|
const getBedrockRuntimeBaseUrl = () => {
|
|
2226
2413
|
var _a, _b;
|
|
2227
|
-
return (_b =
|
|
2228
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${
|
|
2414
|
+
return (_b = withoutTrailingSlash(
|
|
2415
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${loadSetting({
|
|
2229
2416
|
settingValue: options.region,
|
|
2230
2417
|
settingName: "region",
|
|
2231
2418
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2235,8 +2422,8 @@ Original error: ${errorMessage}`
|
|
|
2235
2422
|
};
|
|
2236
2423
|
const getBedrockAgentRuntimeBaseUrl = () => {
|
|
2237
2424
|
var _a, _b;
|
|
2238
|
-
return (_b =
|
|
2239
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${
|
|
2425
|
+
return (_b = withoutTrailingSlash(
|
|
2426
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${loadSetting({
|
|
2240
2427
|
settingValue: options.region,
|
|
2241
2428
|
settingName: "region",
|
|
2242
2429
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2248,7 +2435,7 @@ Original error: ${errorMessage}`
|
|
|
2248
2435
|
baseUrl: getBedrockRuntimeBaseUrl,
|
|
2249
2436
|
headers: getHeaders,
|
|
2250
2437
|
fetch: fetchFunction,
|
|
2251
|
-
generateId
|
|
2438
|
+
generateId
|
|
2252
2439
|
});
|
|
2253
2440
|
const provider = function(modelId) {
|
|
2254
2441
|
if (new.target) {
|
|
@@ -2270,7 +2457,7 @@ Original error: ${errorMessage}`
|
|
|
2270
2457
|
});
|
|
2271
2458
|
const createRerankingModel = (modelId) => new BedrockRerankingModel(modelId, {
|
|
2272
2459
|
baseUrl: getBedrockAgentRuntimeBaseUrl,
|
|
2273
|
-
region:
|
|
2460
|
+
region: loadSetting({
|
|
2274
2461
|
settingValue: options.region,
|
|
2275
2462
|
settingName: "region",
|
|
2276
2463
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2289,14 +2476,13 @@ Original error: ${errorMessage}`
|
|
|
2289
2476
|
provider.imageModel = createImageModel;
|
|
2290
2477
|
provider.reranking = createRerankingModel;
|
|
2291
2478
|
provider.rerankingModel = createRerankingModel;
|
|
2292
|
-
provider.tools =
|
|
2479
|
+
provider.tools = anthropicTools2;
|
|
2293
2480
|
return provider;
|
|
2294
2481
|
}
|
|
2295
2482
|
var bedrock = createAmazonBedrock();
|
|
2296
|
-
|
|
2297
|
-
0 && (module.exports = {
|
|
2483
|
+
export {
|
|
2298
2484
|
VERSION,
|
|
2299
2485
|
bedrock,
|
|
2300
2486
|
createAmazonBedrock
|
|
2301
|
-
}
|
|
2487
|
+
};
|
|
2302
2488
|
//# sourceMappingURL=index.js.map
|