/** * Reads the `type` field off an inbound bridge message, if any. * * Used by both sides of the bridge after the canonical message schema rejects a payload. We still * want to know what type the sender claimed to be sending so we can (a) avoid NACK loops on * `invalidHostMessage` / `invalidSandboxMessage` and (b) include the type in the failure reason * for debugging. */ export function readIncomingType(data: unknown): string | undefined { if ( typeof data === "object" && data !== null && "type" in data && typeof data.type === "string" ) { return data.type } return undefined }