@copilotkit/aimock 1.29.0 → 1.30.0
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 +18 -0
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/bedrock-converse.cjs +63 -31
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +65 -33
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +95 -33
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts.map +1 -1
- package/dist/bedrock.js +97 -35
- package/dist/bedrock.js.map +1 -1
- package/dist/cohere.cjs +49 -15
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +51 -17
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/elevenlabs-audio.cjs +8 -4
- package/dist/elevenlabs-audio.cjs.map +1 -1
- package/dist/elevenlabs-audio.d.cts.map +1 -1
- package/dist/elevenlabs-audio.d.ts.map +1 -1
- package/dist/elevenlabs-audio.js +10 -6
- package/dist/elevenlabs-audio.js.map +1 -1
- package/dist/embeddings.cjs +4 -3
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +6 -5
- package/dist/embeddings.js.map +1 -1
- package/dist/fal-audio.cjs +8 -4
- package/dist/fal-audio.cjs.map +1 -1
- package/dist/fal-audio.d.cts.map +1 -1
- package/dist/fal-audio.d.ts.map +1 -1
- package/dist/fal-audio.js +10 -6
- package/dist/fal-audio.js.map +1 -1
- package/dist/fal.cjs +4 -2
- package/dist/fal.cjs.map +1 -1
- package/dist/fal.d.cts.map +1 -1
- package/dist/fal.d.ts.map +1 -1
- package/dist/fal.js +6 -4
- package/dist/fal.js.map +1 -1
- package/dist/gemini-embeddings.cjs +4 -3
- package/dist/gemini-embeddings.cjs.map +1 -1
- package/dist/gemini-embeddings.js +6 -5
- package/dist/gemini-embeddings.js.map +1 -1
- package/dist/gemini-interactions.cjs +3 -3
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.d.cts.map +1 -1
- package/dist/gemini-interactions.d.ts.map +1 -1
- package/dist/gemini-interactions.js +5 -5
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +55 -24
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +57 -26
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +120 -2
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +43 -3
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +43 -3
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +117 -3
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +12 -6
- package/dist/images.cjs.map +1 -1
- package/dist/images.d.cts.map +1 -1
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +14 -8
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/messages.cjs +325 -85
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +327 -87
- package/dist/messages.js.map +1 -1
- package/dist/model-utils.cjs +68 -0
- package/dist/model-utils.cjs.map +1 -1
- package/dist/model-utils.js +68 -1
- package/dist/model-utils.js.map +1 -1
- package/dist/ollama.cjs +58 -21
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +60 -23
- package/dist/ollama.js.map +1 -1
- package/dist/recorder.cjs +49 -8
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.js +50 -9
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +26 -12
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +28 -14
- package/dist/responses.js.map +1 -1
- package/dist/router.cjs +37 -8
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts +30 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts +30 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +37 -9
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +15 -9
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +17 -11
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +4 -2
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.d.cts.map +1 -1
- package/dist/speech.d.ts.map +1 -1
- package/dist/speech.js +6 -4
- package/dist/speech.js.map +1 -1
- package/dist/stream-collapse.cjs +44 -1
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +28 -0
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +28 -0
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +44 -2
- package/dist/stream-collapse.js.map +1 -1
- package/dist/transcription.cjs +4 -2
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.cts.map +1 -1
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +6 -4
- package/dist/transcription.js.map +1 -1
- package/dist/types.d.cts +42 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/vector-types.d.ts.map +1 -1
- package/dist/video.cjs +4 -2
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +6 -4
- package/dist/video.js.map +1 -1
- package/dist/ws-gemini-live.cjs +4 -3
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +6 -5
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +4 -3
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +6 -5
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +8 -6
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +10 -8
- package/dist/ws-responses.js.map +1 -1
- package/package.json +1 -1
package/dist/bedrock.cjs
CHANGED
|
@@ -146,26 +146,33 @@ function buildBedrockTextResponse(content, model, reasoning, overrides) {
|
|
|
146
146
|
usage: bedrockUsage(overrides)
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function buildBedrockToolCallResponse(toolCalls, model, logger, overrides) {
|
|
149
|
+
function buildBedrockToolCallResponse(toolCalls, model, logger, reasoning, overrides) {
|
|
150
|
+
const contentBlocks = [];
|
|
151
|
+
if (reasoning) contentBlocks.push({
|
|
152
|
+
type: "thinking",
|
|
153
|
+
thinking: reasoning,
|
|
154
|
+
signature: ""
|
|
155
|
+
});
|
|
156
|
+
for (const tc of toolCalls) {
|
|
157
|
+
let argsObj;
|
|
158
|
+
try {
|
|
159
|
+
argsObj = JSON.parse(tc.arguments || "{}");
|
|
160
|
+
} catch {
|
|
161
|
+
logger.warn(`Malformed JSON in fixture tool call arguments for "${tc.name}": ${tc.arguments}`);
|
|
162
|
+
argsObj = {};
|
|
163
|
+
}
|
|
164
|
+
contentBlocks.push({
|
|
165
|
+
type: "tool_use",
|
|
166
|
+
id: tc.id || require_helpers.generateToolUseId(),
|
|
167
|
+
name: tc.name,
|
|
168
|
+
input: argsObj
|
|
169
|
+
});
|
|
170
|
+
}
|
|
150
171
|
return {
|
|
151
172
|
id: overrides?.id ?? require_helpers.generateMessageId(),
|
|
152
173
|
type: "message",
|
|
153
174
|
role: "assistant",
|
|
154
|
-
content:
|
|
155
|
-
let argsObj;
|
|
156
|
-
try {
|
|
157
|
-
argsObj = JSON.parse(tc.arguments || "{}");
|
|
158
|
-
} catch {
|
|
159
|
-
logger.warn(`Malformed JSON in fixture tool call arguments for "${tc.name}": ${tc.arguments}`);
|
|
160
|
-
argsObj = {};
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
type: "tool_use",
|
|
164
|
-
id: tc.id || require_helpers.generateToolUseId(),
|
|
165
|
-
name: tc.name,
|
|
166
|
-
input: argsObj
|
|
167
|
-
};
|
|
168
|
-
}),
|
|
175
|
+
content: contentBlocks,
|
|
169
176
|
model: overrides?.model ?? model,
|
|
170
177
|
stop_reason: bedrockStopReason(overrides?.finishReason, "tool_use"),
|
|
171
178
|
stop_sequence: null,
|
|
@@ -218,7 +225,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
218
225
|
completionReq._endpointType = "chat";
|
|
219
226
|
completionReq._context = require_helpers.getContext(req);
|
|
220
227
|
const testId = require_helpers.getTestId(req);
|
|
221
|
-
const fixture = require_router.
|
|
228
|
+
const { fixture, skippedBySequenceOrTurn } = require_router.matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
222
229
|
if (fixture) logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);
|
|
223
230
|
else logger.debug(`No fixture matched for request`);
|
|
224
231
|
if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures, testId);
|
|
@@ -231,8 +238,8 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
231
238
|
if (!fixture) {
|
|
232
239
|
if (require_helpers.resolveStrictMode(defaults.strict, req.headers)) {
|
|
233
240
|
const strictStatus = 503;
|
|
234
|
-
const strictMessage =
|
|
235
|
-
logger.error(
|
|
241
|
+
const strictMessage = require_helpers.strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
242
|
+
logger.error(require_helpers.strictNoMatchLogLine(req.method ?? "POST", urlPath, skippedBySequenceOrTurn));
|
|
236
243
|
journal.add({
|
|
237
244
|
method: req.method ?? "POST",
|
|
238
245
|
path: urlPath,
|
|
@@ -311,6 +318,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
311
318
|
if (require_helpers.isContentWithToolCallsResponse(response)) {
|
|
312
319
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
313
320
|
const overrides = require_helpers.extractOverrides(response);
|
|
321
|
+
const effReasoning = require_helpers.resolveReasoningForModel(response.reasoning, completionReq.model, require_helpers.resolveStrictMode(defaults.strict, req.headers), logger);
|
|
314
322
|
journal.add({
|
|
315
323
|
method: req.method ?? "POST",
|
|
316
324
|
path: urlPath,
|
|
@@ -321,8 +329,8 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
321
329
|
fixture
|
|
322
330
|
}
|
|
323
331
|
});
|
|
324
|
-
const textBody = buildBedrockTextResponse(response.content, completionReq.model,
|
|
325
|
-
const toolBody = buildBedrockToolCallResponse(response.toolCalls, completionReq.model, logger, overrides);
|
|
332
|
+
const textBody = buildBedrockTextResponse(response.content, completionReq.model, effReasoning, overrides);
|
|
333
|
+
const toolBody = buildBedrockToolCallResponse(response.toolCalls, completionReq.model, logger, void 0, overrides);
|
|
326
334
|
const merged = {
|
|
327
335
|
...textBody,
|
|
328
336
|
content: [...textBody.content, ...toolBody.content],
|
|
@@ -335,6 +343,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
335
343
|
if (require_helpers.isTextResponse(response)) {
|
|
336
344
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
337
345
|
const overrides = require_helpers.extractOverrides(response);
|
|
346
|
+
const effReasoning = require_helpers.resolveReasoningForModel(response.reasoning, completionReq.model, require_helpers.resolveStrictMode(defaults.strict, req.headers), logger);
|
|
338
347
|
journal.add({
|
|
339
348
|
method: req.method ?? "POST",
|
|
340
349
|
path: urlPath,
|
|
@@ -345,7 +354,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
345
354
|
fixture
|
|
346
355
|
}
|
|
347
356
|
});
|
|
348
|
-
const body = buildBedrockTextResponse(response.content, completionReq.model,
|
|
357
|
+
const body = buildBedrockTextResponse(response.content, completionReq.model, effReasoning, overrides);
|
|
349
358
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
350
359
|
res.end(JSON.stringify(body));
|
|
351
360
|
return;
|
|
@@ -353,6 +362,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
353
362
|
if (require_helpers.isToolCallResponse(response)) {
|
|
354
363
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
355
364
|
const overrides = require_helpers.extractOverrides(response);
|
|
365
|
+
const effReasoning = require_helpers.resolveReasoningForModel(response.reasoning, completionReq.model, require_helpers.resolveStrictMode(defaults.strict, req.headers), logger);
|
|
356
366
|
journal.add({
|
|
357
367
|
method: req.method ?? "POST",
|
|
358
368
|
path: urlPath,
|
|
@@ -363,7 +373,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
363
373
|
fixture
|
|
364
374
|
}
|
|
365
375
|
});
|
|
366
|
-
const body = buildBedrockToolCallResponse(response.toolCalls, completionReq.model, logger, overrides);
|
|
376
|
+
const body = buildBedrockToolCallResponse(response.toolCalls, completionReq.model, logger, effReasoning, overrides);
|
|
367
377
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
368
378
|
res.end(JSON.stringify(body));
|
|
369
379
|
return;
|
|
@@ -645,17 +655,66 @@ function buildBedrockStreamContentWithToolCallsEvents(content, toolCalls, model,
|
|
|
645
655
|
events.push(buildBedrockInvokeMessageStop());
|
|
646
656
|
return events;
|
|
647
657
|
}
|
|
648
|
-
function buildBedrockStreamToolCallEvents(toolCalls, model, chunkSize, logger, overrides) {
|
|
658
|
+
function buildBedrockStreamToolCallEvents(toolCalls, model, chunkSize, logger, reasoning, overrides) {
|
|
649
659
|
const events = [];
|
|
650
660
|
events.push(buildBedrockInvokeMessageStart(model, overrides));
|
|
661
|
+
let blockIndex = 0;
|
|
662
|
+
if (reasoning) {
|
|
663
|
+
events.push({
|
|
664
|
+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
665
|
+
payload: {
|
|
666
|
+
type: "content_block_start",
|
|
667
|
+
index: blockIndex,
|
|
668
|
+
content_block: {
|
|
669
|
+
type: "thinking",
|
|
670
|
+
thinking: "",
|
|
671
|
+
signature: ""
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
for (let i = 0; i < reasoning.length; i += chunkSize) {
|
|
676
|
+
const slice = reasoning.slice(i, i + chunkSize);
|
|
677
|
+
events.push({
|
|
678
|
+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
679
|
+
payload: {
|
|
680
|
+
type: "content_block_delta",
|
|
681
|
+
index: blockIndex,
|
|
682
|
+
delta: {
|
|
683
|
+
type: "thinking_delta",
|
|
684
|
+
thinking: slice
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
events.push({
|
|
690
|
+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
691
|
+
payload: {
|
|
692
|
+
type: "content_block_delta",
|
|
693
|
+
index: blockIndex,
|
|
694
|
+
delta: {
|
|
695
|
+
type: "signature_delta",
|
|
696
|
+
signature: ""
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
events.push({
|
|
701
|
+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
702
|
+
payload: {
|
|
703
|
+
type: "content_block_stop",
|
|
704
|
+
index: blockIndex
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
blockIndex++;
|
|
708
|
+
}
|
|
651
709
|
for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {
|
|
652
710
|
const tc = toolCalls[tcIdx];
|
|
653
711
|
const toolUseId = tc.id || require_helpers.generateToolUseId();
|
|
712
|
+
const currentBlock = blockIndex + tcIdx;
|
|
654
713
|
events.push({
|
|
655
714
|
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
656
715
|
payload: {
|
|
657
716
|
type: "content_block_start",
|
|
658
|
-
index:
|
|
717
|
+
index: currentBlock,
|
|
659
718
|
content_block: {
|
|
660
719
|
type: "tool_use",
|
|
661
720
|
id: toolUseId,
|
|
@@ -671,7 +730,7 @@ function buildBedrockStreamToolCallEvents(toolCalls, model, chunkSize, logger, o
|
|
|
671
730
|
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
672
731
|
payload: {
|
|
673
732
|
type: "content_block_delta",
|
|
674
|
-
index:
|
|
733
|
+
index: currentBlock,
|
|
675
734
|
delta: {
|
|
676
735
|
type: "input_json_delta",
|
|
677
736
|
partial_json: slice
|
|
@@ -683,7 +742,7 @@ function buildBedrockStreamToolCallEvents(toolCalls, model, chunkSize, logger, o
|
|
|
683
742
|
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
684
743
|
payload: {
|
|
685
744
|
type: "content_block_stop",
|
|
686
|
-
index:
|
|
745
|
+
index: currentBlock
|
|
687
746
|
}
|
|
688
747
|
});
|
|
689
748
|
}
|
|
@@ -738,7 +797,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
738
797
|
completionReq._endpointType = "chat";
|
|
739
798
|
completionReq._context = require_helpers.getContext(req);
|
|
740
799
|
const testId = require_helpers.getTestId(req);
|
|
741
|
-
const fixture = require_router.
|
|
800
|
+
const { fixture, skippedBySequenceOrTurn } = require_router.matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
742
801
|
if (fixture) logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);
|
|
743
802
|
else logger.debug(`No fixture matched for request`);
|
|
744
803
|
if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures, testId);
|
|
@@ -751,8 +810,8 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
751
810
|
if (!fixture) {
|
|
752
811
|
if (require_helpers.resolveStrictMode(defaults.strict, req.headers)) {
|
|
753
812
|
const strictStatus = 503;
|
|
754
|
-
const strictMessage =
|
|
755
|
-
logger.error(
|
|
813
|
+
const strictMessage = require_helpers.strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
814
|
+
logger.error(require_helpers.strictNoMatchLogLine(req.method ?? "POST", urlPath, skippedBySequenceOrTurn));
|
|
756
815
|
journal.add({
|
|
757
816
|
method: req.method ?? "POST",
|
|
758
817
|
path: urlPath,
|
|
@@ -833,6 +892,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
833
892
|
if (require_helpers.isContentWithToolCallsResponse(response)) {
|
|
834
893
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
835
894
|
const overrides = require_helpers.extractOverrides(response);
|
|
895
|
+
const effReasoning = require_helpers.resolveReasoningForModel(response.reasoning, completionReq.model, require_helpers.resolveStrictMode(defaults.strict, req.headers), logger);
|
|
836
896
|
const journalEntry = journal.add({
|
|
837
897
|
method: req.method ?? "POST",
|
|
838
898
|
path: urlPath,
|
|
@@ -843,7 +903,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
843
903
|
fixture
|
|
844
904
|
}
|
|
845
905
|
});
|
|
846
|
-
const events = buildBedrockStreamContentWithToolCallsEvents(response.content, response.toolCalls, completionReq.model, chunkSize, logger,
|
|
906
|
+
const events = buildBedrockStreamContentWithToolCallsEvents(response.content, response.toolCalls, completionReq.model, chunkSize, logger, effReasoning, overrides);
|
|
847
907
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
848
908
|
if (!await require_aws_event_stream.writeEventStream(res, events, {
|
|
849
909
|
latency,
|
|
@@ -863,6 +923,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
863
923
|
if (require_helpers.isTextResponse(response)) {
|
|
864
924
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
865
925
|
const overrides = require_helpers.extractOverrides(response);
|
|
926
|
+
const effReasoning = require_helpers.resolveReasoningForModel(response.reasoning, completionReq.model, require_helpers.resolveStrictMode(defaults.strict, req.headers), logger);
|
|
866
927
|
const journalEntry = journal.add({
|
|
867
928
|
method: req.method ?? "POST",
|
|
868
929
|
path: urlPath,
|
|
@@ -873,7 +934,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
873
934
|
fixture
|
|
874
935
|
}
|
|
875
936
|
});
|
|
876
|
-
const events = buildBedrockStreamTextEvents(response.content, completionReq.model, chunkSize,
|
|
937
|
+
const events = buildBedrockStreamTextEvents(response.content, completionReq.model, chunkSize, effReasoning, overrides);
|
|
877
938
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
878
939
|
if (!await require_aws_event_stream.writeEventStream(res, events, {
|
|
879
940
|
latency,
|
|
@@ -893,6 +954,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
893
954
|
if (require_helpers.isToolCallResponse(response)) {
|
|
894
955
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
895
956
|
const overrides = require_helpers.extractOverrides(response);
|
|
957
|
+
const effReasoning = require_helpers.resolveReasoningForModel(response.reasoning, completionReq.model, require_helpers.resolveStrictMode(defaults.strict, req.headers), logger);
|
|
896
958
|
const journalEntry = journal.add({
|
|
897
959
|
method: req.method ?? "POST",
|
|
898
960
|
path: urlPath,
|
|
@@ -903,7 +965,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
903
965
|
fixture
|
|
904
966
|
}
|
|
905
967
|
});
|
|
906
|
-
const events = buildBedrockStreamToolCallEvents(response.toolCalls, completionReq.model, chunkSize, logger, overrides);
|
|
968
|
+
const events = buildBedrockStreamToolCallEvents(response.toolCalls, completionReq.model, chunkSize, logger, effReasoning, overrides);
|
|
907
969
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
908
970
|
if (!await require_aws_event_stream.writeEventStream(res, events, {
|
|
909
971
|
latency,
|
package/dist/bedrock.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock.cjs","names":["generateMessageId","generateToolUseId","flattenHeaders","getContext","getTestId","matchFixture","applyChaos","resolveStrictMode","strictOverrideField","proxyAndRecord","resolveResponse","isErrorResponse","isContentWithToolCallsResponse","extractOverrides","isTextResponse","isToolCallResponse","createInterruptionSignal","writeEventStream"],"sources":["../src/bedrock.ts"],"sourcesContent":["/**\n * AWS Bedrock Claude endpoint support — invoke and invoke-with-response-stream.\n *\n * Handles four Bedrock endpoint families (split across two modules):\n *\n * This file (bedrock.ts):\n * - POST /model/{modelId}/invoke — non-streaming invoke\n * - POST /model/{modelId}/invoke-with-response-stream — binary EventStream streaming\n *\n * bedrock-converse.ts:\n * - POST /model/{modelId}/converse — Converse API (non-streaming)\n * - POST /model/{modelId}/converse-stream — Converse API (EventStream streaming)\n *\n * Translates incoming Bedrock Claude format into the ChatCompletionRequest\n * format used by the fixture router, and converts fixture responses back into\n * the appropriate Bedrock response format (JSON for invoke, AWS Event Stream\n * binary encoding for streaming).\n */\n\nimport type * as http from \"node:http\";\nimport type {\n ChatCompletionRequest,\n ChatMessage,\n Fixture,\n HandlerDefaults,\n ResponseOverrides,\n ToolCall,\n ToolDefinition,\n} from \"./types.js\";\nimport {\n generateMessageId,\n generateToolUseId,\n extractOverrides,\n isTextResponse,\n isToolCallResponse,\n isContentWithToolCallsResponse,\n isErrorResponse,\n flattenHeaders,\n getContext,\n getTestId,\n resolveResponse,\n resolveStrictMode,\n strictOverrideField,\n} from \"./helpers.js\";\nimport { matchFixture } from \"./router.js\";\nimport { writeErrorResponse } from \"./sse-writer.js\";\nimport { writeEventStream } from \"./aws-event-stream.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport type { Journal } from \"./journal.js\";\nimport type { Logger } from \"./logger.js\";\nimport { applyChaos } from \"./chaos.js\";\nimport { proxyAndRecord } from \"./recorder.js\";\n\n// ─── Bedrock Claude request types ────────────────────────────────────────────\n\ninterface BedrockContentBlock {\n type: \"text\" | \"tool_use\" | \"tool_result\" | \"image\" | \"document\";\n text?: string;\n id?: string;\n name?: string;\n input?: unknown;\n tool_use_id?: string;\n content?: string | BedrockContentBlock[];\n is_error?: boolean;\n}\n\ninterface BedrockMessage {\n role: \"user\" | \"assistant\";\n content: string | BedrockContentBlock[];\n}\n\ninterface BedrockToolDef {\n name: string;\n description?: string;\n input_schema?: object;\n}\n\ninterface BedrockRequest {\n anthropic_version?: string;\n messages: BedrockMessage[];\n system?: string | BedrockContentBlock[];\n tools?: BedrockToolDef[];\n tool_choice?: unknown;\n max_tokens: number;\n temperature?: number;\n [key: string]: unknown;\n}\n\n// ─── Bedrock stop_reason mapping ───────────────────────────────────────────\n\nfunction bedrockStopReason(\n overrideFinishReason: string | undefined,\n defaultReason: string,\n): string {\n if (!overrideFinishReason) return defaultReason;\n if (overrideFinishReason === \"stop\") return \"end_turn\";\n if (overrideFinishReason === \"tool_calls\") return \"tool_use\";\n if (overrideFinishReason === \"length\") return \"max_tokens\";\n return overrideFinishReason;\n}\n\n/**\n * Build a Bedrock-style usage object from optional overrides.\n *\n * When no overrides are provided (the common case for mock fixtures),\n * returns all-zero token counts. This is intentional — aimock does not\n * attempt to estimate token usage from fixture content. Callers that\n * need realistic usage numbers should set `usage` in their fixture's\n * response overrides.\n */\nfunction bedrockUsage(overrides?: ResponseOverrides): {\n input_tokens: number;\n output_tokens: number;\n} {\n if (!overrides?.usage) return { input_tokens: 0, output_tokens: 0 };\n return {\n input_tokens: overrides.usage.input_tokens ?? overrides.usage.prompt_tokens ?? 0,\n output_tokens: overrides.usage.output_tokens ?? overrides.usage.completion_tokens ?? 0,\n };\n}\n\n// ─── Input conversion: Bedrock → ChatCompletionRequest ──────────────────────\n\nfunction extractTextContent(content: string | BedrockContentBlock[]): string {\n if (typeof content === \"string\") return content;\n return content\n .filter((b) => b.type === \"text\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n}\n\nexport function bedrockToCompletionRequest(\n req: BedrockRequest,\n modelId: string,\n logger?: Logger,\n): ChatCompletionRequest {\n const messages: ChatMessage[] = [];\n\n // system field → system message\n if (req.system) {\n const systemText =\n typeof req.system === \"string\"\n ? req.system\n : req.system\n .filter((b) => b.type === \"text\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n if (systemText) {\n messages.push({ role: \"system\", content: systemText });\n }\n }\n\n for (const msg of req.messages) {\n if (msg.role === \"user\") {\n // Check for tool_result blocks\n if (typeof msg.content !== \"string\" && Array.isArray(msg.content)) {\n // Warn about non-text content blocks that will be dropped (image, document, etc.)\n const unsupportedBlocks = msg.content.filter(\n (b) => b.type !== \"text\" && b.type !== \"tool_result\",\n );\n if (unsupportedBlocks.length > 0 && logger) {\n const types = [...new Set(unsupportedBlocks.map((b) => b.type))].join(\", \");\n logger.warn(\n `Bedrock user message contains unsupported content block types [${types}] — these will be dropped during conversion`,\n );\n }\n\n const toolResults = msg.content.filter((b) => b.type === \"tool_result\");\n const textBlocks = msg.content.filter((b) => b.type === \"text\");\n\n if (toolResults.length > 0) {\n for (const tr of toolResults) {\n const resultContent =\n typeof tr.content === \"string\"\n ? tr.content\n : Array.isArray(tr.content)\n ? tr.content\n .filter((b) => b.type === \"text\")\n .map((b) => b.text ?? \"\")\n .join(\"\")\n : \"\";\n messages.push({\n role: \"tool\",\n content: resultContent,\n tool_call_id: tr.tool_use_id,\n });\n }\n if (textBlocks.length > 0) {\n messages.push({\n role: \"user\",\n content: textBlocks.map((b) => b.text ?? \"\").join(\"\"),\n });\n }\n continue;\n }\n }\n messages.push({\n role: \"user\",\n content: extractTextContent(msg.content),\n });\n } else if (msg.role === \"assistant\") {\n if (typeof msg.content === \"string\") {\n messages.push({ role: \"assistant\", content: msg.content });\n } else if (Array.isArray(msg.content)) {\n const toolUseBlocks = msg.content.filter((b) => b.type === \"tool_use\");\n const textContent = extractTextContent(msg.content);\n\n if (toolUseBlocks.length > 0) {\n messages.push({\n role: \"assistant\",\n content: textContent || null,\n tool_calls: toolUseBlocks.map((b, index) => {\n if (!b.id && logger) {\n logger.warn(\n `Bedrock assistant tool_use block at index ${index} is missing an id — using deterministic fallback \"tool_use_${index}\"`,\n );\n }\n return {\n id: b.id ?? `tool_use_${index}`,\n type: \"function\" as const,\n function: {\n name: b.name ?? \"\",\n arguments: typeof b.input === \"string\" ? b.input : JSON.stringify(b.input ?? {}),\n },\n };\n }),\n });\n } else {\n messages.push({ role: \"assistant\", content: textContent || null });\n }\n } else {\n messages.push({ role: \"assistant\", content: null });\n }\n } else {\n if (logger) {\n logger.warn(\n `Bedrock message has unexpected role \"${(msg as { role: string }).role}\" — skipping`,\n );\n }\n }\n }\n\n // Convert tools\n let tools: ToolDefinition[] | undefined;\n if (req.tools && req.tools.length > 0) {\n tools = req.tools.map((t) => ({\n type: \"function\" as const,\n function: {\n name: t.name,\n description: t.description,\n parameters: t.input_schema,\n },\n }));\n }\n\n return {\n model: modelId,\n messages,\n stream: false,\n temperature: req.temperature,\n max_tokens: req.max_tokens,\n tools,\n };\n}\n\n// ─── Response builders ──────────────────────────────────────────────────────\n\nfunction buildBedrockTextResponse(\n content: string,\n model: string,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n if (reasoning) {\n contentBlocks.push({ type: \"thinking\", thinking: reasoning, signature: \"\" });\n }\n contentBlocks.push({ type: \"text\", text: content });\n\n return {\n id: overrides?.id ?? generateMessageId(),\n type: \"message\",\n role: \"assistant\",\n content: contentBlocks,\n model: overrides?.model ?? model,\n stop_reason: bedrockStopReason(overrides?.finishReason, \"end_turn\"),\n stop_sequence: null,\n usage: bedrockUsage(overrides),\n };\n}\n\nfunction buildBedrockToolCallResponse(\n toolCalls: ToolCall[],\n model: string,\n logger: Logger,\n overrides?: ResponseOverrides,\n): object {\n return {\n id: overrides?.id ?? generateMessageId(),\n type: \"message\",\n role: \"assistant\",\n content: toolCalls.map((tc) => {\n let argsObj: unknown;\n try {\n argsObj = JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsObj = {};\n }\n return {\n type: \"tool_use\",\n id: tc.id || generateToolUseId(),\n name: tc.name,\n input: argsObj,\n };\n }),\n model: overrides?.model ?? model,\n stop_reason: bedrockStopReason(overrides?.finishReason, \"tool_use\"),\n stop_sequence: null,\n usage: bedrockUsage(overrides),\n };\n}\n\n// ─── Request handler ────────────────────────────────────────────────────────\n\nexport async function handleBedrock(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/invoke`;\n\n let bedrockReq: BedrockRequest;\n try {\n bedrockReq = JSON.parse(raw) as BedrockRequest;\n } catch (parseErr) {\n const detail = parseErr instanceof Error ? parseErr.message : \"unknown\";\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: `Malformed JSON: ${detail}`,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!bedrockReq.messages || !Array.isArray(bedrockReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n // Convert to ChatCompletionRequest for fixture matching\n const completionReq = bedrockToCompletionRequest(bedrockReq, modelId, logger);\n completionReq._endpointType = \"chat\";\n completionReq._context = getContext(req);\n\n const testId = getTestId(req);\n const fixture = matchFixture(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n if (effectiveStrict) {\n const strictStatus = 503;\n const strictMessage = \"Strict mode: no fixture matched\";\n logger.error(`STRICT: No fixture matched for ${req.method ?? \"POST\"} ${urlPath}`);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: strictStatus,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome === \"handled_by_hook\") return;\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: 404,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n 404,\n JSON.stringify({\n error: {\n message: \"No fixture matched\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n // Bedrock Claude error format: { type: \"error\", error: { type, message } }\n // Uses ?? (nullish coalescing) intentionally — preserves explicit empty-string types from fixtures.\n const anthropicError = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"api_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(anthropicError), {\n retryAfter: response.retryAfter,\n });\n return;\n }\n\n // Content + tool calls response\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const textBody = buildBedrockTextResponse(\n response.content,\n completionReq.model,\n response.reasoning,\n overrides,\n );\n const toolBody = buildBedrockToolCallResponse(\n response.toolCalls,\n completionReq.model,\n logger,\n overrides,\n );\n // Merge: take the text response as base, append tool_use blocks, set stop_reason to tool_use\n const merged = {\n ...(textBody as Record<string, unknown>),\n content: [\n ...((textBody as Record<string, unknown>).content as object[]),\n ...((toolBody as Record<string, unknown>).content as object[]),\n ],\n stop_reason: bedrockStopReason(overrides?.finishReason, \"tool_use\"),\n };\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(merged));\n return;\n }\n\n // Text response\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildBedrockTextResponse(\n response.content,\n completionReq.model,\n response.reasoning,\n overrides,\n );\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Tool call response\n if (isToolCallResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildBedrockToolCallResponse(\n response.toolCalls,\n completionReq.model,\n logger,\n overrides,\n );\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n\n// ─── Streaming event builders ───────────────────────────────────────────────\n\nconst BEDROCK_INVOKE_STREAM_EVENT_TYPE = \"chunk\";\n\nfunction buildBedrockInvokeMessageStart(\n model: string,\n overrides?: ResponseOverrides,\n): { eventType: string; payload: object } {\n return {\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"message_start\",\n message: {\n id: overrides?.id ?? generateMessageId(),\n type: \"message\",\n role: \"assistant\",\n content: [],\n model: overrides?.model ?? model,\n stop_reason: null,\n stop_sequence: null,\n usage: bedrockUsage(overrides),\n },\n },\n };\n}\n\nfunction buildBedrockInvokeMessageDelta(stopReason: string): {\n eventType: string;\n payload: object;\n} {\n return {\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"message_delta\",\n delta: { stop_reason: stopReason, stop_sequence: null },\n usage: { output_tokens: 0 },\n },\n };\n}\n\nfunction buildBedrockInvokeMessageStop(): { eventType: string; payload: object } {\n return {\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"message_stop\" },\n };\n}\n\nfunction parseToolArgumentsForStream(toolCall: ToolCall, logger: Logger): string {\n try {\n const parsed = JSON.parse(toolCall.arguments || \"{}\");\n return JSON.stringify(parsed);\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${toolCall.name}\": ${toolCall.arguments}`,\n );\n return \"{}\";\n }\n}\n\nexport function buildBedrockStreamTextEvents(\n content: string,\n model: string,\n chunkSize: number,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [];\n\n events.push(buildBedrockInvokeMessageStart(model, overrides));\n\n // Thinking block (emitted before text when reasoning is present)\n if (reasoning) {\n const blockIndex = 0;\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"thinking\", thinking: \"\", signature: \"\" },\n },\n });\n\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n const slice = reasoning.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"thinking_delta\", thinking: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"signature_delta\", signature: \"\" },\n },\n });\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n }\n\n // Text block\n const textBlockIndex = reasoning ? 1 : 0;\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: textBlockIndex,\n content_block: { type: \"text\", text: \"\" },\n },\n });\n\n for (let i = 0; i < content.length; i += chunkSize) {\n const slice = content.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: textBlockIndex,\n delta: { type: \"text_delta\", text: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: textBlockIndex },\n });\n\n events.push(\n buildBedrockInvokeMessageDelta(bedrockStopReason(overrides?.finishReason, \"end_turn\")),\n );\n events.push(buildBedrockInvokeMessageStop());\n\n return events;\n}\n\nexport function buildBedrockStreamContentWithToolCallsEvents(\n content: string,\n toolCalls: ToolCall[],\n model: string,\n chunkSize: number,\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [];\n\n events.push(buildBedrockInvokeMessageStart(model, overrides));\n\n let blockIndex = 0;\n\n // Thinking block (emitted before text when reasoning is present)\n if (reasoning) {\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"thinking\", thinking: \"\", signature: \"\" },\n },\n });\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n const slice = reasoning.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"thinking_delta\", thinking: slice },\n },\n });\n }\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"signature_delta\", signature: \"\" },\n },\n });\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n blockIndex++;\n }\n\n // Text block\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"text\", text: \"\" },\n },\n });\n for (let i = 0; i < content.length; i += chunkSize) {\n const slice = content.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"text_delta\", text: slice },\n },\n });\n }\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n blockIndex++;\n\n // Tool call blocks\n for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {\n const tc = toolCalls[tcIdx];\n const toolUseId = tc.id || generateToolUseId();\n const currentBlock = blockIndex + tcIdx;\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: currentBlock,\n content_block: {\n type: \"tool_use\",\n id: toolUseId,\n name: tc.name,\n input: {},\n },\n },\n });\n\n const argsStr = parseToolArgumentsForStream(tc, logger);\n\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n const slice = argsStr.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: currentBlock,\n delta: { type: \"input_json_delta\", partial_json: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: currentBlock },\n });\n }\n\n events.push(\n buildBedrockInvokeMessageDelta(bedrockStopReason(overrides?.finishReason, \"tool_use\")),\n );\n events.push(buildBedrockInvokeMessageStop());\n\n return events;\n}\n\nexport function buildBedrockStreamToolCallEvents(\n toolCalls: ToolCall[],\n model: string,\n chunkSize: number,\n logger: Logger,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [];\n\n events.push(buildBedrockInvokeMessageStart(model, overrides));\n\n for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {\n const tc = toolCalls[tcIdx];\n const toolUseId = tc.id || generateToolUseId();\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: tcIdx,\n content_block: {\n type: \"tool_use\",\n id: toolUseId,\n name: tc.name,\n input: {},\n },\n },\n });\n\n const argsStr = parseToolArgumentsForStream(tc, logger);\n\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n const slice = argsStr.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: tcIdx,\n delta: { type: \"input_json_delta\", partial_json: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: tcIdx },\n });\n }\n\n events.push(\n buildBedrockInvokeMessageDelta(bedrockStopReason(overrides?.finishReason, \"tool_use\")),\n );\n events.push(buildBedrockInvokeMessageStop());\n\n return events;\n}\n\n// ─── Streaming request handler ──────────────────────────────────────────────\n\nexport async function handleBedrockStream(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/invoke-with-response-stream`;\n\n let bedrockReq: BedrockRequest;\n try {\n bedrockReq = JSON.parse(raw) as BedrockRequest;\n } catch (parseErr) {\n const detail = parseErr instanceof Error ? parseErr.message : \"unknown\";\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: `Malformed JSON: ${detail}`,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!bedrockReq.messages || !Array.isArray(bedrockReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const completionReq = bedrockToCompletionRequest(bedrockReq, modelId, logger);\n completionReq.stream = true;\n completionReq._endpointType = \"chat\";\n completionReq._context = getContext(req);\n\n const testId = getTestId(req);\n const fixture = matchFixture(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n if (effectiveStrict) {\n const strictStatus = 503;\n const strictMessage = \"Strict mode: no fixture matched\";\n logger.error(`STRICT: No fixture matched for ${req.method ?? \"POST\"} ${urlPath}`);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: strictStatus,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome === \"handled_by_hook\") return;\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: 404,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n 404,\n JSON.stringify({\n error: {\n message: \"No fixture matched\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n const latency = fixture.latency ?? defaults.latency;\n const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n // Bedrock Claude error format: { type: \"error\", error: { type, message } }\n // Uses ?? (nullish coalescing) intentionally — preserves explicit empty-string types from fixtures.\n const anthropicError = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"api_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(anthropicError), {\n retryAfter: response.retryAfter,\n });\n return;\n }\n\n // Content + tool calls response — stream as Event Stream\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamContentWithToolCallsEvents(\n response.content,\n response.toolCalls,\n completionReq.model,\n chunkSize,\n logger,\n response.reasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n recordedTimings: fixture.recordedTimings,\n replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Text response — stream as Event Stream\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamTextEvents(\n response.content,\n completionReq.model,\n chunkSize,\n response.reasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n recordedTimings: fixture.recordedTimings,\n replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Tool call response — stream as Event Stream\n if (isToolCallResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamToolCallEvents(\n response.toolCalls,\n completionReq.model,\n chunkSize,\n logger,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n recordedTimings: fixture.recordedTimings,\n replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n"],"mappings":";;;;;;;;;AA0FA,SAAS,kBACP,sBACA,eACQ;AACR,KAAI,CAAC,qBAAsB,QAAO;AAClC,KAAI,yBAAyB,OAAQ,QAAO;AAC5C,KAAI,yBAAyB,aAAc,Q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AM;EACN,UAAU;GAAE,QAAQ;GAAK;GAAS;EACnC,CAAC;AACF,uCACE,KACA,KACA,KAAK,UAAU,EACb,OAAO;EACL,SAAS;EACT,MAAM;EACP,EACF,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"bedrock.cjs","names":["generateMessageId","generateToolUseId","flattenHeaders","getContext","getTestId","matchFixtureDiagnostic","applyChaos","resolveStrictMode","strictNoMatchMessage","strictNoMatchLogLine","strictOverrideField","proxyAndRecord","resolveResponse","isErrorResponse","isContentWithToolCallsResponse","extractOverrides","resolveReasoningForModel","isTextResponse","isToolCallResponse","createInterruptionSignal","writeEventStream"],"sources":["../src/bedrock.ts"],"sourcesContent":["/**\n * AWS Bedrock Claude endpoint support — invoke and invoke-with-response-stream.\n *\n * Handles four Bedrock endpoint families (split across two modules):\n *\n * This file (bedrock.ts):\n * - POST /model/{modelId}/invoke — non-streaming invoke\n * - POST /model/{modelId}/invoke-with-response-stream — binary EventStream streaming\n *\n * bedrock-converse.ts:\n * - POST /model/{modelId}/converse — Converse API (non-streaming)\n * - POST /model/{modelId}/converse-stream — Converse API (EventStream streaming)\n *\n * Translates incoming Bedrock Claude format into the ChatCompletionRequest\n * format used by the fixture router, and converts fixture responses back into\n * the appropriate Bedrock response format (JSON for invoke, AWS Event Stream\n * binary encoding for streaming).\n */\n\nimport type * as http from \"node:http\";\nimport type {\n ChatCompletionRequest,\n ChatMessage,\n Fixture,\n HandlerDefaults,\n ResponseOverrides,\n ToolCall,\n ToolDefinition,\n} from \"./types.js\";\nimport {\n generateMessageId,\n generateToolUseId,\n extractOverrides,\n isTextResponse,\n isToolCallResponse,\n isContentWithToolCallsResponse,\n isErrorResponse,\n flattenHeaders,\n getContext,\n getTestId,\n resolveResponse,\n resolveReasoningForModel,\n resolveStrictMode,\n strictOverrideField,\n strictNoMatchMessage,\n strictNoMatchLogLine,\n} from \"./helpers.js\";\nimport { matchFixtureDiagnostic } from \"./router.js\";\nimport { writeErrorResponse } from \"./sse-writer.js\";\nimport { writeEventStream } from \"./aws-event-stream.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport type { Journal } from \"./journal.js\";\nimport type { Logger } from \"./logger.js\";\nimport { applyChaos } from \"./chaos.js\";\nimport { proxyAndRecord } from \"./recorder.js\";\n\n// ─── Bedrock Claude request types ────────────────────────────────────────────\n\ninterface BedrockContentBlock {\n type: \"text\" | \"tool_use\" | \"tool_result\" | \"image\" | \"document\";\n text?: string;\n id?: string;\n name?: string;\n input?: unknown;\n tool_use_id?: string;\n content?: string | BedrockContentBlock[];\n is_error?: boolean;\n}\n\ninterface BedrockMessage {\n role: \"user\" | \"assistant\";\n content: string | BedrockContentBlock[];\n}\n\ninterface BedrockToolDef {\n name: string;\n description?: string;\n input_schema?: object;\n}\n\ninterface BedrockRequest {\n anthropic_version?: string;\n messages: BedrockMessage[];\n system?: string | BedrockContentBlock[];\n tools?: BedrockToolDef[];\n tool_choice?: unknown;\n max_tokens: number;\n temperature?: number;\n [key: string]: unknown;\n}\n\n// ─── Bedrock stop_reason mapping ───────────────────────────────────────────\n\nfunction bedrockStopReason(\n overrideFinishReason: string | undefined,\n defaultReason: string,\n): string {\n if (!overrideFinishReason) return defaultReason;\n if (overrideFinishReason === \"stop\") return \"end_turn\";\n if (overrideFinishReason === \"tool_calls\") return \"tool_use\";\n if (overrideFinishReason === \"length\") return \"max_tokens\";\n return overrideFinishReason;\n}\n\n/**\n * Build a Bedrock-style usage object from optional overrides.\n *\n * When no overrides are provided (the common case for mock fixtures),\n * returns all-zero token counts. This is intentional — aimock does not\n * attempt to estimate token usage from fixture content. Callers that\n * need realistic usage numbers should set `usage` in their fixture's\n * response overrides.\n */\nfunction bedrockUsage(overrides?: ResponseOverrides): {\n input_tokens: number;\n output_tokens: number;\n} {\n if (!overrides?.usage) return { input_tokens: 0, output_tokens: 0 };\n return {\n input_tokens: overrides.usage.input_tokens ?? overrides.usage.prompt_tokens ?? 0,\n output_tokens: overrides.usage.output_tokens ?? overrides.usage.completion_tokens ?? 0,\n };\n}\n\n// ─── Input conversion: Bedrock → ChatCompletionRequest ──────────────────────\n\nfunction extractTextContent(content: string | BedrockContentBlock[]): string {\n if (typeof content === \"string\") return content;\n return content\n .filter((b) => b.type === \"text\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n}\n\nexport function bedrockToCompletionRequest(\n req: BedrockRequest,\n modelId: string,\n logger?: Logger,\n): ChatCompletionRequest {\n const messages: ChatMessage[] = [];\n\n // system field → system message\n if (req.system) {\n const systemText =\n typeof req.system === \"string\"\n ? req.system\n : req.system\n .filter((b) => b.type === \"text\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n if (systemText) {\n messages.push({ role: \"system\", content: systemText });\n }\n }\n\n for (const msg of req.messages) {\n if (msg.role === \"user\") {\n // Check for tool_result blocks\n if (typeof msg.content !== \"string\" && Array.isArray(msg.content)) {\n // Warn about non-text content blocks that will be dropped (image, document, etc.)\n const unsupportedBlocks = msg.content.filter(\n (b) => b.type !== \"text\" && b.type !== \"tool_result\",\n );\n if (unsupportedBlocks.length > 0 && logger) {\n const types = [...new Set(unsupportedBlocks.map((b) => b.type))].join(\", \");\n logger.warn(\n `Bedrock user message contains unsupported content block types [${types}] — these will be dropped during conversion`,\n );\n }\n\n const toolResults = msg.content.filter((b) => b.type === \"tool_result\");\n const textBlocks = msg.content.filter((b) => b.type === \"text\");\n\n if (toolResults.length > 0) {\n for (const tr of toolResults) {\n const resultContent =\n typeof tr.content === \"string\"\n ? tr.content\n : Array.isArray(tr.content)\n ? tr.content\n .filter((b) => b.type === \"text\")\n .map((b) => b.text ?? \"\")\n .join(\"\")\n : \"\";\n messages.push({\n role: \"tool\",\n content: resultContent,\n tool_call_id: tr.tool_use_id,\n });\n }\n if (textBlocks.length > 0) {\n messages.push({\n role: \"user\",\n content: textBlocks.map((b) => b.text ?? \"\").join(\"\"),\n });\n }\n continue;\n }\n }\n messages.push({\n role: \"user\",\n content: extractTextContent(msg.content),\n });\n } else if (msg.role === \"assistant\") {\n if (typeof msg.content === \"string\") {\n messages.push({ role: \"assistant\", content: msg.content });\n } else if (Array.isArray(msg.content)) {\n const toolUseBlocks = msg.content.filter((b) => b.type === \"tool_use\");\n const textContent = extractTextContent(msg.content);\n\n if (toolUseBlocks.length > 0) {\n messages.push({\n role: \"assistant\",\n content: textContent || null,\n tool_calls: toolUseBlocks.map((b, index) => {\n if (!b.id && logger) {\n logger.warn(\n `Bedrock assistant tool_use block at index ${index} is missing an id — using deterministic fallback \"tool_use_${index}\"`,\n );\n }\n return {\n id: b.id ?? `tool_use_${index}`,\n type: \"function\" as const,\n function: {\n name: b.name ?? \"\",\n arguments: typeof b.input === \"string\" ? b.input : JSON.stringify(b.input ?? {}),\n },\n };\n }),\n });\n } else {\n messages.push({ role: \"assistant\", content: textContent || null });\n }\n } else {\n messages.push({ role: \"assistant\", content: null });\n }\n } else {\n if (logger) {\n logger.warn(\n `Bedrock message has unexpected role \"${(msg as { role: string }).role}\" — skipping`,\n );\n }\n }\n }\n\n // Convert tools\n let tools: ToolDefinition[] | undefined;\n if (req.tools && req.tools.length > 0) {\n tools = req.tools.map((t) => ({\n type: \"function\" as const,\n function: {\n name: t.name,\n description: t.description,\n parameters: t.input_schema,\n },\n }));\n }\n\n return {\n model: modelId,\n messages,\n stream: false,\n temperature: req.temperature,\n max_tokens: req.max_tokens,\n tools,\n };\n}\n\n// ─── Response builders ──────────────────────────────────────────────────────\n\nfunction buildBedrockTextResponse(\n content: string,\n model: string,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n if (reasoning) {\n contentBlocks.push({ type: \"thinking\", thinking: reasoning, signature: \"\" });\n }\n contentBlocks.push({ type: \"text\", text: content });\n\n return {\n id: overrides?.id ?? generateMessageId(),\n type: \"message\",\n role: \"assistant\",\n content: contentBlocks,\n model: overrides?.model ?? model,\n stop_reason: bedrockStopReason(overrides?.finishReason, \"end_turn\"),\n stop_sequence: null,\n usage: bedrockUsage(overrides),\n };\n}\n\nfunction buildBedrockToolCallResponse(\n toolCalls: ToolCall[],\n model: string,\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n // Thinking block (emitted before tool_use blocks when reasoning is present)\n if (reasoning) {\n contentBlocks.push({ type: \"thinking\", thinking: reasoning, signature: \"\" });\n }\n for (const tc of toolCalls) {\n let argsObj: unknown;\n try {\n argsObj = JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsObj = {};\n }\n contentBlocks.push({\n type: \"tool_use\",\n id: tc.id || generateToolUseId(),\n name: tc.name,\n input: argsObj,\n });\n }\n return {\n id: overrides?.id ?? generateMessageId(),\n type: \"message\",\n role: \"assistant\",\n content: contentBlocks,\n model: overrides?.model ?? model,\n stop_reason: bedrockStopReason(overrides?.finishReason, \"tool_use\"),\n stop_sequence: null,\n usage: bedrockUsage(overrides),\n };\n}\n\n// ─── Request handler ────────────────────────────────────────────────────────\n\nexport async function handleBedrock(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/invoke`;\n\n let bedrockReq: BedrockRequest;\n try {\n bedrockReq = JSON.parse(raw) as BedrockRequest;\n } catch (parseErr) {\n const detail = parseErr instanceof Error ? parseErr.message : \"unknown\";\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: `Malformed JSON: ${detail}`,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!bedrockReq.messages || !Array.isArray(bedrockReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n // Convert to ChatCompletionRequest for fixture matching\n const completionReq = bedrockToCompletionRequest(bedrockReq, modelId, logger);\n completionReq._endpointType = \"chat\";\n completionReq._context = getContext(req);\n\n const testId = getTestId(req);\n const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n if (effectiveStrict) {\n const strictStatus = 503;\n const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);\n logger.error(strictNoMatchLogLine(req.method ?? \"POST\", urlPath, skippedBySequenceOrTurn));\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: strictStatus,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome === \"handled_by_hook\") return;\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: 404,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n 404,\n JSON.stringify({\n error: {\n message: \"No fixture matched\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n // Bedrock Claude error format: { type: \"error\", error: { type, message } }\n // Uses ?? (nullish coalescing) intentionally — preserves explicit empty-string types from fixtures.\n const anthropicError = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"api_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(anthropicError), {\n retryAfter: response.retryAfter,\n });\n return;\n }\n\n // Content + tool calls response\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const effReasoning = resolveReasoningForModel(\n response.reasoning,\n completionReq.model,\n resolveStrictMode(defaults.strict, req.headers),\n logger,\n );\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const textBody = buildBedrockTextResponse(\n response.content,\n completionReq.model,\n effReasoning,\n overrides,\n );\n const toolBody = buildBedrockToolCallResponse(\n response.toolCalls,\n completionReq.model,\n logger,\n // Reasoning is rendered by the text response in this merged path; pass\n // undefined here to avoid emitting a duplicate thinking block.\n undefined,\n overrides,\n );\n // Merge: take the text response as base, append tool_use blocks, set stop_reason to tool_use\n const merged = {\n ...(textBody as Record<string, unknown>),\n content: [\n ...((textBody as Record<string, unknown>).content as object[]),\n ...((toolBody as Record<string, unknown>).content as object[]),\n ],\n stop_reason: bedrockStopReason(overrides?.finishReason, \"tool_use\"),\n };\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(merged));\n return;\n }\n\n // Text response\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const effReasoning = resolveReasoningForModel(\n response.reasoning,\n completionReq.model,\n resolveStrictMode(defaults.strict, req.headers),\n logger,\n );\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildBedrockTextResponse(\n response.content,\n completionReq.model,\n effReasoning,\n overrides,\n );\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Tool call response\n if (isToolCallResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const effReasoning = resolveReasoningForModel(\n response.reasoning,\n completionReq.model,\n resolveStrictMode(defaults.strict, req.headers),\n logger,\n );\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildBedrockToolCallResponse(\n response.toolCalls,\n completionReq.model,\n logger,\n effReasoning,\n overrides,\n );\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n\n// ─── Streaming event builders ───────────────────────────────────────────────\n\nconst BEDROCK_INVOKE_STREAM_EVENT_TYPE = \"chunk\";\n\nfunction buildBedrockInvokeMessageStart(\n model: string,\n overrides?: ResponseOverrides,\n): { eventType: string; payload: object } {\n return {\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"message_start\",\n message: {\n id: overrides?.id ?? generateMessageId(),\n type: \"message\",\n role: \"assistant\",\n content: [],\n model: overrides?.model ?? model,\n stop_reason: null,\n stop_sequence: null,\n usage: bedrockUsage(overrides),\n },\n },\n };\n}\n\nfunction buildBedrockInvokeMessageDelta(stopReason: string): {\n eventType: string;\n payload: object;\n} {\n return {\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"message_delta\",\n delta: { stop_reason: stopReason, stop_sequence: null },\n usage: { output_tokens: 0 },\n },\n };\n}\n\nfunction buildBedrockInvokeMessageStop(): { eventType: string; payload: object } {\n return {\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"message_stop\" },\n };\n}\n\nfunction parseToolArgumentsForStream(toolCall: ToolCall, logger: Logger): string {\n try {\n const parsed = JSON.parse(toolCall.arguments || \"{}\");\n return JSON.stringify(parsed);\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${toolCall.name}\": ${toolCall.arguments}`,\n );\n return \"{}\";\n }\n}\n\nexport function buildBedrockStreamTextEvents(\n content: string,\n model: string,\n chunkSize: number,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [];\n\n events.push(buildBedrockInvokeMessageStart(model, overrides));\n\n // Thinking block (emitted before text when reasoning is present)\n if (reasoning) {\n const blockIndex = 0;\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"thinking\", thinking: \"\", signature: \"\" },\n },\n });\n\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n const slice = reasoning.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"thinking_delta\", thinking: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"signature_delta\", signature: \"\" },\n },\n });\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n }\n\n // Text block\n const textBlockIndex = reasoning ? 1 : 0;\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: textBlockIndex,\n content_block: { type: \"text\", text: \"\" },\n },\n });\n\n for (let i = 0; i < content.length; i += chunkSize) {\n const slice = content.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: textBlockIndex,\n delta: { type: \"text_delta\", text: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: textBlockIndex },\n });\n\n events.push(\n buildBedrockInvokeMessageDelta(bedrockStopReason(overrides?.finishReason, \"end_turn\")),\n );\n events.push(buildBedrockInvokeMessageStop());\n\n return events;\n}\n\nexport function buildBedrockStreamContentWithToolCallsEvents(\n content: string,\n toolCalls: ToolCall[],\n model: string,\n chunkSize: number,\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [];\n\n events.push(buildBedrockInvokeMessageStart(model, overrides));\n\n let blockIndex = 0;\n\n // Thinking block (emitted before text when reasoning is present)\n if (reasoning) {\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"thinking\", thinking: \"\", signature: \"\" },\n },\n });\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n const slice = reasoning.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"thinking_delta\", thinking: slice },\n },\n });\n }\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"signature_delta\", signature: \"\" },\n },\n });\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n blockIndex++;\n }\n\n // Text block\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"text\", text: \"\" },\n },\n });\n for (let i = 0; i < content.length; i += chunkSize) {\n const slice = content.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"text_delta\", text: slice },\n },\n });\n }\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n blockIndex++;\n\n // Tool call blocks\n for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {\n const tc = toolCalls[tcIdx];\n const toolUseId = tc.id || generateToolUseId();\n const currentBlock = blockIndex + tcIdx;\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: currentBlock,\n content_block: {\n type: \"tool_use\",\n id: toolUseId,\n name: tc.name,\n input: {},\n },\n },\n });\n\n const argsStr = parseToolArgumentsForStream(tc, logger);\n\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n const slice = argsStr.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: currentBlock,\n delta: { type: \"input_json_delta\", partial_json: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: currentBlock },\n });\n }\n\n events.push(\n buildBedrockInvokeMessageDelta(bedrockStopReason(overrides?.finishReason, \"tool_use\")),\n );\n events.push(buildBedrockInvokeMessageStop());\n\n return events;\n}\n\nexport function buildBedrockStreamToolCallEvents(\n toolCalls: ToolCall[],\n model: string,\n chunkSize: number,\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [];\n\n events.push(buildBedrockInvokeMessageStart(model, overrides));\n\n // Leading reasoning block shifts every subsequent tool_use block index by 1.\n let blockIndex = 0;\n\n // Thinking block (emitted before tool_use blocks when reasoning is present)\n if (reasoning) {\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: blockIndex,\n content_block: { type: \"thinking\", thinking: \"\", signature: \"\" },\n },\n });\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n const slice = reasoning.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"thinking_delta\", thinking: slice },\n },\n });\n }\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: blockIndex,\n delta: { type: \"signature_delta\", signature: \"\" },\n },\n });\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: blockIndex },\n });\n blockIndex++;\n }\n\n for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {\n const tc = toolCalls[tcIdx];\n const toolUseId = tc.id || generateToolUseId();\n const currentBlock = blockIndex + tcIdx;\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_start\",\n index: currentBlock,\n content_block: {\n type: \"tool_use\",\n id: toolUseId,\n name: tc.name,\n input: {},\n },\n },\n });\n\n const argsStr = parseToolArgumentsForStream(tc, logger);\n\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n const slice = argsStr.slice(i, i + chunkSize);\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: {\n type: \"content_block_delta\",\n index: currentBlock,\n delta: { type: \"input_json_delta\", partial_json: slice },\n },\n });\n }\n\n events.push({\n eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,\n payload: { type: \"content_block_stop\", index: currentBlock },\n });\n }\n\n events.push(\n buildBedrockInvokeMessageDelta(bedrockStopReason(overrides?.finishReason, \"tool_use\")),\n );\n events.push(buildBedrockInvokeMessageStop());\n\n return events;\n}\n\n// ─── Streaming request handler ──────────────────────────────────────────────\n\nexport async function handleBedrockStream(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/invoke-with-response-stream`;\n\n let bedrockReq: BedrockRequest;\n try {\n bedrockReq = JSON.parse(raw) as BedrockRequest;\n } catch (parseErr) {\n const detail = parseErr instanceof Error ? parseErr.message : \"unknown\";\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: `Malformed JSON: ${detail}`,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!bedrockReq.messages || !Array.isArray(bedrockReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const completionReq = bedrockToCompletionRequest(bedrockReq, modelId, logger);\n completionReq.stream = true;\n completionReq._endpointType = \"chat\";\n completionReq._context = getContext(req);\n\n const testId = getTestId(req);\n const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n if (effectiveStrict) {\n const strictStatus = 503;\n const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);\n logger.error(strictNoMatchLogLine(req.method ?? \"POST\", urlPath, skippedBySequenceOrTurn));\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: strictStatus,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome === \"handled_by_hook\") return;\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: {\n status: 404,\n fixture: null,\n ...strictOverrideField(defaults.strict, req.headers),\n },\n });\n writeErrorResponse(\n res,\n 404,\n JSON.stringify({\n error: {\n message: \"No fixture matched\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n const latency = fixture.latency ?? defaults.latency;\n const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n // Bedrock Claude error format: { type: \"error\", error: { type, message } }\n // Uses ?? (nullish coalescing) intentionally — preserves explicit empty-string types from fixtures.\n const anthropicError = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"api_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(anthropicError), {\n retryAfter: response.retryAfter,\n });\n return;\n }\n\n // Content + tool calls response — stream as Event Stream\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const effReasoning = resolveReasoningForModel(\n response.reasoning,\n completionReq.model,\n resolveStrictMode(defaults.strict, req.headers),\n logger,\n );\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamContentWithToolCallsEvents(\n response.content,\n response.toolCalls,\n completionReq.model,\n chunkSize,\n logger,\n effReasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n recordedTimings: fixture.recordedTimings,\n replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Text response — stream as Event Stream\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const effReasoning = resolveReasoningForModel(\n response.reasoning,\n completionReq.model,\n resolveStrictMode(defaults.strict, req.headers),\n logger,\n );\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamTextEvents(\n response.content,\n completionReq.model,\n chunkSize,\n effReasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n recordedTimings: fixture.recordedTimings,\n replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Tool call response — stream as Event Stream\n if (isToolCallResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\"webSearches in fixture response are not supported for Bedrock API — ignoring\");\n }\n const overrides = extractOverrides(response);\n const effReasoning = resolveReasoningForModel(\n response.reasoning,\n completionReq.model,\n resolveStrictMode(defaults.strict, req.headers),\n logger,\n );\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamToolCallEvents(\n response.toolCalls,\n completionReq.model,\n chunkSize,\n logger,\n effReasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n recordedTimings: fixture.recordedTimings,\n replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n"],"mappings":";;;;;;;;;AA6FA,SAAS,kBACP,sBACA,eACQ;AACR,KAAI,CAAC,qBAAsB,QAAO;AAClC,KAAI,yBAAyB,OAAQ,QAAO;AAC5C,KAAI,yBAAyB,aAAc,QAAO;AAClD,KAAI,yBAAyB,SAAU,QAAO;AAC9C,QAAO;;;;;;;;;;;AAYT,SAAS,aAAa,WAGpB;AACA,KAAI,CAAC,WAAW,MAAO,QAAO;EAAE,cAAc;EAAG,eAAe;EAAG;AACnE,QAAO;EACL,cAAc,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SAASlB,+BAAe,IAAI,QAAQ;EACpC,MAAM;EACN,UAAU;GAAE,QAAQ;GAAK;GAAS;EACnC,CAAC;AACF,uCACE,KACA,KACA,KAAK,UAAU,EACb,OAAO;EACL,SAAS;EACT,MAAM;EACP,EACF,CAAC,CACH"}
|
package/dist/bedrock.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock.d.cts","names":[],"sources":["../src/bedrock.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"bedrock.d.cts","names":[],"sources":["../src/bedrock.ts"],"sourcesContent":[],"mappings":";;;;;;;UA0DU,mBAAA,CAuRyB;MAC5B,EAAA,MAAK,GAAA,UAAA,GAAA,aAAA,GAAA,OAAA,GAAA,UAAA;MACL,CAAA,EAAA,MAAK;KAGA,EAAA,MAAA;MACD,CAAA,EAAA,MAAA;OACC,CAAA,EAAA,OAAA;aACiB,CAAA,EAAA,MAAA;SAC1B,CAAA,EAAA,MAAA,GAzRkB,mBAyRlB,EAAA;EAAO,QAAA,CAAA,EAAA,OAAA;AA0rBV;UA/8BU,cAAA,CA+8B+B;MAClC,EAAA,MAAK,GAAA,WAAA;SACL,EAAA,MAAK,GA/8BQ,mBA+8BR,EAAA;;UA58BF,cAAA,CAg9BC;MACC,EAAA,MAAA;aACiB,CAAA,EAAA,MAAA;cAC1B,CAAA,EAAA,MAAA;;UA78BO,cAAA;;YAEE;oBACQ;UACV;;;;;;iBAkDM,0BAAA,MACT,0CAEI,SACR;iBAuMmB,aAAA,MACf,MAAA,CAAK,sBACL,MAAA,CAAK,wDAGA,oBACD,mBACC,uCACY,MAAA,CAAK,0BAC1B;iBA0rBmB,mBAAA,MACf,MAAA,CAAK,sBACL,MAAA,CAAK,wDAGA,oBACD,mBACC,uCACY,MAAA,CAAK,0BAC1B"}
|
package/dist/bedrock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock.d.ts","names":[],"sources":["../src/bedrock.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"bedrock.d.ts","names":[],"sources":["../src/bedrock.ts"],"sourcesContent":[],"mappings":";;;;;;;UA0DU,mBAAA,CAuRyB;MAC5B,EAAA,MAAK,GAAA,UAAA,GAAA,aAAA,GAAA,OAAA,GAAA,UAAA;MACL,CAAA,EAAA,MAAK;KAGA,EAAA,MAAA;MACD,CAAA,EAAA,MAAA;OACC,CAAA,EAAA,OAAA;aACiB,CAAA,EAAA,MAAA;SAC1B,CAAA,EAAA,MAAA,GAzRkB,mBAyRlB,EAAA;EAAO,QAAA,CAAA,EAAA,OAAA;AA0rBV;UA/8BU,cAAA,CA+8B+B;MAClC,EAAA,MAAK,GAAA,WAAA;SACL,EAAA,MAAK,GA/8BQ,mBA+8BR,EAAA;;UA58BF,cAAA,CAg9BC;MACC,EAAA,MAAA;aACiB,CAAA,EAAA,MAAA;cAC1B,CAAA,EAAA,MAAA;;UA78BO,cAAA;;YAEE;oBACQ;UACV;;;;;;iBAkDM,0BAAA,MACT,0CAEI,SACR;iBAuMmB,aAAA,MACf,MAAA,CAAK,sBACL,MAAA,CAAK,wDAGA,oBACD,mBACC,uCACY,MAAA,CAAK,0BAC1B;iBA0rBmB,mBAAA,MACf,MAAA,CAAK,sBACL,MAAA,CAAK,wDAGA,oBACD,mBACC,uCACY,MAAA,CAAK,0BAC1B"}
|