@ai-sdk/amazon-bedrock 5.0.0-beta.1 → 5.0.0-beta.11
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 +86 -4
- package/dist/anthropic/index.d.mts +4 -4
- package/dist/anthropic/index.d.ts +4 -4
- package/dist/anthropic/index.js +5 -5
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +2 -2
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +80 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -9
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +15 -0
- package/package.json +4 -6
- package/src/anthropic/bedrock-anthropic-provider.ts +6 -6
- package/src/bedrock-chat-language-model.ts +113 -28
- package/src/bedrock-embedding-model.ts +5 -5
- package/src/bedrock-image-model.ts +9 -9
- package/src/bedrock-prepare-tools.ts +7 -6
- package/src/bedrock-provider.ts +17 -17
- package/src/convert-bedrock-usage.ts +2 -2
- package/src/convert-to-bedrock-chat-messages.ts +10 -10
- package/src/map-bedrock-finish-reason.ts +2 -2
- package/src/reranking/bedrock-reranking-model.ts +5 -5
|
@@ -546,6 +546,11 @@ Via Anthropic, Amazon Bedrock provides three provider-defined tools that can be
|
|
|
546
546
|
|
|
547
547
|
They are available via the `tools` property of the provider instance.
|
|
548
548
|
|
|
549
|
+
<Note>
|
|
550
|
+
Amazon Bedrock does not support strict mode on tool definitions. Setting
|
|
551
|
+
`strict: true` on a tool will be ignored and a warning will be emitted.
|
|
552
|
+
</Note>
|
|
553
|
+
|
|
549
554
|
### Bash Tool
|
|
550
555
|
|
|
551
556
|
The Bash Tool allows running bash commands. Here's how to create and use it:
|
|
@@ -1375,6 +1380,16 @@ const { text } = await generateText({
|
|
|
1375
1380
|
});
|
|
1376
1381
|
```
|
|
1377
1382
|
|
|
1383
|
+
### Provider Options
|
|
1384
|
+
|
|
1385
|
+
The following optional provider options are available for Bedrock Anthropic models:
|
|
1386
|
+
|
|
1387
|
+
- `metadata` _object_
|
|
1388
|
+
|
|
1389
|
+
Optional. Metadata to include with the request. See the [Anthropic API documentation](https://platform.claude.com/docs/en/api/messages/create) for details.
|
|
1390
|
+
|
|
1391
|
+
- `userId` _string_ - An external identifier for the end-user.
|
|
1392
|
+
|
|
1378
1393
|
### Cache Control
|
|
1379
1394
|
|
|
1380
1395
|
In the messages and message parts, you can use the `providerOptions` property to set cache control breakpoints.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@smithy/eventstream-codec": "^4.0.1",
|
|
39
39
|
"@smithy/util-utf8": "^4.0.0",
|
|
40
40
|
"aws4fetch": "^1.0.20",
|
|
41
|
-
"@ai-sdk/anthropic": "4.0.0-beta.
|
|
42
|
-
"@ai-sdk/provider": "4.0.0-beta.
|
|
43
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
41
|
+
"@ai-sdk/anthropic": "4.0.0-beta.11",
|
|
42
|
+
"@ai-sdk/provider": "4.0.0-beta.4",
|
|
43
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "20.17.24",
|
|
@@ -74,9 +74,7 @@
|
|
|
74
74
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
75
75
|
"build:watch": "pnpm clean && tsup --watch",
|
|
76
76
|
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
77
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
78
77
|
"type-check": "tsc --build",
|
|
79
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
80
78
|
"test": "pnpm test:node && pnpm test:edge",
|
|
81
79
|
"test:update": "pnpm test:node -u",
|
|
82
80
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
LanguageModelV4,
|
|
3
3
|
NoSuchModelError,
|
|
4
|
-
|
|
4
|
+
ProviderV4,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
FetchFunction,
|
|
@@ -49,16 +49,16 @@ const BEDROCK_TOOL_BETA_MAP: Record<string, string> = {
|
|
|
49
49
|
computer_20241022: 'computer-use-2024-10-22',
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
export interface BedrockAnthropicProvider extends
|
|
52
|
+
export interface BedrockAnthropicProvider extends ProviderV4 {
|
|
53
53
|
/**
|
|
54
54
|
* Creates a model for text generation.
|
|
55
55
|
*/
|
|
56
|
-
(modelId: BedrockAnthropicModelId):
|
|
56
|
+
(modelId: BedrockAnthropicModelId): LanguageModelV4;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Creates a model for text generation.
|
|
60
60
|
*/
|
|
61
|
-
languageModel(modelId: BedrockAnthropicModelId):
|
|
61
|
+
languageModel(modelId: BedrockAnthropicModelId): LanguageModelV4;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Anthropic-specific computer use tool.
|
|
@@ -333,7 +333,7 @@ export function createBedrockAnthropic(
|
|
|
333
333
|
return createChatModel(modelId);
|
|
334
334
|
};
|
|
335
335
|
|
|
336
|
-
provider.specificationVersion = '
|
|
336
|
+
provider.specificationVersion = 'v4' as const;
|
|
337
337
|
provider.languageModel = createChatModel;
|
|
338
338
|
provider.chat = createChatModel;
|
|
339
339
|
provider.messages = createChatModel;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONObject,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
LanguageModelV4,
|
|
4
|
+
LanguageModelV4CallOptions,
|
|
5
|
+
LanguageModelV4Content,
|
|
6
|
+
LanguageModelV4FinishReason,
|
|
7
|
+
LanguageModelV4FunctionTool,
|
|
8
|
+
LanguageModelV4GenerateResult,
|
|
9
|
+
LanguageModelV4Reasoning,
|
|
10
|
+
LanguageModelV4StreamPart,
|
|
11
|
+
LanguageModelV4StreamResult,
|
|
12
|
+
SharedV4ProviderMetadata,
|
|
13
|
+
SharedV4Warning,
|
|
14
14
|
} from '@ai-sdk/provider';
|
|
15
15
|
import {
|
|
16
16
|
FetchFunction,
|
|
@@ -19,10 +19,14 @@ import {
|
|
|
19
19
|
combineHeaders,
|
|
20
20
|
createJsonErrorResponseHandler,
|
|
21
21
|
createJsonResponseHandler,
|
|
22
|
+
isCustomReasoning,
|
|
23
|
+
mapReasoningToProviderBudget,
|
|
24
|
+
mapReasoningToProviderEffort,
|
|
22
25
|
parseProviderOptions,
|
|
23
26
|
postJsonToApi,
|
|
24
27
|
resolve,
|
|
25
28
|
} from '@ai-sdk/provider-utils';
|
|
29
|
+
import { getModelCapabilities } from '@ai-sdk/anthropic/internal';
|
|
26
30
|
import { z } from 'zod/v4';
|
|
27
31
|
import {
|
|
28
32
|
BEDROCK_STOP_REASONS,
|
|
@@ -30,6 +34,7 @@ import {
|
|
|
30
34
|
BedrockStopReason,
|
|
31
35
|
} from './bedrock-api-types';
|
|
32
36
|
import {
|
|
37
|
+
AmazonBedrockLanguageModelOptions,
|
|
33
38
|
BedrockChatModelId,
|
|
34
39
|
amazonBedrockLanguageModelOptions,
|
|
35
40
|
} from './bedrock-chat-options';
|
|
@@ -48,8 +53,8 @@ type BedrockChatConfig = {
|
|
|
48
53
|
generateId: () => string;
|
|
49
54
|
};
|
|
50
55
|
|
|
51
|
-
export class BedrockChatLanguageModel implements
|
|
52
|
-
readonly specificationVersion = '
|
|
56
|
+
export class BedrockChatLanguageModel implements LanguageModelV4 {
|
|
57
|
+
readonly specificationVersion = 'v4';
|
|
53
58
|
readonly provider = 'amazon-bedrock';
|
|
54
59
|
|
|
55
60
|
constructor(
|
|
@@ -70,22 +75,23 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
70
75
|
seed,
|
|
71
76
|
tools,
|
|
72
77
|
toolChoice,
|
|
78
|
+
reasoning,
|
|
73
79
|
providerOptions,
|
|
74
|
-
}:
|
|
80
|
+
}: LanguageModelV4CallOptions): Promise<{
|
|
75
81
|
command: BedrockConverseInput;
|
|
76
|
-
warnings:
|
|
82
|
+
warnings: SharedV4Warning[];
|
|
77
83
|
usesJsonResponseTool: boolean;
|
|
78
84
|
betas: Set<string>;
|
|
79
85
|
}> {
|
|
80
86
|
// Parse provider options
|
|
81
|
-
|
|
87
|
+
let bedrockOptions =
|
|
82
88
|
(await parseProviderOptions({
|
|
83
89
|
provider: 'bedrock',
|
|
84
90
|
providerOptions,
|
|
85
91
|
schema: amazonBedrockLanguageModelOptions,
|
|
86
92
|
})) ?? {};
|
|
87
93
|
|
|
88
|
-
const warnings:
|
|
94
|
+
const warnings: SharedV4Warning[] = [];
|
|
89
95
|
|
|
90
96
|
if (frequencyPenalty != null) {
|
|
91
97
|
warnings.push({
|
|
@@ -137,6 +143,16 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
const isAnthropicModel = this.modelId.includes('anthropic');
|
|
146
|
+
const isOpenAIModel = this.modelId.startsWith('openai.');
|
|
147
|
+
|
|
148
|
+
bedrockOptions = resolveBedrockReasoningConfig({
|
|
149
|
+
reasoning,
|
|
150
|
+
bedrockOptions,
|
|
151
|
+
warnings,
|
|
152
|
+
isAnthropicModel,
|
|
153
|
+
modelId: this.modelId,
|
|
154
|
+
});
|
|
155
|
+
|
|
140
156
|
const isThinkingEnabled =
|
|
141
157
|
bedrockOptions.reasoningConfig?.type === 'enabled' ||
|
|
142
158
|
bedrockOptions.reasoningConfig?.type === 'adaptive';
|
|
@@ -147,7 +163,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
147
163
|
responseFormat?.type === 'json' &&
|
|
148
164
|
responseFormat.schema != null;
|
|
149
165
|
|
|
150
|
-
const jsonResponseTool:
|
|
166
|
+
const jsonResponseTool: LanguageModelV4FunctionTool | undefined =
|
|
151
167
|
responseFormat?.type === 'json' &&
|
|
152
168
|
responseFormat.schema != null &&
|
|
153
169
|
!useNativeStructuredOutput
|
|
@@ -247,7 +263,6 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
247
263
|
|
|
248
264
|
const maxReasoningEffort =
|
|
249
265
|
bedrockOptions.reasoningConfig?.maxReasoningEffort;
|
|
250
|
-
const isOpenAIModel = this.modelId.startsWith('openai.');
|
|
251
266
|
|
|
252
267
|
if (maxReasoningEffort != null) {
|
|
253
268
|
if (isAnthropicModel) {
|
|
@@ -411,8 +426,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
411
426
|
}
|
|
412
427
|
|
|
413
428
|
async doGenerate(
|
|
414
|
-
options:
|
|
415
|
-
): Promise<
|
|
429
|
+
options: LanguageModelV4CallOptions,
|
|
430
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
416
431
|
const {
|
|
417
432
|
command: args,
|
|
418
433
|
warnings,
|
|
@@ -435,7 +450,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
435
450
|
fetch: this.config.fetch,
|
|
436
451
|
});
|
|
437
452
|
|
|
438
|
-
const content: Array<
|
|
453
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
439
454
|
let isJsonResponseFromTool = false;
|
|
440
455
|
|
|
441
456
|
// map response content to content array
|
|
@@ -448,7 +463,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
448
463
|
// reasoning
|
|
449
464
|
if (part.reasoningContent) {
|
|
450
465
|
if ('reasoningText' in part.reasoningContent) {
|
|
451
|
-
const reasoning:
|
|
466
|
+
const reasoning: LanguageModelV4Reasoning = {
|
|
452
467
|
type: 'reasoning',
|
|
453
468
|
text: part.reasoningContent.reasoningText.text,
|
|
454
469
|
};
|
|
@@ -566,8 +581,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
566
581
|
}
|
|
567
582
|
|
|
568
583
|
async doStream(
|
|
569
|
-
options:
|
|
570
|
-
): Promise<
|
|
584
|
+
options: LanguageModelV4CallOptions,
|
|
585
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
571
586
|
const {
|
|
572
587
|
command: args,
|
|
573
588
|
warnings,
|
|
@@ -591,12 +606,12 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
591
606
|
fetch: this.config.fetch,
|
|
592
607
|
});
|
|
593
608
|
|
|
594
|
-
let finishReason:
|
|
609
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
595
610
|
unified: 'other',
|
|
596
611
|
raw: undefined,
|
|
597
612
|
};
|
|
598
613
|
let usage: BedrockUsage | undefined = undefined;
|
|
599
|
-
let providerMetadata:
|
|
614
|
+
let providerMetadata: SharedV4ProviderMetadata | undefined = undefined;
|
|
600
615
|
let isJsonResponseFromTool = false;
|
|
601
616
|
let stopSequence: string | null = null;
|
|
602
617
|
|
|
@@ -616,7 +631,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
616
631
|
stream: response.pipeThrough(
|
|
617
632
|
new TransformStream<
|
|
618
633
|
ParseResult<z.infer<typeof BedrockStreamSchema>>,
|
|
619
|
-
|
|
634
|
+
LanguageModelV4StreamPart
|
|
620
635
|
>({
|
|
621
636
|
start(controller) {
|
|
622
637
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
@@ -1122,3 +1137,73 @@ export const bedrockReasoningMetadataSchema = z.object({
|
|
|
1122
1137
|
export type BedrockReasoningMetadata = z.infer<
|
|
1123
1138
|
typeof bedrockReasoningMetadataSchema
|
|
1124
1139
|
>;
|
|
1140
|
+
|
|
1141
|
+
const bedrockReasoningEffortMap: Partial<
|
|
1142
|
+
Record<string, 'low' | 'medium' | 'high' | 'max'>
|
|
1143
|
+
> = {
|
|
1144
|
+
minimal: 'low',
|
|
1145
|
+
low: 'low',
|
|
1146
|
+
medium: 'medium',
|
|
1147
|
+
high: 'high',
|
|
1148
|
+
xhigh: 'max',
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
function resolveBedrockReasoningConfig({
|
|
1152
|
+
reasoning,
|
|
1153
|
+
bedrockOptions,
|
|
1154
|
+
warnings,
|
|
1155
|
+
isAnthropicModel,
|
|
1156
|
+
modelId,
|
|
1157
|
+
}: {
|
|
1158
|
+
reasoning: LanguageModelV4CallOptions['reasoning'];
|
|
1159
|
+
bedrockOptions: AmazonBedrockLanguageModelOptions;
|
|
1160
|
+
warnings: SharedV4Warning[];
|
|
1161
|
+
isAnthropicModel: boolean;
|
|
1162
|
+
modelId: string;
|
|
1163
|
+
}): AmazonBedrockLanguageModelOptions {
|
|
1164
|
+
if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
|
|
1165
|
+
return bedrockOptions;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const result = { ...bedrockOptions };
|
|
1169
|
+
|
|
1170
|
+
if (isAnthropicModel) {
|
|
1171
|
+
const capabilities = getModelCapabilities(modelId);
|
|
1172
|
+
|
|
1173
|
+
if (reasoning === 'none') {
|
|
1174
|
+
result.reasoningConfig = { type: 'disabled' };
|
|
1175
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1176
|
+
const effort = mapReasoningToProviderEffort({
|
|
1177
|
+
reasoning,
|
|
1178
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1179
|
+
warnings,
|
|
1180
|
+
});
|
|
1181
|
+
result.reasoningConfig = {
|
|
1182
|
+
type: 'adaptive',
|
|
1183
|
+
maxReasoningEffort: effort,
|
|
1184
|
+
};
|
|
1185
|
+
} else {
|
|
1186
|
+
const budgetTokens = mapReasoningToProviderBudget({
|
|
1187
|
+
reasoning,
|
|
1188
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1189
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1190
|
+
warnings,
|
|
1191
|
+
});
|
|
1192
|
+
if (budgetTokens != null) {
|
|
1193
|
+
result.reasoningConfig = {
|
|
1194
|
+
type: 'enabled',
|
|
1195
|
+
budgetTokens,
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
} else if (reasoning !== 'none') {
|
|
1200
|
+
const effort = mapReasoningToProviderEffort({
|
|
1201
|
+
reasoning,
|
|
1202
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1203
|
+
warnings,
|
|
1204
|
+
});
|
|
1205
|
+
result.reasoningConfig = { maxReasoningEffort: effort };
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
return result;
|
|
1209
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
EmbeddingModelV4,
|
|
3
3
|
TooManyEmbeddingValuesForCallError,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
5
|
import {
|
|
@@ -25,10 +25,10 @@ type BedrockEmbeddingConfig = {
|
|
|
25
25
|
fetch?: FetchFunction;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
type DoEmbedResponse = Awaited<ReturnType<
|
|
28
|
+
type DoEmbedResponse = Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>;
|
|
29
29
|
|
|
30
|
-
export class BedrockEmbeddingModel implements
|
|
31
|
-
readonly specificationVersion = '
|
|
30
|
+
export class BedrockEmbeddingModel implements EmbeddingModelV4 {
|
|
31
|
+
readonly specificationVersion = 'v4';
|
|
32
32
|
readonly provider = 'amazon-bedrock';
|
|
33
33
|
readonly maxEmbeddingsPerCall = 1;
|
|
34
34
|
readonly supportsParallelCalls = true;
|
|
@@ -48,7 +48,7 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
|
|
|
48
48
|
headers,
|
|
49
49
|
abortSignal,
|
|
50
50
|
providerOptions,
|
|
51
|
-
}: Parameters<
|
|
51
|
+
}: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<DoEmbedResponse> {
|
|
52
52
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
53
53
|
throw new TooManyEmbeddingValuesForCallError({
|
|
54
54
|
provider: this.provider,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ImageModelV4,
|
|
3
|
+
ImageModelV4File,
|
|
4
|
+
SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
FetchFunction,
|
|
@@ -29,8 +29,8 @@ type BedrockImageModelConfig = {
|
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export class BedrockImageModel implements
|
|
33
|
-
readonly specificationVersion = '
|
|
32
|
+
export class BedrockImageModel implements ImageModelV4 {
|
|
33
|
+
readonly specificationVersion = 'v4';
|
|
34
34
|
readonly provider = 'amazon-bedrock';
|
|
35
35
|
|
|
36
36
|
get maxImagesPerCall(): number {
|
|
@@ -58,10 +58,10 @@ export class BedrockImageModel implements ImageModelV3 {
|
|
|
58
58
|
abortSignal,
|
|
59
59
|
files,
|
|
60
60
|
mask,
|
|
61
|
-
}: Parameters<
|
|
62
|
-
Awaited<ReturnType<
|
|
61
|
+
}: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
|
|
62
|
+
Awaited<ReturnType<ImageModelV4['doGenerate']>>
|
|
63
63
|
> {
|
|
64
|
-
const warnings: Array<
|
|
64
|
+
const warnings: Array<SharedV4Warning> = [];
|
|
65
65
|
const [width, height] = size ? size.split('x').map(Number) : [];
|
|
66
66
|
|
|
67
67
|
const hasFiles = files != null && files.length > 0;
|
|
@@ -265,7 +265,7 @@ export class BedrockImageModel implements ImageModelV3 {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
function getBase64Data(file:
|
|
268
|
+
function getBase64Data(file: ImageModelV4File): string {
|
|
269
269
|
if (file.type === 'url') {
|
|
270
270
|
throw new Error(
|
|
271
271
|
'URL-based images are not supported for Amazon Bedrock image editing. ' +
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONObject,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
LanguageModelV4CallOptions,
|
|
4
|
+
SharedV4Warning,
|
|
5
5
|
UnsupportedFunctionalityError,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import { asSchema } from '@ai-sdk/provider-utils';
|
|
@@ -16,16 +16,16 @@ export async function prepareTools({
|
|
|
16
16
|
toolChoice,
|
|
17
17
|
modelId,
|
|
18
18
|
}: {
|
|
19
|
-
tools:
|
|
20
|
-
toolChoice?:
|
|
19
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
20
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
21
21
|
modelId: string;
|
|
22
22
|
}): Promise<{
|
|
23
23
|
toolConfig: BedrockToolConfiguration;
|
|
24
24
|
additionalTools: Record<string, unknown> | undefined;
|
|
25
25
|
betas: Set<string>;
|
|
26
|
-
toolWarnings:
|
|
26
|
+
toolWarnings: SharedV4Warning[];
|
|
27
27
|
}> {
|
|
28
|
-
const toolWarnings:
|
|
28
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
29
29
|
const betas = new Set<string>();
|
|
30
30
|
|
|
31
31
|
if (tools == null || tools.length === 0) {
|
|
@@ -82,6 +82,7 @@ export async function prepareTools({
|
|
|
82
82
|
tools: ProviderTools,
|
|
83
83
|
toolChoice,
|
|
84
84
|
supportsStructuredOutput: false,
|
|
85
|
+
supportsStrictTools: false,
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
toolWarnings.push(...anthropicToolWarnings);
|
package/src/bedrock-provider.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { anthropicTools } from '@ai-sdk/anthropic/internal';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
EmbeddingModelV4,
|
|
4
|
+
ImageModelV4,
|
|
5
|
+
LanguageModelV4,
|
|
6
|
+
ProviderV4,
|
|
7
|
+
RerankingModelV4,
|
|
8
8
|
} from '@ai-sdk/provider';
|
|
9
9
|
import {
|
|
10
10
|
FetchFunction,
|
|
@@ -107,50 +107,50 @@ export interface AmazonBedrockProviderSettings {
|
|
|
107
107
|
generateId?: () => string;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export interface AmazonBedrockProvider extends
|
|
111
|
-
(modelId: BedrockChatModelId):
|
|
110
|
+
export interface AmazonBedrockProvider extends ProviderV4 {
|
|
111
|
+
(modelId: BedrockChatModelId): LanguageModelV4;
|
|
112
112
|
|
|
113
|
-
languageModel(modelId: BedrockChatModelId):
|
|
113
|
+
languageModel(modelId: BedrockChatModelId): LanguageModelV4;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Creates a model for text embeddings.
|
|
117
117
|
*/
|
|
118
|
-
embedding(modelId: BedrockEmbeddingModelId):
|
|
118
|
+
embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* Creates a model for text embeddings.
|
|
122
122
|
*/
|
|
123
|
-
embeddingModel(modelId: BedrockEmbeddingModelId):
|
|
123
|
+
embeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* @deprecated Use `embedding` instead.
|
|
127
127
|
*/
|
|
128
|
-
textEmbedding(modelId: BedrockEmbeddingModelId):
|
|
128
|
+
textEmbedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* @deprecated Use `embeddingModel` instead.
|
|
132
132
|
*/
|
|
133
|
-
textEmbeddingModel(modelId: BedrockEmbeddingModelId):
|
|
133
|
+
textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Creates a model for image generation.
|
|
137
137
|
*/
|
|
138
|
-
image(modelId: BedrockImageModelId):
|
|
138
|
+
image(modelId: BedrockImageModelId): ImageModelV4;
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Creates a model for image generation.
|
|
142
142
|
*/
|
|
143
|
-
imageModel(modelId: BedrockImageModelId):
|
|
143
|
+
imageModel(modelId: BedrockImageModelId): ImageModelV4;
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* Creates a model for reranking documents.
|
|
147
147
|
*/
|
|
148
|
-
reranking(modelId: BedrockRerankingModelId):
|
|
148
|
+
reranking(modelId: BedrockRerankingModelId): RerankingModelV4;
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* Creates a model for reranking documents.
|
|
152
152
|
*/
|
|
153
|
-
rerankingModel(modelId: BedrockRerankingModelId):
|
|
153
|
+
rerankingModel(modelId: BedrockRerankingModelId): RerankingModelV4;
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* Anthropic-specific tools that can be used with Anthropic models on Bedrock.
|
|
@@ -330,7 +330,7 @@ export function createAmazonBedrock(
|
|
|
330
330
|
fetch: fetchFunction,
|
|
331
331
|
});
|
|
332
332
|
|
|
333
|
-
provider.specificationVersion = '
|
|
333
|
+
provider.specificationVersion = 'v4' as const;
|
|
334
334
|
provider.languageModel = createChatModel;
|
|
335
335
|
provider.embedding = createEmbeddingModel;
|
|
336
336
|
provider.embeddingModel = createEmbeddingModel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export type BedrockUsage = {
|
|
4
4
|
inputTokens: number;
|
|
@@ -10,7 +10,7 @@ export type BedrockUsage = {
|
|
|
10
10
|
|
|
11
11
|
export function convertBedrockUsage(
|
|
12
12
|
usage: BedrockUsage | undefined | null,
|
|
13
|
-
):
|
|
13
|
+
): LanguageModelV4Usage {
|
|
14
14
|
if (usage == null) {
|
|
15
15
|
return {
|
|
16
16
|
inputTokens: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONObject,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
LanguageModelV4Message,
|
|
4
|
+
LanguageModelV4Prompt,
|
|
5
|
+
SharedV4ProviderMetadata,
|
|
6
6
|
UnsupportedFunctionalityError,
|
|
7
7
|
} from '@ai-sdk/provider';
|
|
8
8
|
import {
|
|
@@ -28,7 +28,7 @@ import { bedrockFilePartProviderOptions } from './bedrock-chat-options';
|
|
|
28
28
|
import { normalizeToolCallId } from './normalize-tool-call-id';
|
|
29
29
|
|
|
30
30
|
function getCachePoint(
|
|
31
|
-
providerMetadata:
|
|
31
|
+
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
32
32
|
): BedrockCachePoint | undefined {
|
|
33
33
|
const cachePointConfig = providerMetadata?.bedrock?.cachePoint as
|
|
34
34
|
| BedrockCachePoint['cachePoint']
|
|
@@ -42,7 +42,7 @@ function getCachePoint(
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async function shouldEnableCitations(
|
|
45
|
-
providerMetadata:
|
|
45
|
+
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
46
46
|
): Promise<boolean> {
|
|
47
47
|
const bedrockOptions = await parseProviderOptions({
|
|
48
48
|
provider: 'bedrock',
|
|
@@ -54,7 +54,7 @@ async function shouldEnableCitations(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export async function convertToBedrockChatMessages(
|
|
57
|
-
prompt:
|
|
57
|
+
prompt: LanguageModelV4Prompt,
|
|
58
58
|
isMistral: boolean = false,
|
|
59
59
|
): Promise<{
|
|
60
60
|
system: BedrockSystemMessages;
|
|
@@ -400,19 +400,19 @@ function trimIfLast(
|
|
|
400
400
|
|
|
401
401
|
type SystemBlock = {
|
|
402
402
|
type: 'system';
|
|
403
|
-
messages: Array<
|
|
403
|
+
messages: Array<LanguageModelV4Message & { role: 'system' }>;
|
|
404
404
|
};
|
|
405
405
|
type AssistantBlock = {
|
|
406
406
|
type: 'assistant';
|
|
407
|
-
messages: Array<
|
|
407
|
+
messages: Array<LanguageModelV4Message & { role: 'assistant' }>;
|
|
408
408
|
};
|
|
409
409
|
type UserBlock = {
|
|
410
410
|
type: 'user';
|
|
411
|
-
messages: Array<
|
|
411
|
+
messages: Array<LanguageModelV4Message & { role: 'user' | 'tool' }>;
|
|
412
412
|
};
|
|
413
413
|
|
|
414
414
|
function groupIntoBlocks(
|
|
415
|
-
prompt:
|
|
415
|
+
prompt: LanguageModelV4Prompt,
|
|
416
416
|
): Array<SystemBlock | AssistantBlock | UserBlock> {
|
|
417
417
|
const blocks: Array<SystemBlock | AssistantBlock | UserBlock> = [];
|
|
418
418
|
let currentBlock: SystemBlock | AssistantBlock | UserBlock | undefined =
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
import { BedrockStopReason } from './bedrock-api-types';
|
|
3
3
|
|
|
4
4
|
export function mapBedrockFinishReason(
|
|
5
5
|
finishReason: BedrockStopReason,
|
|
6
6
|
isJsonResponseFromTool?: boolean,
|
|
7
|
-
):
|
|
7
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
8
8
|
switch (finishReason) {
|
|
9
9
|
case 'stop_sequence':
|
|
10
10
|
case 'end_turn':
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RerankingModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
FetchFunction,
|
|
4
4
|
Resolvable,
|
|
@@ -26,10 +26,10 @@ type BedrockRerankingConfig = {
|
|
|
26
26
|
fetch?: FetchFunction;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
type DoRerankResponse = Awaited<ReturnType<
|
|
29
|
+
type DoRerankResponse = Awaited<ReturnType<RerankingModelV4['doRerank']>>;
|
|
30
30
|
|
|
31
|
-
export class BedrockRerankingModel implements
|
|
32
|
-
readonly specificationVersion = '
|
|
31
|
+
export class BedrockRerankingModel implements RerankingModelV4 {
|
|
32
|
+
readonly specificationVersion = 'v4';
|
|
33
33
|
readonly provider = 'amazon-bedrock';
|
|
34
34
|
|
|
35
35
|
constructor(
|
|
@@ -44,7 +44,7 @@ export class BedrockRerankingModel implements RerankingModelV3 {
|
|
|
44
44
|
topN,
|
|
45
45
|
abortSignal,
|
|
46
46
|
providerOptions,
|
|
47
|
-
}: Parameters<
|
|
47
|
+
}: Parameters<RerankingModelV4['doRerank']>[0]): Promise<DoRerankResponse> {
|
|
48
48
|
const bedrockOptions = await parseProviderOptions({
|
|
49
49
|
provider: 'bedrock',
|
|
50
50
|
providerOptions,
|