@ai-sdk/amazon-bedrock 3.0.0-canary.4 → 3.0.0-canary.6
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 +22 -0
- package/dist/index.d.mts +34 -10
- package/dist/index.d.ts +34 -10
- package/dist/index.js +123 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -132
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 97ea26f: chore(providers/bedrock): convert to providerOptions
|
|
8
|
+
- 97ea26f: chore(providers/bedrock): use camelCase for providerOptions
|
|
9
|
+
- Updated dependencies [411e483]
|
|
10
|
+
- Updated dependencies [79457bd]
|
|
11
|
+
- Updated dependencies [ad80501]
|
|
12
|
+
- Updated dependencies [1766ede]
|
|
13
|
+
- Updated dependencies [f10304b]
|
|
14
|
+
- @ai-sdk/provider@2.0.0-canary.5
|
|
15
|
+
- @ai-sdk/provider-utils@3.0.0-canary.6
|
|
16
|
+
|
|
17
|
+
## 3.0.0-canary.5
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [6f6bb89]
|
|
22
|
+
- @ai-sdk/provider@2.0.0-canary.4
|
|
23
|
+
- @ai-sdk/provider-utils@3.0.0-canary.5
|
|
24
|
+
|
|
3
25
|
## 3.0.0-canary.4
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
import { ProviderV2, LanguageModelV2, EmbeddingModelV1, ImageModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
|
|
4
5
|
type BedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-v1' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-instant-v1' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.command-r-v1:0' | 'cohere.command-r-plus-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-1-405b-instruct-v1:0' | 'meta.llama3-1-70b-instruct-v1:0' | 'meta.llama3-1-8b-instruct-v1:0' | 'meta.llama3-2-11b-instruct-v1:0' | 'meta.llama3-2-1b-instruct-v1:0' | 'meta.llama3-2-3b-instruct-v1:0' | 'meta.llama3-2-90b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'mistral.mistral-small-2402-v1:0' | 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | (string & {});
|
|
5
|
-
|
|
6
|
+
declare const bedrockProviderOptions: z.ZodObject<{
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
additionalModelRequestFields
|
|
12
|
-
|
|
8
|
+
* Additional inference parameters that the model supports,
|
|
9
|
+
* beyond the base set of inference parameters that Converse
|
|
10
|
+
* supports in the inferenceConfig field
|
|
11
|
+
*/
|
|
12
|
+
additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
|
+
reasoningConfig: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
14
|
+
type: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>>;
|
|
15
|
+
budgetTokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
18
|
+
budgetTokens?: number | null | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
21
|
+
budgetTokens?: number | null | undefined;
|
|
22
|
+
}>>>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
25
|
+
reasoningConfig?: {
|
|
26
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
27
|
+
budgetTokens?: number | null | undefined;
|
|
28
|
+
} | null | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
31
|
+
reasoningConfig?: {
|
|
32
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
33
|
+
budgetTokens?: number | null | undefined;
|
|
34
|
+
} | null | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
|
|
13
37
|
|
|
14
38
|
type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
|
|
15
39
|
interface BedrockEmbeddingSettings {
|
|
@@ -84,8 +108,8 @@ interface AmazonBedrockProviderSettings {
|
|
|
84
108
|
generateId?: () => string;
|
|
85
109
|
}
|
|
86
110
|
interface AmazonBedrockProvider extends ProviderV2 {
|
|
87
|
-
(modelId: BedrockChatModelId
|
|
88
|
-
languageModel(modelId: BedrockChatModelId
|
|
111
|
+
(modelId: BedrockChatModelId): LanguageModelV2;
|
|
112
|
+
languageModel(modelId: BedrockChatModelId): LanguageModelV2;
|
|
89
113
|
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV1<string>;
|
|
90
114
|
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
91
115
|
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
@@ -99,4 +123,4 @@ Default Bedrock provider instance.
|
|
|
99
123
|
*/
|
|
100
124
|
declare const bedrock: AmazonBedrockProvider;
|
|
101
125
|
|
|
102
|
-
export { type AmazonBedrockProvider, type AmazonBedrockProviderSettings, bedrock, createAmazonBedrock };
|
|
126
|
+
export { type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type BedrockProviderOptions, bedrock, createAmazonBedrock };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
import { ProviderV2, LanguageModelV2, EmbeddingModelV1, ImageModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
|
|
4
5
|
type BedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-v1' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-instant-v1' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.command-r-v1:0' | 'cohere.command-r-plus-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-1-405b-instruct-v1:0' | 'meta.llama3-1-70b-instruct-v1:0' | 'meta.llama3-1-8b-instruct-v1:0' | 'meta.llama3-2-11b-instruct-v1:0' | 'meta.llama3-2-1b-instruct-v1:0' | 'meta.llama3-2-3b-instruct-v1:0' | 'meta.llama3-2-90b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'mistral.mistral-small-2402-v1:0' | 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | (string & {});
|
|
5
|
-
|
|
6
|
+
declare const bedrockProviderOptions: z.ZodObject<{
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
additionalModelRequestFields
|
|
12
|
-
|
|
8
|
+
* Additional inference parameters that the model supports,
|
|
9
|
+
* beyond the base set of inference parameters that Converse
|
|
10
|
+
* supports in the inferenceConfig field
|
|
11
|
+
*/
|
|
12
|
+
additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
|
+
reasoningConfig: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
14
|
+
type: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>>;
|
|
15
|
+
budgetTokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
18
|
+
budgetTokens?: number | null | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
21
|
+
budgetTokens?: number | null | undefined;
|
|
22
|
+
}>>>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
25
|
+
reasoningConfig?: {
|
|
26
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
27
|
+
budgetTokens?: number | null | undefined;
|
|
28
|
+
} | null | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
31
|
+
reasoningConfig?: {
|
|
32
|
+
type?: "enabled" | "disabled" | null | undefined;
|
|
33
|
+
budgetTokens?: number | null | undefined;
|
|
34
|
+
} | null | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
|
|
13
37
|
|
|
14
38
|
type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
|
|
15
39
|
interface BedrockEmbeddingSettings {
|
|
@@ -84,8 +108,8 @@ interface AmazonBedrockProviderSettings {
|
|
|
84
108
|
generateId?: () => string;
|
|
85
109
|
}
|
|
86
110
|
interface AmazonBedrockProvider extends ProviderV2 {
|
|
87
|
-
(modelId: BedrockChatModelId
|
|
88
|
-
languageModel(modelId: BedrockChatModelId
|
|
111
|
+
(modelId: BedrockChatModelId): LanguageModelV2;
|
|
112
|
+
languageModel(modelId: BedrockChatModelId): LanguageModelV2;
|
|
89
113
|
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV1<string>;
|
|
90
114
|
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
91
115
|
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
@@ -99,4 +123,4 @@ Default Bedrock provider instance.
|
|
|
99
123
|
*/
|
|
100
124
|
declare const bedrock: AmazonBedrockProvider;
|
|
101
125
|
|
|
102
|
-
export { type AmazonBedrockProvider, type AmazonBedrockProviderSettings, bedrock, createAmazonBedrock };
|
|
126
|
+
export { type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type BedrockProviderOptions, bedrock, createAmazonBedrock };
|
package/dist/index.js
CHANGED
|
@@ -29,9 +29,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
29
29
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/bedrock-chat-language-model.ts
|
|
32
|
-
var import_provider4 = require("@ai-sdk/provider");
|
|
33
32
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
34
|
-
var
|
|
33
|
+
var import_zod3 = require("zod");
|
|
35
34
|
|
|
36
35
|
// src/bedrock-api-types.ts
|
|
37
36
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -50,11 +49,26 @@ var BEDROCK_STOP_REASONS = [
|
|
|
50
49
|
"tool_use"
|
|
51
50
|
];
|
|
52
51
|
|
|
53
|
-
// src/bedrock-
|
|
52
|
+
// src/bedrock-chat-options.ts
|
|
54
53
|
var import_zod = require("zod");
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
var bedrockProviderOptions = import_zod.z.object({
|
|
55
|
+
/**
|
|
56
|
+
* Additional inference parameters that the model supports,
|
|
57
|
+
* beyond the base set of inference parameters that Converse
|
|
58
|
+
* supports in the inferenceConfig field
|
|
59
|
+
*/
|
|
60
|
+
additionalModelRequestFields: import_zod.z.record(import_zod.z.any()).optional(),
|
|
61
|
+
reasoningConfig: import_zod.z.object({
|
|
62
|
+
type: import_zod.z.union([import_zod.z.literal("enabled"), import_zod.z.literal("disabled")]).nullish(),
|
|
63
|
+
budgetTokens: import_zod.z.number().nullish()
|
|
64
|
+
}).nullish()
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// src/bedrock-error.ts
|
|
68
|
+
var import_zod2 = require("zod");
|
|
69
|
+
var BedrockErrorSchema = import_zod2.z.object({
|
|
70
|
+
message: import_zod2.z.string(),
|
|
71
|
+
type: import_zod2.z.string().nullish()
|
|
58
72
|
});
|
|
59
73
|
|
|
60
74
|
// src/bedrock-event-stream-response-handler.ts
|
|
@@ -256,7 +270,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
256
270
|
bedrockContent.push({
|
|
257
271
|
image: {
|
|
258
272
|
format: bedrockImageFormat,
|
|
259
|
-
source: { bytes: part.data }
|
|
273
|
+
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
260
274
|
}
|
|
261
275
|
});
|
|
262
276
|
} else {
|
|
@@ -266,9 +280,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
266
280
|
"/"
|
|
267
281
|
)) == null ? void 0 : _d[1],
|
|
268
282
|
name: generateFileId(),
|
|
269
|
-
source: {
|
|
270
|
-
bytes: part.data
|
|
271
|
-
}
|
|
283
|
+
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
272
284
|
}
|
|
273
285
|
});
|
|
274
286
|
}
|
|
@@ -485,9 +497,8 @@ function mapBedrockFinishReason(finishReason) {
|
|
|
485
497
|
|
|
486
498
|
// src/bedrock-chat-language-model.ts
|
|
487
499
|
var BedrockChatLanguageModel = class {
|
|
488
|
-
constructor(modelId,
|
|
500
|
+
constructor(modelId, config) {
|
|
489
501
|
this.modelId = modelId;
|
|
490
|
-
this.settings = settings;
|
|
491
502
|
this.config = config;
|
|
492
503
|
this.specificationVersion = "v2";
|
|
493
504
|
this.provider = "amazon-bedrock";
|
|
@@ -496,7 +507,7 @@ var BedrockChatLanguageModel = class {
|
|
|
496
507
|
}
|
|
497
508
|
getArgs({
|
|
498
509
|
prompt,
|
|
499
|
-
|
|
510
|
+
maxOutputTokens,
|
|
500
511
|
temperature,
|
|
501
512
|
topP,
|
|
502
513
|
topK,
|
|
@@ -509,7 +520,12 @@ var BedrockChatLanguageModel = class {
|
|
|
509
520
|
toolChoice,
|
|
510
521
|
providerOptions
|
|
511
522
|
}) {
|
|
512
|
-
var _a, _b, _c, _d, _e
|
|
523
|
+
var _a, _b, _c, _d, _e;
|
|
524
|
+
const bedrockOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
|
|
525
|
+
provider: "bedrock",
|
|
526
|
+
providerOptions,
|
|
527
|
+
schema: bedrockProviderOptions
|
|
528
|
+
})) != null ? _a : {};
|
|
513
529
|
const warnings = [];
|
|
514
530
|
if (frequencyPenalty != null) {
|
|
515
531
|
warnings.push({
|
|
@@ -543,34 +559,24 @@ var BedrockChatLanguageModel = class {
|
|
|
543
559
|
});
|
|
544
560
|
}
|
|
545
561
|
const { system, messages } = convertToBedrockChatMessages(prompt);
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
);
|
|
549
|
-
if (!reasoningConfigOptions.success) {
|
|
550
|
-
throw new import_provider4.InvalidArgumentError({
|
|
551
|
-
argument: "providerOptions.bedrock.reasoning_config",
|
|
552
|
-
message: "invalid reasoning configuration options",
|
|
553
|
-
cause: reasoningConfigOptions.error
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
const isThinking = ((_b = reasoningConfigOptions.data) == null ? void 0 : _b.type) === "enabled";
|
|
557
|
-
const thinkingBudget = (_e = (_c = reasoningConfigOptions.data) == null ? void 0 : _c.budgetTokens) != null ? _e : (_d = reasoningConfigOptions.data) == null ? void 0 : _d.budget_tokens;
|
|
562
|
+
const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
|
|
563
|
+
const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
|
|
558
564
|
const inferenceConfig = {
|
|
559
|
-
...
|
|
565
|
+
...maxOutputTokens != null && { maxOutputTokens },
|
|
560
566
|
...temperature != null && { temperature },
|
|
561
567
|
...topP != null && { topP },
|
|
562
568
|
...stopSequences != null && { stopSequences }
|
|
563
569
|
};
|
|
564
570
|
if (isThinking && thinkingBudget != null) {
|
|
565
|
-
if (inferenceConfig.
|
|
566
|
-
inferenceConfig.
|
|
571
|
+
if (inferenceConfig.maxOutputTokens != null) {
|
|
572
|
+
inferenceConfig.maxOutputTokens += thinkingBudget;
|
|
567
573
|
} else {
|
|
568
|
-
inferenceConfig.
|
|
574
|
+
inferenceConfig.maxOutputTokens = thinkingBudget + 4096;
|
|
569
575
|
}
|
|
570
|
-
|
|
571
|
-
...
|
|
572
|
-
|
|
573
|
-
type: (
|
|
576
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
577
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
578
|
+
reasoningConfig: {
|
|
579
|
+
type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
|
|
574
580
|
budget_tokens: thinkingBudget
|
|
575
581
|
}
|
|
576
582
|
};
|
|
@@ -596,18 +602,18 @@ var BedrockChatLanguageModel = class {
|
|
|
596
602
|
command: {
|
|
597
603
|
system,
|
|
598
604
|
messages,
|
|
599
|
-
additionalModelRequestFields:
|
|
605
|
+
additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
|
|
600
606
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
601
607
|
inferenceConfig
|
|
602
608
|
},
|
|
603
609
|
...providerOptions == null ? void 0 : providerOptions.bedrock,
|
|
604
|
-
...((
|
|
610
|
+
...((_e = toolConfig.tools) == null ? void 0 : _e.length) ? { toolConfig } : {}
|
|
605
611
|
},
|
|
606
612
|
warnings: [...warnings, ...toolWarnings]
|
|
607
613
|
};
|
|
608
614
|
}
|
|
609
615
|
async doGenerate(options) {
|
|
610
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
616
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
611
617
|
const { command: args, warnings } = this.getArgs(options);
|
|
612
618
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
613
619
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
@@ -630,7 +636,6 @@ var BedrockChatLanguageModel = class {
|
|
|
630
636
|
abortSignal: options.abortSignal,
|
|
631
637
|
fetch: this.config.fetch
|
|
632
638
|
});
|
|
633
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
634
639
|
const providerMetadata = response.trace || response.usage ? {
|
|
635
640
|
bedrock: {
|
|
636
641
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
@@ -679,10 +684,9 @@ var BedrockChatLanguageModel = class {
|
|
|
679
684
|
response.stopReason
|
|
680
685
|
),
|
|
681
686
|
usage: {
|
|
682
|
-
|
|
683
|
-
|
|
687
|
+
inputTokens: (_m = response.usage) == null ? void 0 : _m.inputTokens,
|
|
688
|
+
outputTokens: (_n = response.usage) == null ? void 0 : _n.outputTokens
|
|
684
689
|
},
|
|
685
|
-
rawCall: { rawPrompt, rawSettings },
|
|
686
690
|
response: {
|
|
687
691
|
// TODO add id, timestamp, etc
|
|
688
692
|
headers: responseHeaders
|
|
@@ -710,11 +714,10 @@ var BedrockChatLanguageModel = class {
|
|
|
710
714
|
abortSignal: options.abortSignal,
|
|
711
715
|
fetch: this.config.fetch
|
|
712
716
|
});
|
|
713
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
714
717
|
let finishReason = "unknown";
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
+
const usage = {
|
|
719
|
+
inputTokens: void 0,
|
|
720
|
+
outputTokens: void 0
|
|
718
721
|
};
|
|
719
722
|
let providerMetadata = void 0;
|
|
720
723
|
const toolCallContentBlocks = {};
|
|
@@ -754,10 +757,8 @@ var BedrockChatLanguageModel = class {
|
|
|
754
757
|
);
|
|
755
758
|
}
|
|
756
759
|
if (value.metadata) {
|
|
757
|
-
usage =
|
|
758
|
-
|
|
759
|
-
completionTokens: (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : Number.NaN
|
|
760
|
-
};
|
|
760
|
+
usage.inputTokens = (_b = (_a = value.metadata.usage) == null ? void 0 : _a.inputTokens) != null ? _b : usage.inputTokens;
|
|
761
|
+
usage.outputTokens = (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : usage.outputTokens;
|
|
761
762
|
const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheReadInputTokens) != null || ((_f = value.metadata.usage) == null ? void 0 : _f.cacheWriteInputTokens) != null ? {
|
|
762
763
|
usage: {
|
|
763
764
|
cacheReadInputTokens: (_h = (_g = value.metadata.usage) == null ? void 0 : _g.cacheReadInputTokens) != null ? _h : Number.NaN,
|
|
@@ -849,7 +850,6 @@ var BedrockChatLanguageModel = class {
|
|
|
849
850
|
}
|
|
850
851
|
})
|
|
851
852
|
),
|
|
852
|
-
rawCall: { rawPrompt, rawSettings },
|
|
853
853
|
response: { headers: responseHeaders },
|
|
854
854
|
warnings
|
|
855
855
|
};
|
|
@@ -859,110 +859,105 @@ var BedrockChatLanguageModel = class {
|
|
|
859
859
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
860
860
|
}
|
|
861
861
|
};
|
|
862
|
-
var
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
budgetTokens: import_zod2.z.number().nullish()
|
|
866
|
-
}).nullish();
|
|
867
|
-
var BedrockStopReasonSchema = import_zod2.z.union([
|
|
868
|
-
import_zod2.z.enum(BEDROCK_STOP_REASONS),
|
|
869
|
-
import_zod2.z.string()
|
|
862
|
+
var BedrockStopReasonSchema = import_zod3.z.union([
|
|
863
|
+
import_zod3.z.enum(BEDROCK_STOP_REASONS),
|
|
864
|
+
import_zod3.z.string()
|
|
870
865
|
]);
|
|
871
|
-
var BedrockToolUseSchema =
|
|
872
|
-
toolUseId:
|
|
873
|
-
name:
|
|
874
|
-
input:
|
|
866
|
+
var BedrockToolUseSchema = import_zod3.z.object({
|
|
867
|
+
toolUseId: import_zod3.z.string(),
|
|
868
|
+
name: import_zod3.z.string(),
|
|
869
|
+
input: import_zod3.z.unknown()
|
|
875
870
|
});
|
|
876
|
-
var BedrockReasoningTextSchema =
|
|
877
|
-
signature:
|
|
878
|
-
text:
|
|
871
|
+
var BedrockReasoningTextSchema = import_zod3.z.object({
|
|
872
|
+
signature: import_zod3.z.string().nullish(),
|
|
873
|
+
text: import_zod3.z.string()
|
|
879
874
|
});
|
|
880
|
-
var BedrockRedactedReasoningSchema =
|
|
881
|
-
data:
|
|
875
|
+
var BedrockRedactedReasoningSchema = import_zod3.z.object({
|
|
876
|
+
data: import_zod3.z.string()
|
|
882
877
|
});
|
|
883
|
-
var BedrockResponseSchema =
|
|
884
|
-
metrics:
|
|
885
|
-
latencyMs:
|
|
878
|
+
var BedrockResponseSchema = import_zod3.z.object({
|
|
879
|
+
metrics: import_zod3.z.object({
|
|
880
|
+
latencyMs: import_zod3.z.number()
|
|
886
881
|
}).nullish(),
|
|
887
|
-
output:
|
|
888
|
-
message:
|
|
889
|
-
content:
|
|
890
|
-
|
|
891
|
-
text:
|
|
882
|
+
output: import_zod3.z.object({
|
|
883
|
+
message: import_zod3.z.object({
|
|
884
|
+
content: import_zod3.z.array(
|
|
885
|
+
import_zod3.z.object({
|
|
886
|
+
text: import_zod3.z.string().nullish(),
|
|
892
887
|
toolUse: BedrockToolUseSchema.nullish(),
|
|
893
|
-
reasoningContent:
|
|
894
|
-
|
|
888
|
+
reasoningContent: import_zod3.z.union([
|
|
889
|
+
import_zod3.z.object({
|
|
895
890
|
reasoningText: BedrockReasoningTextSchema
|
|
896
891
|
}),
|
|
897
|
-
|
|
892
|
+
import_zod3.z.object({
|
|
898
893
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
899
894
|
})
|
|
900
895
|
]).nullish()
|
|
901
896
|
})
|
|
902
897
|
),
|
|
903
|
-
role:
|
|
898
|
+
role: import_zod3.z.string()
|
|
904
899
|
})
|
|
905
900
|
}),
|
|
906
901
|
stopReason: BedrockStopReasonSchema,
|
|
907
|
-
trace:
|
|
908
|
-
usage:
|
|
909
|
-
inputTokens:
|
|
910
|
-
outputTokens:
|
|
911
|
-
totalTokens:
|
|
912
|
-
cacheReadInputTokens:
|
|
913
|
-
cacheWriteInputTokens:
|
|
902
|
+
trace: import_zod3.z.unknown().nullish(),
|
|
903
|
+
usage: import_zod3.z.object({
|
|
904
|
+
inputTokens: import_zod3.z.number(),
|
|
905
|
+
outputTokens: import_zod3.z.number(),
|
|
906
|
+
totalTokens: import_zod3.z.number(),
|
|
907
|
+
cacheReadInputTokens: import_zod3.z.number().nullish(),
|
|
908
|
+
cacheWriteInputTokens: import_zod3.z.number().nullish()
|
|
914
909
|
})
|
|
915
910
|
});
|
|
916
|
-
var BedrockStreamSchema =
|
|
917
|
-
contentBlockDelta:
|
|
918
|
-
contentBlockIndex:
|
|
919
|
-
delta:
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
reasoningContent:
|
|
911
|
+
var BedrockStreamSchema = import_zod3.z.object({
|
|
912
|
+
contentBlockDelta: import_zod3.z.object({
|
|
913
|
+
contentBlockIndex: import_zod3.z.number(),
|
|
914
|
+
delta: import_zod3.z.union([
|
|
915
|
+
import_zod3.z.object({ text: import_zod3.z.string() }),
|
|
916
|
+
import_zod3.z.object({ toolUse: import_zod3.z.object({ input: import_zod3.z.string() }) }),
|
|
917
|
+
import_zod3.z.object({
|
|
918
|
+
reasoningContent: import_zod3.z.object({ text: import_zod3.z.string() })
|
|
924
919
|
}),
|
|
925
|
-
|
|
926
|
-
reasoningContent:
|
|
927
|
-
signature:
|
|
920
|
+
import_zod3.z.object({
|
|
921
|
+
reasoningContent: import_zod3.z.object({
|
|
922
|
+
signature: import_zod3.z.string()
|
|
928
923
|
})
|
|
929
924
|
}),
|
|
930
|
-
|
|
931
|
-
reasoningContent:
|
|
925
|
+
import_zod3.z.object({
|
|
926
|
+
reasoningContent: import_zod3.z.object({ data: import_zod3.z.string() })
|
|
932
927
|
})
|
|
933
928
|
]).nullish()
|
|
934
929
|
}).nullish(),
|
|
935
|
-
contentBlockStart:
|
|
936
|
-
contentBlockIndex:
|
|
937
|
-
start:
|
|
930
|
+
contentBlockStart: import_zod3.z.object({
|
|
931
|
+
contentBlockIndex: import_zod3.z.number(),
|
|
932
|
+
start: import_zod3.z.object({
|
|
938
933
|
toolUse: BedrockToolUseSchema.nullish()
|
|
939
934
|
}).nullish()
|
|
940
935
|
}).nullish(),
|
|
941
|
-
contentBlockStop:
|
|
942
|
-
contentBlockIndex:
|
|
936
|
+
contentBlockStop: import_zod3.z.object({
|
|
937
|
+
contentBlockIndex: import_zod3.z.number()
|
|
943
938
|
}).nullish(),
|
|
944
|
-
internalServerException:
|
|
945
|
-
messageStop:
|
|
946
|
-
additionalModelResponseFields:
|
|
939
|
+
internalServerException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
940
|
+
messageStop: import_zod3.z.object({
|
|
941
|
+
additionalModelResponseFields: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
947
942
|
stopReason: BedrockStopReasonSchema
|
|
948
943
|
}).nullish(),
|
|
949
|
-
metadata:
|
|
950
|
-
trace:
|
|
951
|
-
usage:
|
|
952
|
-
cacheReadInputTokens:
|
|
953
|
-
cacheWriteInputTokens:
|
|
954
|
-
inputTokens:
|
|
955
|
-
outputTokens:
|
|
944
|
+
metadata: import_zod3.z.object({
|
|
945
|
+
trace: import_zod3.z.unknown().nullish(),
|
|
946
|
+
usage: import_zod3.z.object({
|
|
947
|
+
cacheReadInputTokens: import_zod3.z.number().nullish(),
|
|
948
|
+
cacheWriteInputTokens: import_zod3.z.number().nullish(),
|
|
949
|
+
inputTokens: import_zod3.z.number(),
|
|
950
|
+
outputTokens: import_zod3.z.number()
|
|
956
951
|
}).nullish()
|
|
957
952
|
}).nullish(),
|
|
958
|
-
modelStreamErrorException:
|
|
959
|
-
throttlingException:
|
|
960
|
-
validationException:
|
|
953
|
+
modelStreamErrorException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
954
|
+
throttlingException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
955
|
+
validationException: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
961
956
|
});
|
|
962
957
|
|
|
963
958
|
// src/bedrock-embedding-model.ts
|
|
964
959
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
965
|
-
var
|
|
960
|
+
var import_zod4 = require("zod");
|
|
966
961
|
var BedrockEmbeddingModel = class {
|
|
967
962
|
constructor(modelId, settings, config) {
|
|
968
963
|
this.modelId = modelId;
|
|
@@ -1021,9 +1016,9 @@ var BedrockEmbeddingModel = class {
|
|
|
1021
1016
|
);
|
|
1022
1017
|
}
|
|
1023
1018
|
};
|
|
1024
|
-
var BedrockEmbeddingResponseSchema =
|
|
1025
|
-
embedding:
|
|
1026
|
-
inputTextTokenCount:
|
|
1019
|
+
var BedrockEmbeddingResponseSchema = import_zod4.z.object({
|
|
1020
|
+
embedding: import_zod4.z.array(import_zod4.z.number()),
|
|
1021
|
+
inputTextTokenCount: import_zod4.z.number()
|
|
1027
1022
|
});
|
|
1028
1023
|
|
|
1029
1024
|
// src/bedrock-image-model.ts
|
|
@@ -1035,7 +1030,7 @@ var modelMaxImagesPerCall = {
|
|
|
1035
1030
|
};
|
|
1036
1031
|
|
|
1037
1032
|
// src/bedrock-image-model.ts
|
|
1038
|
-
var
|
|
1033
|
+
var import_zod5 = require("zod");
|
|
1039
1034
|
var BedrockImageModel = class {
|
|
1040
1035
|
constructor(modelId, settings, config) {
|
|
1041
1036
|
this.modelId = modelId;
|
|
@@ -1117,8 +1112,8 @@ var BedrockImageModel = class {
|
|
|
1117
1112
|
};
|
|
1118
1113
|
}
|
|
1119
1114
|
};
|
|
1120
|
-
var bedrockImageResponseSchema =
|
|
1121
|
-
images:
|
|
1115
|
+
var bedrockImageResponseSchema = import_zod5.z.object({
|
|
1116
|
+
images: import_zod5.z.array(import_zod5.z.string())
|
|
1122
1117
|
});
|
|
1123
1118
|
|
|
1124
1119
|
// src/headers-utils.ts
|
|
@@ -1240,22 +1235,22 @@ function createAmazonBedrock(options = {}) {
|
|
|
1240
1235
|
})}.amazonaws.com`
|
|
1241
1236
|
)) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
|
|
1242
1237
|
};
|
|
1243
|
-
const createChatModel = (modelId
|
|
1238
|
+
const createChatModel = (modelId) => {
|
|
1244
1239
|
var _a;
|
|
1245
|
-
return new BedrockChatLanguageModel(modelId,
|
|
1240
|
+
return new BedrockChatLanguageModel(modelId, {
|
|
1246
1241
|
baseUrl: getBaseUrl,
|
|
1247
1242
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1248
1243
|
fetch: sigv4Fetch,
|
|
1249
1244
|
generateId: import_provider_utils7.generateId
|
|
1250
1245
|
});
|
|
1251
1246
|
};
|
|
1252
|
-
const provider = function(modelId
|
|
1247
|
+
const provider = function(modelId) {
|
|
1253
1248
|
if (new.target) {
|
|
1254
1249
|
throw new Error(
|
|
1255
1250
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
1256
1251
|
);
|
|
1257
1252
|
}
|
|
1258
|
-
return createChatModel(modelId
|
|
1253
|
+
return createChatModel(modelId);
|
|
1259
1254
|
};
|
|
1260
1255
|
const createEmbeddingModel = (modelId, settings = {}) => {
|
|
1261
1256
|
var _a;
|