MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / validateRuntimeResponse

Function validateRuntimeResponse

projects/runtime-protocol/src/protocol.ts:436–448  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

434}
435
436export function validateRuntimeResponse(value: unknown): RuntimeValidationResult<RuntimeResponse> {
437 if (!isRecord(value)) return validationError("$", "Runtime response must be an object")
438 if (!isRequestId(value.id)) return validationError("$.id", "Runtime response id must be a string or finite number")
439 if (!("result" in value) && !("error" in value)) return validationError("$", "Runtime response must include result or error")
440 if ("error" in value) {
441 if (!isRecord(value.error)) return validationError("$.error", "Runtime response error must be an object")
442 if (typeof value.error.code !== "string" || value.error.code.length < 1) return validationError("$.error.code", "Runtime response error code must be a non-empty string")
443 if (typeof value.error.message !== "string" || value.error.message.length < 1) {
444 return validationError("$.error.message", "Runtime response error message must be a non-empty string")
445 }
446 }
447 return { ok: true, value: value as unknown as RuntimeResponse }
448}
449
450export function validateRuntimeNotification(value: unknown): RuntimeValidationResult<RuntimeNotification> {
451 if (!isRecord(value)) return validationError("$", "Runtime notification must be an object")

Callers 3

handleMessageMethod · 0.90
requestRawMethod · 0.90
isRuntimeResponseFunction · 0.85

Calls 3

validationErrorFunction · 0.85
isRequestIdFunction · 0.85
isRecordFunction · 0.70

Tested by

no test coverage detected