I think your blocker is that the custom module in the lib folder is not available during registration time? Or is the flow file itself not available as well? Because if it’s just the lib folder, you can work around this my importing that module inside tasks so that importing is deferred to runtime.
If you don’t even have the flow file itself, it becomes very hard. First, the flow is serialized into a string representation, and then registered with an API call. If you don’t have the Flow, you at least need the string representation, which is quite hard to work with. But without the file, I’m not sure where you would get this string representation from other than constructing it somewhere else, which seems a bit brittle of a design.
This discussion may shed some insight if you haven’t seen it yet