MCPcopy Create free account
hub / github.com/continuedev/continue / processJsonOutput

Function processJsonOutput

extensions/cli/src/commands/chat.ts:44–60  ·  view source on GitHub ↗

* Processes and validates JSON output for headless mode * @param response - The raw response from the LLM * @returns Valid JSON string

(response: string)

Source from the content-addressed store, hash-verified

42 * @returns Valid JSON string
43 */
44function processJsonOutput(response: string): string {
45 const trimmedResponse = response.trim();
46
47 try {
48 // Try to parse the response as JSON to validate it
49 JSON.parse(trimmedResponse);
50 // If it parses successfully, return as-is
51 return trimmedResponse;
52 } catch {
53 // If it's not valid JSON, wrap it in a JSON object
54 return JSON.stringify({
55 response: trimmedResponse,
56 status: "success",
57 note: "Response was not valid JSON, so it was wrapped in a JSON object",
58 });
59 }
60}
61
62/**
63 * Strips <think></think> tags and excess whitespace from response

Callers 1

processAndOutputResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected