import { AsyncLocalStorage } from "async_hooks" export type State = { id?: string session?: string project?: string } // Ensure "ALS" lives between bun's hot reloads const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage } export const ALS = g.__thread ??= new AsyncLocalStorage() export function getState(): State | undefined { return ALS.getStore() }