@ai-sdk/amazon-bedrock 4.0.28 → 4.0.30
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 +16 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +42 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -10
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +7 -0
- package/package.json +10 -6
- package/src/bedrock-embedding-model.ts +48 -11
- package/src/bedrock-embedding-options.ts +14 -0
- package/src/__fixtures__/bedrock-json-only-text-first.1.chunks.txt +0 -7
- package/src/__fixtures__/bedrock-json-other-tool.1.chunks.txt +0 -6
- package/src/__fixtures__/bedrock-json-other-tool.1.json +0 -24
- package/src/__fixtures__/bedrock-json-tool-text-then-weather-then-json.1.chunks.txt +0 -12
- package/src/__fixtures__/bedrock-json-tool-with-answer.1.json +0 -29
- package/src/__fixtures__/bedrock-json-tool.1.chunks.txt +0 -4
- package/src/__fixtures__/bedrock-json-tool.1.json +0 -35
- package/src/__fixtures__/bedrock-json-tool.2.chunks.txt +0 -6
- package/src/__fixtures__/bedrock-json-tool.2.json +0 -28
- package/src/__fixtures__/bedrock-json-tool.3.chunks.txt +0 -7
- package/src/__fixtures__/bedrock-json-tool.3.json +0 -36
- package/src/__fixtures__/bedrock-json-with-tool.1.chunks.txt +0 -9
- package/src/__fixtures__/bedrock-json-with-tool.1.json +0 -41
- package/src/__fixtures__/bedrock-json-with-tools.1.chunks.txt +0 -12
- package/src/__fixtures__/bedrock-json-with-tools.1.json +0 -50
- package/src/__fixtures__/bedrock-tool-call.1.chunks.txt +0 -6
- package/src/__fixtures__/bedrock-tool-call.1.json +0 -24
- package/src/__fixtures__/bedrock-tool-no-args.chunks.txt +0 -8
- package/src/__fixtures__/bedrock-tool-no-args.json +0 -25
- package/src/anthropic/bedrock-anthropic-fetch.test.ts +0 -344
- package/src/anthropic/bedrock-anthropic-provider.test.ts +0 -456
- package/src/bedrock-chat-language-model.test.ts +0 -4569
- package/src/bedrock-embedding-model.test.ts +0 -148
- package/src/bedrock-event-stream-response-handler.test.ts +0 -233
- package/src/bedrock-image-model.test.ts +0 -866
- package/src/bedrock-provider.test.ts +0 -457
- package/src/bedrock-sigv4-fetch.test.ts +0 -675
- package/src/convert-bedrock-usage.test.ts +0 -207
- package/src/convert-to-bedrock-chat-messages.test.ts +0 -1175
- package/src/inject-fetch-headers.test.ts +0 -135
- package/src/normalize-tool-call-id.test.ts +0 -72
- package/src/reranking/__fixtures__/bedrock-reranking.1.json +0 -12
- package/src/reranking/bedrock-reranking-model.test.ts +0 -299
package/dist/index.mjs
CHANGED
|
@@ -1502,7 +1502,17 @@ var bedrockEmbeddingProviderOptions = z4.object({
|
|
|
1502
1502
|
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
1503
1503
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
1504
1504
|
*/
|
|
1505
|
-
normalize: z4.boolean().optional()
|
|
1505
|
+
normalize: z4.boolean().optional(),
|
|
1506
|
+
/**
|
|
1507
|
+
Input type for Cohere embedding models on Bedrock.
|
|
1508
|
+
Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
1509
|
+
If not set, the provider defaults to `search_query`.
|
|
1510
|
+
*/
|
|
1511
|
+
inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
1512
|
+
/**
|
|
1513
|
+
Truncation behavior for Cohere embedding models on Bedrock.
|
|
1514
|
+
*/
|
|
1515
|
+
truncate: z4.enum(["NONE", "START", "END"]).optional()
|
|
1506
1516
|
});
|
|
1507
1517
|
|
|
1508
1518
|
// src/bedrock-embedding-model.ts
|
|
@@ -1526,7 +1536,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1526
1536
|
abortSignal,
|
|
1527
1537
|
providerOptions
|
|
1528
1538
|
}) {
|
|
1529
|
-
var _a;
|
|
1539
|
+
var _a, _b;
|
|
1530
1540
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1531
1541
|
throw new TooManyEmbeddingValuesForCallError({
|
|
1532
1542
|
provider: this.provider,
|
|
@@ -1540,7 +1550,13 @@ var BedrockEmbeddingModel = class {
|
|
|
1540
1550
|
providerOptions,
|
|
1541
1551
|
schema: bedrockEmbeddingProviderOptions
|
|
1542
1552
|
})) != null ? _a : {};
|
|
1543
|
-
const args = {
|
|
1553
|
+
const args = this.modelId.startsWith("cohere.embed-") ? {
|
|
1554
|
+
// Cohere embedding models on Bedrock require `input_type`.
|
|
1555
|
+
// Without it, the service attempts other schema branches and rejects the request.
|
|
1556
|
+
input_type: (_b = bedrockOptions.inputType) != null ? _b : "search_query",
|
|
1557
|
+
texts: [values[0]],
|
|
1558
|
+
truncate: bedrockOptions.truncate
|
|
1559
|
+
} : {
|
|
1544
1560
|
inputText: values[0],
|
|
1545
1561
|
dimensions: bedrockOptions.dimensions,
|
|
1546
1562
|
normalize: bedrockOptions.normalize
|
|
@@ -1562,17 +1578,33 @@ var BedrockEmbeddingModel = class {
|
|
|
1562
1578
|
fetch: this.config.fetch,
|
|
1563
1579
|
abortSignal
|
|
1564
1580
|
});
|
|
1581
|
+
const embedding = "embedding" in response ? response.embedding : Array.isArray(response.embeddings) ? response.embeddings[0] : response.embeddings.float[0];
|
|
1565
1582
|
return {
|
|
1566
1583
|
warnings: [],
|
|
1567
|
-
embeddings: [
|
|
1568
|
-
usage: {
|
|
1584
|
+
embeddings: [embedding],
|
|
1585
|
+
usage: {
|
|
1586
|
+
tokens: "inputTextTokenCount" in response ? response.inputTextTokenCount : NaN
|
|
1587
|
+
}
|
|
1569
1588
|
};
|
|
1570
1589
|
}
|
|
1571
1590
|
};
|
|
1572
|
-
var BedrockEmbeddingResponseSchema = z5.
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1591
|
+
var BedrockEmbeddingResponseSchema = z5.union([
|
|
1592
|
+
// Titan-style response
|
|
1593
|
+
z5.object({
|
|
1594
|
+
embedding: z5.array(z5.number()),
|
|
1595
|
+
inputTextTokenCount: z5.number()
|
|
1596
|
+
}),
|
|
1597
|
+
// Cohere v3-style response
|
|
1598
|
+
z5.object({
|
|
1599
|
+
embeddings: z5.array(z5.array(z5.number()))
|
|
1600
|
+
}),
|
|
1601
|
+
// Cohere v4-style response
|
|
1602
|
+
z5.object({
|
|
1603
|
+
embeddings: z5.object({
|
|
1604
|
+
float: z5.array(z5.array(z5.number()))
|
|
1605
|
+
})
|
|
1606
|
+
})
|
|
1607
|
+
]);
|
|
1576
1608
|
|
|
1577
1609
|
// src/bedrock-image-model.ts
|
|
1578
1610
|
import {
|
|
@@ -1798,7 +1830,7 @@ import {
|
|
|
1798
1830
|
import { AwsV4Signer } from "aws4fetch";
|
|
1799
1831
|
|
|
1800
1832
|
// src/version.ts
|
|
1801
|
-
var VERSION = true ? "4.0.
|
|
1833
|
+
var VERSION = true ? "4.0.30" : "0.0.0-test";
|
|
1802
1834
|
|
|
1803
1835
|
// src/bedrock-sigv4-fetch.ts
|
|
1804
1836
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|