"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "storageContextFromDefaults", {
    enumerable: true,
    get: function() {
        return storageContextFromDefaults;
    }
});
const _env = require("@llamaindex/env");
const _Node = require("../Node.js");
const _imageembedmodel = require("../internal/settings/image-embed-model.js");
const _constants = require("./constants.js");
const _SimpleDocumentStore = require("./docStore/SimpleDocumentStore.js");
const _SimpleIndexStore = require("./indexStore/SimpleIndexStore.js");
const _SimpleVectorStore = require("./vectorStore/SimpleVectorStore.js");
async function storageContextFromDefaults({ docStore, indexStore, vectorStore, vectorStores, storeImages, persistDir }) {
    vectorStores = vectorStores ?? {};
    if (!persistDir) {
        docStore = docStore ?? new _SimpleDocumentStore.SimpleDocumentStore();
        indexStore = indexStore ?? new _SimpleIndexStore.SimpleIndexStore();
        if (!(_Node.ModalityType.TEXT in vectorStores)) {
            vectorStores[_Node.ModalityType.TEXT] = vectorStore ?? new _SimpleVectorStore.SimpleVectorStore();
        }
        if (storeImages && !(_Node.ModalityType.IMAGE in vectorStores)) {
            vectorStores[_Node.ModalityType.IMAGE] = new _SimpleVectorStore.SimpleVectorStore({
                embedModel: new (await (0, _imageembedmodel.getImageEmbedModel)())()
            });
        }
    } else {
        docStore = docStore || await _SimpleDocumentStore.SimpleDocumentStore.fromPersistDir(persistDir, _constants.DEFAULT_NAMESPACE);
        indexStore = indexStore || await _SimpleIndexStore.SimpleIndexStore.fromPersistDir(persistDir);
        if (!(_Node.ObjectType.TEXT in vectorStores)) {
            vectorStores[_Node.ModalityType.TEXT] = vectorStore ?? await _SimpleVectorStore.SimpleVectorStore.fromPersistDir(persistDir);
        }
        if (storeImages && !(_Node.ObjectType.IMAGE in vectorStores)) {
            vectorStores[_Node.ModalityType.IMAGE] = await _SimpleVectorStore.SimpleVectorStore.fromPersistDir(_env.path.join(persistDir, _constants.DEFAULT_IMAGE_VECTOR_NAMESPACE), new (await (0, _imageembedmodel.getImageEmbedModel)())());
        }
    }
    return {
        docStore,
        indexStore,
        vectorStores
    };
}
