MCPcopy Create free account
hub / github.com/Noumena-Network/code / validateHookJson

Function validateHookJson

src/utils/hooks.ts:383–398  ·  view source on GitHub ↗

* Parse and validate a JSON string against the hook output Zod schema. * Returns the validated output or formatted validation errors.

(
  jsonString: string,
)

Source from the content-addressed store, hash-verified

381 * Returns the validated output or formatted validation errors.
382 */
383function validateHookJson(
384 jsonString: string,
385): { json: HookJSONOutput } | { validationError: string } {
386 const parsed = jsonParse(jsonString)
387 const validation = hookJSONOutputSchema().safeParse(parsed)
388 if (validation.success) {
389 logForDebugging('Successfully parsed and validated hook JSON output')
390 return { json: validation.data }
391 }
392 const errors = validation.error.issues
393 .map(err => ` - ${err.path.join('.')}: ${err.message}`)
394 .join('\n')
395 return {
396 validationError: `Hook JSON output validation failed:\n${errors}\n\nThe hook's output was: ${jsonStringify(parsed, null, 2)}`,
397 }
398}
399
400function parseHookOutput(stdout: string): {
401 json?: HookJSONOutput

Callers 2

parseHookOutputFunction · 0.85
parseHttpHookOutputFunction · 0.85

Calls 3

jsonParseFunction · 0.85
jsonStringifyFunction · 0.85
logForDebuggingFunction · 0.70

Tested by

no test coverage detected