This repo is an example setup of how to use a global xstate machine in sveltekit with full type safety.
Basically you'll need to pass it in the context