import { path } from "@llamaindex/env";
import { ModalityType, ObjectType } from "../Node.js";
import { getImageEmbedModel } from "../internal/settings/image-embed-model.js";
import { DEFAULT_IMAGE_VECTOR_NAMESPACE, DEFAULT_NAMESPACE } from "./constants.js";
import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore.js";
import { SimpleIndexStore } from "./indexStore/SimpleIndexStore.js";
import { SimpleVectorStore } from "./vectorStore/SimpleVectorStore.js";
export async function storageContextFromDefaults({ docStore, indexStore, vectorStore, vectorStores, storeImages, persistDir }) {
    vectorStores = vectorStores ?? {};
    if (!persistDir) {
        docStore = docStore ?? new SimpleDocumentStore();
        indexStore = indexStore ?? new SimpleIndexStore();
        if (!(ModalityType.TEXT in vectorStores)) {
            vectorStores[ModalityType.TEXT] = vectorStore ?? new SimpleVectorStore();
        }
        if (storeImages && !(ModalityType.IMAGE in vectorStores)) {
            vectorStores[ModalityType.IMAGE] = new SimpleVectorStore({
                embedModel: new (await getImageEmbedModel())()
            });
        }
    } else {
        docStore = docStore || await SimpleDocumentStore.fromPersistDir(persistDir, DEFAULT_NAMESPACE);
        indexStore = indexStore || await SimpleIndexStore.fromPersistDir(persistDir);
        if (!(ObjectType.TEXT in vectorStores)) {
            vectorStores[ModalityType.TEXT] = vectorStore ?? await SimpleVectorStore.fromPersistDir(persistDir);
        }
        if (storeImages && !(ObjectType.IMAGE in vectorStores)) {
            vectorStores[ModalityType.IMAGE] = await SimpleVectorStore.fromPersistDir(path.join(persistDir, DEFAULT_IMAGE_VECTOR_NAMESPACE), new (await getImageEmbedModel())());
        }
    }
    return {
        docStore,
        indexStore,
        vectorStores
    };
}
