import { AsyncLocalStorage } from "@llamaindex/env";
import { OpenAIEmbedding } from "../../embeddings/OpenAIEmbedding.js";
const embeddedModelAsyncLocalStorage = new AsyncLocalStorage();
let globalEmbeddedModel = null;
export function getEmbeddedModel() {
    if (globalEmbeddedModel === null) {
        globalEmbeddedModel = new OpenAIEmbedding();
    }
    return embeddedModelAsyncLocalStorage.getStore() ?? globalEmbeddedModel;
}
export function setEmbeddedModel(embeddedModel) {
    globalEmbeddedModel = embeddedModel;
}
export function withEmbeddedModel(embeddedModel, fn) {
    return embeddedModelAsyncLocalStorage.run(embeddedModel, fn);
}
