import { AsyncLocalStorage } from "@llamaindex/env";
import { CallbackManager } from "../../callbacks/CallbackManager.js";
const callbackManagerAsyncLocalStorage = new AsyncLocalStorage();
let globalCallbackManager = null;
export function getCallbackManager() {
    if (globalCallbackManager === null) {
        globalCallbackManager = new CallbackManager();
    }
    return callbackManagerAsyncLocalStorage.getStore() ?? globalCallbackManager;
}
export function setCallbackManager(callbackManager) {
    globalCallbackManager = callbackManager;
}
export function withCallbackManager(callbackManager, fn) {
    return callbackManagerAsyncLocalStorage.run(callbackManager, fn);
}
