@copilotkit/aimock 1.46.0 → 1.47.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +12 -1
- package/README.md +4 -1
- package/dist/aws-event-stream.cjs +20 -23
- package/dist/aws-event-stream.cjs.map +1 -1
- package/dist/aws-event-stream.d.cts +0 -1
- package/dist/aws-event-stream.d.ts +0 -1
- package/dist/aws-event-stream.js +20 -24
- package/dist/aws-event-stream.js.map +1 -1
- package/dist/bedrock-converse.cjs +79 -82
- 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 +80 -83
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +112 -121
- 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 +113 -122
- package/dist/bedrock.js.map +1 -1
- package/dist/cohere.cjs +58 -106
- 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 +60 -108
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/fixture-loader.cjs +103 -2
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +104 -4
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-interactions.cjs +63 -121
- 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 +65 -123
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +242 -155
- 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 +244 -157
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +400 -7
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +51 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +51 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +391 -8
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/mcp-fakes.d.cts.map +1 -1
- package/dist/messages.cjs +159 -141
- 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 +161 -143
- package/dist/messages.js.map +1 -1
- package/dist/misbehavior.cjs +62 -3
- package/dist/misbehavior.cjs.map +1 -1
- package/dist/misbehavior.d.cts.map +1 -1
- package/dist/misbehavior.d.ts.map +1 -1
- package/dist/misbehavior.js +63 -4
- package/dist/misbehavior.js.map +1 -1
- package/dist/ndjson-writer.cjs +21 -23
- package/dist/ndjson-writer.cjs.map +1 -1
- package/dist/ndjson-writer.d.cts +0 -1
- package/dist/ndjson-writer.d.cts.map +1 -1
- package/dist/ndjson-writer.d.ts +0 -1
- package/dist/ndjson-writer.d.ts.map +1 -1
- package/dist/ndjson-writer.js +21 -24
- package/dist/ndjson-writer.js.map +1 -1
- package/dist/ollama.cjs +153 -147
- 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 +155 -149
- package/dist/ollama.js.map +1 -1
- package/dist/openrouter-chat.cjs +1 -1
- package/dist/openrouter-chat.js +1 -1
- package/dist/raw-validation.cjs +177 -0
- package/dist/raw-validation.cjs.map +1 -0
- package/dist/raw-validation.js +176 -0
- package/dist/raw-validation.js.map +1 -0
- package/dist/response/deliver.cjs +144 -0
- package/dist/response/deliver.cjs.map +1 -0
- package/dist/response/deliver.js +143 -0
- package/dist/response/deliver.js.map +1 -0
- package/dist/response/frame-loop.cjs +102 -0
- package/dist/response/frame-loop.cjs.map +1 -0
- package/dist/response/frame-loop.js +100 -0
- package/dist/response/frame-loop.js.map +1 -0
- package/dist/response/lifecycle.cjs +223 -0
- package/dist/response/lifecycle.cjs.map +1 -0
- package/dist/response/lifecycle.js +211 -0
- package/dist/response/lifecycle.js.map +1 -0
- package/dist/response/proxy.cjs +71 -0
- package/dist/response/proxy.cjs.map +1 -0
- package/dist/response/proxy.js +70 -0
- package/dist/response/proxy.js.map +1 -0
- package/dist/response/raw.cjs +228 -0
- package/dist/response/raw.cjs.map +1 -0
- package/dist/response/raw.js +227 -0
- package/dist/response/raw.js.map +1 -0
- package/dist/response/timing.cjs +157 -0
- package/dist/response/timing.cjs.map +1 -0
- package/dist/response/timing.js +150 -0
- package/dist/response/timing.js.map +1 -0
- package/dist/responses.cjs +269 -148
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +270 -149
- package/dist/responses.js.map +1 -1
- package/dist/router.cjs +20 -4
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts +7 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts +7 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +21 -5
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +89 -120
- 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 +91 -122
- package/dist/server.js.map +1 -1
- package/dist/sse-writer.cjs +49 -30
- package/dist/sse-writer.cjs.map +1 -1
- package/dist/sse-writer.d.cts +0 -1
- package/dist/sse-writer.d.cts.map +1 -1
- package/dist/sse-writer.d.ts +0 -1
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/sse-writer.js +49 -31
- package/dist/sse-writer.js.map +1 -1
- package/dist/transcription.cjs +19 -33
- 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 +20 -34
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +173 -10
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +173 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ws-framing.cjs +12 -6
- package/dist/ws-framing.cjs.map +1 -1
- package/dist/ws-framing.d.cts +2 -0
- package/dist/ws-framing.d.cts.map +1 -1
- package/dist/ws-framing.d.ts +2 -0
- package/dist/ws-framing.d.ts.map +1 -1
- package/dist/ws-framing.js +12 -6
- package/dist/ws-framing.js.map +1 -1
- package/dist/ws-gemini-live.cjs +120 -93
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.js +120 -93
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +80 -70
- 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 +80 -70
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +72 -53
- 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 +73 -54
- package/dist/ws-responses.js.map +1 -1
- package/package.json +1 -1
- package/skills/write-fixtures/SKILL.md +34 -2
package/dist/bedrock-converse.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { renderError } from "./response/errors.js";
|
|
2
2
|
import { resolveRequestDecisions, strictOverrideField } from "./response/policy.js";
|
|
3
|
-
import { InvalidToolArgumentsError, estimatePromptTokens, estimateTokens, extractOverrides, flattenHeaders, generateToolUseId, getContext, getTestId, isCombinedFixtureResponse, isErrorResponse, isJsonObject, isTextResponse, isToolCallResponse, requireEmittedFunctionToolCalls, resolveFixtureBlockOutcome, resolveReasoningForModel, resolveResponse, servedToolArgs, strictNoMatchLogLine, strictNoMatchMessage, toolArgsForWire } from "./helpers.js";
|
|
3
|
+
import { InvalidToolArgumentsError, estimatePromptTokens, estimateTokens, extractOverrides, flattenHeaders, generateToolUseId, getContext, getTestId, isCombinedFixtureResponse, isErrorResponse, isJsonObject, isRawResponse, isTextResponse, isToolCallResponse, requireEmittedFunctionToolCalls, resolveFixtureBlockOutcome, resolveReasoningForModel, resolveResponse, servedToolArgs, strictNoMatchLogLine, strictNoMatchMessage, toolArgsForWire } from "./helpers.js";
|
|
4
4
|
import { writeErrorResponse } from "./sse-writer.js";
|
|
5
5
|
import { applyChaosAsync } from "./chaos.js";
|
|
6
6
|
import { planMisbehavior, recordMisbehaviorOutcome } from "./misbehavior.js";
|
|
7
7
|
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
|
|
8
8
|
import { proxyAndRecord } from "./recorder.js";
|
|
9
|
-
import {
|
|
9
|
+
import { misbehaviorPayloadLength, servedPayloadLength } from "./response/timing.js";
|
|
10
|
+
import { deliverJson, deliverStream } from "./response/deliver.js";
|
|
11
|
+
import { proxyInterruption, withHangUpDetection } from "./response/proxy.js";
|
|
12
|
+
import { eventStreamCodec } from "./aws-event-stream.js";
|
|
13
|
+
import { serveRawResponse } from "./response/raw.js";
|
|
10
14
|
import { mapAnthropicFinish } from "./response/finish.js";
|
|
11
|
-
import { writeEventStream } from "./aws-event-stream.js";
|
|
12
15
|
import { render } from "./response/usage/codecs/converse.js";
|
|
13
16
|
|
|
14
17
|
//#region src/bedrock-converse.ts
|
|
@@ -685,7 +688,10 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
685
688
|
completionReq._endpointType = "chat";
|
|
686
689
|
completionReq._context = getContext(req);
|
|
687
690
|
const testId = getTestId(req);
|
|
688
|
-
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform,
|
|
691
|
+
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform, {
|
|
692
|
+
...recordMatchOptions(!!defaults.record, defaults.logger),
|
|
693
|
+
wire: "bedrock-converse"
|
|
694
|
+
});
|
|
689
695
|
if (fixture) logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);
|
|
690
696
|
else logger.debug(`No fixture matched for request`);
|
|
691
697
|
if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures, testId);
|
|
@@ -718,7 +724,7 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
718
724
|
return;
|
|
719
725
|
}
|
|
720
726
|
if (defaults.record) {
|
|
721
|
-
const outcome = await proxyAndRecord(req, res, completionReq, "bedrock", urlPath, fixtures, defaults, raw);
|
|
727
|
+
const { outcome, clientHungUp } = await withHangUpDetection(req, res, () => proxyAndRecord(req, res, completionReq, "bedrock", urlPath, fixtures, defaults, raw));
|
|
722
728
|
if (outcome === "handled_by_hook") return;
|
|
723
729
|
if (outcome !== "not_configured") {
|
|
724
730
|
journal.add({
|
|
@@ -729,7 +735,8 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
729
735
|
response: {
|
|
730
736
|
status: res.statusCode ?? 200,
|
|
731
737
|
fixture: null,
|
|
732
|
-
source: "proxy"
|
|
738
|
+
source: "proxy",
|
|
739
|
+
...proxyInterruption(res, clientHungUp)
|
|
733
740
|
}
|
|
734
741
|
});
|
|
735
742
|
return;
|
|
@@ -796,11 +803,19 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
796
803
|
}).body);
|
|
797
804
|
return;
|
|
798
805
|
}
|
|
806
|
+
const jsonOpts = (payloadLength, duplicateId = false) => ({
|
|
807
|
+
surface: "other",
|
|
808
|
+
payloadLength,
|
|
809
|
+
chunkSize: Math.max(1, fixture.chunkSize ?? defaults.chunkSize),
|
|
810
|
+
recordedTimings: fixture.recordedTimings,
|
|
811
|
+
duplicateId,
|
|
812
|
+
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed
|
|
813
|
+
});
|
|
799
814
|
if (misbehavior.kind === "applied") {
|
|
800
815
|
const prepared = prepareConverseMisbehavior(misbehavior, completionReq, false, defaults, req.headers);
|
|
801
816
|
misbehavior = prepared.plan;
|
|
802
817
|
const body = buildConverseMisbehaviorResponse(prepared);
|
|
803
|
-
addResponseEntry({
|
|
818
|
+
await deliverJson(res, addResponseEntry({
|
|
804
819
|
method: req.method ?? "POST",
|
|
805
820
|
path: urlPath,
|
|
806
821
|
headers: flattenHeaders(req.headers),
|
|
@@ -809,9 +824,24 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
809
824
|
status: 200,
|
|
810
825
|
fixture
|
|
811
826
|
}
|
|
827
|
+
}), fixture, () => body, jsonOpts(misbehaviorPayloadLength(prepared.plan, prepared.plan.reasoning === void 0 ? prepared.reasoning : void 0), !!prepared.plan.duplicateId));
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (isRawResponse(response)) {
|
|
831
|
+
await serveRawResponse({
|
|
832
|
+
wire: "bedrock-converse",
|
|
833
|
+
stream: false,
|
|
834
|
+
req,
|
|
835
|
+
res,
|
|
836
|
+
fixture,
|
|
837
|
+
response,
|
|
838
|
+
body: completionReq,
|
|
839
|
+
journal,
|
|
840
|
+
defaults,
|
|
841
|
+
testId,
|
|
842
|
+
misbehaviorSummary: misbehavior.summary,
|
|
843
|
+
errorWire: "bedrock-converse"
|
|
812
844
|
});
|
|
813
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
814
|
-
res.end(JSON.stringify(body));
|
|
815
845
|
return;
|
|
816
846
|
}
|
|
817
847
|
if (isErrorResponse(response)) {
|
|
@@ -836,7 +866,7 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
836
866
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock Converse API — ignoring");
|
|
837
867
|
const overrides = extractOverrides(response);
|
|
838
868
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression, logger);
|
|
839
|
-
addResponseEntry({
|
|
869
|
+
const journalEntry = addResponseEntry({
|
|
840
870
|
method: req.method ?? "POST",
|
|
841
871
|
path: urlPath,
|
|
842
872
|
headers: flattenHeaders(req.headers),
|
|
@@ -847,16 +877,14 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
847
877
|
}
|
|
848
878
|
});
|
|
849
879
|
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Bedrock Converse");
|
|
850
|
-
|
|
851
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
852
|
-
res.end(JSON.stringify(body));
|
|
880
|
+
await deliverJson(res, journalEntry, fixture, () => buildConverseContentWithToolCallsResponse(response.content ?? "", functionToolCalls, logger, effReasoning, overrides, response.blocks), jsonOpts(servedPayloadLength(response, effReasoning)));
|
|
853
881
|
return;
|
|
854
882
|
}
|
|
855
883
|
if (isTextResponse(response)) {
|
|
856
884
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock Converse API — ignoring");
|
|
857
885
|
const overrides = extractOverrides(response);
|
|
858
886
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression, logger);
|
|
859
|
-
addResponseEntry({
|
|
887
|
+
await deliverJson(res, addResponseEntry({
|
|
860
888
|
method: req.method ?? "POST",
|
|
861
889
|
path: urlPath,
|
|
862
890
|
headers: flattenHeaders(req.headers),
|
|
@@ -865,17 +893,14 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
865
893
|
status: 200,
|
|
866
894
|
fixture
|
|
867
895
|
}
|
|
868
|
-
});
|
|
869
|
-
const body = buildConverseTextResponse(response.content, effReasoning, overrides);
|
|
870
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
871
|
-
res.end(JSON.stringify(body));
|
|
896
|
+
}), fixture, () => buildConverseTextResponse(response.content, effReasoning, overrides), jsonOpts(servedPayloadLength(response, effReasoning)));
|
|
872
897
|
return;
|
|
873
898
|
}
|
|
874
899
|
if (isToolCallResponse(response)) {
|
|
875
900
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock Converse API — ignoring");
|
|
876
901
|
const overrides = extractOverrides(response);
|
|
877
902
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression, logger);
|
|
878
|
-
addResponseEntry({
|
|
903
|
+
const journalEntry = addResponseEntry({
|
|
879
904
|
method: req.method ?? "POST",
|
|
880
905
|
path: urlPath,
|
|
881
906
|
headers: flattenHeaders(req.headers),
|
|
@@ -885,9 +910,8 @@ async function handleConverse(req, res, raw, modelId, fixtures, journal, default
|
|
|
885
910
|
fixture
|
|
886
911
|
}
|
|
887
912
|
});
|
|
888
|
-
const
|
|
889
|
-
res
|
|
890
|
-
res.end(JSON.stringify(body));
|
|
913
|
+
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Bedrock Converse");
|
|
914
|
+
await deliverJson(res, journalEntry, fixture, () => buildConverseToolCallResponse(functionToolCalls, logger, effReasoning, overrides), jsonOpts(servedPayloadLength(response, effReasoning)));
|
|
891
915
|
return;
|
|
892
916
|
}
|
|
893
917
|
addResponseEntry({
|
|
@@ -970,7 +994,10 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
970
994
|
completionReq._endpointType = "chat";
|
|
971
995
|
completionReq._context = getContext(req);
|
|
972
996
|
const testId = getTestId(req);
|
|
973
|
-
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform,
|
|
997
|
+
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform, {
|
|
998
|
+
...recordMatchOptions(!!defaults.record, defaults.logger),
|
|
999
|
+
wire: "bedrock-converse"
|
|
1000
|
+
});
|
|
974
1001
|
if (fixture) logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);
|
|
975
1002
|
else logger.debug(`No fixture matched for request`);
|
|
976
1003
|
if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures, testId);
|
|
@@ -1003,7 +1030,7 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1003
1030
|
return;
|
|
1004
1031
|
}
|
|
1005
1032
|
if (defaults.record) {
|
|
1006
|
-
const outcome = await proxyAndRecord(req, res, completionReq, "bedrock", urlPath, fixtures, defaults, raw);
|
|
1033
|
+
const { outcome, clientHungUp } = await withHangUpDetection(req, res, () => proxyAndRecord(req, res, completionReq, "bedrock", urlPath, fixtures, defaults, raw));
|
|
1007
1034
|
if (outcome === "handled_by_hook") return;
|
|
1008
1035
|
if (outcome !== "not_configured") {
|
|
1009
1036
|
journal.add({
|
|
@@ -1014,7 +1041,8 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1014
1041
|
response: {
|
|
1015
1042
|
status: res.statusCode ?? 200,
|
|
1016
1043
|
fixture: null,
|
|
1017
|
-
source: "proxy"
|
|
1044
|
+
source: "proxy",
|
|
1045
|
+
...proxyInterruption(res, clientHungUp)
|
|
1018
1046
|
}
|
|
1019
1047
|
});
|
|
1020
1048
|
return;
|
|
@@ -1081,13 +1109,18 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1081
1109
|
}).body);
|
|
1082
1110
|
return;
|
|
1083
1111
|
}
|
|
1084
|
-
const latency = fixture.latency ?? defaults.latency;
|
|
1085
1112
|
const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);
|
|
1113
|
+
const streamTiming = {
|
|
1114
|
+
latency: fixture.latency ?? defaults.latency,
|
|
1115
|
+
streamingProfile: fixture.streamingProfile,
|
|
1116
|
+
recordedTimings: fixture.recordedTimings,
|
|
1117
|
+
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed
|
|
1118
|
+
};
|
|
1086
1119
|
if (misbehavior.kind === "applied") {
|
|
1087
1120
|
const prepared = prepareConverseMisbehavior(misbehavior, completionReq, true, defaults, req.headers);
|
|
1088
1121
|
misbehavior = prepared.plan;
|
|
1089
1122
|
const events = buildConverseMisbehaviorEvents(prepared, chunkSize);
|
|
1090
|
-
|
|
1123
|
+
await deliverStream(res, addResponseEntry({
|
|
1091
1124
|
method: req.method ?? "POST",
|
|
1092
1125
|
path: urlPath,
|
|
1093
1126
|
headers: flattenHeaders(req.headers),
|
|
@@ -1096,21 +1129,24 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1096
1129
|
status: 200,
|
|
1097
1130
|
fixture
|
|
1098
1131
|
}
|
|
1132
|
+
}), fixture, eventStreamCodec(), events, streamTiming);
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
if (isRawResponse(response)) {
|
|
1136
|
+
await serveRawResponse({
|
|
1137
|
+
wire: "bedrock-converse",
|
|
1138
|
+
stream: true,
|
|
1139
|
+
req,
|
|
1140
|
+
res,
|
|
1141
|
+
fixture,
|
|
1142
|
+
response,
|
|
1143
|
+
body: completionReq,
|
|
1144
|
+
journal,
|
|
1145
|
+
defaults,
|
|
1146
|
+
testId,
|
|
1147
|
+
misbehaviorSummary: misbehavior.summary,
|
|
1148
|
+
errorWire: "bedrock-converse"
|
|
1099
1149
|
});
|
|
1100
|
-
const interruption = createInterruptionSignal(fixture);
|
|
1101
|
-
if (!await writeEventStream(res, events, {
|
|
1102
|
-
latency,
|
|
1103
|
-
streamingProfile: fixture.streamingProfile,
|
|
1104
|
-
recordedTimings: fixture.recordedTimings,
|
|
1105
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
1106
|
-
signal: interruption?.signal,
|
|
1107
|
-
onChunkSent: interruption?.tick
|
|
1108
|
-
})) {
|
|
1109
|
-
if (!res.writableEnded) res.destroy();
|
|
1110
|
-
entry.response.interrupted = true;
|
|
1111
|
-
entry.response.interruptReason = interruption?.reason();
|
|
1112
|
-
}
|
|
1113
|
-
interruption?.cleanup();
|
|
1114
1150
|
return;
|
|
1115
1151
|
}
|
|
1116
1152
|
if (isErrorResponse(response)) {
|
|
@@ -1147,20 +1183,7 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1147
1183
|
});
|
|
1148
1184
|
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Bedrock Converse");
|
|
1149
1185
|
const events = buildBedrockStreamContentWithToolCallsEvents(response.content ?? "", functionToolCalls, chunkSize, logger, effReasoning, overrides, response.blocks);
|
|
1150
|
-
|
|
1151
|
-
if (!await writeEventStream(res, events, {
|
|
1152
|
-
latency,
|
|
1153
|
-
streamingProfile: fixture.streamingProfile,
|
|
1154
|
-
recordedTimings: fixture.recordedTimings,
|
|
1155
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
1156
|
-
signal: interruption?.signal,
|
|
1157
|
-
onChunkSent: interruption?.tick
|
|
1158
|
-
})) {
|
|
1159
|
-
if (!res.writableEnded) res.destroy();
|
|
1160
|
-
journalEntry.response.interrupted = true;
|
|
1161
|
-
journalEntry.response.interruptReason = interruption?.reason();
|
|
1162
|
-
}
|
|
1163
|
-
interruption?.cleanup();
|
|
1186
|
+
await deliverStream(res, journalEntry, fixture, eventStreamCodec(), events, streamTiming);
|
|
1164
1187
|
return;
|
|
1165
1188
|
}
|
|
1166
1189
|
if (isTextResponse(response)) {
|
|
@@ -1178,20 +1201,7 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1178
1201
|
}
|
|
1179
1202
|
});
|
|
1180
1203
|
const events = buildBedrockStreamTextEvents(response.content, chunkSize, effReasoning, overrides);
|
|
1181
|
-
|
|
1182
|
-
if (!await writeEventStream(res, events, {
|
|
1183
|
-
latency,
|
|
1184
|
-
streamingProfile: fixture.streamingProfile,
|
|
1185
|
-
recordedTimings: fixture.recordedTimings,
|
|
1186
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
1187
|
-
signal: interruption?.signal,
|
|
1188
|
-
onChunkSent: interruption?.tick
|
|
1189
|
-
})) {
|
|
1190
|
-
if (!res.writableEnded) res.destroy();
|
|
1191
|
-
journalEntry.response.interrupted = true;
|
|
1192
|
-
journalEntry.response.interruptReason = interruption?.reason();
|
|
1193
|
-
}
|
|
1194
|
-
interruption?.cleanup();
|
|
1204
|
+
await deliverStream(res, journalEntry, fixture, eventStreamCodec(), events, streamTiming);
|
|
1195
1205
|
return;
|
|
1196
1206
|
}
|
|
1197
1207
|
if (isToolCallResponse(response)) {
|
|
@@ -1209,20 +1219,7 @@ async function handleConverseStream(req, res, raw, modelId, fixtures, journal, d
|
|
|
1209
1219
|
}
|
|
1210
1220
|
});
|
|
1211
1221
|
const events = buildBedrockStreamToolCallEvents(requireEmittedFunctionToolCalls(response, "Bedrock Converse"), chunkSize, logger, effReasoning, overrides);
|
|
1212
|
-
|
|
1213
|
-
if (!await writeEventStream(res, events, {
|
|
1214
|
-
latency,
|
|
1215
|
-
streamingProfile: fixture.streamingProfile,
|
|
1216
|
-
recordedTimings: fixture.recordedTimings,
|
|
1217
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
1218
|
-
signal: interruption?.signal,
|
|
1219
|
-
onChunkSent: interruption?.tick
|
|
1220
|
-
})) {
|
|
1221
|
-
if (!res.writableEnded) res.destroy();
|
|
1222
|
-
journalEntry.response.interrupted = true;
|
|
1223
|
-
journalEntry.response.interruptReason = interruption?.reason();
|
|
1224
|
-
}
|
|
1225
|
-
interruption?.cleanup();
|
|
1222
|
+
await deliverStream(res, journalEntry, fixture, eventStreamCodec(), events, streamTiming);
|
|
1226
1223
|
return;
|
|
1227
1224
|
}
|
|
1228
1225
|
addResponseEntry({
|