@copilotkit/aimock 1.43.0 → 1.45.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 +46 -0
- package/README.md +14 -2
- package/dist/agui-handler.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +31 -5
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.d.cts.map +1 -1
- package/dist/aimock-cli.d.ts.map +1 -1
- package/dist/aimock-cli.js +31 -5
- package/dist/aimock-cli.js.map +1 -1
- package/dist/bedrock-converse.cjs +344 -43
- 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 +345 -44
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +195 -42
- 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 +196 -43
- package/dist/bedrock.js.map +1 -1
- package/dist/chaos.cjs +9 -5
- package/dist/chaos.cjs.map +1 -1
- package/dist/chaos.d.cts.map +1 -1
- package/dist/chaos.d.ts.map +1 -1
- package/dist/chaos.js +10 -7
- package/dist/chaos.js.map +1 -1
- package/dist/cli.cjs +238 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +242 -13
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +159 -72
- 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 +160 -73
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +63 -5
- package/dist/config-loader.cjs.map +1 -1
- package/dist/config-loader.d.cts +37 -4
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts +37 -4
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +63 -5
- package/dist/config-loader.js.map +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +6 -2
- package/dist/constants.d.ts +6 -2
- package/dist/constants.js +8 -1
- package/dist/constants.js.map +1 -1
- package/dist/echo-text.cjs +65 -0
- package/dist/echo-text.cjs.map +1 -0
- package/dist/echo-text.d.cts +22 -0
- package/dist/echo-text.d.cts.map +1 -0
- package/dist/echo-text.d.ts +22 -0
- package/dist/echo-text.d.ts.map +1 -0
- package/dist/echo-text.js +65 -0
- package/dist/echo-text.js.map +1 -0
- package/dist/embeddings.cjs +18 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +1 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +1 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +18 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/fakes-plugin.cjs +131 -0
- package/dist/fakes-plugin.cjs.map +1 -0
- package/dist/fakes-plugin.d.cts +23 -0
- package/dist/fakes-plugin.d.cts.map +1 -0
- package/dist/fakes-plugin.d.ts +23 -0
- package/dist/fakes-plugin.d.ts.map +1 -0
- package/dist/fakes-plugin.js +127 -0
- package/dist/fakes-plugin.js.map +1 -0
- package/dist/files.cjs +9 -11
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +10 -13
- package/dist/files.js.map +1 -1
- package/dist/fine-tuning.cjs +1 -19
- package/dist/fine-tuning.cjs.map +1 -1
- package/dist/fine-tuning.d.cts.map +1 -1
- package/dist/fine-tuning.d.ts.map +1 -1
- package/dist/fine-tuning.js +2 -20
- package/dist/fine-tuning.js.map +1 -1
- package/dist/fixture-loader-services.cjs +116 -0
- package/dist/fixture-loader-services.cjs.map +1 -0
- package/dist/fixture-loader-services.d.cts +48 -0
- package/dist/fixture-loader-services.d.cts.map +1 -0
- package/dist/fixture-loader-services.d.ts +48 -0
- package/dist/fixture-loader-services.d.ts.map +1 -0
- package/dist/fixture-loader-services.js +114 -0
- package/dist/fixture-loader-services.js.map +1 -0
- package/dist/fixture-loader.cjs +552 -29
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts +140 -2
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts +140 -2
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +542 -31
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-embeddings.cjs +42 -2
- package/dist/gemini-embeddings.cjs.map +1 -1
- package/dist/gemini-embeddings.js +43 -3
- package/dist/gemini-embeddings.js.map +1 -1
- package/dist/gemini-interactions.cjs +288 -52
- 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 +289 -53
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +234 -38
- 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 +235 -39
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +1157 -12
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +85 -4
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +85 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +1113 -14
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +3 -2
- package/dist/images.cjs.map +1 -1
- package/dist/images.js +3 -2
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +39 -1
- package/dist/index.d.cts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +11 -4
- package/dist/jest.cjs +43 -14
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +47 -5
- package/dist/jest.d.cts.map +1 -1
- package/dist/jest.d.ts +47 -5
- package/dist/jest.d.ts.map +1 -1
- package/dist/jest.js +45 -16
- package/dist/jest.js.map +1 -1
- package/dist/journal.cjs +155 -13
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts +54 -4
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts +54 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +155 -13
- package/dist/journal.js.map +1 -1
- package/dist/live-sanitize.cjs +4 -32
- package/dist/live-sanitize.cjs.map +1 -1
- package/dist/live-sanitize.js +4 -32
- package/dist/live-sanitize.js.map +1 -1
- package/dist/llmock.cjs +204 -39
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +51 -1
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +51 -1
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +206 -41
- package/dist/llmock.js.map +1 -1
- package/dist/mcp-fakes-mount.cjs +217 -0
- package/dist/mcp-fakes-mount.cjs.map +1 -0
- package/dist/mcp-fakes-mount.js +211 -0
- package/dist/mcp-fakes-mount.js.map +1 -0
- package/dist/mcp-fakes-report.cjs +111 -0
- package/dist/mcp-fakes-report.cjs.map +1 -0
- package/dist/mcp-fakes-report.d.cts +40 -0
- package/dist/mcp-fakes-report.d.cts.map +1 -0
- package/dist/mcp-fakes-report.d.ts +40 -0
- package/dist/mcp-fakes-report.d.ts.map +1 -0
- package/dist/mcp-fakes-report.js +107 -0
- package/dist/mcp-fakes-report.js.map +1 -0
- package/dist/mcp-fakes.cjs +1942 -0
- package/dist/mcp-fakes.cjs.map +1 -0
- package/dist/mcp-fakes.d.cts +504 -0
- package/dist/mcp-fakes.d.cts.map +1 -0
- package/dist/mcp-fakes.d.ts +504 -0
- package/dist/mcp-fakes.d.ts.map +1 -0
- package/dist/mcp-fakes.js +1937 -0
- package/dist/mcp-fakes.js.map +1 -0
- package/dist/mcp-handler.cjs +534 -27
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.d.cts +49 -0
- package/dist/mcp-handler.d.cts.map +1 -0
- package/dist/mcp-handler.d.ts +49 -0
- package/dist/mcp-handler.d.ts.map +1 -0
- package/dist/mcp-handler.js +530 -28
- package/dist/mcp-handler.js.map +1 -1
- package/dist/mcp-mock.cjs +326 -47
- package/dist/mcp-mock.cjs.map +1 -1
- package/dist/mcp-mock.d.cts +97 -1
- package/dist/mcp-mock.d.cts.map +1 -1
- package/dist/mcp-mock.d.ts +97 -1
- package/dist/mcp-mock.d.ts.map +1 -1
- package/dist/mcp-mock.js +327 -48
- package/dist/mcp-mock.js.map +1 -1
- package/dist/mcp-recorder.cjs +1224 -0
- package/dist/mcp-recorder.cjs.map +1 -0
- package/dist/mcp-recorder.d.cts +108 -0
- package/dist/mcp-recorder.d.cts.map +1 -0
- package/dist/mcp-recorder.d.ts +108 -0
- package/dist/mcp-recorder.d.ts.map +1 -0
- package/dist/mcp-recorder.js +1215 -0
- package/dist/mcp-recorder.js.map +1 -0
- package/dist/mcp-stub.cjs +5 -1
- package/dist/mcp-stub.d.cts +3 -1
- package/dist/mcp-stub.d.ts +3 -1
- package/dist/mcp-stub.js +3 -1
- package/dist/mcp-types.d.cts +6 -0
- package/dist/mcp-types.d.ts +6 -0
- package/dist/message-text.cjs +192 -0
- package/dist/message-text.cjs.map +1 -0
- package/dist/message-text.d.cts +31 -0
- package/dist/message-text.d.cts.map +1 -0
- package/dist/message-text.d.ts +31 -0
- package/dist/message-text.d.ts.map +1 -0
- package/dist/message-text.js +184 -0
- package/dist/message-text.js.map +1 -0
- package/dist/messages.cjs +400 -56
- 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 +401 -58
- package/dist/messages.js.map +1 -1
- package/dist/metrics.cjs +46 -66
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.cts +14 -6
- package/dist/metrics.d.cts.map +1 -1
- package/dist/metrics.d.ts +14 -6
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +32 -40
- package/dist/metrics.js.map +1 -1
- package/dist/misbehavior.cjs +1523 -0
- package/dist/misbehavior.cjs.map +1 -0
- package/dist/misbehavior.d.cts +43 -0
- package/dist/misbehavior.d.cts.map +1 -0
- package/dist/misbehavior.d.ts +43 -0
- package/dist/misbehavior.d.ts.map +1 -0
- package/dist/misbehavior.js +1511 -0
- package/dist/misbehavior.js.map +1 -0
- package/dist/ollama.cjs +315 -113
- 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 +316 -114
- package/dist/ollama.js.map +1 -1
- package/dist/openapi.cjs +3405 -0
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +30 -0
- package/dist/openapi.d.cts.map +1 -0
- package/dist/openapi.d.ts +30 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +3404 -0
- package/dist/openapi.js.map +1 -0
- package/dist/openrouter-video.cjs +4 -4
- package/dist/openrouter-video.cjs.map +1 -1
- package/dist/openrouter-video.d.cts.map +1 -1
- package/dist/openrouter-video.d.ts.map +1 -1
- package/dist/openrouter-video.js +4 -4
- package/dist/openrouter-video.js.map +1 -1
- package/dist/record-sanitize.cjs +231 -0
- package/dist/record-sanitize.cjs.map +1 -0
- package/dist/record-sanitize.js +224 -0
- package/dist/record-sanitize.js.map +1 -0
- package/dist/recorder.cjs +115 -6
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts +2 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts +2 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +116 -8
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +701 -166
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +5 -13
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +5 -13
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +699 -169
- package/dist/responses.js.map +1 -1
- package/dist/route-registry.cjs +951 -0
- package/dist/route-registry.cjs.map +1 -0
- package/dist/route-registry.d.cts +33 -0
- package/dist/route-registry.d.cts.map +1 -0
- package/dist/route-registry.d.ts +33 -0
- package/dist/route-registry.d.ts.map +1 -0
- package/dist/route-registry.js +866 -0
- package/dist/route-registry.js.map +1 -0
- package/dist/router.cjs +24 -2
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +25 -4
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +1159 -264
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +4 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1067 -172
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +4 -2
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.js +4 -2
- package/dist/speech.js.map +1 -1
- package/dist/stream-collapse.cjs +236 -34
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +39 -4
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +39 -4
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +235 -35
- package/dist/stream-collapse.js.map +1 -1
- package/dist/suite.cjs +1 -1
- package/dist/suite.js +1 -1
- package/dist/transcription.cjs +2 -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 +2 -2
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs +18 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +516 -5
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +516 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/validate-cli.cjs +123 -33
- package/dist/validate-cli.cjs.map +1 -1
- package/dist/validate-cli.js +125 -35
- package/dist/validate-cli.js.map +1 -1
- package/dist/vector-stores.cjs +1180 -0
- package/dist/vector-stores.cjs.map +1 -0
- package/dist/vector-stores.d.cts +106 -0
- package/dist/vector-stores.d.cts.map +1 -0
- package/dist/vector-stores.d.ts +106 -0
- package/dist/vector-stores.d.ts.map +1 -0
- package/dist/vector-stores.js +1164 -0
- package/dist/vector-stores.js.map +1 -0
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/version.cjs +45 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +44 -0
- package/dist/version.js.map +1 -0
- package/dist/video.cjs +19 -0
- 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 +19 -0
- package/dist/video.js.map +1 -1
- package/dist/vitest.cjs +77 -16
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +38 -5
- package/dist/vitest.d.cts.map +1 -1
- package/dist/vitest.d.ts +38 -5
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +78 -17
- package/dist/vitest.js.map +1 -1
- package/dist/watcher.cjs +6 -2
- package/dist/watcher.cjs.map +1 -1
- package/dist/watcher.js +6 -2
- package/dist/watcher.js.map +1 -1
- package/dist/ws-gemini-live.cjs +210 -101
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +9 -3
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts +9 -3
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +211 -102
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +175 -62
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts +8 -3
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts +8 -3
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +176 -63
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +121 -16
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts +8 -12
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts +8 -12
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +123 -18
- package/dist/ws-responses.js.map +1 -1
- package/package.json +13 -2
- package/skills/write-fixtures/SKILL.md +179 -21
package/dist/bedrock.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { extractOverrides, flattenHeaders, generateMessageId, generateToolUseId, getContext, getTestId,
|
|
1
|
+
import { extractOverrides, flattenHeaders, generateMessageId, generateToolUseId, getContext, getTestId, isCombinedFixtureResponse, isErrorResponse, isJsonObject, isTextResponse, isToolCallResponse, requireEmittedFunctionToolCalls, resolveFixtureBlockOutcome, resolveReasoningForModel, resolveResponse, resolveStrictMode, servedToolArgs, strictNoMatchLogLine, strictNoMatchMessage, strictOverrideField, validateChatMessages, validateToolsField } from "./helpers.js";
|
|
2
2
|
import { writeErrorResponse } from "./sse-writer.js";
|
|
3
3
|
import { applyChaosAsync } from "./chaos.js";
|
|
4
|
+
import { planMisbehavior, recordMisbehaviorOutcome } from "./misbehavior.js";
|
|
4
5
|
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
|
|
5
6
|
import { proxyAndRecord } from "./recorder.js";
|
|
6
7
|
import { createInterruptionSignal } from "./interruption.js";
|
|
8
|
+
import { prepareClaudeMisbehavior } from "./messages.js";
|
|
7
9
|
import { writeEventStream } from "./aws-event-stream.js";
|
|
8
10
|
|
|
9
11
|
//#region src/bedrock.ts
|
|
@@ -155,18 +157,12 @@ function buildBedrockToolCallResponse(toolCalls, model, logger, reasoning, overr
|
|
|
155
157
|
signature: ""
|
|
156
158
|
});
|
|
157
159
|
for (const tc of toolCalls) {
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
argsObj = JSON.parse(tc.arguments || "{}");
|
|
161
|
-
} catch {
|
|
162
|
-
logger.warn(`Malformed JSON in fixture tool call arguments for "${tc.name}": ${tc.arguments}`);
|
|
163
|
-
argsObj = {};
|
|
164
|
-
}
|
|
160
|
+
const args = servedToolArgs(tc, "object", logger);
|
|
165
161
|
contentBlocks.push({
|
|
166
162
|
type: "tool_use",
|
|
167
163
|
id: tc.id || generateToolUseId(),
|
|
168
164
|
name: tc.name,
|
|
169
|
-
input:
|
|
165
|
+
input: args.value
|
|
170
166
|
});
|
|
171
167
|
}
|
|
172
168
|
return {
|
|
@@ -205,18 +201,12 @@ function buildBedrockBlocksResponse(blocks, model, logger, reasoning, overrides)
|
|
|
205
201
|
text: block.text
|
|
206
202
|
});
|
|
207
203
|
else {
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
argsObj = JSON.parse(block.arguments || "{}");
|
|
211
|
-
} catch {
|
|
212
|
-
logger.warn(`Malformed JSON in fixture tool call arguments for "${block.name}": ${block.arguments}`);
|
|
213
|
-
argsObj = {};
|
|
214
|
-
}
|
|
204
|
+
const args = servedToolArgs(block, "object", logger);
|
|
215
205
|
contentBlocks.push({
|
|
216
206
|
type: "tool_use",
|
|
217
207
|
id: block.id || generateToolUseId(),
|
|
218
208
|
name: block.name,
|
|
219
|
-
input:
|
|
209
|
+
input: args.value
|
|
220
210
|
});
|
|
221
211
|
}
|
|
222
212
|
return {
|
|
@@ -362,9 +352,79 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
362
352
|
return;
|
|
363
353
|
}
|
|
364
354
|
const response = await resolveResponse(fixture, completionReq);
|
|
355
|
+
const misbehavior = planMisbehavior({
|
|
356
|
+
wire: "bedrock-invoke",
|
|
357
|
+
emitsToolCallIds: true,
|
|
358
|
+
fixture,
|
|
359
|
+
response,
|
|
360
|
+
request: completionReq,
|
|
361
|
+
stream: completionReq.stream === true,
|
|
362
|
+
defaults,
|
|
363
|
+
rawHeaders: req.headers,
|
|
364
|
+
url: req.url
|
|
365
|
+
});
|
|
366
|
+
const addResponseEntry = (input) => {
|
|
367
|
+
const entry = journal.add(input);
|
|
368
|
+
recordMisbehaviorOutcome({
|
|
369
|
+
entry,
|
|
370
|
+
summary: misbehavior.summary,
|
|
371
|
+
defaults,
|
|
372
|
+
testId
|
|
373
|
+
});
|
|
374
|
+
return entry;
|
|
375
|
+
};
|
|
376
|
+
if (misbehavior.kind === "error") {
|
|
377
|
+
if (!misbehavior.summary?.evaluations.length) logger.error(`[misbehavior] ${misbehavior.message}`);
|
|
378
|
+
addResponseEntry({
|
|
379
|
+
method: req.method ?? "POST",
|
|
380
|
+
path: urlPath,
|
|
381
|
+
headers: flattenHeaders(req.headers),
|
|
382
|
+
body: completionReq,
|
|
383
|
+
response: {
|
|
384
|
+
status: misbehavior.status,
|
|
385
|
+
fixture
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
const type = misbehavior.status === 400 ? "ValidationException" : "NotImplementedException";
|
|
389
|
+
res.setHeader("x-amzn-errortype", type);
|
|
390
|
+
writeErrorResponse(res, misbehavior.status, JSON.stringify({
|
|
391
|
+
__type: type,
|
|
392
|
+
code: misbehavior.code,
|
|
393
|
+
message: misbehavior.message
|
|
394
|
+
}));
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (misbehavior.kind === "applied") {
|
|
398
|
+
const prepared = prepareClaudeMisbehavior(misbehavior, {
|
|
399
|
+
request: completionReq,
|
|
400
|
+
stream: false,
|
|
401
|
+
chunkSize: Math.max(1, fixture.chunkSize ?? defaults.chunkSize),
|
|
402
|
+
logger,
|
|
403
|
+
strict: resolveStrictMode(defaults.strict, req.headers)
|
|
404
|
+
});
|
|
405
|
+
if (prepared.stream) throw new TypeError("InvokeModel requires non-stream Claude output");
|
|
406
|
+
recordMisbehaviorOutcome({
|
|
407
|
+
entry: journal.add({
|
|
408
|
+
method: req.method ?? "POST",
|
|
409
|
+
path: urlPath,
|
|
410
|
+
headers: flattenHeaders(req.headers),
|
|
411
|
+
body: completionReq,
|
|
412
|
+
response: {
|
|
413
|
+
status: 200,
|
|
414
|
+
fixture
|
|
415
|
+
}
|
|
416
|
+
}),
|
|
417
|
+
summary: prepared.plan.summary,
|
|
418
|
+
defaults,
|
|
419
|
+
testId
|
|
420
|
+
});
|
|
421
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
422
|
+
res.end(JSON.stringify(prepared.body));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
365
425
|
if (isErrorResponse(response)) {
|
|
366
426
|
const status = response.status ?? 500;
|
|
367
|
-
|
|
427
|
+
addResponseEntry({
|
|
368
428
|
method: req.method ?? "POST",
|
|
369
429
|
path: urlPath,
|
|
370
430
|
headers: flattenHeaders(req.headers),
|
|
@@ -384,11 +444,11 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
384
444
|
writeErrorResponse(res, status, JSON.stringify(anthropicError), { retryAfter: response.retryAfter });
|
|
385
445
|
return;
|
|
386
446
|
}
|
|
387
|
-
if (
|
|
447
|
+
if (isCombinedFixtureResponse(response)) {
|
|
388
448
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
389
449
|
const overrides = extractOverrides(response);
|
|
390
450
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveStrictMode(defaults.strict, req.headers), logger);
|
|
391
|
-
|
|
451
|
+
addResponseEntry({
|
|
392
452
|
method: req.method ?? "POST",
|
|
393
453
|
path: urlPath,
|
|
394
454
|
headers: flattenHeaders(req.headers),
|
|
@@ -398,6 +458,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
398
458
|
fixture
|
|
399
459
|
}
|
|
400
460
|
});
|
|
461
|
+
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Bedrock InvokeModel");
|
|
401
462
|
if (response.blocks && response.blocks.length > 0) {
|
|
402
463
|
const blocksBody = buildBedrockBlocksResponse(response.blocks, completionReq.model, logger, effReasoning, overrides);
|
|
403
464
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -405,7 +466,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
405
466
|
return;
|
|
406
467
|
}
|
|
407
468
|
const textBody = buildBedrockTextResponse(response.content ?? "", completionReq.model, effReasoning, overrides);
|
|
408
|
-
const toolBody = buildBedrockToolCallResponse(
|
|
469
|
+
const toolBody = buildBedrockToolCallResponse(functionToolCalls, completionReq.model, logger, void 0, overrides);
|
|
409
470
|
const merged = {
|
|
410
471
|
...textBody,
|
|
411
472
|
content: [...textBody.content, ...toolBody.content],
|
|
@@ -419,7 +480,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
419
480
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
420
481
|
const overrides = extractOverrides(response);
|
|
421
482
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveStrictMode(defaults.strict, req.headers), logger);
|
|
422
|
-
|
|
483
|
+
addResponseEntry({
|
|
423
484
|
method: req.method ?? "POST",
|
|
424
485
|
path: urlPath,
|
|
425
486
|
headers: flattenHeaders(req.headers),
|
|
@@ -438,7 +499,7 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
438
499
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
439
500
|
const overrides = extractOverrides(response);
|
|
440
501
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveStrictMode(defaults.strict, req.headers), logger);
|
|
441
|
-
|
|
502
|
+
addResponseEntry({
|
|
442
503
|
method: req.method ?? "POST",
|
|
443
504
|
path: urlPath,
|
|
444
505
|
headers: flattenHeaders(req.headers),
|
|
@@ -448,12 +509,12 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
448
509
|
fixture
|
|
449
510
|
}
|
|
450
511
|
});
|
|
451
|
-
const body = buildBedrockToolCallResponse(response
|
|
512
|
+
const body = buildBedrockToolCallResponse(requireEmittedFunctionToolCalls(response, "Bedrock InvokeModel"), completionReq.model, logger, effReasoning, overrides);
|
|
452
513
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
453
514
|
res.end(JSON.stringify(body));
|
|
454
515
|
return;
|
|
455
516
|
}
|
|
456
|
-
|
|
517
|
+
addResponseEntry({
|
|
457
518
|
method: req.method ?? "POST",
|
|
458
519
|
path: urlPath,
|
|
459
520
|
headers: flattenHeaders(req.headers),
|
|
@@ -469,6 +530,13 @@ async function handleBedrock(req, res, raw, modelId, fixtures, journal, defaults
|
|
|
469
530
|
} }));
|
|
470
531
|
}
|
|
471
532
|
const BEDROCK_INVOKE_STREAM_EVENT_TYPE = "chunk";
|
|
533
|
+
/** Serialize Claude events as InvokeModel PayloadPart, leaving generic AWS framing unchanged. */
|
|
534
|
+
function writeBedrockInvokeStream(res, events, options) {
|
|
535
|
+
return writeEventStream(res, events.map((event) => ({
|
|
536
|
+
eventType: event.eventType,
|
|
537
|
+
payload: { bytes: Buffer.from(JSON.stringify(event.payload), "utf8").toString("base64") }
|
|
538
|
+
})), options);
|
|
539
|
+
}
|
|
472
540
|
function buildBedrockInvokeMessageStart(model, overrides) {
|
|
473
541
|
return {
|
|
474
542
|
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
@@ -507,13 +575,7 @@ function buildBedrockInvokeMessageStop() {
|
|
|
507
575
|
};
|
|
508
576
|
}
|
|
509
577
|
function parseToolArgumentsForStream(toolCall, logger) {
|
|
510
|
-
|
|
511
|
-
const parsed = JSON.parse(toolCall.arguments || "{}");
|
|
512
|
-
return JSON.stringify(parsed);
|
|
513
|
-
} catch {
|
|
514
|
-
logger.warn(`Malformed JSON in fixture tool call arguments for "${toolCall.name}": ${toolCall.arguments}`);
|
|
515
|
-
return "{}";
|
|
516
|
-
}
|
|
578
|
+
return servedToolArgs(toolCall, "string", logger).text;
|
|
517
579
|
}
|
|
518
580
|
function buildBedrockStreamTextEvents(content, model, chunkSize, reasoning, overrides) {
|
|
519
581
|
const events = [];
|
|
@@ -1041,11 +1103,101 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1041
1103
|
return;
|
|
1042
1104
|
}
|
|
1043
1105
|
const response = await resolveResponse(fixture, completionReq);
|
|
1106
|
+
const misbehavior = planMisbehavior({
|
|
1107
|
+
wire: "bedrock-invoke",
|
|
1108
|
+
emitsToolCallIds: true,
|
|
1109
|
+
fixture,
|
|
1110
|
+
response,
|
|
1111
|
+
request: completionReq,
|
|
1112
|
+
stream: completionReq.stream === true,
|
|
1113
|
+
defaults,
|
|
1114
|
+
rawHeaders: req.headers,
|
|
1115
|
+
url: req.url
|
|
1116
|
+
});
|
|
1117
|
+
const addResponseEntry = (input) => {
|
|
1118
|
+
const entry = journal.add(input);
|
|
1119
|
+
recordMisbehaviorOutcome({
|
|
1120
|
+
entry,
|
|
1121
|
+
summary: misbehavior.summary,
|
|
1122
|
+
defaults,
|
|
1123
|
+
testId
|
|
1124
|
+
});
|
|
1125
|
+
return entry;
|
|
1126
|
+
};
|
|
1127
|
+
if (misbehavior.kind === "error") {
|
|
1128
|
+
if (!misbehavior.summary?.evaluations.length) logger.error(`[misbehavior] ${misbehavior.message}`);
|
|
1129
|
+
addResponseEntry({
|
|
1130
|
+
method: req.method ?? "POST",
|
|
1131
|
+
path: urlPath,
|
|
1132
|
+
headers: flattenHeaders(req.headers),
|
|
1133
|
+
body: completionReq,
|
|
1134
|
+
response: {
|
|
1135
|
+
status: misbehavior.status,
|
|
1136
|
+
fixture
|
|
1137
|
+
}
|
|
1138
|
+
});
|
|
1139
|
+
const type = misbehavior.status === 400 ? "ValidationException" : "NotImplementedException";
|
|
1140
|
+
res.setHeader("x-amzn-errortype", type);
|
|
1141
|
+
writeErrorResponse(res, misbehavior.status, JSON.stringify({
|
|
1142
|
+
__type: type,
|
|
1143
|
+
code: misbehavior.code,
|
|
1144
|
+
message: misbehavior.message
|
|
1145
|
+
}));
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1044
1148
|
const latency = fixture.latency ?? defaults.latency;
|
|
1045
1149
|
const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);
|
|
1150
|
+
if (misbehavior.kind === "applied") {
|
|
1151
|
+
const prepared = prepareClaudeMisbehavior(misbehavior, {
|
|
1152
|
+
request: completionReq,
|
|
1153
|
+
stream: true,
|
|
1154
|
+
chunkSize,
|
|
1155
|
+
logger,
|
|
1156
|
+
strict: resolveStrictMode(defaults.strict, req.headers)
|
|
1157
|
+
});
|
|
1158
|
+
if (!prepared.stream) throw new TypeError("InvokeModel stream requires Claude events");
|
|
1159
|
+
const entry = journal.add({
|
|
1160
|
+
method: req.method ?? "POST",
|
|
1161
|
+
path: urlPath,
|
|
1162
|
+
headers: flattenHeaders(req.headers),
|
|
1163
|
+
body: completionReq,
|
|
1164
|
+
response: {
|
|
1165
|
+
status: 200,
|
|
1166
|
+
fixture
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
recordMisbehaviorOutcome({
|
|
1170
|
+
entry,
|
|
1171
|
+
summary: prepared.plan.summary,
|
|
1172
|
+
defaults,
|
|
1173
|
+
testId
|
|
1174
|
+
});
|
|
1175
|
+
const events = prepared.events.map((event) => ({
|
|
1176
|
+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
|
|
1177
|
+
payload: event
|
|
1178
|
+
}));
|
|
1179
|
+
const interruption = createInterruptionSignal(fixture);
|
|
1180
|
+
try {
|
|
1181
|
+
if (!await writeBedrockInvokeStream(res, events, {
|
|
1182
|
+
latency,
|
|
1183
|
+
streamingProfile: fixture.streamingProfile,
|
|
1184
|
+
recordedTimings: fixture.recordedTimings,
|
|
1185
|
+
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
1186
|
+
signal: interruption?.signal,
|
|
1187
|
+
onChunkSent: interruption?.tick
|
|
1188
|
+
})) {
|
|
1189
|
+
if (!res.writableEnded) res.destroy();
|
|
1190
|
+
entry.response.interrupted = true;
|
|
1191
|
+
entry.response.interruptReason = interruption?.reason();
|
|
1192
|
+
}
|
|
1193
|
+
} finally {
|
|
1194
|
+
interruption?.cleanup();
|
|
1195
|
+
}
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1046
1198
|
if (isErrorResponse(response)) {
|
|
1047
1199
|
const status = response.status ?? 500;
|
|
1048
|
-
|
|
1200
|
+
addResponseEntry({
|
|
1049
1201
|
method: req.method ?? "POST",
|
|
1050
1202
|
path: urlPath,
|
|
1051
1203
|
headers: flattenHeaders(req.headers),
|
|
@@ -1065,11 +1217,11 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1065
1217
|
writeErrorResponse(res, status, JSON.stringify(anthropicError), { retryAfter: response.retryAfter });
|
|
1066
1218
|
return;
|
|
1067
1219
|
}
|
|
1068
|
-
if (
|
|
1220
|
+
if (isCombinedFixtureResponse(response)) {
|
|
1069
1221
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
1070
1222
|
const overrides = extractOverrides(response);
|
|
1071
1223
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveStrictMode(defaults.strict, req.headers), logger);
|
|
1072
|
-
const journalEntry =
|
|
1224
|
+
const journalEntry = addResponseEntry({
|
|
1073
1225
|
method: req.method ?? "POST",
|
|
1074
1226
|
path: urlPath,
|
|
1075
1227
|
headers: flattenHeaders(req.headers),
|
|
@@ -1079,9 +1231,10 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1079
1231
|
fixture
|
|
1080
1232
|
}
|
|
1081
1233
|
});
|
|
1082
|
-
const
|
|
1234
|
+
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Bedrock InvokeModel");
|
|
1235
|
+
const events = buildBedrockStreamContentWithToolCallsEvents(response.content ?? "", functionToolCalls, completionReq.model, chunkSize, logger, effReasoning, overrides, response.blocks);
|
|
1083
1236
|
const interruption = createInterruptionSignal(fixture);
|
|
1084
|
-
if (!await
|
|
1237
|
+
if (!await writeBedrockInvokeStream(res, events, {
|
|
1085
1238
|
latency,
|
|
1086
1239
|
streamingProfile: fixture.streamingProfile,
|
|
1087
1240
|
recordedTimings: fixture.recordedTimings,
|
|
@@ -1100,7 +1253,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1100
1253
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
1101
1254
|
const overrides = extractOverrides(response);
|
|
1102
1255
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveStrictMode(defaults.strict, req.headers), logger);
|
|
1103
|
-
const journalEntry =
|
|
1256
|
+
const journalEntry = addResponseEntry({
|
|
1104
1257
|
method: req.method ?? "POST",
|
|
1105
1258
|
path: urlPath,
|
|
1106
1259
|
headers: flattenHeaders(req.headers),
|
|
@@ -1112,7 +1265,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1112
1265
|
});
|
|
1113
1266
|
const events = buildBedrockStreamTextEvents(response.content, completionReq.model, chunkSize, effReasoning, overrides);
|
|
1114
1267
|
const interruption = createInterruptionSignal(fixture);
|
|
1115
|
-
if (!await
|
|
1268
|
+
if (!await writeBedrockInvokeStream(res, events, {
|
|
1116
1269
|
latency,
|
|
1117
1270
|
streamingProfile: fixture.streamingProfile,
|
|
1118
1271
|
recordedTimings: fixture.recordedTimings,
|
|
@@ -1131,7 +1284,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1131
1284
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Bedrock API — ignoring");
|
|
1132
1285
|
const overrides = extractOverrides(response);
|
|
1133
1286
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, resolveStrictMode(defaults.strict, req.headers), logger);
|
|
1134
|
-
const journalEntry =
|
|
1287
|
+
const journalEntry = addResponseEntry({
|
|
1135
1288
|
method: req.method ?? "POST",
|
|
1136
1289
|
path: urlPath,
|
|
1137
1290
|
headers: flattenHeaders(req.headers),
|
|
@@ -1141,9 +1294,9 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1141
1294
|
fixture
|
|
1142
1295
|
}
|
|
1143
1296
|
});
|
|
1144
|
-
const events = buildBedrockStreamToolCallEvents(response
|
|
1297
|
+
const events = buildBedrockStreamToolCallEvents(requireEmittedFunctionToolCalls(response, "Bedrock InvokeModel"), completionReq.model, chunkSize, logger, effReasoning, overrides);
|
|
1145
1298
|
const interruption = createInterruptionSignal(fixture);
|
|
1146
|
-
if (!await
|
|
1299
|
+
if (!await writeBedrockInvokeStream(res, events, {
|
|
1147
1300
|
latency,
|
|
1148
1301
|
streamingProfile: fixture.streamingProfile,
|
|
1149
1302
|
recordedTimings: fixture.recordedTimings,
|
|
@@ -1158,7 +1311,7 @@ async function handleBedrockStream(req, res, raw, modelId, fixtures, journal, de
|
|
|
1158
1311
|
interruption?.cleanup();
|
|
1159
1312
|
return;
|
|
1160
1313
|
}
|
|
1161
|
-
|
|
1314
|
+
addResponseEntry({
|
|
1162
1315
|
method: req.method ?? "POST",
|
|
1163
1316
|
path: urlPath,
|
|
1164
1317
|
headers: flattenHeaders(req.headers),
|