nose-pluto/app/src/session.ts
2025-09-26 21:12:48 -07:00

19 lines
484 B
TypeScript

////
// Session storage. 1 browser tab = 1 session
import { AsyncLocalStorage } from "async_hooks"
export type Session = {
taskId?: string
sessionId?: string
project?: string
ws?: any
}
// Ensure "ALS" lives between bun's hot reloads
const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage<Session> }
export const ALS = g.__thread ??= new AsyncLocalStorage<Session>()
export function getState(): Session | undefined {
return ALS.getStore()
}