19 lines
484 B
TypeScript
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()
|
|
} |