1import { AsyncLocalStorage } from 'node:async_hooks'3export type PtGenContext = Record<string, unknown>5const ctxRegistry = globalThis as unknown as Record<symbol, boolean>7export const genContext = <T extends unknown = PtGenContext>(debugName?: string): AsyncLocalStorage<T> => {8 if (debugName) {9 const sym = Symbol.for(`pt.ctx.${debugName}`)10 if (ctxRegistry[sym]) console.warn(`[genContext] dup:${debugName}`)11 ctxRegistry[sym] = true12 }13 return new AsyncLocalStorage<T>()14}