MCPcopy Create free account
hub / github.com/CopilotKit/aimock / normalizeResponse

Function normalizeResponse

src/fixture-loader.ts:30–69  ·  view source on GitHub ↗
(raw: FixtureFileResponse)

Source from the content-addressed store, hash-verified

28 * All other fields (including ResponseOverrides) pass through unmodified.
29 */
30export function normalizeResponse(raw: FixtureFileResponse): FixtureResponse {
31 // Shallow-clone so we don't mutate the parsed JSON input.
32 const response = { ...raw } as Record<string, unknown>;
33
34 // Auto-stringify object content (e.g. structured output)
35 if (typeof response.content === "object" && response.content !== null) {
36 response.content = JSON.stringify(response.content);
37 }
38
39 // Auto-stringify object arguments in toolCalls
40 if (Array.isArray(response.toolCalls)) {
41 response.toolCalls = (response.toolCalls as Array<Record<string, unknown>>).map((tc) => {
42 if (typeof tc.arguments === "object" && tc.arguments !== null) {
43 return { ...tc, arguments: JSON.stringify(tc.arguments) };
44 }
45 return tc;
46 });
47 }
48
49 // Carry the optional ordered `blocks` array through, mirroring the
50 // toolCalls[].arguments idiom above: auto-stringify object `arguments` on
51 // each `toolCall` block. Gated on Array.isArray so a malformed (non-array)
52 // `blocks` value passes through untouched rather than crashing — downstream
53 // validation/builders own shape rejection. Absent `blocks` → key absent.
54 if (Array.isArray(response.blocks)) {
55 response.blocks = (response.blocks as Array<Record<string, unknown>>).map((block) => {
56 if (
57 block != null &&
58 block.type === "toolCall" &&
59 typeof block.arguments === "object" &&
60 block.arguments !== null
61 ) {
62 return { ...block, arguments: JSON.stringify(block.arguments) };
63 }
64 return block;
65 });
66 }
67
68 return response as unknown as FixtureResponse;
69}
70
71export function entryToFixture(entry: FixtureFileEntry, logger?: Logger): Fixture {
72 const fixture: Fixture = {

Callers 2

entryToFixtureFunction · 0.85
onMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…