@ai-sdk/amazon-bedrock 5.0.0-beta.4 → 5.0.0-beta.40
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 +312 -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 +7 -1
- package/dist/index.js +469 -300
- 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 +120 -6
- package/src/bedrock-chat-options.ts +12 -0
- 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,71 @@ 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", "max"]).optional()
|
|
97
89
|
}).optional(),
|
|
98
90
|
/**
|
|
99
91
|
* Anthropic beta features to enable
|
|
100
92
|
*/
|
|
101
|
-
anthropicBeta:
|
|
93
|
+
anthropicBeta: z.array(z.string()).optional(),
|
|
94
|
+
/**
|
|
95
|
+
* Service tier for the request.
|
|
96
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
|
|
97
|
+
*
|
|
98
|
+
* - 'reserved': Uses provisioned throughput capacity
|
|
99
|
+
* - 'priority': Prioritizes low-latency inference when capacity is available
|
|
100
|
+
* - 'default': Standard on-demand tier
|
|
101
|
+
* - 'flex': Lower-cost tier for flexible latency workloads
|
|
102
|
+
*/
|
|
103
|
+
serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
102
104
|
});
|
|
103
105
|
|
|
104
106
|
// src/bedrock-error.ts
|
|
105
|
-
|
|
106
|
-
var BedrockErrorSchema =
|
|
107
|
-
message:
|
|
108
|
-
type:
|
|
107
|
+
import { z as z2 } from "zod/v4";
|
|
108
|
+
var BedrockErrorSchema = z2.object({
|
|
109
|
+
message: z2.string(),
|
|
110
|
+
type: z2.string().nullish()
|
|
109
111
|
});
|
|
110
112
|
|
|
111
113
|
// src/bedrock-event-stream-response-handler.ts
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
import { EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
115
|
+
import {
|
|
116
|
+
safeParseJSON,
|
|
117
|
+
extractResponseHeaders,
|
|
118
|
+
safeValidateTypes
|
|
119
|
+
} from "@ai-sdk/provider-utils";
|
|
114
120
|
|
|
115
121
|
// src/bedrock-event-stream-decoder.ts
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
123
|
+
import { toUtf8, fromUtf8 } from "@smithy/util-utf8";
|
|
118
124
|
function createBedrockEventStreamDecoder(body, processEvent) {
|
|
119
|
-
const codec = new
|
|
125
|
+
const codec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
120
126
|
let buffer = new Uint8Array(0);
|
|
121
127
|
const textDecoder = new TextDecoder();
|
|
122
128
|
return body.pipeThrough(
|
|
@@ -155,9 +161,9 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
155
161
|
|
|
156
162
|
// src/bedrock-event-stream-response-handler.ts
|
|
157
163
|
var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
158
|
-
const responseHeaders =
|
|
164
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
159
165
|
if (response.body == null) {
|
|
160
|
-
throw new
|
|
166
|
+
throw new EmptyResponseBodyError({});
|
|
161
167
|
}
|
|
162
168
|
return {
|
|
163
169
|
responseHeaders,
|
|
@@ -165,7 +171,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
165
171
|
response.body,
|
|
166
172
|
async (event, controller) => {
|
|
167
173
|
if (event.messageType === "event") {
|
|
168
|
-
const parsedDataResult = await
|
|
174
|
+
const parsedDataResult = await safeParseJSON({ text: event.data });
|
|
169
175
|
if (!parsedDataResult.success) {
|
|
170
176
|
controller.enqueue(parsedDataResult);
|
|
171
177
|
return;
|
|
@@ -174,7 +180,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
174
180
|
const wrappedData = {
|
|
175
181
|
[event.eventType]: parsedDataResult.value
|
|
176
182
|
};
|
|
177
|
-
const validatedWrappedData = await
|
|
183
|
+
const validatedWrappedData = await safeValidateTypes({
|
|
178
184
|
value: wrappedData,
|
|
179
185
|
schema: chunkSchema
|
|
180
186
|
});
|
|
@@ -194,9 +200,14 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
194
200
|
};
|
|
195
201
|
|
|
196
202
|
// src/bedrock-prepare-tools.ts
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
import {
|
|
204
|
+
UnsupportedFunctionalityError
|
|
205
|
+
} from "@ai-sdk/provider";
|
|
206
|
+
import { asSchema } from "@ai-sdk/provider-utils";
|
|
207
|
+
import {
|
|
208
|
+
anthropicTools,
|
|
209
|
+
prepareTools as prepareAnthropicTools
|
|
210
|
+
} from "@ai-sdk/anthropic/internal";
|
|
200
211
|
async function prepareTools({
|
|
201
212
|
tools,
|
|
202
213
|
toolChoice,
|
|
@@ -243,7 +254,7 @@ async function prepareTools({
|
|
|
243
254
|
toolChoice: preparedAnthropicToolChoice,
|
|
244
255
|
toolWarnings: anthropicToolWarnings,
|
|
245
256
|
betas: anthropicBetas
|
|
246
|
-
} = await (
|
|
257
|
+
} = await prepareAnthropicTools({
|
|
247
258
|
tools: ProviderTools,
|
|
248
259
|
toolChoice,
|
|
249
260
|
supportsStructuredOutput: false,
|
|
@@ -257,7 +268,7 @@ async function prepareTools({
|
|
|
257
268
|
};
|
|
258
269
|
}
|
|
259
270
|
for (const tool of ProviderTools) {
|
|
260
|
-
const toolFactory = Object.values(
|
|
271
|
+
const toolFactory = Object.values(anthropicTools).find((factory) => {
|
|
261
272
|
const instance = factory({});
|
|
262
273
|
return instance.id === tool.id;
|
|
263
274
|
});
|
|
@@ -267,7 +278,7 @@ async function prepareTools({
|
|
|
267
278
|
toolSpec: {
|
|
268
279
|
name: tool.name,
|
|
269
280
|
inputSchema: {
|
|
270
|
-
json: await
|
|
281
|
+
json: await asSchema(fullToolDefinition.inputSchema).jsonSchema
|
|
271
282
|
}
|
|
272
283
|
}
|
|
273
284
|
});
|
|
@@ -312,7 +323,7 @@ async function prepareTools({
|
|
|
312
323
|
break;
|
|
313
324
|
default: {
|
|
314
325
|
const _exhaustiveCheck = type;
|
|
315
|
-
throw new
|
|
326
|
+
throw new UnsupportedFunctionalityError({
|
|
316
327
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
317
328
|
});
|
|
318
329
|
}
|
|
@@ -367,8 +378,15 @@ function convertBedrockUsage(usage) {
|
|
|
367
378
|
}
|
|
368
379
|
|
|
369
380
|
// src/convert-to-bedrock-chat-messages.ts
|
|
370
|
-
|
|
371
|
-
|
|
381
|
+
import {
|
|
382
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
383
|
+
} from "@ai-sdk/provider";
|
|
384
|
+
import {
|
|
385
|
+
convertToBase64,
|
|
386
|
+
isProviderReference,
|
|
387
|
+
parseProviderOptions,
|
|
388
|
+
stripFileExtension
|
|
389
|
+
} from "@ai-sdk/provider-utils";
|
|
372
390
|
|
|
373
391
|
// src/normalize-tool-call-id.ts
|
|
374
392
|
function isMistralModel(modelId) {
|
|
@@ -393,7 +411,7 @@ function getCachePoint(providerMetadata) {
|
|
|
393
411
|
}
|
|
394
412
|
async function shouldEnableCitations(providerMetadata) {
|
|
395
413
|
var _a, _b;
|
|
396
|
-
const bedrockOptions = await
|
|
414
|
+
const bedrockOptions = await parseProviderOptions({
|
|
397
415
|
provider: "bedrock",
|
|
398
416
|
providerOptions: providerMetadata,
|
|
399
417
|
schema: bedrockFilePartProviderOptions
|
|
@@ -414,7 +432,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
414
432
|
switch (type) {
|
|
415
433
|
case "system": {
|
|
416
434
|
if (messages.length > 0) {
|
|
417
|
-
throw new
|
|
435
|
+
throw new UnsupportedFunctionalityError2({
|
|
418
436
|
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
419
437
|
});
|
|
420
438
|
}
|
|
@@ -443,8 +461,13 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
443
461
|
break;
|
|
444
462
|
}
|
|
445
463
|
case "file": {
|
|
464
|
+
if (isProviderReference(part.data)) {
|
|
465
|
+
throw new UnsupportedFunctionalityError2({
|
|
466
|
+
functionality: "file parts with provider references"
|
|
467
|
+
});
|
|
468
|
+
}
|
|
446
469
|
if (part.data instanceof URL) {
|
|
447
|
-
throw new
|
|
470
|
+
throw new UnsupportedFunctionalityError2({
|
|
448
471
|
functionality: "File URL data"
|
|
449
472
|
});
|
|
450
473
|
}
|
|
@@ -452,12 +475,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
452
475
|
bedrockContent.push({
|
|
453
476
|
image: {
|
|
454
477
|
format: getBedrockImageFormat(part.mediaType),
|
|
455
|
-
source: { bytes:
|
|
478
|
+
source: { bytes: convertToBase64(part.data) }
|
|
456
479
|
}
|
|
457
480
|
});
|
|
458
481
|
} else {
|
|
459
482
|
if (!part.mediaType) {
|
|
460
|
-
throw new
|
|
483
|
+
throw new UnsupportedFunctionalityError2({
|
|
461
484
|
functionality: "file without mime type",
|
|
462
485
|
message: "File mime type is required in user message part content"
|
|
463
486
|
});
|
|
@@ -468,8 +491,8 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
468
491
|
bedrockContent.push({
|
|
469
492
|
document: {
|
|
470
493
|
format: getBedrockDocumentFormat(part.mediaType),
|
|
471
|
-
name: part.filename ?
|
|
472
|
-
source: { bytes:
|
|
494
|
+
name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
|
|
495
|
+
source: { bytes: convertToBase64(part.data) },
|
|
473
496
|
...enableCitations && {
|
|
474
497
|
citations: { enabled: true }
|
|
475
498
|
}
|
|
@@ -495,9 +518,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
495
518
|
switch (contentPart.type) {
|
|
496
519
|
case "text":
|
|
497
520
|
return { text: contentPart.text };
|
|
498
|
-
case "
|
|
521
|
+
case "file-data":
|
|
499
522
|
if (!contentPart.mediaType.startsWith("image/")) {
|
|
500
|
-
throw new
|
|
523
|
+
throw new UnsupportedFunctionalityError2({
|
|
501
524
|
functionality: `media type: ${contentPart.mediaType}`
|
|
502
525
|
});
|
|
503
526
|
}
|
|
@@ -511,7 +534,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
511
534
|
}
|
|
512
535
|
};
|
|
513
536
|
default: {
|
|
514
|
-
throw new
|
|
537
|
+
throw new UnsupportedFunctionalityError2({
|
|
515
538
|
functionality: `unsupported tool content part type: ${contentPart.type}`
|
|
516
539
|
});
|
|
517
540
|
}
|
|
@@ -564,12 +587,15 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
564
587
|
const message = block.messages[j];
|
|
565
588
|
const isLastMessage = j === block.messages.length - 1;
|
|
566
589
|
const { content } = message;
|
|
590
|
+
const hasReasoningBlocks = content.some(
|
|
591
|
+
(part) => part.type === "reasoning"
|
|
592
|
+
);
|
|
567
593
|
for (let k = 0; k < content.length; k++) {
|
|
568
594
|
const part = content[k];
|
|
569
595
|
const isLastContentPart = k === content.length - 1;
|
|
570
596
|
switch (part.type) {
|
|
571
597
|
case "text": {
|
|
572
|
-
if (!part.text.trim()) {
|
|
598
|
+
if (!part.text.trim() && !hasReasoningBlocks) {
|
|
573
599
|
break;
|
|
574
600
|
}
|
|
575
601
|
bedrockContent.push({
|
|
@@ -588,38 +614,41 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
588
614
|
break;
|
|
589
615
|
}
|
|
590
616
|
case "reasoning": {
|
|
591
|
-
const reasoningMetadata = await
|
|
617
|
+
const reasoningMetadata = await parseProviderOptions({
|
|
592
618
|
provider: "bedrock",
|
|
593
619
|
providerOptions: part.providerOptions,
|
|
594
620
|
schema: bedrockReasoningMetadataSchema
|
|
595
621
|
});
|
|
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
|
-
}
|
|
622
|
+
if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
|
|
623
|
+
bedrockContent.push({
|
|
624
|
+
reasoningContent: {
|
|
625
|
+
reasoningText: {
|
|
626
|
+
text: part.text,
|
|
627
|
+
signature: reasoningMetadata.signature
|
|
612
628
|
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
632
|
+
bedrockContent.push({
|
|
633
|
+
reasoningContent: {
|
|
634
|
+
redactedReasoning: {
|
|
635
|
+
data: reasoningMetadata.redactedData
|
|
620
636
|
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
} else {
|
|
640
|
+
bedrockContent.push({
|
|
641
|
+
reasoningContent: {
|
|
642
|
+
reasoningText: {
|
|
643
|
+
text: trimIfLast(
|
|
644
|
+
isLastBlock,
|
|
645
|
+
isLastMessage,
|
|
646
|
+
isLastContentPart,
|
|
647
|
+
part.text
|
|
648
|
+
)
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
});
|
|
623
652
|
}
|
|
624
653
|
break;
|
|
625
654
|
}
|
|
@@ -653,14 +682,14 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
653
682
|
}
|
|
654
683
|
function getBedrockImageFormat(mimeType) {
|
|
655
684
|
if (!mimeType) {
|
|
656
|
-
throw new
|
|
685
|
+
throw new UnsupportedFunctionalityError2({
|
|
657
686
|
functionality: "image without mime type",
|
|
658
687
|
message: "Image mime type is required in user message part content"
|
|
659
688
|
});
|
|
660
689
|
}
|
|
661
690
|
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
662
691
|
if (!format) {
|
|
663
|
-
throw new
|
|
692
|
+
throw new UnsupportedFunctionalityError2({
|
|
664
693
|
functionality: `image mime type: ${mimeType}`,
|
|
665
694
|
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
666
695
|
});
|
|
@@ -670,7 +699,7 @@ function getBedrockImageFormat(mimeType) {
|
|
|
670
699
|
function getBedrockDocumentFormat(mimeType) {
|
|
671
700
|
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
672
701
|
if (!format) {
|
|
673
|
-
throw new
|
|
702
|
+
throw new UnsupportedFunctionalityError2({
|
|
674
703
|
functionality: `file mime type: ${mimeType}`,
|
|
675
704
|
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
676
705
|
});
|
|
@@ -746,7 +775,7 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
746
775
|
}
|
|
747
776
|
|
|
748
777
|
// src/bedrock-chat-language-model.ts
|
|
749
|
-
var BedrockChatLanguageModel = class {
|
|
778
|
+
var BedrockChatLanguageModel = class _BedrockChatLanguageModel {
|
|
750
779
|
constructor(modelId, config) {
|
|
751
780
|
this.modelId = modelId;
|
|
752
781
|
this.config = config;
|
|
@@ -756,6 +785,15 @@ var BedrockChatLanguageModel = class {
|
|
|
756
785
|
// no supported urls for bedrock
|
|
757
786
|
};
|
|
758
787
|
}
|
|
788
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
789
|
+
return serializeModelOptions({
|
|
790
|
+
modelId: model.modelId,
|
|
791
|
+
config: model.config
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
795
|
+
return new _BedrockChatLanguageModel(options.modelId, options.config);
|
|
796
|
+
}
|
|
759
797
|
async getArgs({
|
|
760
798
|
prompt,
|
|
761
799
|
maxOutputTokens,
|
|
@@ -769,10 +807,11 @@ var BedrockChatLanguageModel = class {
|
|
|
769
807
|
seed,
|
|
770
808
|
tools,
|
|
771
809
|
toolChoice,
|
|
810
|
+
reasoning,
|
|
772
811
|
providerOptions
|
|
773
812
|
}) {
|
|
774
813
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
775
|
-
|
|
814
|
+
let bedrockOptions = (_a = await parseProviderOptions2({
|
|
776
815
|
provider: "bedrock",
|
|
777
816
|
providerOptions,
|
|
778
817
|
schema: amazonBedrockLanguageModelOptions
|
|
@@ -819,8 +858,17 @@ var BedrockChatLanguageModel = class {
|
|
|
819
858
|
});
|
|
820
859
|
}
|
|
821
860
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
861
|
+
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
862
|
+
bedrockOptions = resolveBedrockReasoningConfig({
|
|
863
|
+
reasoning,
|
|
864
|
+
bedrockOptions,
|
|
865
|
+
warnings,
|
|
866
|
+
isAnthropicModel,
|
|
867
|
+
modelId: this.modelId
|
|
868
|
+
});
|
|
822
869
|
const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
|
|
823
|
-
const
|
|
870
|
+
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
871
|
+
const useNativeStructuredOutput = isAnthropicModel && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
824
872
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
825
873
|
type: "function",
|
|
826
874
|
name: "json",
|
|
@@ -896,7 +944,6 @@ var BedrockChatLanguageModel = class {
|
|
|
896
944
|
}
|
|
897
945
|
}
|
|
898
946
|
const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
|
|
899
|
-
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
900
947
|
if (maxReasoningEffort != null) {
|
|
901
948
|
if (isAnthropicModel) {
|
|
902
949
|
bedrockOptions.additionalModelRequestFields = {
|
|
@@ -992,6 +1039,7 @@ var BedrockChatLanguageModel = class {
|
|
|
992
1039
|
const {
|
|
993
1040
|
reasoningConfig: _,
|
|
994
1041
|
additionalModelRequestFields: __,
|
|
1042
|
+
serviceTier: ___,
|
|
995
1043
|
...filteredBedrockOptions
|
|
996
1044
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
997
1045
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -1006,6 +1054,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1006
1054
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
1007
1055
|
inferenceConfig
|
|
1008
1056
|
},
|
|
1057
|
+
...bedrockOptions.serviceTier != null && {
|
|
1058
|
+
serviceTier: {
|
|
1059
|
+
type: bedrockOptions.serviceTier
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1009
1062
|
...filteredBedrockOptions,
|
|
1010
1063
|
...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
|
|
1011
1064
|
},
|
|
@@ -1017,7 +1070,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1017
1070
|
async getHeaders({
|
|
1018
1071
|
headers
|
|
1019
1072
|
}) {
|
|
1020
|
-
return
|
|
1073
|
+
return combineHeaders(
|
|
1074
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
1075
|
+
headers
|
|
1076
|
+
);
|
|
1021
1077
|
}
|
|
1022
1078
|
async doGenerate(options) {
|
|
1023
1079
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
@@ -1027,18 +1083,18 @@ var BedrockChatLanguageModel = class {
|
|
|
1027
1083
|
usesJsonResponseTool
|
|
1028
1084
|
} = await this.getArgs(options);
|
|
1029
1085
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
1030
|
-
const { value: response, responseHeaders } = await
|
|
1086
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1031
1087
|
url,
|
|
1032
1088
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1033
1089
|
body: args,
|
|
1034
|
-
failedResponseHandler:
|
|
1090
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
1035
1091
|
errorSchema: BedrockErrorSchema,
|
|
1036
1092
|
errorToMessage: (error) => {
|
|
1037
1093
|
var _a2;
|
|
1038
1094
|
return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
|
|
1039
1095
|
}
|
|
1040
1096
|
}),
|
|
1041
|
-
successfulResponseHandler:
|
|
1097
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1042
1098
|
BedrockResponseSchema
|
|
1043
1099
|
),
|
|
1044
1100
|
abortSignal: options.abortSignal,
|
|
@@ -1047,7 +1103,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1047
1103
|
const content = [];
|
|
1048
1104
|
let isJsonResponseFromTool = false;
|
|
1049
1105
|
for (const part of response.output.message.content) {
|
|
1050
|
-
if (part.text) {
|
|
1106
|
+
if (part.text != null) {
|
|
1051
1107
|
content.push({ type: "text", text: part.text });
|
|
1052
1108
|
}
|
|
1053
1109
|
if (part.reasoningContent) {
|
|
@@ -1149,11 +1205,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1149
1205
|
const modelId = this.modelId;
|
|
1150
1206
|
const isMistral = isMistralModel(modelId);
|
|
1151
1207
|
const url = `${this.getUrl(modelId)}/converse-stream`;
|
|
1152
|
-
const { value: response, responseHeaders } = await
|
|
1208
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1153
1209
|
url,
|
|
1154
1210
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1155
1211
|
body: args,
|
|
1156
|
-
failedResponseHandler:
|
|
1212
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
1157
1213
|
errorSchema: BedrockErrorSchema,
|
|
1158
1214
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1159
1215
|
}),
|
|
@@ -1444,146 +1500,214 @@ var BedrockChatLanguageModel = class {
|
|
|
1444
1500
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
1445
1501
|
}
|
|
1446
1502
|
};
|
|
1447
|
-
var BedrockStopReasonSchema =
|
|
1448
|
-
|
|
1449
|
-
|
|
1503
|
+
var BedrockStopReasonSchema = z3.union([
|
|
1504
|
+
z3.enum(BEDROCK_STOP_REASONS),
|
|
1505
|
+
z3.string()
|
|
1450
1506
|
]);
|
|
1451
|
-
var BedrockAdditionalModelResponseFieldsSchema =
|
|
1452
|
-
delta:
|
|
1453
|
-
stop_sequence:
|
|
1507
|
+
var BedrockAdditionalModelResponseFieldsSchema = z3.object({
|
|
1508
|
+
delta: z3.object({
|
|
1509
|
+
stop_sequence: z3.string().nullish()
|
|
1454
1510
|
}).nullish()
|
|
1455
|
-
}).catchall(
|
|
1456
|
-
var BedrockToolUseSchema =
|
|
1457
|
-
toolUseId:
|
|
1458
|
-
name:
|
|
1459
|
-
input:
|
|
1511
|
+
}).catchall(z3.unknown());
|
|
1512
|
+
var BedrockToolUseSchema = z3.object({
|
|
1513
|
+
toolUseId: z3.string(),
|
|
1514
|
+
name: z3.string(),
|
|
1515
|
+
input: z3.unknown()
|
|
1460
1516
|
});
|
|
1461
|
-
var BedrockReasoningTextSchema =
|
|
1462
|
-
signature:
|
|
1463
|
-
text:
|
|
1517
|
+
var BedrockReasoningTextSchema = z3.object({
|
|
1518
|
+
signature: z3.string().nullish(),
|
|
1519
|
+
text: z3.string()
|
|
1464
1520
|
});
|
|
1465
|
-
var BedrockRedactedReasoningSchema =
|
|
1466
|
-
data:
|
|
1521
|
+
var BedrockRedactedReasoningSchema = z3.object({
|
|
1522
|
+
data: z3.string()
|
|
1467
1523
|
});
|
|
1468
|
-
var BedrockResponseSchema =
|
|
1469
|
-
metrics:
|
|
1470
|
-
latencyMs:
|
|
1524
|
+
var BedrockResponseSchema = z3.object({
|
|
1525
|
+
metrics: z3.object({
|
|
1526
|
+
latencyMs: z3.number()
|
|
1471
1527
|
}).nullish(),
|
|
1472
|
-
output:
|
|
1473
|
-
message:
|
|
1474
|
-
content:
|
|
1475
|
-
|
|
1476
|
-
text:
|
|
1528
|
+
output: z3.object({
|
|
1529
|
+
message: z3.object({
|
|
1530
|
+
content: z3.array(
|
|
1531
|
+
z3.object({
|
|
1532
|
+
text: z3.string().nullish(),
|
|
1477
1533
|
toolUse: BedrockToolUseSchema.nullish(),
|
|
1478
|
-
reasoningContent:
|
|
1479
|
-
|
|
1534
|
+
reasoningContent: z3.union([
|
|
1535
|
+
z3.object({
|
|
1480
1536
|
reasoningText: BedrockReasoningTextSchema
|
|
1481
1537
|
}),
|
|
1482
|
-
|
|
1538
|
+
z3.object({
|
|
1483
1539
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
1484
1540
|
})
|
|
1485
1541
|
]).nullish()
|
|
1486
1542
|
})
|
|
1487
1543
|
),
|
|
1488
|
-
role:
|
|
1544
|
+
role: z3.string()
|
|
1489
1545
|
})
|
|
1490
1546
|
}),
|
|
1491
1547
|
stopReason: BedrockStopReasonSchema,
|
|
1492
1548
|
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1493
|
-
trace:
|
|
1494
|
-
performanceConfig:
|
|
1495
|
-
serviceTier:
|
|
1496
|
-
usage:
|
|
1497
|
-
inputTokens:
|
|
1498
|
-
outputTokens:
|
|
1499
|
-
totalTokens:
|
|
1500
|
-
cacheReadInputTokens:
|
|
1501
|
-
cacheWriteInputTokens:
|
|
1502
|
-
cacheDetails:
|
|
1549
|
+
trace: z3.unknown().nullish(),
|
|
1550
|
+
performanceConfig: z3.object({ latency: z3.string() }).nullish(),
|
|
1551
|
+
serviceTier: z3.object({ type: z3.string() }).nullish(),
|
|
1552
|
+
usage: z3.object({
|
|
1553
|
+
inputTokens: z3.number(),
|
|
1554
|
+
outputTokens: z3.number(),
|
|
1555
|
+
totalTokens: z3.number(),
|
|
1556
|
+
cacheReadInputTokens: z3.number().nullish(),
|
|
1557
|
+
cacheWriteInputTokens: z3.number().nullish(),
|
|
1558
|
+
cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish()
|
|
1503
1559
|
})
|
|
1504
1560
|
});
|
|
1505
|
-
var BedrockStreamSchema =
|
|
1506
|
-
contentBlockDelta:
|
|
1507
|
-
contentBlockIndex:
|
|
1508
|
-
delta:
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
reasoningContent:
|
|
1561
|
+
var BedrockStreamSchema = z3.object({
|
|
1562
|
+
contentBlockDelta: z3.object({
|
|
1563
|
+
contentBlockIndex: z3.number(),
|
|
1564
|
+
delta: z3.union([
|
|
1565
|
+
z3.object({ text: z3.string() }),
|
|
1566
|
+
z3.object({ toolUse: z3.object({ input: z3.string() }) }),
|
|
1567
|
+
z3.object({
|
|
1568
|
+
reasoningContent: z3.object({ text: z3.string() })
|
|
1513
1569
|
}),
|
|
1514
|
-
|
|
1515
|
-
reasoningContent:
|
|
1516
|
-
signature:
|
|
1570
|
+
z3.object({
|
|
1571
|
+
reasoningContent: z3.object({
|
|
1572
|
+
signature: z3.string()
|
|
1517
1573
|
})
|
|
1518
1574
|
}),
|
|
1519
|
-
|
|
1520
|
-
reasoningContent:
|
|
1575
|
+
z3.object({
|
|
1576
|
+
reasoningContent: z3.object({ data: z3.string() })
|
|
1521
1577
|
})
|
|
1522
1578
|
]).nullish()
|
|
1523
1579
|
}).nullish(),
|
|
1524
|
-
contentBlockStart:
|
|
1525
|
-
contentBlockIndex:
|
|
1526
|
-
start:
|
|
1580
|
+
contentBlockStart: z3.object({
|
|
1581
|
+
contentBlockIndex: z3.number(),
|
|
1582
|
+
start: z3.object({
|
|
1527
1583
|
toolUse: BedrockToolUseSchema.nullish()
|
|
1528
1584
|
}).nullish()
|
|
1529
1585
|
}).nullish(),
|
|
1530
|
-
contentBlockStop:
|
|
1531
|
-
contentBlockIndex:
|
|
1586
|
+
contentBlockStop: z3.object({
|
|
1587
|
+
contentBlockIndex: z3.number()
|
|
1532
1588
|
}).nullish(),
|
|
1533
|
-
internalServerException:
|
|
1534
|
-
messageStop:
|
|
1589
|
+
internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1590
|
+
messageStop: z3.object({
|
|
1535
1591
|
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1536
1592
|
stopReason: BedrockStopReasonSchema
|
|
1537
1593
|
}).nullish(),
|
|
1538
|
-
metadata:
|
|
1539
|
-
trace:
|
|
1540
|
-
performanceConfig:
|
|
1541
|
-
serviceTier:
|
|
1542
|
-
usage:
|
|
1543
|
-
cacheReadInputTokens:
|
|
1544
|
-
cacheWriteInputTokens:
|
|
1545
|
-
cacheDetails:
|
|
1546
|
-
inputTokens:
|
|
1547
|
-
outputTokens:
|
|
1594
|
+
metadata: z3.object({
|
|
1595
|
+
trace: z3.unknown().nullish(),
|
|
1596
|
+
performanceConfig: z3.object({ latency: z3.string() }).nullish(),
|
|
1597
|
+
serviceTier: z3.object({ type: z3.string() }).nullish(),
|
|
1598
|
+
usage: z3.object({
|
|
1599
|
+
cacheReadInputTokens: z3.number().nullish(),
|
|
1600
|
+
cacheWriteInputTokens: z3.number().nullish(),
|
|
1601
|
+
cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish(),
|
|
1602
|
+
inputTokens: z3.number(),
|
|
1603
|
+
outputTokens: z3.number()
|
|
1548
1604
|
}).nullish()
|
|
1549
1605
|
}).nullish(),
|
|
1550
|
-
modelStreamErrorException:
|
|
1551
|
-
throttlingException:
|
|
1552
|
-
validationException:
|
|
1606
|
+
modelStreamErrorException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1607
|
+
throttlingException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1608
|
+
validationException: z3.record(z3.string(), z3.unknown()).nullish()
|
|
1553
1609
|
});
|
|
1554
|
-
var bedrockReasoningMetadataSchema =
|
|
1555
|
-
signature:
|
|
1556
|
-
redactedData:
|
|
1610
|
+
var bedrockReasoningMetadataSchema = z3.object({
|
|
1611
|
+
signature: z3.string().optional(),
|
|
1612
|
+
redactedData: z3.string().optional()
|
|
1557
1613
|
});
|
|
1614
|
+
var bedrockReasoningEffortMap = {
|
|
1615
|
+
minimal: "low",
|
|
1616
|
+
low: "low",
|
|
1617
|
+
medium: "medium",
|
|
1618
|
+
high: "high",
|
|
1619
|
+
xhigh: "max"
|
|
1620
|
+
};
|
|
1621
|
+
function resolveBedrockReasoningConfig({
|
|
1622
|
+
reasoning,
|
|
1623
|
+
bedrockOptions,
|
|
1624
|
+
warnings,
|
|
1625
|
+
isAnthropicModel,
|
|
1626
|
+
modelId
|
|
1627
|
+
}) {
|
|
1628
|
+
if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
|
|
1629
|
+
return bedrockOptions;
|
|
1630
|
+
}
|
|
1631
|
+
const result = { ...bedrockOptions };
|
|
1632
|
+
if (isAnthropicModel) {
|
|
1633
|
+
const capabilities = getModelCapabilities(modelId);
|
|
1634
|
+
if (reasoning === "none") {
|
|
1635
|
+
result.reasoningConfig = { type: "disabled" };
|
|
1636
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1637
|
+
const effort = mapReasoningToProviderEffort({
|
|
1638
|
+
reasoning,
|
|
1639
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1640
|
+
warnings
|
|
1641
|
+
});
|
|
1642
|
+
result.reasoningConfig = {
|
|
1643
|
+
type: "adaptive",
|
|
1644
|
+
maxReasoningEffort: effort
|
|
1645
|
+
};
|
|
1646
|
+
} else {
|
|
1647
|
+
const budgetTokens = mapReasoningToProviderBudget({
|
|
1648
|
+
reasoning,
|
|
1649
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1650
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1651
|
+
warnings
|
|
1652
|
+
});
|
|
1653
|
+
if (budgetTokens != null) {
|
|
1654
|
+
result.reasoningConfig = {
|
|
1655
|
+
type: "enabled",
|
|
1656
|
+
budgetTokens
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
} else if (reasoning !== "none") {
|
|
1661
|
+
const effort = mapReasoningToProviderEffort({
|
|
1662
|
+
reasoning,
|
|
1663
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1664
|
+
warnings
|
|
1665
|
+
});
|
|
1666
|
+
result.reasoningConfig = { maxReasoningEffort: effort };
|
|
1667
|
+
}
|
|
1668
|
+
return result;
|
|
1669
|
+
}
|
|
1558
1670
|
|
|
1559
1671
|
// src/bedrock-embedding-model.ts
|
|
1560
|
-
|
|
1561
|
-
|
|
1672
|
+
import {
|
|
1673
|
+
TooManyEmbeddingValuesForCallError
|
|
1674
|
+
} from "@ai-sdk/provider";
|
|
1675
|
+
import {
|
|
1676
|
+
combineHeaders as combineHeaders2,
|
|
1677
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1678
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1679
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1680
|
+
postJsonToApi as postJsonToApi2,
|
|
1681
|
+
resolve as resolve2,
|
|
1682
|
+
serializeModelOptions as serializeModelOptions2,
|
|
1683
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
1684
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
1685
|
+
} from "@ai-sdk/provider-utils";
|
|
1562
1686
|
|
|
1563
1687
|
// src/bedrock-embedding-options.ts
|
|
1564
|
-
|
|
1565
|
-
var amazonBedrockEmbeddingModelOptionsSchema =
|
|
1688
|
+
import { z as z4 } from "zod/v4";
|
|
1689
|
+
var amazonBedrockEmbeddingModelOptionsSchema = z4.object({
|
|
1566
1690
|
/**
|
|
1567
1691
|
* The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
1568
1692
|
* Only supported in amazon.titan-embed-text-v2:0.
|
|
1569
1693
|
*/
|
|
1570
|
-
dimensions:
|
|
1694
|
+
dimensions: z4.union([z4.literal(1024), z4.literal(512), z4.literal(256)]).optional(),
|
|
1571
1695
|
/**
|
|
1572
1696
|
* Flag indicating whether or not to normalize the output embeddings. Defaults to true.
|
|
1573
1697
|
* Only supported in amazon.titan-embed-text-v2:0.
|
|
1574
1698
|
*/
|
|
1575
|
-
normalize:
|
|
1699
|
+
normalize: z4.boolean().optional(),
|
|
1576
1700
|
/**
|
|
1577
1701
|
* The number of dimensions for Nova embedding models (defaults to 1024).
|
|
1578
1702
|
* Supported values: 256, 384, 1024, 3072.
|
|
1579
1703
|
* Only supported in amazon.nova-* embedding models.
|
|
1580
1704
|
*/
|
|
1581
|
-
embeddingDimension:
|
|
1705
|
+
embeddingDimension: z4.union([z4.literal(256), z4.literal(384), z4.literal(1024), z4.literal(3072)]).optional(),
|
|
1582
1706
|
/**
|
|
1583
1707
|
* The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
|
|
1584
1708
|
* Only supported in amazon.nova-* embedding models.
|
|
1585
1709
|
*/
|
|
1586
|
-
embeddingPurpose:
|
|
1710
|
+
embeddingPurpose: z4.enum([
|
|
1587
1711
|
"GENERIC_INDEX",
|
|
1588
1712
|
"TEXT_RETRIEVAL",
|
|
1589
1713
|
"IMAGE_RETRIEVAL",
|
|
@@ -1599,22 +1723,22 @@ var amazonBedrockEmbeddingModelOptionsSchema = import_v44.z.object({
|
|
|
1599
1723
|
* Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
1600
1724
|
* If not set, the provider defaults to `search_query`.
|
|
1601
1725
|
*/
|
|
1602
|
-
inputType:
|
|
1726
|
+
inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
1603
1727
|
/**
|
|
1604
1728
|
* Truncation behavior when input exceeds the model's context length.
|
|
1605
1729
|
* Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
|
|
1606
1730
|
*/
|
|
1607
|
-
truncate:
|
|
1731
|
+
truncate: z4.enum(["NONE", "START", "END"]).optional(),
|
|
1608
1732
|
/**
|
|
1609
1733
|
* The number of dimensions the resulting output embeddings should have (defaults to 1536).
|
|
1610
1734
|
* Only supported in cohere.embed-v4:0 and newer Cohere embedding models.
|
|
1611
1735
|
*/
|
|
1612
|
-
outputDimension:
|
|
1736
|
+
outputDimension: z4.union([z4.literal(256), z4.literal(512), z4.literal(1024), z4.literal(1536)]).optional()
|
|
1613
1737
|
});
|
|
1614
1738
|
|
|
1615
1739
|
// src/bedrock-embedding-model.ts
|
|
1616
|
-
|
|
1617
|
-
var BedrockEmbeddingModel = class {
|
|
1740
|
+
import { z as z5 } from "zod/v4";
|
|
1741
|
+
var BedrockEmbeddingModel = class _BedrockEmbeddingModel {
|
|
1618
1742
|
constructor(modelId, config) {
|
|
1619
1743
|
this.modelId = modelId;
|
|
1620
1744
|
this.config = config;
|
|
@@ -1623,6 +1747,15 @@ var BedrockEmbeddingModel = class {
|
|
|
1623
1747
|
this.maxEmbeddingsPerCall = 1;
|
|
1624
1748
|
this.supportsParallelCalls = true;
|
|
1625
1749
|
}
|
|
1750
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
1751
|
+
return serializeModelOptions2({
|
|
1752
|
+
modelId: model.modelId,
|
|
1753
|
+
config: model.config
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
1757
|
+
return new _BedrockEmbeddingModel(options.modelId, options.config);
|
|
1758
|
+
}
|
|
1626
1759
|
getUrl(modelId) {
|
|
1627
1760
|
const encodedModelId = encodeURIComponent(modelId);
|
|
1628
1761
|
return `${this.config.baseUrl()}/model/${encodedModelId}/invoke`;
|
|
@@ -1635,14 +1768,14 @@ var BedrockEmbeddingModel = class {
|
|
|
1635
1768
|
}) {
|
|
1636
1769
|
var _a, _b, _c, _d, _e, _f;
|
|
1637
1770
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1638
|
-
throw new
|
|
1771
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
1639
1772
|
provider: this.provider,
|
|
1640
1773
|
modelId: this.modelId,
|
|
1641
1774
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1642
1775
|
values
|
|
1643
1776
|
});
|
|
1644
1777
|
}
|
|
1645
|
-
const bedrockOptions = (_a = await (
|
|
1778
|
+
const bedrockOptions = (_a = await parseProviderOptions3({
|
|
1646
1779
|
provider: "bedrock",
|
|
1647
1780
|
providerOptions,
|
|
1648
1781
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
@@ -1672,17 +1805,20 @@ var BedrockEmbeddingModel = class {
|
|
|
1672
1805
|
normalize: bedrockOptions.normalize
|
|
1673
1806
|
};
|
|
1674
1807
|
const url = this.getUrl(this.modelId);
|
|
1675
|
-
const { value: response } = await (
|
|
1808
|
+
const { value: response } = await postJsonToApi2({
|
|
1676
1809
|
url,
|
|
1677
|
-
headers: await (
|
|
1678
|
-
(
|
|
1810
|
+
headers: await resolve2(
|
|
1811
|
+
combineHeaders2(
|
|
1812
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
1813
|
+
headers
|
|
1814
|
+
)
|
|
1679
1815
|
),
|
|
1680
1816
|
body: args,
|
|
1681
|
-
failedResponseHandler: (
|
|
1817
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1682
1818
|
errorSchema: BedrockErrorSchema,
|
|
1683
1819
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1684
1820
|
}),
|
|
1685
|
-
successfulResponseHandler: (
|
|
1821
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
1686
1822
|
BedrockEmbeddingResponseSchema
|
|
1687
1823
|
),
|
|
1688
1824
|
fetch: this.config.fetch,
|
|
@@ -1709,36 +1845,46 @@ var BedrockEmbeddingModel = class {
|
|
|
1709
1845
|
};
|
|
1710
1846
|
}
|
|
1711
1847
|
};
|
|
1712
|
-
var BedrockEmbeddingResponseSchema =
|
|
1848
|
+
var BedrockEmbeddingResponseSchema = z5.union([
|
|
1713
1849
|
// Titan-style response
|
|
1714
|
-
|
|
1715
|
-
embedding:
|
|
1716
|
-
inputTextTokenCount:
|
|
1850
|
+
z5.object({
|
|
1851
|
+
embedding: z5.array(z5.number()),
|
|
1852
|
+
inputTextTokenCount: z5.number()
|
|
1717
1853
|
}),
|
|
1718
1854
|
// Nova-style response
|
|
1719
|
-
|
|
1720
|
-
embeddings:
|
|
1721
|
-
|
|
1722
|
-
embeddingType:
|
|
1723
|
-
embedding:
|
|
1855
|
+
z5.object({
|
|
1856
|
+
embeddings: z5.array(
|
|
1857
|
+
z5.object({
|
|
1858
|
+
embeddingType: z5.string(),
|
|
1859
|
+
embedding: z5.array(z5.number())
|
|
1724
1860
|
})
|
|
1725
1861
|
),
|
|
1726
|
-
inputTokenCount:
|
|
1862
|
+
inputTokenCount: z5.number().optional()
|
|
1727
1863
|
}),
|
|
1728
1864
|
// Cohere v3-style response
|
|
1729
|
-
|
|
1730
|
-
embeddings:
|
|
1865
|
+
z5.object({
|
|
1866
|
+
embeddings: z5.array(z5.array(z5.number()))
|
|
1731
1867
|
}),
|
|
1732
1868
|
// Cohere v4-style response
|
|
1733
|
-
|
|
1734
|
-
embeddings:
|
|
1735
|
-
float:
|
|
1869
|
+
z5.object({
|
|
1870
|
+
embeddings: z5.object({
|
|
1871
|
+
float: z5.array(z5.array(z5.number()))
|
|
1736
1872
|
})
|
|
1737
1873
|
})
|
|
1738
1874
|
]);
|
|
1739
1875
|
|
|
1740
1876
|
// src/bedrock-image-model.ts
|
|
1741
|
-
|
|
1877
|
+
import {
|
|
1878
|
+
combineHeaders as combineHeaders3,
|
|
1879
|
+
convertUint8ArrayToBase64,
|
|
1880
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
1881
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1882
|
+
postJsonToApi as postJsonToApi3,
|
|
1883
|
+
resolve as resolve3,
|
|
1884
|
+
serializeModelOptions as serializeModelOptions3,
|
|
1885
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
1886
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
|
|
1887
|
+
} from "@ai-sdk/provider-utils";
|
|
1742
1888
|
|
|
1743
1889
|
// src/bedrock-image-settings.ts
|
|
1744
1890
|
var modelMaxImagesPerCall = {
|
|
@@ -1746,14 +1892,23 @@ var modelMaxImagesPerCall = {
|
|
|
1746
1892
|
};
|
|
1747
1893
|
|
|
1748
1894
|
// src/bedrock-image-model.ts
|
|
1749
|
-
|
|
1750
|
-
var BedrockImageModel = class {
|
|
1895
|
+
import { z as z6 } from "zod/v4";
|
|
1896
|
+
var BedrockImageModel = class _BedrockImageModel {
|
|
1751
1897
|
constructor(modelId, config) {
|
|
1752
1898
|
this.modelId = modelId;
|
|
1753
1899
|
this.config = config;
|
|
1754
1900
|
this.specificationVersion = "v4";
|
|
1755
1901
|
this.provider = "amazon-bedrock";
|
|
1756
1902
|
}
|
|
1903
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
1904
|
+
return serializeModelOptions3({
|
|
1905
|
+
modelId: model.modelId,
|
|
1906
|
+
config: model.config
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
1910
|
+
return new _BedrockImageModel(options.modelId, options.config);
|
|
1911
|
+
}
|
|
1757
1912
|
get maxImagesPerCall() {
|
|
1758
1913
|
var _a;
|
|
1759
1914
|
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
@@ -1882,17 +2037,20 @@ var BedrockImageModel = class {
|
|
|
1882
2037
|
});
|
|
1883
2038
|
}
|
|
1884
2039
|
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 (
|
|
2040
|
+
const { value: response, responseHeaders } = await postJsonToApi3({
|
|
1886
2041
|
url: this.getUrl(this.modelId),
|
|
1887
|
-
headers: await (
|
|
1888
|
-
(
|
|
2042
|
+
headers: await resolve3(
|
|
2043
|
+
combineHeaders3(
|
|
2044
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
2045
|
+
headers
|
|
2046
|
+
)
|
|
1889
2047
|
),
|
|
1890
2048
|
body: args,
|
|
1891
|
-
failedResponseHandler: (
|
|
2049
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
1892
2050
|
errorSchema: BedrockErrorSchema,
|
|
1893
2051
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1894
2052
|
}),
|
|
1895
|
-
successfulResponseHandler: (
|
|
2053
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1896
2054
|
bedrockImageResponseSchema
|
|
1897
2055
|
),
|
|
1898
2056
|
abortSignal,
|
|
@@ -1928,42 +2086,47 @@ function getBase64Data(file) {
|
|
|
1928
2086
|
);
|
|
1929
2087
|
}
|
|
1930
2088
|
if (file.data instanceof Uint8Array) {
|
|
1931
|
-
return
|
|
2089
|
+
return convertUint8ArrayToBase64(file.data);
|
|
1932
2090
|
}
|
|
1933
2091
|
return file.data;
|
|
1934
2092
|
}
|
|
1935
|
-
var bedrockImageResponseSchema =
|
|
2093
|
+
var bedrockImageResponseSchema = z6.object({
|
|
1936
2094
|
// Normal successful response
|
|
1937
|
-
images:
|
|
2095
|
+
images: z6.array(z6.string()).optional(),
|
|
1938
2096
|
// Moderation response fields
|
|
1939
|
-
id:
|
|
1940
|
-
status:
|
|
1941
|
-
result:
|
|
1942
|
-
progress:
|
|
1943
|
-
details:
|
|
1944
|
-
preview:
|
|
2097
|
+
id: z6.string().optional(),
|
|
2098
|
+
status: z6.string().optional(),
|
|
2099
|
+
result: z6.unknown().optional(),
|
|
2100
|
+
progress: z6.unknown().optional(),
|
|
2101
|
+
details: z6.record(z6.string(), z6.unknown()).optional(),
|
|
2102
|
+
preview: z6.unknown().optional()
|
|
1945
2103
|
});
|
|
1946
2104
|
|
|
1947
2105
|
// src/bedrock-sigv4-fetch.ts
|
|
1948
|
-
|
|
1949
|
-
|
|
2106
|
+
import {
|
|
2107
|
+
combineHeaders as combineHeaders4,
|
|
2108
|
+
normalizeHeaders,
|
|
2109
|
+
withUserAgentSuffix,
|
|
2110
|
+
getRuntimeEnvironmentUserAgent
|
|
2111
|
+
} from "@ai-sdk/provider-utils";
|
|
2112
|
+
import { AwsV4Signer } from "aws4fetch";
|
|
1950
2113
|
|
|
1951
2114
|
// src/version.ts
|
|
1952
|
-
var VERSION = true ? "5.0.0-beta.
|
|
2115
|
+
var VERSION = true ? "5.0.0-beta.40" : "0.0.0-test";
|
|
1953
2116
|
|
|
1954
2117
|
// src/bedrock-sigv4-fetch.ts
|
|
1955
2118
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
1956
2119
|
return async (input, init) => {
|
|
1957
2120
|
var _a, _b;
|
|
1958
2121
|
const request = input instanceof Request ? input : void 0;
|
|
1959
|
-
const originalHeaders = (
|
|
1960
|
-
|
|
1961
|
-
|
|
2122
|
+
const originalHeaders = combineHeaders4(
|
|
2123
|
+
normalizeHeaders(request == null ? void 0 : request.headers),
|
|
2124
|
+
normalizeHeaders(init == null ? void 0 : init.headers)
|
|
1962
2125
|
);
|
|
1963
|
-
const headersWithUserAgent =
|
|
2126
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
1964
2127
|
originalHeaders,
|
|
1965
2128
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1966
|
-
|
|
2129
|
+
getRuntimeEnvironmentUserAgent()
|
|
1967
2130
|
);
|
|
1968
2131
|
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
1969
2132
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
@@ -1982,7 +2145,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1982
2145
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
1983
2146
|
const body = prepareBodyString(effectiveBody);
|
|
1984
2147
|
const credentials = await getCredentials();
|
|
1985
|
-
const signer = new
|
|
2148
|
+
const signer = new AwsV4Signer({
|
|
1986
2149
|
url,
|
|
1987
2150
|
method: "POST",
|
|
1988
2151
|
headers: Object.entries(headersWithUserAgent),
|
|
@@ -1994,8 +2157,8 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1994
2157
|
service: "bedrock"
|
|
1995
2158
|
});
|
|
1996
2159
|
const signingResult = await signer.sign();
|
|
1997
|
-
const signedHeaders =
|
|
1998
|
-
const combinedHeaders = (
|
|
2160
|
+
const signedHeaders = normalizeHeaders(signingResult.headers);
|
|
2161
|
+
const combinedHeaders = combineHeaders4(headersWithUserAgent, signedHeaders);
|
|
1999
2162
|
return fetch(input, {
|
|
2000
2163
|
...init,
|
|
2001
2164
|
body,
|
|
@@ -2016,13 +2179,13 @@ function prepareBodyString(body) {
|
|
|
2016
2179
|
}
|
|
2017
2180
|
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
2018
2181
|
return async (input, init) => {
|
|
2019
|
-
const originalHeaders =
|
|
2020
|
-
const headersWithUserAgent =
|
|
2182
|
+
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
2183
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
2021
2184
|
originalHeaders,
|
|
2022
2185
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
2023
|
-
|
|
2186
|
+
getRuntimeEnvironmentUserAgent()
|
|
2024
2187
|
);
|
|
2025
|
-
const finalHeaders = (
|
|
2188
|
+
const finalHeaders = combineHeaders4(headersWithUserAgent, {
|
|
2026
2189
|
Authorization: `Bearer ${apiKey}`
|
|
2027
2190
|
});
|
|
2028
2191
|
return fetch(input, {
|
|
@@ -2033,39 +2196,46 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
|
2033
2196
|
}
|
|
2034
2197
|
|
|
2035
2198
|
// src/reranking/bedrock-reranking-model.ts
|
|
2036
|
-
|
|
2199
|
+
import {
|
|
2200
|
+
combineHeaders as combineHeaders5,
|
|
2201
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
2202
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2203
|
+
parseProviderOptions as parseProviderOptions4,
|
|
2204
|
+
postJsonToApi as postJsonToApi4,
|
|
2205
|
+
resolve as resolve4
|
|
2206
|
+
} from "@ai-sdk/provider-utils";
|
|
2037
2207
|
|
|
2038
2208
|
// src/reranking/bedrock-reranking-api.ts
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
var bedrockRerankingResponseSchema =
|
|
2042
|
-
() =>
|
|
2043
|
-
|
|
2044
|
-
results:
|
|
2045
|
-
|
|
2046
|
-
index:
|
|
2047
|
-
relevanceScore:
|
|
2209
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
2210
|
+
import { z as z7 } from "zod/v4";
|
|
2211
|
+
var bedrockRerankingResponseSchema = lazySchema(
|
|
2212
|
+
() => zodSchema(
|
|
2213
|
+
z7.object({
|
|
2214
|
+
results: z7.array(
|
|
2215
|
+
z7.object({
|
|
2216
|
+
index: z7.number(),
|
|
2217
|
+
relevanceScore: z7.number()
|
|
2048
2218
|
})
|
|
2049
2219
|
),
|
|
2050
|
-
nextToken:
|
|
2220
|
+
nextToken: z7.string().optional()
|
|
2051
2221
|
})
|
|
2052
2222
|
)
|
|
2053
2223
|
);
|
|
2054
2224
|
|
|
2055
2225
|
// src/reranking/bedrock-reranking-options.ts
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
var amazonBedrockRerankingModelOptionsSchema = (
|
|
2059
|
-
() => (
|
|
2060
|
-
|
|
2226
|
+
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
2227
|
+
import { z as z8 } from "zod/v4";
|
|
2228
|
+
var amazonBedrockRerankingModelOptionsSchema = lazySchema2(
|
|
2229
|
+
() => zodSchema2(
|
|
2230
|
+
z8.object({
|
|
2061
2231
|
/**
|
|
2062
2232
|
* 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
2233
|
*/
|
|
2064
|
-
nextToken:
|
|
2234
|
+
nextToken: z8.string().optional(),
|
|
2065
2235
|
/**
|
|
2066
2236
|
* Additional model request fields to pass to the model.
|
|
2067
2237
|
*/
|
|
2068
|
-
additionalModelRequestFields:
|
|
2238
|
+
additionalModelRequestFields: z8.record(z8.string(), z8.any()).optional()
|
|
2069
2239
|
})
|
|
2070
2240
|
)
|
|
2071
2241
|
);
|
|
@@ -2086,7 +2256,7 @@ var BedrockRerankingModel = class {
|
|
|
2086
2256
|
abortSignal,
|
|
2087
2257
|
providerOptions
|
|
2088
2258
|
}) {
|
|
2089
|
-
const bedrockOptions = await (
|
|
2259
|
+
const bedrockOptions = await parseProviderOptions4({
|
|
2090
2260
|
provider: "bedrock",
|
|
2091
2261
|
providerOptions,
|
|
2092
2262
|
schema: amazonBedrockRerankingModelOptionsSchema
|
|
@@ -2095,10 +2265,10 @@ var BedrockRerankingModel = class {
|
|
|
2095
2265
|
value: response,
|
|
2096
2266
|
responseHeaders,
|
|
2097
2267
|
rawValue
|
|
2098
|
-
} = await (
|
|
2268
|
+
} = await postJsonToApi4({
|
|
2099
2269
|
url: `${this.config.baseUrl()}/rerank`,
|
|
2100
|
-
headers: await (
|
|
2101
|
-
(
|
|
2270
|
+
headers: await resolve4(
|
|
2271
|
+
combineHeaders5(await resolve4(this.config.headers), headers)
|
|
2102
2272
|
),
|
|
2103
2273
|
body: {
|
|
2104
2274
|
nextToken: bedrockOptions == null ? void 0 : bedrockOptions.nextToken,
|
|
@@ -2129,11 +2299,11 @@ var BedrockRerankingModel = class {
|
|
|
2129
2299
|
}
|
|
2130
2300
|
}))
|
|
2131
2301
|
},
|
|
2132
|
-
failedResponseHandler: (
|
|
2302
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
2133
2303
|
errorSchema: BedrockErrorSchema,
|
|
2134
2304
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
2135
2305
|
}),
|
|
2136
|
-
successfulResponseHandler: (
|
|
2306
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2137
2307
|
bedrockRerankingResponseSchema
|
|
2138
2308
|
),
|
|
2139
2309
|
fetch: this.config.fetch,
|
|
@@ -2151,13 +2321,13 @@ var BedrockRerankingModel = class {
|
|
|
2151
2321
|
|
|
2152
2322
|
// src/bedrock-provider.ts
|
|
2153
2323
|
function createAmazonBedrock(options = {}) {
|
|
2154
|
-
const rawApiKey =
|
|
2324
|
+
const rawApiKey = loadOptionalSetting({
|
|
2155
2325
|
settingValue: options.apiKey,
|
|
2156
2326
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
2157
2327
|
});
|
|
2158
2328
|
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
2159
2329
|
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
2160
|
-
const region =
|
|
2330
|
+
const region = loadSetting({
|
|
2161
2331
|
settingValue: options.region,
|
|
2162
2332
|
settingName: "region",
|
|
2163
2333
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2179,19 +2349,19 @@ function createAmazonBedrock(options = {}) {
|
|
|
2179
2349
|
try {
|
|
2180
2350
|
return {
|
|
2181
2351
|
region,
|
|
2182
|
-
accessKeyId:
|
|
2352
|
+
accessKeyId: loadSetting({
|
|
2183
2353
|
settingValue: options.accessKeyId,
|
|
2184
2354
|
settingName: "accessKeyId",
|
|
2185
2355
|
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
2186
2356
|
description: "AWS access key ID"
|
|
2187
2357
|
}),
|
|
2188
|
-
secretAccessKey:
|
|
2358
|
+
secretAccessKey: loadSetting({
|
|
2189
2359
|
settingValue: options.secretAccessKey,
|
|
2190
2360
|
settingName: "secretAccessKey",
|
|
2191
2361
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
2192
2362
|
description: "AWS secret access key"
|
|
2193
2363
|
}),
|
|
2194
|
-
sessionToken:
|
|
2364
|
+
sessionToken: loadOptionalSetting({
|
|
2195
2365
|
settingValue: options.sessionToken,
|
|
2196
2366
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
2197
2367
|
})
|
|
@@ -2220,12 +2390,12 @@ Original error: ${errorMessage}`
|
|
|
2220
2390
|
const getHeaders = () => {
|
|
2221
2391
|
var _a;
|
|
2222
2392
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2223
|
-
return (
|
|
2393
|
+
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2224
2394
|
};
|
|
2225
2395
|
const getBedrockRuntimeBaseUrl = () => {
|
|
2226
2396
|
var _a, _b;
|
|
2227
|
-
return (_b =
|
|
2228
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${
|
|
2397
|
+
return (_b = withoutTrailingSlash(
|
|
2398
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${loadSetting({
|
|
2229
2399
|
settingValue: options.region,
|
|
2230
2400
|
settingName: "region",
|
|
2231
2401
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2235,8 +2405,8 @@ Original error: ${errorMessage}`
|
|
|
2235
2405
|
};
|
|
2236
2406
|
const getBedrockAgentRuntimeBaseUrl = () => {
|
|
2237
2407
|
var _a, _b;
|
|
2238
|
-
return (_b =
|
|
2239
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${
|
|
2408
|
+
return (_b = withoutTrailingSlash(
|
|
2409
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${loadSetting({
|
|
2240
2410
|
settingValue: options.region,
|
|
2241
2411
|
settingName: "region",
|
|
2242
2412
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2248,7 +2418,7 @@ Original error: ${errorMessage}`
|
|
|
2248
2418
|
baseUrl: getBedrockRuntimeBaseUrl,
|
|
2249
2419
|
headers: getHeaders,
|
|
2250
2420
|
fetch: fetchFunction,
|
|
2251
|
-
generateId
|
|
2421
|
+
generateId
|
|
2252
2422
|
});
|
|
2253
2423
|
const provider = function(modelId) {
|
|
2254
2424
|
if (new.target) {
|
|
@@ -2270,7 +2440,7 @@ Original error: ${errorMessage}`
|
|
|
2270
2440
|
});
|
|
2271
2441
|
const createRerankingModel = (modelId) => new BedrockRerankingModel(modelId, {
|
|
2272
2442
|
baseUrl: getBedrockAgentRuntimeBaseUrl,
|
|
2273
|
-
region:
|
|
2443
|
+
region: loadSetting({
|
|
2274
2444
|
settingValue: options.region,
|
|
2275
2445
|
settingName: "region",
|
|
2276
2446
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2289,14 +2459,13 @@ Original error: ${errorMessage}`
|
|
|
2289
2459
|
provider.imageModel = createImageModel;
|
|
2290
2460
|
provider.reranking = createRerankingModel;
|
|
2291
2461
|
provider.rerankingModel = createRerankingModel;
|
|
2292
|
-
provider.tools =
|
|
2462
|
+
provider.tools = anthropicTools2;
|
|
2293
2463
|
return provider;
|
|
2294
2464
|
}
|
|
2295
2465
|
var bedrock = createAmazonBedrock();
|
|
2296
|
-
|
|
2297
|
-
0 && (module.exports = {
|
|
2466
|
+
export {
|
|
2298
2467
|
VERSION,
|
|
2299
2468
|
bedrock,
|
|
2300
2469
|
createAmazonBedrock
|
|
2301
|
-
}
|
|
2470
|
+
};
|
|
2302
2471
|
//# sourceMappingURL=index.js.map
|