@ai-sdk/amazon-bedrock 5.0.0-beta.7 → 5.0.0-beta.85
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 +677 -4
- package/README.md +2 -0
- package/dist/anthropic/index.d.ts +10 -10
- package/dist/anthropic/index.js +151 -117
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +36 -23
- package/dist/index.js +881 -604
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +253 -0
- package/dist/mantle/index.cjs.map +1 -0
- package/dist/mantle/index.d.cts +99 -0
- package/dist/mantle/index.d.ts +99 -0
- package/dist/mantle/index.js +240 -0
- package/dist/mantle/index.js.map +1 -0
- package/docs/08-amazon-bedrock.mdx +310 -84
- package/mantle/index.d.ts +1 -0
- package/package.json +27 -20
- package/src/amazon-bedrock-api-types.ts +228 -0
- package/src/{bedrock-chat-options.ts → amazon-bedrock-chat-language-model-options.ts} +27 -8
- package/src/{bedrock-chat-language-model.ts → amazon-bedrock-chat-language-model.ts} +350 -180
- package/src/{bedrock-embedding-options.ts → amazon-bedrock-embedding-model-options.ts} +1 -1
- package/src/{bedrock-embedding-model.ts → amazon-bedrock-embedding-model.ts} +61 -29
- package/src/{bedrock-error.ts → amazon-bedrock-error.ts} +1 -1
- package/src/{bedrock-event-stream-decoder.ts → amazon-bedrock-event-stream-decoder.ts} +1 -1
- package/src/{bedrock-event-stream-response-handler.ts → amazon-bedrock-event-stream-response-handler.ts} +6 -6
- package/src/{bedrock-image-model.ts → amazon-bedrock-image-model.ts} +62 -38
- package/src/amazon-bedrock-image-settings.ts +9 -0
- package/src/{bedrock-prepare-tools.ts → amazon-bedrock-prepare-tools.ts} +22 -18
- package/src/{bedrock-provider.ts → amazon-bedrock-provider.ts} +53 -46
- package/src/amazon-bedrock-reasoning-metadata.ts +10 -0
- package/src/{bedrock-sigv4-fetch.ts → amazon-bedrock-sigv4-fetch.ts} +17 -9
- package/src/anthropic/amazon-bedrock-anthropic-fetch.ts +104 -0
- package/src/anthropic/{bedrock-anthropic-options.ts → amazon-bedrock-anthropic-options.ts} +7 -1
- package/src/anthropic/{bedrock-anthropic-provider.ts → amazon-bedrock-anthropic-provider.ts} +40 -24
- package/src/anthropic/index.ts +19 -7
- package/src/{convert-bedrock-usage.ts → convert-amazon-bedrock-usage.ts} +4 -4
- package/src/convert-to-amazon-bedrock-chat-messages.ts +556 -0
- package/src/index.ts +15 -8
- package/src/inject-fetch-headers.ts +1 -1
- package/src/mantle/bedrock-mantle-options.ts +15 -0
- package/src/mantle/bedrock-mantle-provider.ts +283 -0
- package/src/mantle/index.ts +6 -0
- package/src/{map-bedrock-finish-reason.ts → map-amazon-bedrock-finish-reason.ts} +4 -4
- package/src/reranking/{bedrock-reranking-api.ts → amazon-bedrock-reranking-api.ts} +3 -3
- package/src/reranking/{bedrock-reranking-options.ts → amazon-bedrock-reranking-model-options.ts} +1 -1
- package/src/reranking/{bedrock-reranking-model.ts → amazon-bedrock-reranking-model.ts} +32 -25
- 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/src/anthropic/bedrock-anthropic-fetch.ts +0 -68
- package/src/bedrock-api-types.ts +0 -216
- package/src/bedrock-image-settings.ts +0 -6
- package/src/convert-to-bedrock-chat-messages.ts +0 -468
package/dist/index.js
CHANGED
|
@@ -1,40 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
// src/bedrock-provider.ts
|
|
30
|
-
var import_internal2 = require("@ai-sdk/anthropic/internal");
|
|
31
|
-
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1
|
+
// src/amazon-bedrock-provider.ts
|
|
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
|
-
// src/bedrock-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
// src/amazon-bedrock-chat-language-model.ts
|
|
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 z4 } from "zod/v4";
|
|
36
28
|
|
|
37
|
-
// src/bedrock-api-types.ts
|
|
29
|
+
// src/amazon-bedrock-api-types.ts
|
|
38
30
|
var BEDROCK_STOP_REASONS = [
|
|
39
31
|
"stop",
|
|
40
32
|
"stop_sequence",
|
|
@@ -65,58 +57,73 @@ var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
|
65
57
|
"text/markdown": "md"
|
|
66
58
|
};
|
|
67
59
|
|
|
68
|
-
// src/bedrock-chat-options.ts
|
|
69
|
-
|
|
70
|
-
var
|
|
60
|
+
// src/amazon-bedrock-chat-language-model-options.ts
|
|
61
|
+
import { z } from "zod/v4";
|
|
62
|
+
var amazonBedrockFilePartProviderOptions = 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
|
|
74
|
+
var amazonBedrockLanguageModelChatOptions = 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", "xhigh", "max"]).optional(),
|
|
89
|
+
display: z.enum(["omitted", "summarized"]).optional()
|
|
97
90
|
}).optional(),
|
|
98
91
|
/**
|
|
99
92
|
* Anthropic beta features to enable
|
|
100
93
|
*/
|
|
101
|
-
anthropicBeta:
|
|
94
|
+
anthropicBeta: z.array(z.string()).optional(),
|
|
95
|
+
/**
|
|
96
|
+
* Service tier for the request.
|
|
97
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
|
|
98
|
+
*
|
|
99
|
+
* - 'reserved': Uses provisioned throughput capacity
|
|
100
|
+
* - 'priority': Prioritizes low-latency inference when capacity is available
|
|
101
|
+
* - 'default': Standard on-demand tier
|
|
102
|
+
* - 'flex': Lower-cost tier for flexible latency workloads
|
|
103
|
+
*/
|
|
104
|
+
serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
102
105
|
});
|
|
103
106
|
|
|
104
|
-
// src/bedrock-error.ts
|
|
105
|
-
|
|
106
|
-
var
|
|
107
|
-
message:
|
|
108
|
-
type:
|
|
107
|
+
// src/amazon-bedrock-error.ts
|
|
108
|
+
import { z as z2 } from "zod/v4";
|
|
109
|
+
var AmazonBedrockErrorSchema = z2.object({
|
|
110
|
+
message: z2.string(),
|
|
111
|
+
type: z2.string().nullish()
|
|
109
112
|
});
|
|
110
113
|
|
|
111
|
-
// src/bedrock-event-stream-response-handler.ts
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
// src/amazon-bedrock-event-stream-response-handler.ts
|
|
115
|
+
import { EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
116
|
+
import {
|
|
117
|
+
safeParseJSON,
|
|
118
|
+
extractResponseHeaders,
|
|
119
|
+
safeValidateTypes
|
|
120
|
+
} from "@ai-sdk/provider-utils";
|
|
114
121
|
|
|
115
|
-
// src/bedrock-event-stream-decoder.ts
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
function
|
|
119
|
-
const codec = new
|
|
122
|
+
// src/amazon-bedrock-event-stream-decoder.ts
|
|
123
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
124
|
+
import { toUtf8, fromUtf8 } from "@smithy/util-utf8";
|
|
125
|
+
function createAmazonBedrockEventStreamDecoder(body, processEvent) {
|
|
126
|
+
const codec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
120
127
|
let buffer = new Uint8Array(0);
|
|
121
128
|
const textDecoder = new TextDecoder();
|
|
122
129
|
return body.pipeThrough(
|
|
@@ -153,19 +160,19 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
153
160
|
);
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
// src/bedrock-event-stream-response-handler.ts
|
|
157
|
-
var
|
|
158
|
-
const responseHeaders =
|
|
163
|
+
// src/amazon-bedrock-event-stream-response-handler.ts
|
|
164
|
+
var createAmazonBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
165
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
159
166
|
if (response.body == null) {
|
|
160
|
-
throw new
|
|
167
|
+
throw new EmptyResponseBodyError({});
|
|
161
168
|
}
|
|
162
169
|
return {
|
|
163
170
|
responseHeaders,
|
|
164
|
-
value:
|
|
171
|
+
value: createAmazonBedrockEventStreamDecoder(
|
|
165
172
|
response.body,
|
|
166
173
|
async (event, controller) => {
|
|
167
174
|
if (event.messageType === "event") {
|
|
168
|
-
const parsedDataResult = await
|
|
175
|
+
const parsedDataResult = await safeParseJSON({ text: event.data });
|
|
169
176
|
if (!parsedDataResult.success) {
|
|
170
177
|
controller.enqueue(parsedDataResult);
|
|
171
178
|
return;
|
|
@@ -174,7 +181,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
174
181
|
const wrappedData = {
|
|
175
182
|
[event.eventType]: parsedDataResult.value
|
|
176
183
|
};
|
|
177
|
-
const validatedWrappedData = await
|
|
184
|
+
const validatedWrappedData = await safeValidateTypes({
|
|
178
185
|
value: wrappedData,
|
|
179
186
|
schema: chunkSchema
|
|
180
187
|
});
|
|
@@ -193,10 +200,15 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
193
200
|
};
|
|
194
201
|
};
|
|
195
202
|
|
|
196
|
-
// src/bedrock-prepare-tools.ts
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
// src/amazon-bedrock-prepare-tools.ts
|
|
204
|
+
import {
|
|
205
|
+
UnsupportedFunctionalityError
|
|
206
|
+
} from "@ai-sdk/provider";
|
|
207
|
+
import { asSchema } from "@ai-sdk/provider-utils";
|
|
208
|
+
import {
|
|
209
|
+
anthropicTools,
|
|
210
|
+
prepareTools as prepareAnthropicTools
|
|
211
|
+
} from "@ai-sdk/anthropic/internal";
|
|
200
212
|
async function prepareTools({
|
|
201
213
|
tools,
|
|
202
214
|
toolChoice,
|
|
@@ -236,14 +248,14 @@ async function prepareTools({
|
|
|
236
248
|
const ProviderTools = supportedTools.filter((t) => t.type === "provider");
|
|
237
249
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
238
250
|
let additionalTools = void 0;
|
|
239
|
-
const
|
|
251
|
+
const amazonBedrockTools = [];
|
|
240
252
|
const usingAnthropicTools = isAnthropicModel && ProviderTools.length > 0;
|
|
241
253
|
if (usingAnthropicTools) {
|
|
242
254
|
const {
|
|
243
255
|
toolChoice: preparedAnthropicToolChoice,
|
|
244
256
|
toolWarnings: anthropicToolWarnings,
|
|
245
257
|
betas: anthropicBetas
|
|
246
|
-
} = await (
|
|
258
|
+
} = await prepareAnthropicTools({
|
|
247
259
|
tools: ProviderTools,
|
|
248
260
|
toolChoice,
|
|
249
261
|
supportsStructuredOutput: false,
|
|
@@ -257,17 +269,17 @@ async function prepareTools({
|
|
|
257
269
|
};
|
|
258
270
|
}
|
|
259
271
|
for (const tool of ProviderTools) {
|
|
260
|
-
const toolFactory = Object.values(
|
|
272
|
+
const toolFactory = Object.values(anthropicTools).find((factory) => {
|
|
261
273
|
const instance = factory({});
|
|
262
274
|
return instance.id === tool.id;
|
|
263
275
|
});
|
|
264
276
|
if (toolFactory != null) {
|
|
265
277
|
const fullToolDefinition = toolFactory({});
|
|
266
|
-
|
|
278
|
+
amazonBedrockTools.push({
|
|
267
279
|
toolSpec: {
|
|
268
280
|
name: tool.name,
|
|
269
281
|
inputSchema: {
|
|
270
|
-
json: await
|
|
282
|
+
json: await asSchema(fullToolDefinition.inputSchema).jsonSchema
|
|
271
283
|
}
|
|
272
284
|
}
|
|
273
285
|
});
|
|
@@ -282,7 +294,7 @@ async function prepareTools({
|
|
|
282
294
|
}
|
|
283
295
|
const filteredFunctionTools = (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? functionTools.filter((t) => t.name === toolChoice.toolName) : functionTools;
|
|
284
296
|
for (const tool of filteredFunctionTools) {
|
|
285
|
-
|
|
297
|
+
amazonBedrockTools.push({
|
|
286
298
|
toolSpec: {
|
|
287
299
|
name: tool.name,
|
|
288
300
|
...((_a = tool.description) == null ? void 0 : _a.trim()) !== "" ? { description: tool.description } : {},
|
|
@@ -293,32 +305,32 @@ async function prepareTools({
|
|
|
293
305
|
}
|
|
294
306
|
});
|
|
295
307
|
}
|
|
296
|
-
let
|
|
297
|
-
if (!usingAnthropicTools &&
|
|
308
|
+
let amazonBedrockToolChoice = void 0;
|
|
309
|
+
if (!usingAnthropicTools && amazonBedrockTools.length > 0 && toolChoice) {
|
|
298
310
|
const type = toolChoice.type;
|
|
299
311
|
switch (type) {
|
|
300
312
|
case "auto":
|
|
301
|
-
|
|
313
|
+
amazonBedrockToolChoice = { auto: {} };
|
|
302
314
|
break;
|
|
303
315
|
case "required":
|
|
304
|
-
|
|
316
|
+
amazonBedrockToolChoice = { any: {} };
|
|
305
317
|
break;
|
|
306
318
|
case "none":
|
|
307
|
-
|
|
308
|
-
|
|
319
|
+
amazonBedrockTools.length = 0;
|
|
320
|
+
amazonBedrockToolChoice = void 0;
|
|
309
321
|
break;
|
|
310
322
|
case "tool":
|
|
311
|
-
|
|
323
|
+
amazonBedrockToolChoice = { tool: { name: toolChoice.toolName } };
|
|
312
324
|
break;
|
|
313
325
|
default: {
|
|
314
326
|
const _exhaustiveCheck = type;
|
|
315
|
-
throw new
|
|
327
|
+
throw new UnsupportedFunctionalityError({
|
|
316
328
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
317
329
|
});
|
|
318
330
|
}
|
|
319
331
|
}
|
|
320
332
|
}
|
|
321
|
-
const toolConfig =
|
|
333
|
+
const toolConfig = amazonBedrockTools.length > 0 ? { tools: amazonBedrockTools, toolChoice: amazonBedrockToolChoice } : {};
|
|
322
334
|
return {
|
|
323
335
|
toolConfig,
|
|
324
336
|
additionalTools,
|
|
@@ -327,8 +339,8 @@ async function prepareTools({
|
|
|
327
339
|
};
|
|
328
340
|
}
|
|
329
341
|
|
|
330
|
-
// src/convert-bedrock-usage.ts
|
|
331
|
-
function
|
|
342
|
+
// src/convert-amazon-bedrock-usage.ts
|
|
343
|
+
function convertAmazonBedrockUsage(usage) {
|
|
332
344
|
var _a, _b;
|
|
333
345
|
if (usage == null) {
|
|
334
346
|
return {
|
|
@@ -366,9 +378,25 @@ function convertBedrockUsage(usage) {
|
|
|
366
378
|
};
|
|
367
379
|
}
|
|
368
380
|
|
|
369
|
-
// src/convert-to-bedrock-chat-messages.ts
|
|
370
|
-
|
|
371
|
-
|
|
381
|
+
// src/convert-to-amazon-bedrock-chat-messages.ts
|
|
382
|
+
import {
|
|
383
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
384
|
+
} from "@ai-sdk/provider";
|
|
385
|
+
import {
|
|
386
|
+
convertToBase64,
|
|
387
|
+
getTopLevelMediaType,
|
|
388
|
+
isFullMediaType,
|
|
389
|
+
parseProviderOptions,
|
|
390
|
+
resolveFullMediaType,
|
|
391
|
+
stripFileExtension
|
|
392
|
+
} from "@ai-sdk/provider-utils";
|
|
393
|
+
|
|
394
|
+
// src/amazon-bedrock-reasoning-metadata.ts
|
|
395
|
+
import { z as z3 } from "zod/v4";
|
|
396
|
+
var amazonBedrockReasoningMetadataSchema = z3.object({
|
|
397
|
+
signature: z3.string().optional(),
|
|
398
|
+
redactedData: z3.string().optional()
|
|
399
|
+
});
|
|
372
400
|
|
|
373
401
|
// src/normalize-tool-call-id.ts
|
|
374
402
|
function isMistralModel(modelId) {
|
|
@@ -382,26 +410,36 @@ function normalizeToolCallId(toolCallId, isMistral) {
|
|
|
382
410
|
return alphanumericChars.slice(0, 9);
|
|
383
411
|
}
|
|
384
412
|
|
|
385
|
-
// src/convert-to-bedrock-chat-messages.ts
|
|
413
|
+
// src/convert-to-amazon-bedrock-chat-messages.ts
|
|
386
414
|
function getCachePoint(providerMetadata) {
|
|
387
|
-
var _a;
|
|
388
|
-
const cachePointConfig = (_a = providerMetadata == null ? void 0 : providerMetadata.
|
|
415
|
+
var _a, _b, _c;
|
|
416
|
+
const cachePointConfig = (_c = (_a = providerMetadata == null ? void 0 : providerMetadata.amazonBedrock) == null ? void 0 : _a.cachePoint) != null ? _c : (_b = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _b.cachePoint;
|
|
389
417
|
if (!cachePointConfig) {
|
|
390
418
|
return void 0;
|
|
391
419
|
}
|
|
392
420
|
return { cachePoint: cachePointConfig };
|
|
393
421
|
}
|
|
422
|
+
function pushCachePoint(content, providerMetadata) {
|
|
423
|
+
const cachePoint = getCachePoint(providerMetadata);
|
|
424
|
+
if (cachePoint) {
|
|
425
|
+
content.push(cachePoint);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
394
428
|
async function shouldEnableCitations(providerMetadata) {
|
|
395
|
-
var _a, _b;
|
|
396
|
-
const
|
|
429
|
+
var _a, _b, _c;
|
|
430
|
+
const amazonBedrockOptions = (_a = await parseProviderOptions({
|
|
431
|
+
provider: "amazonBedrock",
|
|
432
|
+
providerOptions: providerMetadata,
|
|
433
|
+
schema: amazonBedrockFilePartProviderOptions
|
|
434
|
+
})) != null ? _a : await parseProviderOptions({
|
|
397
435
|
provider: "bedrock",
|
|
398
436
|
providerOptions: providerMetadata,
|
|
399
|
-
schema:
|
|
437
|
+
schema: amazonBedrockFilePartProviderOptions
|
|
400
438
|
});
|
|
401
|
-
return (
|
|
439
|
+
return (_c = (_b = amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.citations) == null ? void 0 : _b.enabled) != null ? _c : false;
|
|
402
440
|
}
|
|
403
|
-
async function
|
|
404
|
-
var _a;
|
|
441
|
+
async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
442
|
+
var _a, _b;
|
|
405
443
|
const blocks = groupIntoBlocks(prompt);
|
|
406
444
|
let system = [];
|
|
407
445
|
const messages = [];
|
|
@@ -414,7 +452,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
414
452
|
switch (type) {
|
|
415
453
|
case "system": {
|
|
416
454
|
if (messages.length > 0) {
|
|
417
|
-
throw new
|
|
455
|
+
throw new UnsupportedFunctionalityError2({
|
|
418
456
|
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
419
457
|
});
|
|
420
458
|
}
|
|
@@ -428,7 +466,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
428
466
|
break;
|
|
429
467
|
}
|
|
430
468
|
case "user": {
|
|
431
|
-
const
|
|
469
|
+
const amazonBedrockContent = [];
|
|
432
470
|
for (const message of block.messages) {
|
|
433
471
|
const { role, content, providerOptions } = message;
|
|
434
472
|
switch (role) {
|
|
@@ -437,48 +475,79 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
437
475
|
const part = content[j];
|
|
438
476
|
switch (part.type) {
|
|
439
477
|
case "text": {
|
|
440
|
-
|
|
478
|
+
amazonBedrockContent.push({
|
|
441
479
|
text: part.text
|
|
442
480
|
});
|
|
443
481
|
break;
|
|
444
482
|
}
|
|
445
483
|
case "file": {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
if (part.mediaType.startsWith("image/")) {
|
|
452
|
-
bedrockContent.push({
|
|
453
|
-
image: {
|
|
454
|
-
format: getBedrockImageFormat(part.mediaType),
|
|
455
|
-
source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) }
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
} else {
|
|
459
|
-
if (!part.mediaType) {
|
|
460
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
461
|
-
functionality: "file without mime type",
|
|
462
|
-
message: "File mime type is required in user message part content"
|
|
484
|
+
switch (part.data.type) {
|
|
485
|
+
case "reference": {
|
|
486
|
+
throw new UnsupportedFunctionalityError2({
|
|
487
|
+
functionality: "file parts with provider references"
|
|
463
488
|
});
|
|
464
489
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
490
|
+
case "url": {
|
|
491
|
+
throw new UnsupportedFunctionalityError2({
|
|
492
|
+
functionality: "File URL data"
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
case "text": {
|
|
496
|
+
const textMediaType = isFullMediaType(part.mediaType) ? part.mediaType : "text/plain";
|
|
497
|
+
const enableCitations = await shouldEnableCitations(
|
|
498
|
+
part.providerOptions
|
|
499
|
+
);
|
|
500
|
+
amazonBedrockContent.push({
|
|
501
|
+
document: {
|
|
502
|
+
format: getAmazonBedrockDocumentFormat(textMediaType),
|
|
503
|
+
name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
|
|
504
|
+
source: {
|
|
505
|
+
bytes: convertToBase64(
|
|
506
|
+
new TextEncoder().encode(part.data.text)
|
|
507
|
+
)
|
|
508
|
+
},
|
|
509
|
+
...enableCitations && {
|
|
510
|
+
citations: { enabled: true }
|
|
511
|
+
}
|
|
475
512
|
}
|
|
513
|
+
});
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
case "data": {
|
|
517
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
518
|
+
if (getTopLevelMediaType(fullMediaType) === "image") {
|
|
519
|
+
amazonBedrockContent.push({
|
|
520
|
+
image: {
|
|
521
|
+
format: getAmazonBedrockImageFormat(fullMediaType),
|
|
522
|
+
source: {
|
|
523
|
+
bytes: convertToBase64(part.data.data)
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
} else {
|
|
528
|
+
const enableCitations = await shouldEnableCitations(
|
|
529
|
+
part.providerOptions
|
|
530
|
+
);
|
|
531
|
+
amazonBedrockContent.push({
|
|
532
|
+
document: {
|
|
533
|
+
format: getAmazonBedrockDocumentFormat(fullMediaType),
|
|
534
|
+
name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
|
|
535
|
+
source: {
|
|
536
|
+
bytes: convertToBase64(part.data.data)
|
|
537
|
+
},
|
|
538
|
+
...enableCitations && {
|
|
539
|
+
citations: { enabled: true }
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
});
|
|
476
543
|
}
|
|
477
|
-
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
478
546
|
}
|
|
479
547
|
break;
|
|
480
548
|
}
|
|
481
549
|
}
|
|
550
|
+
pushCachePoint(amazonBedrockContent, part.providerOptions);
|
|
482
551
|
}
|
|
483
552
|
break;
|
|
484
553
|
}
|
|
@@ -491,32 +560,58 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
491
560
|
const output = part.output;
|
|
492
561
|
switch (output.type) {
|
|
493
562
|
case "content": {
|
|
494
|
-
toolResultContent =
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
563
|
+
toolResultContent = await Promise.all(
|
|
564
|
+
output.value.map(async (contentPart) => {
|
|
565
|
+
switch (contentPart.type) {
|
|
566
|
+
case "text":
|
|
567
|
+
return { text: contentPart.text };
|
|
568
|
+
case "file": {
|
|
569
|
+
if (contentPart.data.type !== "data") {
|
|
570
|
+
throw new UnsupportedFunctionalityError2({
|
|
571
|
+
functionality: `tool result file data of type "${contentPart.data.type}"`
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
const fullMediaType = resolveFullMediaType({
|
|
575
|
+
part: contentPart
|
|
502
576
|
});
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
577
|
+
if (getTopLevelMediaType(fullMediaType) !== "image") {
|
|
578
|
+
const enableCitations = await shouldEnableCitations(
|
|
579
|
+
contentPart.providerOptions
|
|
580
|
+
);
|
|
581
|
+
return {
|
|
582
|
+
document: {
|
|
583
|
+
format: getAmazonBedrockDocumentFormat(
|
|
584
|
+
fullMediaType
|
|
585
|
+
),
|
|
586
|
+
name: contentPart.filename ? stripFileExtension(contentPart.filename) : generateDocumentName(),
|
|
587
|
+
source: {
|
|
588
|
+
bytes: convertToBase64(
|
|
589
|
+
contentPart.data.data
|
|
590
|
+
)
|
|
591
|
+
},
|
|
592
|
+
...enableCitations && {
|
|
593
|
+
citations: { enabled: true }
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
};
|
|
511
597
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
598
|
+
return {
|
|
599
|
+
image: {
|
|
600
|
+
format: getAmazonBedrockImageFormat(fullMediaType),
|
|
601
|
+
source: {
|
|
602
|
+
bytes: convertToBase64(contentPart.data.data)
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
default: {
|
|
608
|
+
throw new UnsupportedFunctionalityError2({
|
|
609
|
+
functionality: `unsupported tool content part type: ${contentPart.type}`
|
|
610
|
+
});
|
|
611
|
+
}
|
|
517
612
|
}
|
|
518
|
-
}
|
|
519
|
-
|
|
613
|
+
})
|
|
614
|
+
);
|
|
520
615
|
break;
|
|
521
616
|
}
|
|
522
617
|
case "text":
|
|
@@ -525,7 +620,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
525
620
|
break;
|
|
526
621
|
case "execution-denied":
|
|
527
622
|
toolResultContent = [
|
|
528
|
-
{ text: (_a = output.reason) != null ? _a : "Tool execution denied." }
|
|
623
|
+
{ text: (_a = output.reason) != null ? _a : "Tool call execution denied." }
|
|
529
624
|
];
|
|
530
625
|
break;
|
|
531
626
|
case "json":
|
|
@@ -536,12 +631,13 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
536
631
|
];
|
|
537
632
|
break;
|
|
538
633
|
}
|
|
539
|
-
|
|
634
|
+
amazonBedrockContent.push({
|
|
540
635
|
toolResult: {
|
|
541
636
|
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
542
637
|
content: toolResultContent
|
|
543
638
|
}
|
|
544
639
|
});
|
|
640
|
+
pushCachePoint(amazonBedrockContent, part.providerOptions);
|
|
545
641
|
}
|
|
546
642
|
break;
|
|
547
643
|
}
|
|
@@ -550,29 +646,29 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
550
646
|
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
551
647
|
}
|
|
552
648
|
}
|
|
553
|
-
|
|
554
|
-
if (cachePoint) {
|
|
555
|
-
bedrockContent.push(cachePoint);
|
|
556
|
-
}
|
|
649
|
+
pushCachePoint(amazonBedrockContent, providerOptions);
|
|
557
650
|
}
|
|
558
|
-
messages.push({ role: "user", content:
|
|
651
|
+
messages.push({ role: "user", content: amazonBedrockContent });
|
|
559
652
|
break;
|
|
560
653
|
}
|
|
561
654
|
case "assistant": {
|
|
562
|
-
const
|
|
655
|
+
const amazonBedrockContent = [];
|
|
563
656
|
for (let j = 0; j < block.messages.length; j++) {
|
|
564
657
|
const message = block.messages[j];
|
|
565
658
|
const isLastMessage = j === block.messages.length - 1;
|
|
566
659
|
const { content } = message;
|
|
660
|
+
const hasReasoningBlocks = content.some(
|
|
661
|
+
(part) => part.type === "reasoning"
|
|
662
|
+
);
|
|
567
663
|
for (let k = 0; k < content.length; k++) {
|
|
568
664
|
const part = content[k];
|
|
569
665
|
const isLastContentPart = k === content.length - 1;
|
|
570
666
|
switch (part.type) {
|
|
571
667
|
case "text": {
|
|
572
|
-
if (!part.text.trim()) {
|
|
668
|
+
if (!part.text.trim() && !hasReasoningBlocks) {
|
|
573
669
|
break;
|
|
574
670
|
}
|
|
575
|
-
|
|
671
|
+
amazonBedrockContent.push({
|
|
576
672
|
text: (
|
|
577
673
|
// trim the last text part if it's the last message in the block
|
|
578
674
|
// because Bedrock does not allow trailing whitespace
|
|
@@ -588,43 +684,37 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
588
684
|
break;
|
|
589
685
|
}
|
|
590
686
|
case "reasoning": {
|
|
591
|
-
const reasoningMetadata = await
|
|
687
|
+
const reasoningMetadata = (_b = await parseProviderOptions({
|
|
688
|
+
provider: "amazonBedrock",
|
|
689
|
+
providerOptions: part.providerOptions,
|
|
690
|
+
schema: amazonBedrockReasoningMetadataSchema
|
|
691
|
+
})) != null ? _b : await parseProviderOptions({
|
|
592
692
|
provider: "bedrock",
|
|
593
693
|
providerOptions: part.providerOptions,
|
|
594
|
-
schema:
|
|
694
|
+
schema: amazonBedrockReasoningMetadataSchema
|
|
595
695
|
});
|
|
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
|
-
}
|
|
696
|
+
if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
|
|
697
|
+
amazonBedrockContent.push({
|
|
698
|
+
reasoningContent: {
|
|
699
|
+
reasoningText: {
|
|
700
|
+
text: part.text,
|
|
701
|
+
signature: reasoningMetadata.signature
|
|
612
702
|
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
706
|
+
amazonBedrockContent.push({
|
|
707
|
+
reasoningContent: {
|
|
708
|
+
redactedReasoning: {
|
|
709
|
+
data: reasoningMetadata.redactedData
|
|
620
710
|
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
711
|
+
}
|
|
712
|
+
});
|
|
623
713
|
}
|
|
624
714
|
break;
|
|
625
715
|
}
|
|
626
716
|
case "tool-call": {
|
|
627
|
-
|
|
717
|
+
amazonBedrockContent.push({
|
|
628
718
|
toolUse: {
|
|
629
719
|
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
630
720
|
name: part.toolName,
|
|
@@ -634,13 +724,11 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
634
724
|
break;
|
|
635
725
|
}
|
|
636
726
|
}
|
|
727
|
+
pushCachePoint(amazonBedrockContent, part.providerOptions);
|
|
637
728
|
}
|
|
638
|
-
|
|
639
|
-
if (cachePoint) {
|
|
640
|
-
bedrockContent.push(cachePoint);
|
|
641
|
-
}
|
|
729
|
+
pushCachePoint(amazonBedrockContent, message.providerOptions);
|
|
642
730
|
}
|
|
643
|
-
messages.push({ role: "assistant", content:
|
|
731
|
+
messages.push({ role: "assistant", content: amazonBedrockContent });
|
|
644
732
|
break;
|
|
645
733
|
}
|
|
646
734
|
default: {
|
|
@@ -651,26 +739,20 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
651
739
|
}
|
|
652
740
|
return { system, messages };
|
|
653
741
|
}
|
|
654
|
-
function
|
|
655
|
-
if (!mimeType) {
|
|
656
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
657
|
-
functionality: "image without mime type",
|
|
658
|
-
message: "Image mime type is required in user message part content"
|
|
659
|
-
});
|
|
660
|
-
}
|
|
742
|
+
function getAmazonBedrockImageFormat(mimeType) {
|
|
661
743
|
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
662
744
|
if (!format) {
|
|
663
|
-
throw new
|
|
745
|
+
throw new UnsupportedFunctionalityError2({
|
|
664
746
|
functionality: `image mime type: ${mimeType}`,
|
|
665
747
|
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
666
748
|
});
|
|
667
749
|
}
|
|
668
750
|
return format;
|
|
669
751
|
}
|
|
670
|
-
function
|
|
752
|
+
function getAmazonBedrockDocumentFormat(mimeType) {
|
|
671
753
|
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
672
754
|
if (!format) {
|
|
673
|
-
throw new
|
|
755
|
+
throw new UnsupportedFunctionalityError2({
|
|
674
756
|
functionality: `file mime type: ${mimeType}`,
|
|
675
757
|
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
676
758
|
});
|
|
@@ -727,8 +809,8 @@ function groupIntoBlocks(prompt) {
|
|
|
727
809
|
return blocks;
|
|
728
810
|
}
|
|
729
811
|
|
|
730
|
-
// src/map-bedrock-finish-reason.ts
|
|
731
|
-
function
|
|
812
|
+
// src/map-amazon-bedrock-finish-reason.ts
|
|
813
|
+
function mapAmazonBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
732
814
|
switch (finishReason) {
|
|
733
815
|
case "stop_sequence":
|
|
734
816
|
case "end_turn":
|
|
@@ -745,8 +827,8 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
745
827
|
}
|
|
746
828
|
}
|
|
747
829
|
|
|
748
|
-
// src/bedrock-chat-language-model.ts
|
|
749
|
-
var
|
|
830
|
+
// src/amazon-bedrock-chat-language-model.ts
|
|
831
|
+
var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
750
832
|
constructor(modelId, config) {
|
|
751
833
|
this.modelId = modelId;
|
|
752
834
|
this.config = config;
|
|
@@ -756,6 +838,15 @@ var BedrockChatLanguageModel = class {
|
|
|
756
838
|
// no supported urls for bedrock
|
|
757
839
|
};
|
|
758
840
|
}
|
|
841
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
842
|
+
return serializeModelOptions({
|
|
843
|
+
modelId: model.modelId,
|
|
844
|
+
config: model.config
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
848
|
+
return new _AmazonBedrockChatLanguageModel(options.modelId, options.config);
|
|
849
|
+
}
|
|
759
850
|
async getArgs({
|
|
760
851
|
prompt,
|
|
761
852
|
maxOutputTokens,
|
|
@@ -769,14 +860,19 @@ var BedrockChatLanguageModel = class {
|
|
|
769
860
|
seed,
|
|
770
861
|
tools,
|
|
771
862
|
toolChoice,
|
|
863
|
+
reasoning,
|
|
772
864
|
providerOptions
|
|
773
865
|
}) {
|
|
774
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
775
|
-
|
|
866
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
867
|
+
let amazonBedrockOptions = (_b = (_a = await parseProviderOptions2({
|
|
868
|
+
provider: "amazonBedrock",
|
|
869
|
+
providerOptions,
|
|
870
|
+
schema: amazonBedrockLanguageModelChatOptions
|
|
871
|
+
})) != null ? _a : await parseProviderOptions2({
|
|
776
872
|
provider: "bedrock",
|
|
777
873
|
providerOptions,
|
|
778
|
-
schema:
|
|
779
|
-
})) != null ?
|
|
874
|
+
schema: amazonBedrockLanguageModelChatOptions
|
|
875
|
+
})) != null ? _b : {};
|
|
780
876
|
const warnings = [];
|
|
781
877
|
if (frequencyPenalty != null) {
|
|
782
878
|
warnings.push({
|
|
@@ -819,8 +915,17 @@ var BedrockChatLanguageModel = class {
|
|
|
819
915
|
});
|
|
820
916
|
}
|
|
821
917
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
822
|
-
const
|
|
823
|
-
|
|
918
|
+
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
919
|
+
amazonBedrockOptions = resolveAmazonBedrockReasoningConfig({
|
|
920
|
+
reasoning,
|
|
921
|
+
amazonBedrockOptions,
|
|
922
|
+
warnings,
|
|
923
|
+
isAnthropicModel,
|
|
924
|
+
modelId: this.modelId
|
|
925
|
+
});
|
|
926
|
+
const isThinkingEnabled = ((_c = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "enabled" || ((_d = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _d.type) === "adaptive";
|
|
927
|
+
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
928
|
+
const useNativeStructuredOutput = isAnthropicModel && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
824
929
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
825
930
|
type: "function",
|
|
826
931
|
name: "json",
|
|
@@ -834,21 +939,22 @@ var BedrockChatLanguageModel = class {
|
|
|
834
939
|
});
|
|
835
940
|
warnings.push(...toolWarnings);
|
|
836
941
|
if (additionalTools) {
|
|
837
|
-
|
|
838
|
-
...
|
|
942
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
943
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
839
944
|
...additionalTools
|
|
840
945
|
};
|
|
841
946
|
}
|
|
842
|
-
if (betas.size > 0 ||
|
|
843
|
-
const existingBetas = (
|
|
947
|
+
if (betas.size > 0 || amazonBedrockOptions.anthropicBeta) {
|
|
948
|
+
const existingBetas = (_e = amazonBedrockOptions.anthropicBeta) != null ? _e : [];
|
|
844
949
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
845
|
-
|
|
846
|
-
...
|
|
950
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
951
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
847
952
|
anthropic_beta: mergedBetas
|
|
848
953
|
};
|
|
849
954
|
}
|
|
850
|
-
const thinkingType = (
|
|
851
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
955
|
+
const thinkingType = (_f = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _f.type;
|
|
956
|
+
const thinkingBudget = thinkingType === "enabled" ? (_g = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _g.budgetTokens : void 0;
|
|
957
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_h = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _h.display : void 0;
|
|
852
958
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
853
959
|
const inferenceConfig = {
|
|
854
960
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -864,23 +970,24 @@ var BedrockChatLanguageModel = class {
|
|
|
864
970
|
} else {
|
|
865
971
|
inferenceConfig.maxTokens = thinkingBudget + 4096;
|
|
866
972
|
}
|
|
867
|
-
|
|
868
|
-
...
|
|
973
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
974
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
869
975
|
thinking: {
|
|
870
976
|
type: "enabled",
|
|
871
977
|
budget_tokens: thinkingBudget
|
|
872
978
|
}
|
|
873
979
|
};
|
|
874
980
|
} else if (thinkingType === "adaptive") {
|
|
875
|
-
|
|
876
|
-
...
|
|
981
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
982
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
877
983
|
thinking: {
|
|
878
|
-
type: "adaptive"
|
|
984
|
+
type: "adaptive",
|
|
985
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
879
986
|
}
|
|
880
987
|
};
|
|
881
988
|
}
|
|
882
989
|
} else if (!isAnthropicModel) {
|
|
883
|
-
if (((
|
|
990
|
+
if (((_i = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens) != null) {
|
|
884
991
|
warnings.push({
|
|
885
992
|
type: "unsupported",
|
|
886
993
|
feature: "budgetTokens",
|
|
@@ -895,25 +1002,24 @@ var BedrockChatLanguageModel = class {
|
|
|
895
1002
|
});
|
|
896
1003
|
}
|
|
897
1004
|
}
|
|
898
|
-
const maxReasoningEffort = (
|
|
899
|
-
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
1005
|
+
const maxReasoningEffort = (_j = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _j.maxReasoningEffort;
|
|
900
1006
|
if (maxReasoningEffort != null) {
|
|
901
1007
|
if (isAnthropicModel) {
|
|
902
|
-
|
|
903
|
-
...
|
|
1008
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1009
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
904
1010
|
output_config: {
|
|
905
|
-
...(
|
|
1011
|
+
...(_k = amazonBedrockOptions.additionalModelRequestFields) == null ? void 0 : _k.output_config,
|
|
906
1012
|
effort: maxReasoningEffort
|
|
907
1013
|
}
|
|
908
1014
|
};
|
|
909
1015
|
} else if (isOpenAIModel) {
|
|
910
|
-
|
|
911
|
-
...
|
|
1016
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1017
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
912
1018
|
reasoning_effort: maxReasoningEffort
|
|
913
1019
|
};
|
|
914
1020
|
} else {
|
|
915
|
-
|
|
916
|
-
...
|
|
1021
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1022
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
917
1023
|
reasoningConfig: {
|
|
918
1024
|
...thinkingType != null && thinkingType !== "adaptive" && { type: thinkingType },
|
|
919
1025
|
...thinkingBudget != null && { budgetTokens: thinkingBudget },
|
|
@@ -923,10 +1029,10 @@ var BedrockChatLanguageModel = class {
|
|
|
923
1029
|
}
|
|
924
1030
|
}
|
|
925
1031
|
if (useNativeStructuredOutput) {
|
|
926
|
-
|
|
927
|
-
...
|
|
1032
|
+
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1033
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
928
1034
|
output_config: {
|
|
929
|
-
...(
|
|
1035
|
+
...(_l = amazonBedrockOptions.additionalModelRequestFields) == null ? void 0 : _l.output_config,
|
|
930
1036
|
format: {
|
|
931
1037
|
type: "json_schema",
|
|
932
1038
|
schema: responseFormat.schema
|
|
@@ -958,7 +1064,7 @@ var BedrockChatLanguageModel = class {
|
|
|
958
1064
|
details: "topK is not supported when thinking is enabled"
|
|
959
1065
|
});
|
|
960
1066
|
}
|
|
961
|
-
const hasAnyTools = ((
|
|
1067
|
+
const hasAnyTools = ((_n = (_m = toolConfig.tools) == null ? void 0 : _m.length) != null ? _n : 0) > 0 || additionalTools;
|
|
962
1068
|
let filteredPrompt = prompt;
|
|
963
1069
|
if (!hasAnyTools) {
|
|
964
1070
|
const hasToolContent = prompt.some(
|
|
@@ -985,28 +1091,34 @@ var BedrockChatLanguageModel = class {
|
|
|
985
1091
|
}
|
|
986
1092
|
}
|
|
987
1093
|
const isMistral = isMistralModel(this.modelId);
|
|
988
|
-
const { system, messages } = await
|
|
1094
|
+
const { system, messages } = await convertToAmazonBedrockChatMessages(
|
|
989
1095
|
filteredPrompt,
|
|
990
1096
|
isMistral
|
|
991
1097
|
);
|
|
992
1098
|
const {
|
|
993
1099
|
reasoningConfig: _,
|
|
994
1100
|
additionalModelRequestFields: __,
|
|
995
|
-
|
|
996
|
-
|
|
1101
|
+
serviceTier: ___,
|
|
1102
|
+
...filteredAmazonBedrockOptions
|
|
1103
|
+
} = (_p = (_o = providerOptions == null ? void 0 : providerOptions.amazonBedrock) != null ? _o : providerOptions == null ? void 0 : providerOptions.bedrock) != null ? _p : {};
|
|
997
1104
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
998
1105
|
return {
|
|
999
1106
|
command: {
|
|
1000
1107
|
system,
|
|
1001
1108
|
messages,
|
|
1002
|
-
additionalModelRequestFields:
|
|
1109
|
+
additionalModelRequestFields: amazonBedrockOptions.additionalModelRequestFields,
|
|
1003
1110
|
...additionalModelResponseFieldPaths && {
|
|
1004
1111
|
additionalModelResponseFieldPaths
|
|
1005
1112
|
},
|
|
1006
1113
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
1007
1114
|
inferenceConfig
|
|
1008
1115
|
},
|
|
1009
|
-
...
|
|
1116
|
+
...amazonBedrockOptions.serviceTier != null && {
|
|
1117
|
+
serviceTier: {
|
|
1118
|
+
type: amazonBedrockOptions.serviceTier
|
|
1119
|
+
}
|
|
1120
|
+
},
|
|
1121
|
+
...filteredAmazonBedrockOptions,
|
|
1010
1122
|
...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
|
|
1011
1123
|
},
|
|
1012
1124
|
warnings,
|
|
@@ -1017,7 +1129,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1017
1129
|
async getHeaders({
|
|
1018
1130
|
headers
|
|
1019
1131
|
}) {
|
|
1020
|
-
return
|
|
1132
|
+
return combineHeaders(
|
|
1133
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
1134
|
+
headers
|
|
1135
|
+
);
|
|
1021
1136
|
}
|
|
1022
1137
|
async doGenerate(options) {
|
|
1023
1138
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
@@ -1027,19 +1142,19 @@ var BedrockChatLanguageModel = class {
|
|
|
1027
1142
|
usesJsonResponseTool
|
|
1028
1143
|
} = await this.getArgs(options);
|
|
1029
1144
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
1030
|
-
const { value: response, responseHeaders } = await
|
|
1145
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1031
1146
|
url,
|
|
1032
1147
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1033
1148
|
body: args,
|
|
1034
|
-
failedResponseHandler:
|
|
1035
|
-
errorSchema:
|
|
1149
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
1150
|
+
errorSchema: AmazonBedrockErrorSchema,
|
|
1036
1151
|
errorToMessage: (error) => {
|
|
1037
1152
|
var _a2;
|
|
1038
1153
|
return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
|
|
1039
1154
|
}
|
|
1040
1155
|
}),
|
|
1041
|
-
successfulResponseHandler:
|
|
1042
|
-
|
|
1156
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1157
|
+
AmazonBedrockResponseSchema
|
|
1043
1158
|
),
|
|
1044
1159
|
abortSignal: options.abortSignal,
|
|
1045
1160
|
fetch: this.config.fetch
|
|
@@ -1047,7 +1162,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1047
1162
|
const content = [];
|
|
1048
1163
|
let isJsonResponseFromTool = false;
|
|
1049
1164
|
for (const part of response.output.message.content) {
|
|
1050
|
-
if (part.text) {
|
|
1165
|
+
if (part.text != null) {
|
|
1051
1166
|
content.push({ type: "text", text: part.text });
|
|
1052
1167
|
}
|
|
1053
1168
|
if (part.reasoningContent) {
|
|
@@ -1057,21 +1172,25 @@ var BedrockChatLanguageModel = class {
|
|
|
1057
1172
|
text: part.reasoningContent.reasoningText.text
|
|
1058
1173
|
};
|
|
1059
1174
|
if (part.reasoningContent.reasoningText.signature) {
|
|
1175
|
+
const reasoningPayload = {
|
|
1176
|
+
signature: part.reasoningContent.reasoningText.signature
|
|
1177
|
+
};
|
|
1060
1178
|
reasoning.providerMetadata = {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1179
|
+
amazonBedrock: reasoningPayload,
|
|
1180
|
+
bedrock: reasoningPayload
|
|
1064
1181
|
};
|
|
1065
1182
|
}
|
|
1066
1183
|
content.push(reasoning);
|
|
1067
1184
|
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
1185
|
+
const redactedPayload = {
|
|
1186
|
+
redactedData: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
|
|
1187
|
+
};
|
|
1068
1188
|
content.push({
|
|
1069
1189
|
type: "reasoning",
|
|
1070
1190
|
text: "",
|
|
1071
1191
|
providerMetadata: {
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
}
|
|
1192
|
+
amazonBedrock: redactedPayload,
|
|
1193
|
+
bedrock: redactedPayload
|
|
1075
1194
|
}
|
|
1076
1195
|
});
|
|
1077
1196
|
}
|
|
@@ -1097,39 +1216,41 @@ var BedrockChatLanguageModel = class {
|
|
|
1097
1216
|
}
|
|
1098
1217
|
}
|
|
1099
1218
|
const stopSequence = (_j = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.delta) == null ? void 0 : _i.stop_sequence) != null ? _j : null;
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
usage
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
cacheDetails: response.usage.cacheDetails
|
|
1116
|
-
}
|
|
1219
|
+
const providerMetadataPayload = response.trace || response.usage || response.performanceConfig || response.serviceTier || isJsonResponseFromTool || stopSequence ? {
|
|
1220
|
+
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
1221
|
+
...response.performanceConfig && {
|
|
1222
|
+
performanceConfig: response.performanceConfig
|
|
1223
|
+
},
|
|
1224
|
+
...response.serviceTier && {
|
|
1225
|
+
serviceTier: response.serviceTier
|
|
1226
|
+
},
|
|
1227
|
+
...(((_k = response.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null || ((_l = response.usage) == null ? void 0 : _l.cacheDetails) != null) && {
|
|
1228
|
+
usage: {
|
|
1229
|
+
...response.usage.cacheWriteInputTokens != null && {
|
|
1230
|
+
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
1231
|
+
},
|
|
1232
|
+
...response.usage.cacheDetails != null && {
|
|
1233
|
+
cacheDetails: response.usage.cacheDetails
|
|
1117
1234
|
}
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
...isJsonResponseFromTool && { isJsonResponseFromTool: true },
|
|
1238
|
+
stopSequence
|
|
1239
|
+
} : void 0;
|
|
1240
|
+
const providerMetadata = providerMetadataPayload ? {
|
|
1241
|
+
amazonBedrock: providerMetadataPayload,
|
|
1242
|
+
bedrock: providerMetadataPayload
|
|
1122
1243
|
} : void 0;
|
|
1123
1244
|
return {
|
|
1124
1245
|
content,
|
|
1125
1246
|
finishReason: {
|
|
1126
|
-
unified:
|
|
1247
|
+
unified: mapAmazonBedrockFinishReason(
|
|
1127
1248
|
response.stopReason,
|
|
1128
1249
|
isJsonResponseFromTool
|
|
1129
1250
|
),
|
|
1130
1251
|
raw: (_m = response.stopReason) != null ? _m : void 0
|
|
1131
1252
|
},
|
|
1132
|
-
usage:
|
|
1253
|
+
usage: convertAmazonBedrockUsage(response.usage),
|
|
1133
1254
|
response: {
|
|
1134
1255
|
id: (_n = responseHeaders == null ? void 0 : responseHeaders["x-amzn-requestid"]) != null ? _n : void 0,
|
|
1135
1256
|
timestamp: (responseHeaders == null ? void 0 : responseHeaders["date"]) != null ? new Date(responseHeaders["date"]) : void 0,
|
|
@@ -1149,15 +1270,17 @@ var BedrockChatLanguageModel = class {
|
|
|
1149
1270
|
const modelId = this.modelId;
|
|
1150
1271
|
const isMistral = isMistralModel(modelId);
|
|
1151
1272
|
const url = `${this.getUrl(modelId)}/converse-stream`;
|
|
1152
|
-
const { value: response, responseHeaders } = await
|
|
1273
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1153
1274
|
url,
|
|
1154
1275
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1155
1276
|
body: args,
|
|
1156
|
-
failedResponseHandler:
|
|
1157
|
-
errorSchema:
|
|
1277
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
1278
|
+
errorSchema: AmazonBedrockErrorSchema,
|
|
1158
1279
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1159
1280
|
}),
|
|
1160
|
-
successfulResponseHandler:
|
|
1281
|
+
successfulResponseHandler: createAmazonBedrockEventStreamResponseHandler(
|
|
1282
|
+
AmazonBedrockStreamSchema
|
|
1283
|
+
),
|
|
1161
1284
|
abortSignal: options.abortSignal,
|
|
1162
1285
|
fetch: this.config.fetch
|
|
1163
1286
|
});
|
|
@@ -1185,9 +1308,9 @@ var BedrockChatLanguageModel = class {
|
|
|
1185
1308
|
},
|
|
1186
1309
|
transform(chunk, controller) {
|
|
1187
1310
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1188
|
-
function enqueueError(
|
|
1311
|
+
function enqueueError(amazonBedrockError) {
|
|
1189
1312
|
finishReason = { unified: "error", raw: void 0 };
|
|
1190
|
-
controller.enqueue({ type: "error", error:
|
|
1313
|
+
controller.enqueue({ type: "error", error: amazonBedrockError });
|
|
1191
1314
|
}
|
|
1192
1315
|
if (options.includeRawChunks) {
|
|
1193
1316
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
@@ -1215,7 +1338,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1215
1338
|
}
|
|
1216
1339
|
if (value.messageStop) {
|
|
1217
1340
|
finishReason = {
|
|
1218
|
-
unified:
|
|
1341
|
+
unified: mapAmazonBedrockFinishReason(
|
|
1219
1342
|
value.messageStop.stopReason,
|
|
1220
1343
|
isJsonResponseFromTool
|
|
1221
1344
|
),
|
|
@@ -1241,18 +1364,20 @@ var BedrockChatLanguageModel = class {
|
|
|
1241
1364
|
trace: value.metadata.trace
|
|
1242
1365
|
} : void 0;
|
|
1243
1366
|
if (cacheUsage || trace || value.metadata.performanceConfig || value.metadata.serviceTier) {
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
serviceTier: value.metadata.serviceTier
|
|
1253
|
-
}
|
|
1367
|
+
const metadataPayload = {
|
|
1368
|
+
...cacheUsage,
|
|
1369
|
+
...trace,
|
|
1370
|
+
...value.metadata.performanceConfig && {
|
|
1371
|
+
performanceConfig: value.metadata.performanceConfig
|
|
1372
|
+
},
|
|
1373
|
+
...value.metadata.serviceTier && {
|
|
1374
|
+
serviceTier: value.metadata.serviceTier
|
|
1254
1375
|
}
|
|
1255
1376
|
};
|
|
1377
|
+
providerMetadata = {
|
|
1378
|
+
amazonBedrock: metadataPayload,
|
|
1379
|
+
bedrock: metadataPayload
|
|
1380
|
+
};
|
|
1256
1381
|
}
|
|
1257
1382
|
}
|
|
1258
1383
|
if (((_i = value.contentBlockStart) == null ? void 0 : _i.contentBlockIndex) != null && !((_k = (_j = value.contentBlockStart) == null ? void 0 : _j.start) == null ? void 0 : _k.toolUse)) {
|
|
@@ -1341,27 +1466,49 @@ var BedrockChatLanguageModel = class {
|
|
|
1341
1466
|
delta: reasoningContent.text
|
|
1342
1467
|
});
|
|
1343
1468
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
1344
|
-
|
|
1345
|
-
type: "reasoning
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1469
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1470
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1471
|
+
controller.enqueue({
|
|
1472
|
+
type: "reasoning-start",
|
|
1473
|
+
id: String(blockIndex)
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
{
|
|
1477
|
+
const signaturePayload = {
|
|
1478
|
+
signature: reasoningContent.signature
|
|
1479
|
+
};
|
|
1480
|
+
controller.enqueue({
|
|
1481
|
+
type: "reasoning-delta",
|
|
1482
|
+
id: String(blockIndex),
|
|
1483
|
+
delta: "",
|
|
1484
|
+
providerMetadata: {
|
|
1485
|
+
amazonBedrock: signaturePayload,
|
|
1486
|
+
bedrock: signaturePayload
|
|
1351
1487
|
}
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1354
1490
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
1355
|
-
|
|
1356
|
-
type: "reasoning
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1491
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1492
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1493
|
+
controller.enqueue({
|
|
1494
|
+
type: "reasoning-start",
|
|
1495
|
+
id: String(blockIndex)
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
{
|
|
1499
|
+
const redactedPayload = {
|
|
1500
|
+
redactedData: reasoningContent.data
|
|
1501
|
+
};
|
|
1502
|
+
controller.enqueue({
|
|
1503
|
+
type: "reasoning-delta",
|
|
1504
|
+
id: String(blockIndex),
|
|
1505
|
+
delta: "",
|
|
1506
|
+
providerMetadata: {
|
|
1507
|
+
amazonBedrock: redactedPayload,
|
|
1508
|
+
bedrock: redactedPayload
|
|
1362
1509
|
}
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1365
1512
|
}
|
|
1366
1513
|
}
|
|
1367
1514
|
const contentBlockStart = value.contentBlockStart;
|
|
@@ -1406,30 +1553,25 @@ var BedrockChatLanguageModel = class {
|
|
|
1406
1553
|
}
|
|
1407
1554
|
},
|
|
1408
1555
|
flush(controller) {
|
|
1556
|
+
var _a;
|
|
1409
1557
|
if (isJsonResponseFromTool || stopSequence != null) {
|
|
1410
|
-
|
|
1411
|
-
providerMetadata.
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
isJsonResponseFromTool: true
|
|
1423
|
-
},
|
|
1424
|
-
stopSequence
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
}
|
|
1558
|
+
const updatePayload = {
|
|
1559
|
+
...(_a = providerMetadata == null ? void 0 : providerMetadata.amazonBedrock) != null ? _a : providerMetadata == null ? void 0 : providerMetadata.bedrock,
|
|
1560
|
+
...isJsonResponseFromTool && {
|
|
1561
|
+
isJsonResponseFromTool: true
|
|
1562
|
+
},
|
|
1563
|
+
stopSequence
|
|
1564
|
+
};
|
|
1565
|
+
providerMetadata = {
|
|
1566
|
+
...providerMetadata,
|
|
1567
|
+
amazonBedrock: updatePayload,
|
|
1568
|
+
bedrock: updatePayload
|
|
1569
|
+
};
|
|
1428
1570
|
}
|
|
1429
1571
|
controller.enqueue({
|
|
1430
1572
|
type: "finish",
|
|
1431
1573
|
finishReason,
|
|
1432
|
-
usage:
|
|
1574
|
+
usage: convertAmazonBedrockUsage(usage),
|
|
1433
1575
|
...providerMetadata && { providerMetadata }
|
|
1434
1576
|
});
|
|
1435
1577
|
}
|
|
@@ -1444,146 +1586,220 @@ var BedrockChatLanguageModel = class {
|
|
|
1444
1586
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
1445
1587
|
}
|
|
1446
1588
|
};
|
|
1447
|
-
var
|
|
1448
|
-
|
|
1449
|
-
|
|
1589
|
+
var AmazonBedrockStopReasonSchema = z4.union([
|
|
1590
|
+
z4.enum(BEDROCK_STOP_REASONS),
|
|
1591
|
+
z4.string()
|
|
1450
1592
|
]);
|
|
1451
|
-
var
|
|
1452
|
-
delta:
|
|
1453
|
-
stop_sequence:
|
|
1593
|
+
var AmazonBedrockAdditionalModelResponseFieldsSchema = z4.object({
|
|
1594
|
+
delta: z4.object({
|
|
1595
|
+
stop_sequence: z4.string().nullish()
|
|
1454
1596
|
}).nullish()
|
|
1455
|
-
}).catchall(
|
|
1456
|
-
var
|
|
1457
|
-
toolUseId:
|
|
1458
|
-
name:
|
|
1459
|
-
input:
|
|
1597
|
+
}).catchall(z4.unknown());
|
|
1598
|
+
var AmazonBedrockToolUseSchema = z4.object({
|
|
1599
|
+
toolUseId: z4.string(),
|
|
1600
|
+
name: z4.string(),
|
|
1601
|
+
input: z4.unknown().optional()
|
|
1460
1602
|
});
|
|
1461
|
-
var
|
|
1462
|
-
signature:
|
|
1463
|
-
text:
|
|
1603
|
+
var AmazonBedrockReasoningTextSchema = z4.object({
|
|
1604
|
+
signature: z4.string().nullish(),
|
|
1605
|
+
text: z4.string()
|
|
1464
1606
|
});
|
|
1465
|
-
var
|
|
1466
|
-
data:
|
|
1607
|
+
var AmazonBedrockRedactedReasoningSchema = z4.object({
|
|
1608
|
+
data: z4.string()
|
|
1467
1609
|
});
|
|
1468
|
-
var
|
|
1469
|
-
metrics:
|
|
1470
|
-
latencyMs:
|
|
1610
|
+
var AmazonBedrockResponseSchema = z4.object({
|
|
1611
|
+
metrics: z4.object({
|
|
1612
|
+
latencyMs: z4.number()
|
|
1471
1613
|
}).nullish(),
|
|
1472
|
-
output:
|
|
1473
|
-
message:
|
|
1474
|
-
content:
|
|
1475
|
-
|
|
1476
|
-
text:
|
|
1477
|
-
toolUse:
|
|
1478
|
-
reasoningContent:
|
|
1479
|
-
|
|
1480
|
-
reasoningText:
|
|
1614
|
+
output: z4.object({
|
|
1615
|
+
message: z4.object({
|
|
1616
|
+
content: z4.array(
|
|
1617
|
+
z4.object({
|
|
1618
|
+
text: z4.string().nullish(),
|
|
1619
|
+
toolUse: AmazonBedrockToolUseSchema.nullish(),
|
|
1620
|
+
reasoningContent: z4.union([
|
|
1621
|
+
z4.object({
|
|
1622
|
+
reasoningText: AmazonBedrockReasoningTextSchema
|
|
1481
1623
|
}),
|
|
1482
|
-
|
|
1483
|
-
redactedReasoning:
|
|
1624
|
+
z4.object({
|
|
1625
|
+
redactedReasoning: AmazonBedrockRedactedReasoningSchema
|
|
1484
1626
|
})
|
|
1485
1627
|
]).nullish()
|
|
1486
1628
|
})
|
|
1487
1629
|
),
|
|
1488
|
-
role:
|
|
1630
|
+
role: z4.string()
|
|
1489
1631
|
})
|
|
1490
1632
|
}),
|
|
1491
|
-
stopReason:
|
|
1492
|
-
additionalModelResponseFields:
|
|
1493
|
-
trace:
|
|
1494
|
-
performanceConfig:
|
|
1495
|
-
serviceTier:
|
|
1496
|
-
usage:
|
|
1497
|
-
inputTokens:
|
|
1498
|
-
outputTokens:
|
|
1499
|
-
totalTokens:
|
|
1500
|
-
cacheReadInputTokens:
|
|
1501
|
-
cacheWriteInputTokens:
|
|
1502
|
-
cacheDetails:
|
|
1633
|
+
stopReason: AmazonBedrockStopReasonSchema,
|
|
1634
|
+
additionalModelResponseFields: AmazonBedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1635
|
+
trace: z4.unknown().nullish(),
|
|
1636
|
+
performanceConfig: z4.object({ latency: z4.string() }).nullish(),
|
|
1637
|
+
serviceTier: z4.object({ type: z4.string() }).nullish(),
|
|
1638
|
+
usage: z4.object({
|
|
1639
|
+
inputTokens: z4.number(),
|
|
1640
|
+
outputTokens: z4.number(),
|
|
1641
|
+
totalTokens: z4.number(),
|
|
1642
|
+
cacheReadInputTokens: z4.number().nullish(),
|
|
1643
|
+
cacheWriteInputTokens: z4.number().nullish(),
|
|
1644
|
+
cacheDetails: z4.array(z4.object({ inputTokens: z4.number(), ttl: z4.string() })).nullish()
|
|
1503
1645
|
})
|
|
1504
1646
|
});
|
|
1505
|
-
var
|
|
1506
|
-
contentBlockDelta:
|
|
1507
|
-
contentBlockIndex:
|
|
1508
|
-
delta:
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
reasoningContent:
|
|
1647
|
+
var AmazonBedrockStreamSchema = z4.object({
|
|
1648
|
+
contentBlockDelta: z4.object({
|
|
1649
|
+
contentBlockIndex: z4.number(),
|
|
1650
|
+
delta: z4.union([
|
|
1651
|
+
z4.object({ text: z4.string() }),
|
|
1652
|
+
z4.object({ toolUse: z4.object({ input: z4.string() }) }),
|
|
1653
|
+
z4.object({
|
|
1654
|
+
reasoningContent: z4.object({ text: z4.string() })
|
|
1513
1655
|
}),
|
|
1514
|
-
|
|
1515
|
-
reasoningContent:
|
|
1516
|
-
signature:
|
|
1656
|
+
z4.object({
|
|
1657
|
+
reasoningContent: z4.object({
|
|
1658
|
+
signature: z4.string()
|
|
1517
1659
|
})
|
|
1518
1660
|
}),
|
|
1519
|
-
|
|
1520
|
-
reasoningContent:
|
|
1661
|
+
z4.object({
|
|
1662
|
+
reasoningContent: z4.object({ data: z4.string() })
|
|
1521
1663
|
})
|
|
1522
1664
|
]).nullish()
|
|
1523
1665
|
}).nullish(),
|
|
1524
|
-
contentBlockStart:
|
|
1525
|
-
contentBlockIndex:
|
|
1526
|
-
start:
|
|
1527
|
-
toolUse:
|
|
1666
|
+
contentBlockStart: z4.object({
|
|
1667
|
+
contentBlockIndex: z4.number(),
|
|
1668
|
+
start: z4.object({
|
|
1669
|
+
toolUse: AmazonBedrockToolUseSchema.nullish()
|
|
1528
1670
|
}).nullish()
|
|
1529
1671
|
}).nullish(),
|
|
1530
|
-
contentBlockStop:
|
|
1531
|
-
contentBlockIndex:
|
|
1672
|
+
contentBlockStop: z4.object({
|
|
1673
|
+
contentBlockIndex: z4.number()
|
|
1532
1674
|
}).nullish(),
|
|
1533
|
-
internalServerException:
|
|
1534
|
-
messageStop:
|
|
1535
|
-
additionalModelResponseFields:
|
|
1536
|
-
stopReason:
|
|
1675
|
+
internalServerException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1676
|
+
messageStop: z4.object({
|
|
1677
|
+
additionalModelResponseFields: AmazonBedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1678
|
+
stopReason: AmazonBedrockStopReasonSchema
|
|
1537
1679
|
}).nullish(),
|
|
1538
|
-
metadata:
|
|
1539
|
-
trace:
|
|
1540
|
-
performanceConfig:
|
|
1541
|
-
serviceTier:
|
|
1542
|
-
usage:
|
|
1543
|
-
cacheReadInputTokens:
|
|
1544
|
-
cacheWriteInputTokens:
|
|
1545
|
-
cacheDetails:
|
|
1546
|
-
inputTokens:
|
|
1547
|
-
outputTokens:
|
|
1680
|
+
metadata: z4.object({
|
|
1681
|
+
trace: z4.unknown().nullish(),
|
|
1682
|
+
performanceConfig: z4.object({ latency: z4.string() }).nullish(),
|
|
1683
|
+
serviceTier: z4.object({ type: z4.string() }).nullish(),
|
|
1684
|
+
usage: z4.object({
|
|
1685
|
+
cacheReadInputTokens: z4.number().nullish(),
|
|
1686
|
+
cacheWriteInputTokens: z4.number().nullish(),
|
|
1687
|
+
cacheDetails: z4.array(z4.object({ inputTokens: z4.number(), ttl: z4.string() })).nullish(),
|
|
1688
|
+
inputTokens: z4.number(),
|
|
1689
|
+
outputTokens: z4.number()
|
|
1548
1690
|
}).nullish()
|
|
1549
1691
|
}).nullish(),
|
|
1550
|
-
modelStreamErrorException:
|
|
1551
|
-
throttlingException:
|
|
1552
|
-
validationException:
|
|
1553
|
-
});
|
|
1554
|
-
var bedrockReasoningMetadataSchema = import_v43.z.object({
|
|
1555
|
-
signature: import_v43.z.string().optional(),
|
|
1556
|
-
redactedData: import_v43.z.string().optional()
|
|
1692
|
+
modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1693
|
+
throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1694
|
+
validationException: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1557
1695
|
});
|
|
1696
|
+
var amazonBedrockReasoningEffortMap = {
|
|
1697
|
+
minimal: "low",
|
|
1698
|
+
low: "low",
|
|
1699
|
+
medium: "medium",
|
|
1700
|
+
high: "high",
|
|
1701
|
+
xhigh: "max"
|
|
1702
|
+
};
|
|
1703
|
+
function resolveAmazonBedrockReasoningConfig({
|
|
1704
|
+
reasoning,
|
|
1705
|
+
amazonBedrockOptions,
|
|
1706
|
+
warnings,
|
|
1707
|
+
isAnthropicModel,
|
|
1708
|
+
modelId
|
|
1709
|
+
}) {
|
|
1710
|
+
var _a;
|
|
1711
|
+
if (!isCustomReasoning(reasoning)) {
|
|
1712
|
+
return amazonBedrockOptions;
|
|
1713
|
+
}
|
|
1714
|
+
const result = { ...amazonBedrockOptions };
|
|
1715
|
+
if (isAnthropicModel) {
|
|
1716
|
+
const capabilities = getModelCapabilities(modelId);
|
|
1717
|
+
if (reasoning === "none") {
|
|
1718
|
+
result.reasoningConfig = { type: "disabled" };
|
|
1719
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1720
|
+
const effort = mapReasoningToProviderEffort({
|
|
1721
|
+
reasoning,
|
|
1722
|
+
effortMap: amazonBedrockReasoningEffortMap,
|
|
1723
|
+
warnings
|
|
1724
|
+
});
|
|
1725
|
+
result.reasoningConfig = {
|
|
1726
|
+
type: "adaptive",
|
|
1727
|
+
maxReasoningEffort: effort,
|
|
1728
|
+
...amazonBedrockOptions.reasoningConfig
|
|
1729
|
+
};
|
|
1730
|
+
} else {
|
|
1731
|
+
const budgetTokens = mapReasoningToProviderBudget({
|
|
1732
|
+
reasoning,
|
|
1733
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1734
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1735
|
+
warnings
|
|
1736
|
+
});
|
|
1737
|
+
if (budgetTokens != null) {
|
|
1738
|
+
result.reasoningConfig = {
|
|
1739
|
+
type: "enabled",
|
|
1740
|
+
budgetTokens,
|
|
1741
|
+
...amazonBedrockOptions.reasoningConfig
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
} else if (reasoning !== "none") {
|
|
1746
|
+
const effort = mapReasoningToProviderEffort({
|
|
1747
|
+
reasoning,
|
|
1748
|
+
effortMap: amazonBedrockReasoningEffortMap,
|
|
1749
|
+
warnings
|
|
1750
|
+
});
|
|
1751
|
+
result.reasoningConfig = {
|
|
1752
|
+
maxReasoningEffort: effort,
|
|
1753
|
+
...amazonBedrockOptions.reasoningConfig
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
if (((_a = result.reasoningConfig) == null ? void 0 : _a.type) === "disabled") {
|
|
1757
|
+
delete result.reasoningConfig.maxReasoningEffort;
|
|
1758
|
+
delete result.reasoningConfig.budgetTokens;
|
|
1759
|
+
}
|
|
1760
|
+
return result;
|
|
1761
|
+
}
|
|
1558
1762
|
|
|
1559
|
-
// src/bedrock-embedding-model.ts
|
|
1560
|
-
|
|
1561
|
-
|
|
1763
|
+
// src/amazon-bedrock-embedding-model.ts
|
|
1764
|
+
import {
|
|
1765
|
+
TooManyEmbeddingValuesForCallError
|
|
1766
|
+
} from "@ai-sdk/provider";
|
|
1767
|
+
import {
|
|
1768
|
+
combineHeaders as combineHeaders2,
|
|
1769
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1770
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1771
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1772
|
+
postJsonToApi as postJsonToApi2,
|
|
1773
|
+
resolve as resolve2,
|
|
1774
|
+
serializeModelOptions as serializeModelOptions2,
|
|
1775
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
1776
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
1777
|
+
} from "@ai-sdk/provider-utils";
|
|
1562
1778
|
|
|
1563
|
-
// src/bedrock-embedding-options.ts
|
|
1564
|
-
|
|
1565
|
-
var amazonBedrockEmbeddingModelOptionsSchema =
|
|
1779
|
+
// src/amazon-bedrock-embedding-model-options.ts
|
|
1780
|
+
import { z as z5 } from "zod/v4";
|
|
1781
|
+
var amazonBedrockEmbeddingModelOptionsSchema = z5.object({
|
|
1566
1782
|
/**
|
|
1567
1783
|
* The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
1568
1784
|
* Only supported in amazon.titan-embed-text-v2:0.
|
|
1569
1785
|
*/
|
|
1570
|
-
dimensions:
|
|
1786
|
+
dimensions: z5.union([z5.literal(1024), z5.literal(512), z5.literal(256)]).optional(),
|
|
1571
1787
|
/**
|
|
1572
1788
|
* Flag indicating whether or not to normalize the output embeddings. Defaults to true.
|
|
1573
1789
|
* Only supported in amazon.titan-embed-text-v2:0.
|
|
1574
1790
|
*/
|
|
1575
|
-
normalize:
|
|
1791
|
+
normalize: z5.boolean().optional(),
|
|
1576
1792
|
/**
|
|
1577
1793
|
* The number of dimensions for Nova embedding models (defaults to 1024).
|
|
1578
1794
|
* Supported values: 256, 384, 1024, 3072.
|
|
1579
1795
|
* Only supported in amazon.nova-* embedding models.
|
|
1580
1796
|
*/
|
|
1581
|
-
embeddingDimension:
|
|
1797
|
+
embeddingDimension: z5.union([z5.literal(256), z5.literal(384), z5.literal(1024), z5.literal(3072)]).optional(),
|
|
1582
1798
|
/**
|
|
1583
1799
|
* The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
|
|
1584
1800
|
* Only supported in amazon.nova-* embedding models.
|
|
1585
1801
|
*/
|
|
1586
|
-
embeddingPurpose:
|
|
1802
|
+
embeddingPurpose: z5.enum([
|
|
1587
1803
|
"GENERIC_INDEX",
|
|
1588
1804
|
"TEXT_RETRIEVAL",
|
|
1589
1805
|
"IMAGE_RETRIEVAL",
|
|
@@ -1599,22 +1815,22 @@ var amazonBedrockEmbeddingModelOptionsSchema = import_v44.z.object({
|
|
|
1599
1815
|
* Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
1600
1816
|
* If not set, the provider defaults to `search_query`.
|
|
1601
1817
|
*/
|
|
1602
|
-
inputType:
|
|
1818
|
+
inputType: z5.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
1603
1819
|
/**
|
|
1604
1820
|
* Truncation behavior when input exceeds the model's context length.
|
|
1605
1821
|
* Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
|
|
1606
1822
|
*/
|
|
1607
|
-
truncate:
|
|
1823
|
+
truncate: z5.enum(["NONE", "START", "END"]).optional(),
|
|
1608
1824
|
/**
|
|
1609
1825
|
* The number of dimensions the resulting output embeddings should have (defaults to 1536).
|
|
1610
1826
|
* Only supported in cohere.embed-v4:0 and newer Cohere embedding models.
|
|
1611
1827
|
*/
|
|
1612
|
-
outputDimension:
|
|
1828
|
+
outputDimension: z5.union([z5.literal(256), z5.literal(512), z5.literal(1024), z5.literal(1536)]).optional()
|
|
1613
1829
|
});
|
|
1614
1830
|
|
|
1615
|
-
// src/bedrock-embedding-model.ts
|
|
1616
|
-
|
|
1617
|
-
var
|
|
1831
|
+
// src/amazon-bedrock-embedding-model.ts
|
|
1832
|
+
import { z as z6 } from "zod/v4";
|
|
1833
|
+
var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
1618
1834
|
constructor(modelId, config) {
|
|
1619
1835
|
this.modelId = modelId;
|
|
1620
1836
|
this.config = config;
|
|
@@ -1623,6 +1839,15 @@ var BedrockEmbeddingModel = class {
|
|
|
1623
1839
|
this.maxEmbeddingsPerCall = 1;
|
|
1624
1840
|
this.supportsParallelCalls = true;
|
|
1625
1841
|
}
|
|
1842
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
1843
|
+
return serializeModelOptions2({
|
|
1844
|
+
modelId: model.modelId,
|
|
1845
|
+
config: model.config
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
1849
|
+
return new _AmazonBedrockEmbeddingModel(options.modelId, options.config);
|
|
1850
|
+
}
|
|
1626
1851
|
getUrl(modelId) {
|
|
1627
1852
|
const encodedModelId = encodeURIComponent(modelId);
|
|
1628
1853
|
return `${this.config.baseUrl()}/model/${encodedModelId}/invoke`;
|
|
@@ -1633,57 +1858,64 @@ var BedrockEmbeddingModel = class {
|
|
|
1633
1858
|
abortSignal,
|
|
1634
1859
|
providerOptions
|
|
1635
1860
|
}) {
|
|
1636
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1861
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1637
1862
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1638
|
-
throw new
|
|
1863
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
1639
1864
|
provider: this.provider,
|
|
1640
1865
|
modelId: this.modelId,
|
|
1641
1866
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1642
1867
|
values
|
|
1643
1868
|
});
|
|
1644
1869
|
}
|
|
1645
|
-
const
|
|
1870
|
+
const amazonBedrockOptions = (_b = (_a = await parseProviderOptions3({
|
|
1871
|
+
provider: "amazonBedrock",
|
|
1872
|
+
providerOptions,
|
|
1873
|
+
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
1874
|
+
})) != null ? _a : await parseProviderOptions3({
|
|
1646
1875
|
provider: "bedrock",
|
|
1647
1876
|
providerOptions,
|
|
1648
1877
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
1649
|
-
})) != null ?
|
|
1878
|
+
})) != null ? _b : {};
|
|
1650
1879
|
const isNovaModel = this.modelId.startsWith("amazon.nova-") && this.modelId.includes("embed");
|
|
1651
|
-
const isCohereModel = this.modelId.
|
|
1880
|
+
const isCohereModel = this.modelId.includes("cohere.embed-");
|
|
1652
1881
|
const args = isNovaModel ? {
|
|
1653
1882
|
taskType: "SINGLE_EMBEDDING",
|
|
1654
1883
|
singleEmbeddingParams: {
|
|
1655
|
-
embeddingPurpose: (
|
|
1656
|
-
embeddingDimension: (
|
|
1884
|
+
embeddingPurpose: (_c = amazonBedrockOptions.embeddingPurpose) != null ? _c : "GENERIC_INDEX",
|
|
1885
|
+
embeddingDimension: (_d = amazonBedrockOptions.embeddingDimension) != null ? _d : 1024,
|
|
1657
1886
|
text: {
|
|
1658
|
-
truncationMode: (
|
|
1887
|
+
truncationMode: (_e = amazonBedrockOptions.truncate) != null ? _e : "END",
|
|
1659
1888
|
value: values[0]
|
|
1660
1889
|
}
|
|
1661
1890
|
}
|
|
1662
1891
|
} : isCohereModel ? {
|
|
1663
1892
|
// Cohere embedding models on Bedrock require `input_type`.
|
|
1664
1893
|
// Without it, the service attempts other schema branches and rejects the request.
|
|
1665
|
-
input_type: (
|
|
1894
|
+
input_type: (_f = amazonBedrockOptions.inputType) != null ? _f : "search_query",
|
|
1666
1895
|
texts: [values[0]],
|
|
1667
|
-
truncate:
|
|
1668
|
-
output_dimension:
|
|
1896
|
+
truncate: amazonBedrockOptions.truncate,
|
|
1897
|
+
output_dimension: amazonBedrockOptions.outputDimension
|
|
1669
1898
|
} : {
|
|
1670
1899
|
inputText: values[0],
|
|
1671
|
-
dimensions:
|
|
1672
|
-
normalize:
|
|
1900
|
+
dimensions: amazonBedrockOptions.dimensions,
|
|
1901
|
+
normalize: amazonBedrockOptions.normalize
|
|
1673
1902
|
};
|
|
1674
1903
|
const url = this.getUrl(this.modelId);
|
|
1675
|
-
const { value: response } = await (
|
|
1904
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
1676
1905
|
url,
|
|
1677
|
-
headers: await (
|
|
1678
|
-
(
|
|
1906
|
+
headers: await resolve2(
|
|
1907
|
+
combineHeaders2(
|
|
1908
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
1909
|
+
headers
|
|
1910
|
+
)
|
|
1679
1911
|
),
|
|
1680
1912
|
body: args,
|
|
1681
|
-
failedResponseHandler: (
|
|
1682
|
-
errorSchema:
|
|
1913
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1914
|
+
errorSchema: AmazonBedrockErrorSchema,
|
|
1683
1915
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1684
1916
|
}),
|
|
1685
|
-
successfulResponseHandler: (
|
|
1686
|
-
|
|
1917
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
1918
|
+
AmazonBedrockEmbeddingResponseSchema
|
|
1687
1919
|
),
|
|
1688
1920
|
fetch: this.config.fetch,
|
|
1689
1921
|
abortSignal
|
|
@@ -1701,7 +1933,10 @@ var BedrockEmbeddingModel = class {
|
|
|
1701
1933
|
} else {
|
|
1702
1934
|
embedding = response.embeddings.float[0];
|
|
1703
1935
|
}
|
|
1704
|
-
const
|
|
1936
|
+
const headerTokenCount = Number(
|
|
1937
|
+
responseHeaders == null ? void 0 : responseHeaders["x-amzn-bedrock-input-token-count"]
|
|
1938
|
+
);
|
|
1939
|
+
const tokens = "inputTextTokenCount" in response ? response.inputTextTokenCount : "inputTokenCount" in response ? (_g = response.inputTokenCount) != null ? _g : 0 : headerTokenCount;
|
|
1705
1940
|
return {
|
|
1706
1941
|
embeddings: [embedding],
|
|
1707
1942
|
usage: { tokens },
|
|
@@ -1709,51 +1944,70 @@ var BedrockEmbeddingModel = class {
|
|
|
1709
1944
|
};
|
|
1710
1945
|
}
|
|
1711
1946
|
};
|
|
1712
|
-
var
|
|
1947
|
+
var AmazonBedrockEmbeddingResponseSchema = z6.union([
|
|
1713
1948
|
// Titan-style response
|
|
1714
|
-
|
|
1715
|
-
embedding:
|
|
1716
|
-
inputTextTokenCount:
|
|
1949
|
+
z6.object({
|
|
1950
|
+
embedding: z6.array(z6.number()),
|
|
1951
|
+
inputTextTokenCount: z6.number()
|
|
1717
1952
|
}),
|
|
1718
1953
|
// Nova-style response
|
|
1719
|
-
|
|
1720
|
-
embeddings:
|
|
1721
|
-
|
|
1722
|
-
embeddingType:
|
|
1723
|
-
embedding:
|
|
1954
|
+
z6.object({
|
|
1955
|
+
embeddings: z6.array(
|
|
1956
|
+
z6.object({
|
|
1957
|
+
embeddingType: z6.string(),
|
|
1958
|
+
embedding: z6.array(z6.number())
|
|
1724
1959
|
})
|
|
1725
1960
|
),
|
|
1726
|
-
inputTokenCount:
|
|
1961
|
+
inputTokenCount: z6.number().optional()
|
|
1727
1962
|
}),
|
|
1728
1963
|
// Cohere v3-style response
|
|
1729
|
-
|
|
1730
|
-
embeddings:
|
|
1964
|
+
z6.object({
|
|
1965
|
+
embeddings: z6.array(z6.array(z6.number()))
|
|
1731
1966
|
}),
|
|
1732
1967
|
// Cohere v4-style response
|
|
1733
|
-
|
|
1734
|
-
embeddings:
|
|
1735
|
-
float:
|
|
1968
|
+
z6.object({
|
|
1969
|
+
embeddings: z6.object({
|
|
1970
|
+
float: z6.array(z6.array(z6.number()))
|
|
1736
1971
|
})
|
|
1737
1972
|
})
|
|
1738
1973
|
]);
|
|
1739
1974
|
|
|
1740
|
-
// src/bedrock-image-model.ts
|
|
1741
|
-
|
|
1975
|
+
// src/amazon-bedrock-image-model.ts
|
|
1976
|
+
import {
|
|
1977
|
+
combineHeaders as combineHeaders3,
|
|
1978
|
+
convertUint8ArrayToBase64,
|
|
1979
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
1980
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1981
|
+
postJsonToApi as postJsonToApi3,
|
|
1982
|
+
resolve as resolve3,
|
|
1983
|
+
serializeModelOptions as serializeModelOptions3,
|
|
1984
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
1985
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
|
|
1986
|
+
} from "@ai-sdk/provider-utils";
|
|
1742
1987
|
|
|
1743
|
-
// src/bedrock-image-settings.ts
|
|
1988
|
+
// src/amazon-bedrock-image-settings.ts
|
|
1744
1989
|
var modelMaxImagesPerCall = {
|
|
1745
1990
|
"amazon.nova-canvas-v1:0": 5
|
|
1746
1991
|
};
|
|
1747
1992
|
|
|
1748
|
-
// src/bedrock-image-model.ts
|
|
1749
|
-
|
|
1750
|
-
var
|
|
1993
|
+
// src/amazon-bedrock-image-model.ts
|
|
1994
|
+
import { z as z7 } from "zod/v4";
|
|
1995
|
+
var AmazonBedrockImageModel = class _AmazonBedrockImageModel {
|
|
1751
1996
|
constructor(modelId, config) {
|
|
1752
1997
|
this.modelId = modelId;
|
|
1753
1998
|
this.config = config;
|
|
1754
1999
|
this.specificationVersion = "v4";
|
|
1755
2000
|
this.provider = "amazon-bedrock";
|
|
1756
2001
|
}
|
|
2002
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
2003
|
+
return serializeModelOptions3({
|
|
2004
|
+
modelId: model.modelId,
|
|
2005
|
+
config: model.config
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
2009
|
+
return new _AmazonBedrockImageModel(options.modelId, options.config);
|
|
2010
|
+
}
|
|
1757
2011
|
get maxImagesPerCall() {
|
|
1758
2012
|
var _a;
|
|
1759
2013
|
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
@@ -1774,35 +2028,36 @@ var BedrockImageModel = class {
|
|
|
1774
2028
|
files,
|
|
1775
2029
|
mask
|
|
1776
2030
|
}) {
|
|
1777
|
-
var _a, _b, _c, _d, _e, _f
|
|
2031
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1778
2032
|
const warnings = [];
|
|
1779
2033
|
const [width, height] = size ? size.split("x").map(Number) : [];
|
|
1780
2034
|
const hasFiles = files != null && files.length > 0;
|
|
2035
|
+
const amazonBedrockOptions = (_a = providerOptions == null ? void 0 : providerOptions.amazonBedrock) != null ? _a : providerOptions == null ? void 0 : providerOptions.bedrock;
|
|
1781
2036
|
const imageGenerationConfig = {
|
|
1782
2037
|
...width ? { width } : {},
|
|
1783
2038
|
...height ? { height } : {},
|
|
1784
2039
|
...seed ? { seed } : {},
|
|
1785
2040
|
...n ? { numberOfImages: n } : {},
|
|
1786
|
-
...(
|
|
1787
|
-
...(
|
|
2041
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.quality) ? { quality: amazonBedrockOptions.quality } : {},
|
|
2042
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.cfgScale) ? { cfgScale: amazonBedrockOptions.cfgScale } : {}
|
|
1788
2043
|
};
|
|
1789
2044
|
let args;
|
|
1790
2045
|
if (hasFiles) {
|
|
1791
2046
|
const hasMask = (mask == null ? void 0 : mask.type) != null;
|
|
1792
|
-
const hasMaskPrompt = (
|
|
1793
|
-
const taskType = (
|
|
2047
|
+
const hasMaskPrompt = (amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.maskPrompt) != null;
|
|
2048
|
+
const taskType = (_b = amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.taskType) != null ? _b : hasMask || hasMaskPrompt ? "INPAINTING" : "IMAGE_VARIATION";
|
|
1794
2049
|
const sourceImageBase64 = getBase64Data(files[0]);
|
|
1795
2050
|
switch (taskType) {
|
|
1796
2051
|
case "INPAINTING": {
|
|
1797
2052
|
const inPaintingParams = {
|
|
1798
2053
|
image: sourceImageBase64,
|
|
1799
2054
|
...prompt ? { text: prompt } : {},
|
|
1800
|
-
...(
|
|
2055
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.negativeText) ? { negativeText: amazonBedrockOptions.negativeText } : {}
|
|
1801
2056
|
};
|
|
1802
2057
|
if (hasMask) {
|
|
1803
2058
|
inPaintingParams.maskImage = getBase64Data(mask);
|
|
1804
2059
|
} else if (hasMaskPrompt) {
|
|
1805
|
-
inPaintingParams.maskPrompt =
|
|
2060
|
+
inPaintingParams.maskPrompt = amazonBedrockOptions.maskPrompt;
|
|
1806
2061
|
}
|
|
1807
2062
|
args = {
|
|
1808
2063
|
taskType: "INPAINTING",
|
|
@@ -1815,13 +2070,13 @@ var BedrockImageModel = class {
|
|
|
1815
2070
|
const outPaintingParams = {
|
|
1816
2071
|
image: sourceImageBase64,
|
|
1817
2072
|
...prompt ? { text: prompt } : {},
|
|
1818
|
-
...(
|
|
1819
|
-
...(
|
|
2073
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.negativeText) ? { negativeText: amazonBedrockOptions.negativeText } : {},
|
|
2074
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.outPaintingMode) ? { outPaintingMode: amazonBedrockOptions.outPaintingMode } : {}
|
|
1820
2075
|
};
|
|
1821
2076
|
if (hasMask) {
|
|
1822
2077
|
outPaintingParams.maskImage = getBase64Data(mask);
|
|
1823
2078
|
} else if (hasMaskPrompt) {
|
|
1824
|
-
outPaintingParams.maskPrompt =
|
|
2079
|
+
outPaintingParams.maskPrompt = amazonBedrockOptions.maskPrompt;
|
|
1825
2080
|
}
|
|
1826
2081
|
args = {
|
|
1827
2082
|
taskType: "OUTPAINTING",
|
|
@@ -1844,9 +2099,9 @@ var BedrockImageModel = class {
|
|
|
1844
2099
|
const imageVariationParams = {
|
|
1845
2100
|
images,
|
|
1846
2101
|
...prompt ? { text: prompt } : {},
|
|
1847
|
-
...(
|
|
1848
|
-
...(
|
|
1849
|
-
similarityStrength:
|
|
2102
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.negativeText) ? { negativeText: amazonBedrockOptions.negativeText } : {},
|
|
2103
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.similarityStrength) != null ? {
|
|
2104
|
+
similarityStrength: amazonBedrockOptions.similarityStrength
|
|
1850
2105
|
} : {}
|
|
1851
2106
|
};
|
|
1852
2107
|
args = {
|
|
@@ -1864,11 +2119,11 @@ var BedrockImageModel = class {
|
|
|
1864
2119
|
taskType: "TEXT_IMAGE",
|
|
1865
2120
|
textToImageParams: {
|
|
1866
2121
|
text: prompt,
|
|
1867
|
-
...(
|
|
1868
|
-
negativeText:
|
|
2122
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.negativeText) ? {
|
|
2123
|
+
negativeText: amazonBedrockOptions.negativeText
|
|
1869
2124
|
} : {},
|
|
1870
|
-
...(
|
|
1871
|
-
style:
|
|
2125
|
+
...(amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.style) ? {
|
|
2126
|
+
style: amazonBedrockOptions.style
|
|
1872
2127
|
} : {}
|
|
1873
2128
|
},
|
|
1874
2129
|
imageGenerationConfig
|
|
@@ -1881,25 +2136,28 @@ var BedrockImageModel = class {
|
|
|
1881
2136
|
details: "This model does not support aspect ratio. Use `size` instead."
|
|
1882
2137
|
});
|
|
1883
2138
|
}
|
|
1884
|
-
const currentDate = (
|
|
1885
|
-
const { value: response, responseHeaders } = await (
|
|
2139
|
+
const currentDate = (_e = (_d = (_c = this.config._internal) == null ? void 0 : _c.currentDate) == null ? void 0 : _d.call(_c)) != null ? _e : /* @__PURE__ */ new Date();
|
|
2140
|
+
const { value: response, responseHeaders } = await postJsonToApi3({
|
|
1886
2141
|
url: this.getUrl(this.modelId),
|
|
1887
|
-
headers: await (
|
|
1888
|
-
(
|
|
2142
|
+
headers: await resolve3(
|
|
2143
|
+
combineHeaders3(
|
|
2144
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
2145
|
+
headers
|
|
2146
|
+
)
|
|
1889
2147
|
),
|
|
1890
2148
|
body: args,
|
|
1891
|
-
failedResponseHandler: (
|
|
1892
|
-
errorSchema:
|
|
2149
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
2150
|
+
errorSchema: AmazonBedrockErrorSchema,
|
|
1893
2151
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1894
2152
|
}),
|
|
1895
|
-
successfulResponseHandler: (
|
|
1896
|
-
|
|
2153
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
2154
|
+
amazonBedrockImageResponseSchema
|
|
1897
2155
|
),
|
|
1898
2156
|
abortSignal,
|
|
1899
2157
|
fetch: this.config.fetch
|
|
1900
2158
|
});
|
|
1901
2159
|
if (response.status === "Request Moderated") {
|
|
1902
|
-
const moderationReasons = (
|
|
2160
|
+
const moderationReasons = (_f = response.details) == null ? void 0 : _f["Moderation Reasons"];
|
|
1903
2161
|
const reasons = Array.isArray(moderationReasons) ? moderationReasons : ["Unknown"];
|
|
1904
2162
|
throw new Error(
|
|
1905
2163
|
`Amazon Bedrock request was moderated: ${reasons.join(", ")}`
|
|
@@ -1928,42 +2186,48 @@ function getBase64Data(file) {
|
|
|
1928
2186
|
);
|
|
1929
2187
|
}
|
|
1930
2188
|
if (file.data instanceof Uint8Array) {
|
|
1931
|
-
return
|
|
2189
|
+
return convertUint8ArrayToBase64(file.data);
|
|
1932
2190
|
}
|
|
1933
2191
|
return file.data;
|
|
1934
2192
|
}
|
|
1935
|
-
var
|
|
2193
|
+
var amazonBedrockImageResponseSchema = z7.object({
|
|
1936
2194
|
// Normal successful response
|
|
1937
|
-
images:
|
|
2195
|
+
images: z7.array(z7.string()).optional(),
|
|
1938
2196
|
// Moderation response fields
|
|
1939
|
-
id:
|
|
1940
|
-
status:
|
|
1941
|
-
result:
|
|
1942
|
-
progress:
|
|
1943
|
-
details:
|
|
1944
|
-
preview:
|
|
2197
|
+
id: z7.string().optional(),
|
|
2198
|
+
status: z7.string().optional(),
|
|
2199
|
+
result: z7.unknown().optional(),
|
|
2200
|
+
progress: z7.unknown().optional(),
|
|
2201
|
+
details: z7.record(z7.string(), z7.unknown()).optional(),
|
|
2202
|
+
preview: z7.unknown().optional()
|
|
1945
2203
|
});
|
|
1946
2204
|
|
|
1947
|
-
// src/bedrock-sigv4-fetch.ts
|
|
1948
|
-
|
|
1949
|
-
|
|
2205
|
+
// src/amazon-bedrock-sigv4-fetch.ts
|
|
2206
|
+
import {
|
|
2207
|
+
combineHeaders as combineHeaders4,
|
|
2208
|
+
normalizeHeaders,
|
|
2209
|
+
withUserAgentSuffix,
|
|
2210
|
+
getRuntimeEnvironmentUserAgent
|
|
2211
|
+
} from "@ai-sdk/provider-utils";
|
|
2212
|
+
import { AwsV4Signer } from "aws4fetch";
|
|
1950
2213
|
|
|
1951
2214
|
// src/version.ts
|
|
1952
|
-
var VERSION = true ? "5.0.0-beta.
|
|
2215
|
+
var VERSION = true ? "5.0.0-beta.85" : "0.0.0-test";
|
|
1953
2216
|
|
|
1954
|
-
// src/bedrock-sigv4-fetch.ts
|
|
1955
|
-
function createSigV4FetchFunction(getCredentials, fetch =
|
|
2217
|
+
// src/amazon-bedrock-sigv4-fetch.ts
|
|
2218
|
+
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
1956
2219
|
return async (input, init) => {
|
|
1957
2220
|
var _a, _b;
|
|
2221
|
+
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
1958
2222
|
const request = input instanceof Request ? input : void 0;
|
|
1959
|
-
const originalHeaders = (
|
|
1960
|
-
|
|
1961
|
-
|
|
2223
|
+
const originalHeaders = combineHeaders4(
|
|
2224
|
+
normalizeHeaders(request == null ? void 0 : request.headers),
|
|
2225
|
+
normalizeHeaders(init == null ? void 0 : init.headers)
|
|
1962
2226
|
);
|
|
1963
|
-
const headersWithUserAgent =
|
|
2227
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
1964
2228
|
originalHeaders,
|
|
1965
2229
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1966
|
-
|
|
2230
|
+
getRuntimeEnvironmentUserAgent()
|
|
1967
2231
|
);
|
|
1968
2232
|
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
1969
2233
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
@@ -1974,7 +2238,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1974
2238
|
}
|
|
1975
2239
|
const effectiveMethod = (_b = init == null ? void 0 : init.method) != null ? _b : request == null ? void 0 : request.method;
|
|
1976
2240
|
if ((effectiveMethod == null ? void 0 : effectiveMethod.toUpperCase()) !== "POST" || !effectiveBody) {
|
|
1977
|
-
return
|
|
2241
|
+
return effectiveFetch(input, {
|
|
1978
2242
|
...init,
|
|
1979
2243
|
headers: headersWithUserAgent
|
|
1980
2244
|
});
|
|
@@ -1982,7 +2246,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1982
2246
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
1983
2247
|
const body = prepareBodyString(effectiveBody);
|
|
1984
2248
|
const credentials = await getCredentials();
|
|
1985
|
-
const signer = new
|
|
2249
|
+
const signer = new AwsV4Signer({
|
|
1986
2250
|
url,
|
|
1987
2251
|
method: "POST",
|
|
1988
2252
|
headers: Object.entries(headersWithUserAgent),
|
|
@@ -1991,12 +2255,12 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1991
2255
|
accessKeyId: credentials.accessKeyId,
|
|
1992
2256
|
secretAccessKey: credentials.secretAccessKey,
|
|
1993
2257
|
sessionToken: credentials.sessionToken,
|
|
1994
|
-
service
|
|
2258
|
+
service
|
|
1995
2259
|
});
|
|
1996
2260
|
const signingResult = await signer.sign();
|
|
1997
|
-
const signedHeaders =
|
|
1998
|
-
const combinedHeaders = (
|
|
1999
|
-
return
|
|
2261
|
+
const signedHeaders = normalizeHeaders(signingResult.headers);
|
|
2262
|
+
const combinedHeaders = combineHeaders4(headersWithUserAgent, signedHeaders);
|
|
2263
|
+
return effectiveFetch(input, {
|
|
2000
2264
|
...init,
|
|
2001
2265
|
body,
|
|
2002
2266
|
headers: combinedHeaders
|
|
@@ -2014,64 +2278,72 @@ function prepareBodyString(body) {
|
|
|
2014
2278
|
return JSON.stringify(body);
|
|
2015
2279
|
}
|
|
2016
2280
|
}
|
|
2017
|
-
function createApiKeyFetchFunction(apiKey, fetch
|
|
2281
|
+
function createApiKeyFetchFunction(apiKey, fetch) {
|
|
2018
2282
|
return async (input, init) => {
|
|
2019
|
-
const
|
|
2020
|
-
const
|
|
2283
|
+
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
2284
|
+
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
2285
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
2021
2286
|
originalHeaders,
|
|
2022
2287
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
2023
|
-
|
|
2288
|
+
getRuntimeEnvironmentUserAgent()
|
|
2024
2289
|
);
|
|
2025
|
-
const finalHeaders = (
|
|
2290
|
+
const finalHeaders = combineHeaders4(headersWithUserAgent, {
|
|
2026
2291
|
Authorization: `Bearer ${apiKey}`
|
|
2027
2292
|
});
|
|
2028
|
-
return
|
|
2293
|
+
return effectiveFetch(input, {
|
|
2029
2294
|
...init,
|
|
2030
2295
|
headers: finalHeaders
|
|
2031
2296
|
});
|
|
2032
2297
|
};
|
|
2033
2298
|
}
|
|
2034
2299
|
|
|
2035
|
-
// src/reranking/bedrock-reranking-model.ts
|
|
2036
|
-
|
|
2300
|
+
// src/reranking/amazon-bedrock-reranking-model.ts
|
|
2301
|
+
import {
|
|
2302
|
+
combineHeaders as combineHeaders5,
|
|
2303
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
2304
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2305
|
+
parseProviderOptions as parseProviderOptions4,
|
|
2306
|
+
postJsonToApi as postJsonToApi4,
|
|
2307
|
+
resolve as resolve4
|
|
2308
|
+
} from "@ai-sdk/provider-utils";
|
|
2037
2309
|
|
|
2038
|
-
// src/reranking/bedrock-reranking-api.ts
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
var
|
|
2042
|
-
() =>
|
|
2043
|
-
|
|
2044
|
-
results:
|
|
2045
|
-
|
|
2046
|
-
index:
|
|
2047
|
-
relevanceScore:
|
|
2310
|
+
// src/reranking/amazon-bedrock-reranking-api.ts
|
|
2311
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
2312
|
+
import { z as z8 } from "zod/v4";
|
|
2313
|
+
var amazonBedrockRerankingResponseSchema = lazySchema(
|
|
2314
|
+
() => zodSchema(
|
|
2315
|
+
z8.object({
|
|
2316
|
+
results: z8.array(
|
|
2317
|
+
z8.object({
|
|
2318
|
+
index: z8.number(),
|
|
2319
|
+
relevanceScore: z8.number()
|
|
2048
2320
|
})
|
|
2049
2321
|
),
|
|
2050
|
-
nextToken:
|
|
2322
|
+
nextToken: z8.string().optional()
|
|
2051
2323
|
})
|
|
2052
2324
|
)
|
|
2053
2325
|
);
|
|
2054
2326
|
|
|
2055
|
-
// src/reranking/bedrock-reranking-options.ts
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
var amazonBedrockRerankingModelOptionsSchema = (
|
|
2059
|
-
() => (
|
|
2060
|
-
|
|
2327
|
+
// src/reranking/amazon-bedrock-reranking-model-options.ts
|
|
2328
|
+
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
2329
|
+
import { z as z9 } from "zod/v4";
|
|
2330
|
+
var amazonBedrockRerankingModelOptionsSchema = lazySchema2(
|
|
2331
|
+
() => zodSchema2(
|
|
2332
|
+
z9.object({
|
|
2061
2333
|
/**
|
|
2062
2334
|
* 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
2335
|
*/
|
|
2064
|
-
nextToken:
|
|
2336
|
+
nextToken: z9.string().optional(),
|
|
2065
2337
|
/**
|
|
2066
2338
|
* Additional model request fields to pass to the model.
|
|
2067
2339
|
*/
|
|
2068
|
-
additionalModelRequestFields:
|
|
2340
|
+
additionalModelRequestFields: z9.record(z9.string(), z9.any()).optional()
|
|
2069
2341
|
})
|
|
2070
2342
|
)
|
|
2071
2343
|
);
|
|
2072
2344
|
|
|
2073
|
-
// src/reranking/bedrock-reranking-model.ts
|
|
2074
|
-
var
|
|
2345
|
+
// src/reranking/amazon-bedrock-reranking-model.ts
|
|
2346
|
+
var AmazonBedrockRerankingModel = class {
|
|
2075
2347
|
constructor(modelId, config) {
|
|
2076
2348
|
this.modelId = modelId;
|
|
2077
2349
|
this.config = config;
|
|
@@ -2086,7 +2358,12 @@ var BedrockRerankingModel = class {
|
|
|
2086
2358
|
abortSignal,
|
|
2087
2359
|
providerOptions
|
|
2088
2360
|
}) {
|
|
2089
|
-
|
|
2361
|
+
var _a;
|
|
2362
|
+
const amazonBedrockOptions = (_a = await parseProviderOptions4({
|
|
2363
|
+
provider: "amazonBedrock",
|
|
2364
|
+
providerOptions,
|
|
2365
|
+
schema: amazonBedrockRerankingModelOptionsSchema
|
|
2366
|
+
})) != null ? _a : await parseProviderOptions4({
|
|
2090
2367
|
provider: "bedrock",
|
|
2091
2368
|
providerOptions,
|
|
2092
2369
|
schema: amazonBedrockRerankingModelOptionsSchema
|
|
@@ -2095,13 +2372,13 @@ var BedrockRerankingModel = class {
|
|
|
2095
2372
|
value: response,
|
|
2096
2373
|
responseHeaders,
|
|
2097
2374
|
rawValue
|
|
2098
|
-
} = await (
|
|
2375
|
+
} = await postJsonToApi4({
|
|
2099
2376
|
url: `${this.config.baseUrl()}/rerank`,
|
|
2100
|
-
headers: await (
|
|
2101
|
-
(
|
|
2377
|
+
headers: await resolve4(
|
|
2378
|
+
combineHeaders5(await resolve4(this.config.headers), headers)
|
|
2102
2379
|
),
|
|
2103
2380
|
body: {
|
|
2104
|
-
nextToken:
|
|
2381
|
+
nextToken: amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.nextToken,
|
|
2105
2382
|
queries: [
|
|
2106
2383
|
{
|
|
2107
2384
|
textQuery: { text: query },
|
|
@@ -2109,10 +2386,10 @@ var BedrockRerankingModel = class {
|
|
|
2109
2386
|
}
|
|
2110
2387
|
],
|
|
2111
2388
|
rerankingConfiguration: {
|
|
2112
|
-
|
|
2389
|
+
amazonBedrockRerankingConfiguration: {
|
|
2113
2390
|
modelConfiguration: {
|
|
2114
2391
|
modelArn: `arn:aws:bedrock:${this.config.region}::foundation-model/${this.modelId}`,
|
|
2115
|
-
additionalModelRequestFields:
|
|
2392
|
+
additionalModelRequestFields: amazonBedrockOptions == null ? void 0 : amazonBedrockOptions.additionalModelRequestFields
|
|
2116
2393
|
},
|
|
2117
2394
|
numberOfResults: topN
|
|
2118
2395
|
},
|
|
@@ -2129,12 +2406,12 @@ var BedrockRerankingModel = class {
|
|
|
2129
2406
|
}
|
|
2130
2407
|
}))
|
|
2131
2408
|
},
|
|
2132
|
-
failedResponseHandler: (
|
|
2133
|
-
errorSchema:
|
|
2409
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
2410
|
+
errorSchema: AmazonBedrockErrorSchema,
|
|
2134
2411
|
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
2135
2412
|
}),
|
|
2136
|
-
successfulResponseHandler: (
|
|
2137
|
-
|
|
2413
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2414
|
+
amazonBedrockRerankingResponseSchema
|
|
2138
2415
|
),
|
|
2139
2416
|
fetch: this.config.fetch,
|
|
2140
2417
|
abortSignal
|
|
@@ -2149,15 +2426,15 @@ var BedrockRerankingModel = class {
|
|
|
2149
2426
|
}
|
|
2150
2427
|
};
|
|
2151
2428
|
|
|
2152
|
-
// src/bedrock-provider.ts
|
|
2429
|
+
// src/amazon-bedrock-provider.ts
|
|
2153
2430
|
function createAmazonBedrock(options = {}) {
|
|
2154
|
-
const rawApiKey =
|
|
2431
|
+
const rawApiKey = loadOptionalSetting({
|
|
2155
2432
|
settingValue: options.apiKey,
|
|
2156
2433
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
2157
2434
|
});
|
|
2158
2435
|
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
2159
2436
|
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
2160
|
-
const region =
|
|
2437
|
+
const region = loadSetting({
|
|
2161
2438
|
settingValue: options.region,
|
|
2162
2439
|
settingName: "region",
|
|
2163
2440
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2179,19 +2456,19 @@ function createAmazonBedrock(options = {}) {
|
|
|
2179
2456
|
try {
|
|
2180
2457
|
return {
|
|
2181
2458
|
region,
|
|
2182
|
-
accessKeyId:
|
|
2459
|
+
accessKeyId: loadSetting({
|
|
2183
2460
|
settingValue: options.accessKeyId,
|
|
2184
2461
|
settingName: "accessKeyId",
|
|
2185
2462
|
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
2186
2463
|
description: "AWS access key ID"
|
|
2187
2464
|
}),
|
|
2188
|
-
secretAccessKey:
|
|
2465
|
+
secretAccessKey: loadSetting({
|
|
2189
2466
|
settingValue: options.secretAccessKey,
|
|
2190
2467
|
settingName: "secretAccessKey",
|
|
2191
2468
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
2192
2469
|
description: "AWS secret access key"
|
|
2193
2470
|
}),
|
|
2194
|
-
sessionToken:
|
|
2471
|
+
sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : loadOptionalSetting({
|
|
2195
2472
|
settingValue: options.sessionToken,
|
|
2196
2473
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
2197
2474
|
})
|
|
@@ -2220,12 +2497,12 @@ Original error: ${errorMessage}`
|
|
|
2220
2497
|
const getHeaders = () => {
|
|
2221
2498
|
var _a;
|
|
2222
2499
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2223
|
-
return (
|
|
2500
|
+
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2224
2501
|
};
|
|
2225
|
-
const
|
|
2502
|
+
const getAmazonBedrockRuntimeBaseUrl = () => {
|
|
2226
2503
|
var _a, _b;
|
|
2227
|
-
return (_b =
|
|
2228
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${
|
|
2504
|
+
return (_b = withoutTrailingSlash(
|
|
2505
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${loadSetting({
|
|
2229
2506
|
settingValue: options.region,
|
|
2230
2507
|
settingName: "region",
|
|
2231
2508
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2233,10 +2510,10 @@ Original error: ${errorMessage}`
|
|
|
2233
2510
|
})}.amazonaws.com`
|
|
2234
2511
|
)) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
|
|
2235
2512
|
};
|
|
2236
|
-
const
|
|
2513
|
+
const getAmazonBedrockAgentRuntimeBaseUrl = () => {
|
|
2237
2514
|
var _a, _b;
|
|
2238
|
-
return (_b =
|
|
2239
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${
|
|
2515
|
+
return (_b = withoutTrailingSlash(
|
|
2516
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${loadSetting({
|
|
2240
2517
|
settingValue: options.region,
|
|
2241
2518
|
settingName: "region",
|
|
2242
2519
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2244,11 +2521,11 @@ Original error: ${errorMessage}`
|
|
|
2244
2521
|
})}.amazonaws.com`
|
|
2245
2522
|
)) != null ? _b : `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;
|
|
2246
2523
|
};
|
|
2247
|
-
const createChatModel = (modelId) => new
|
|
2248
|
-
baseUrl:
|
|
2524
|
+
const createChatModel = (modelId) => new AmazonBedrockChatLanguageModel(modelId, {
|
|
2525
|
+
baseUrl: getAmazonBedrockRuntimeBaseUrl,
|
|
2249
2526
|
headers: getHeaders,
|
|
2250
2527
|
fetch: fetchFunction,
|
|
2251
|
-
generateId
|
|
2528
|
+
generateId
|
|
2252
2529
|
});
|
|
2253
2530
|
const provider = function(modelId) {
|
|
2254
2531
|
if (new.target) {
|
|
@@ -2258,19 +2535,19 @@ Original error: ${errorMessage}`
|
|
|
2258
2535
|
}
|
|
2259
2536
|
return createChatModel(modelId);
|
|
2260
2537
|
};
|
|
2261
|
-
const createEmbeddingModel = (modelId) => new
|
|
2262
|
-
baseUrl:
|
|
2538
|
+
const createEmbeddingModel = (modelId) => new AmazonBedrockEmbeddingModel(modelId, {
|
|
2539
|
+
baseUrl: getAmazonBedrockRuntimeBaseUrl,
|
|
2263
2540
|
headers: getHeaders,
|
|
2264
2541
|
fetch: fetchFunction
|
|
2265
2542
|
});
|
|
2266
|
-
const createImageModel = (modelId) => new
|
|
2267
|
-
baseUrl:
|
|
2543
|
+
const createImageModel = (modelId) => new AmazonBedrockImageModel(modelId, {
|
|
2544
|
+
baseUrl: getAmazonBedrockRuntimeBaseUrl,
|
|
2268
2545
|
headers: getHeaders,
|
|
2269
2546
|
fetch: fetchFunction
|
|
2270
2547
|
});
|
|
2271
|
-
const createRerankingModel = (modelId) => new
|
|
2272
|
-
baseUrl:
|
|
2273
|
-
region:
|
|
2548
|
+
const createRerankingModel = (modelId) => new AmazonBedrockRerankingModel(modelId, {
|
|
2549
|
+
baseUrl: getAmazonBedrockAgentRuntimeBaseUrl,
|
|
2550
|
+
region: loadSetting({
|
|
2274
2551
|
settingValue: options.region,
|
|
2275
2552
|
settingName: "region",
|
|
2276
2553
|
environmentVariableName: "AWS_REGION",
|
|
@@ -2289,14 +2566,14 @@ Original error: ${errorMessage}`
|
|
|
2289
2566
|
provider.imageModel = createImageModel;
|
|
2290
2567
|
provider.reranking = createRerankingModel;
|
|
2291
2568
|
provider.rerankingModel = createRerankingModel;
|
|
2292
|
-
provider.tools =
|
|
2569
|
+
provider.tools = anthropicTools2;
|
|
2293
2570
|
return provider;
|
|
2294
2571
|
}
|
|
2295
|
-
var
|
|
2296
|
-
|
|
2297
|
-
0 && (module.exports = {
|
|
2572
|
+
var amazonBedrock = createAmazonBedrock();
|
|
2573
|
+
export {
|
|
2298
2574
|
VERSION,
|
|
2299
|
-
|
|
2575
|
+
amazonBedrock,
|
|
2576
|
+
amazonBedrock as bedrock,
|
|
2300
2577
|
createAmazonBedrock
|
|
2301
|
-
}
|
|
2578
|
+
};
|
|
2302
2579
|
//# sourceMappingURL=index.js.map
|