import { AsyncLocalStorage } from "node:async_hooks"; export type LarkTicket = { messageId: string; chatId: string; accountId: string; startTime: number; senderOpenId?: string; chatType?: "p2p" | "group" | "private"; threadId?: string; }; const store = new AsyncLocalStorage(); export function withTicket(ticket: LarkTicket, fn: () => T | Promise): T | Promise { return store.run(ticket, fn); } export function getTicket(): LarkTicket | undefined { return store.getStore(); } export function ticketElapsed(): number { const ticket = getTicket(); return ticket ? Date.now() - ticket.startTime : 0; }