@ai-sdk/amazon-bedrock 5.0.86 → 5.0.87
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 +13 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/index.js +66 -23
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/package.json +4 -4
- package/src/amazon-bedrock-chat-language-model.ts +5 -5
- package/src/amazon-bedrock-embedding-model.ts +2 -6
- package/src/amazon-bedrock-error.ts +8 -0
- package/src/amazon-bedrock-image-model.ts +2 -6
- package/src/amazon-bedrock-prepare-tools.ts +90 -1
- package/src/reranking/amazon-bedrock-reranking-model.ts +2 -6
package/dist/mantle/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "5.0.
|
|
38
|
+
var VERSION = true ? "5.0.87" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "5.0.
|
|
26
|
+
var VERSION = true ? "5.0.87" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
29
29
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.87",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@ai-sdk/anthropic": "4.0.
|
|
45
|
-
"@ai-sdk/openai": "4.0.
|
|
44
|
+
"@ai-sdk/anthropic": "4.0.57",
|
|
45
|
+
"@ai-sdk/openai": "4.0.70",
|
|
46
46
|
"@ai-sdk/provider": "4.0.17",
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.44",
|
|
48
48
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
49
49
|
"@smithy/util-utf8": "^4.3.3",
|
|
50
50
|
"aws4fetch": "^1.0.20"
|
|
@@ -52,7 +52,10 @@ import {
|
|
|
52
52
|
supportsNativeStructuredOutput,
|
|
53
53
|
supportsStrictTools,
|
|
54
54
|
} from './amazon-bedrock-anthropic-model-support';
|
|
55
|
-
import {
|
|
55
|
+
import {
|
|
56
|
+
amazonBedrockFailedResponseHandler,
|
|
57
|
+
AmazonBedrockErrorSchema,
|
|
58
|
+
} from './amazon-bedrock-error';
|
|
56
59
|
import { createAmazonBedrockEventStreamResponseHandler } from './amazon-bedrock-event-stream-response-handler';
|
|
57
60
|
import {
|
|
58
61
|
getAmazonBedrockStreamErrorMetadata,
|
|
@@ -811,10 +814,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
811
814
|
url,
|
|
812
815
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
813
816
|
body: args,
|
|
814
|
-
failedResponseHandler:
|
|
815
|
-
errorSchema: AmazonBedrockErrorSchema,
|
|
816
|
-
errorToMessage: error => `${error.type}: ${error.message}`,
|
|
817
|
-
}),
|
|
817
|
+
failedResponseHandler: amazonBedrockFailedResponseHandler,
|
|
818
818
|
successfulResponseHandler: createAmazonBedrockEventStreamResponseHandler(
|
|
819
819
|
AmazonBedrockStreamSchema,
|
|
820
820
|
),
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
5
|
import {
|
|
6
6
|
combineHeaders,
|
|
7
|
-
createJsonErrorResponseHandler,
|
|
8
7
|
createJsonResponseHandler,
|
|
9
8
|
parseProviderOptions,
|
|
10
9
|
postJsonToApi,
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
type AmazonBedrockEmbeddingModelId,
|
|
21
20
|
type AmazonBedrockEmbeddingModelSettings,
|
|
22
21
|
} from './amazon-bedrock-embedding-model-options';
|
|
23
|
-
import {
|
|
22
|
+
import { amazonBedrockFailedResponseHandler } from './amazon-bedrock-error';
|
|
24
23
|
import { z } from 'zod/v4';
|
|
25
24
|
|
|
26
25
|
type AmazonBedrockEmbeddingConfig = {
|
|
@@ -146,10 +145,7 @@ export class AmazonBedrockEmbeddingModel implements EmbeddingModelV4 {
|
|
|
146
145
|
),
|
|
147
146
|
),
|
|
148
147
|
body: args,
|
|
149
|
-
failedResponseHandler:
|
|
150
|
-
errorSchema: AmazonBedrockErrorSchema,
|
|
151
|
-
errorToMessage: error => `${error.type}: ${error.message}`,
|
|
152
|
-
}),
|
|
148
|
+
failedResponseHandler: amazonBedrockFailedResponseHandler,
|
|
153
149
|
successfulResponseHandler: createJsonResponseHandler(
|
|
154
150
|
AmazonBedrockEmbeddingResponseSchema,
|
|
155
151
|
),
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
3
|
|
|
3
4
|
export const AmazonBedrockErrorSchema = z.object({
|
|
4
5
|
message: z.string(),
|
|
5
6
|
type: z.string().nullish(),
|
|
6
7
|
});
|
|
8
|
+
|
|
9
|
+
export const amazonBedrockFailedResponseHandler =
|
|
10
|
+
createJsonErrorResponseHandler({
|
|
11
|
+
errorSchema: AmazonBedrockErrorSchema,
|
|
12
|
+
errorToMessage: error =>
|
|
13
|
+
error.type == null ? error.message : `${error.type}: ${error.message}`,
|
|
14
|
+
});
|
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
8
8
|
convertUint8ArrayToBase64,
|
|
9
|
-
createJsonErrorResponseHandler,
|
|
10
9
|
createJsonResponseHandler,
|
|
11
10
|
parseProviderOptions,
|
|
12
11
|
postJsonToApi,
|
|
@@ -22,7 +21,7 @@ import {
|
|
|
22
21
|
type AmazonBedrockImageModelId,
|
|
23
22
|
} from './amazon-bedrock-image-settings';
|
|
24
23
|
import { amazonBedrockImageModelOptionsSchema } from './amazon-bedrock-image-model-options';
|
|
25
|
-
import {
|
|
24
|
+
import { amazonBedrockFailedResponseHandler } from './amazon-bedrock-error';
|
|
26
25
|
import { z } from 'zod/v4';
|
|
27
26
|
|
|
28
27
|
type AmazonBedrockImageModelConfig = {
|
|
@@ -259,10 +258,7 @@ export class AmazonBedrockImageModel implements ImageModelV4 {
|
|
|
259
258
|
),
|
|
260
259
|
),
|
|
261
260
|
body: args,
|
|
262
|
-
failedResponseHandler:
|
|
263
|
-
errorSchema: AmazonBedrockErrorSchema,
|
|
264
|
-
errorToMessage: error => `${error.type}: ${error.message}`,
|
|
265
|
-
}),
|
|
261
|
+
failedResponseHandler: amazonBedrockFailedResponseHandler,
|
|
266
262
|
successfulResponseHandler: createJsonResponseHandler(
|
|
267
263
|
amazonBedrockImageResponseSchema,
|
|
268
264
|
),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UnsupportedFunctionalityError,
|
|
3
3
|
type JSONObject,
|
|
4
|
+
type JSONSchema7Definition,
|
|
4
5
|
type LanguageModelV4CallOptions,
|
|
5
6
|
type SharedV4Warning,
|
|
6
7
|
} from '@ai-sdk/provider';
|
|
@@ -153,12 +154,22 @@ export async function prepareTools({
|
|
|
153
154
|
const supportsStrictOnTools = supportsStrictTools(modelId);
|
|
154
155
|
|
|
155
156
|
for (const tool of filteredFunctionTools) {
|
|
157
|
+
const supportsStrictForTool =
|
|
158
|
+
supportsStrictOnTools &&
|
|
159
|
+
(tool.strict !== true || isStrictToolSchemaCompatible(tool.inputSchema));
|
|
160
|
+
|
|
156
161
|
if (!supportsStrictOnTools && tool.strict != null) {
|
|
157
162
|
toolWarnings.push({
|
|
158
163
|
type: 'unsupported',
|
|
159
164
|
feature: 'strict',
|
|
160
165
|
details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this model on Amazon Bedrock. The strict property will be ignored.`,
|
|
161
166
|
});
|
|
167
|
+
} else if (tool.strict === true && !supportsStrictForTool) {
|
|
168
|
+
toolWarnings.push({
|
|
169
|
+
type: 'unsupported',
|
|
170
|
+
feature: 'strict',
|
|
171
|
+
details: `Tool '${tool.name}' has strict: true, but Amazon Bedrock requires every object in a strict tool schema to set additionalProperties: false. The strict property will be ignored.`,
|
|
172
|
+
});
|
|
162
173
|
}
|
|
163
174
|
|
|
164
175
|
amazonBedrockTools.push({
|
|
@@ -167,7 +178,7 @@ export async function prepareTools({
|
|
|
167
178
|
...(tool.description?.trim() !== ''
|
|
168
179
|
? { description: tool.description }
|
|
169
180
|
: {}),
|
|
170
|
-
...(tool.strict != null &&
|
|
181
|
+
...(tool.strict != null && supportsStrictForTool
|
|
171
182
|
? { strict: tool.strict }
|
|
172
183
|
: {}),
|
|
173
184
|
inputSchema: {
|
|
@@ -243,3 +254,81 @@ export async function prepareTools({
|
|
|
243
254
|
toolWarnings,
|
|
244
255
|
};
|
|
245
256
|
}
|
|
257
|
+
|
|
258
|
+
function isStrictToolSchemaCompatible(schema: JSONSchema7Definition): boolean {
|
|
259
|
+
if (typeof schema === 'boolean') {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const schemaWithDefs = schema as typeof schema & {
|
|
264
|
+
$defs?: Record<string, JSONSchema7Definition>;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
if (
|
|
268
|
+
(schema.type === 'object' ||
|
|
269
|
+
(Array.isArray(schema.type) && schema.type.includes('object'))) &&
|
|
270
|
+
schema.additionalProperties !== false
|
|
271
|
+
) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const schemaMaps = [
|
|
276
|
+
schema.properties,
|
|
277
|
+
schema.patternProperties,
|
|
278
|
+
schema.definitions,
|
|
279
|
+
schemaWithDefs.$defs,
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
for (const schemaMap of schemaMaps) {
|
|
283
|
+
if (
|
|
284
|
+
schemaMap != null &&
|
|
285
|
+
Object.values(schemaMap).some(
|
|
286
|
+
definition => !isStrictToolSchemaCompatible(definition),
|
|
287
|
+
)
|
|
288
|
+
) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (
|
|
294
|
+
schema.dependencies != null &&
|
|
295
|
+
Object.values(schema.dependencies).some(
|
|
296
|
+
dependency =>
|
|
297
|
+
!Array.isArray(dependency) && !isStrictToolSchemaCompatible(dependency),
|
|
298
|
+
)
|
|
299
|
+
) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const nestedSchemas = [
|
|
304
|
+
schema.propertyNames,
|
|
305
|
+
schema.contains,
|
|
306
|
+
schema.not,
|
|
307
|
+
schema.if,
|
|
308
|
+
schema.then,
|
|
309
|
+
schema.else,
|
|
310
|
+
];
|
|
311
|
+
|
|
312
|
+
if (
|
|
313
|
+
nestedSchemas.some(
|
|
314
|
+
nestedSchema =>
|
|
315
|
+
nestedSchema != null && !isStrictToolSchemaCompatible(nestedSchema),
|
|
316
|
+
)
|
|
317
|
+
) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (
|
|
322
|
+
schema.items != null &&
|
|
323
|
+
(Array.isArray(schema.items)
|
|
324
|
+
? schema.items.some(item => !isStrictToolSchemaCompatible(item))
|
|
325
|
+
: !isStrictToolSchemaCompatible(schema.items))
|
|
326
|
+
) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return [schema.anyOf, schema.allOf, schema.oneOf].every(
|
|
331
|
+
alternatives =>
|
|
332
|
+
alternatives == null || alternatives.every(isStrictToolSchemaCompatible),
|
|
333
|
+
);
|
|
334
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RerankingModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
combineHeaders,
|
|
4
|
-
createJsonErrorResponseHandler,
|
|
5
4
|
createJsonResponseHandler,
|
|
6
5
|
parseProviderOptions,
|
|
7
6
|
postJsonToApi,
|
|
@@ -9,7 +8,7 @@ import {
|
|
|
9
8
|
type FetchFunction,
|
|
10
9
|
type Resolvable,
|
|
11
10
|
} from '@ai-sdk/provider-utils';
|
|
12
|
-
import {
|
|
11
|
+
import { amazonBedrockFailedResponseHandler } from '../amazon-bedrock-error';
|
|
13
12
|
import {
|
|
14
13
|
amazonBedrockRerankingResponseSchema,
|
|
15
14
|
type AmazonBedrockRerankingInput,
|
|
@@ -100,10 +99,7 @@ export class AmazonBedrockRerankingModel implements RerankingModelV4 {
|
|
|
100
99
|
},
|
|
101
100
|
})),
|
|
102
101
|
} satisfies AmazonBedrockRerankingInput,
|
|
103
|
-
failedResponseHandler:
|
|
104
|
-
errorSchema: AmazonBedrockErrorSchema,
|
|
105
|
-
errorToMessage: error => `${error.type}: ${error.message}`,
|
|
106
|
-
}),
|
|
102
|
+
failedResponseHandler: amazonBedrockFailedResponseHandler,
|
|
107
103
|
successfulResponseHandler: createJsonResponseHandler(
|
|
108
104
|
amazonBedrockRerankingResponseSchema,
|
|
109
105
|
),
|