"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fileSearch = fileSearch;
const glob_1 = require("glob");
const embeddings_1 = require("../../embeddings");
const config_1 = require("../../config");
const utils_1 = require("../../utils");
async function fileSearch(searchTerm) {
    const searchTermLower = searchTerm.toLowerCase();
    const pattern = `./**/*${searchTermLower}*`;
    const ignore = await (0, config_1.getIgnorePattern)();
    console.log({ pattern, ignore });
    const globFiles = (0, glob_1.globSync)(pattern, {
        ignore,
        nocase: true,
    });
    const embeddings = await (0, embeddings_1.getConfiguredEmbeddings)();
    const embeddingsArray = Array.isArray(embeddings) ? embeddings : [];
    const embeddingFiles = embeddingsArray.filter((embedding) => embedding.id.toLowerCase().includes(searchTermLower));
    const embeddingIds = embeddingFiles.map((r) => {
        const parts = r.id.split("-");
        return parts.slice(0, -1).join("-");
    });
    const allFiles = (0, utils_1.toUniqueArray)([...globFiles, ...embeddingIds]);
    return allFiles;
}
//# sourceMappingURL=fileSearch.js.map