dist / documentSearch.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareDocumentSearch = prepareDocumentSearch;
const historyDocuments_1 = require("./fileSearch/historyDocuments");
const toolNames_1 = require("./fileSearch/toolNames");
function hasDocumentSearch(tools) {
    return ["list_documents", "search_documents", "read_document"].every(name => tools.some(tool => {
        const actual = tool.function.name;
        const schema = tool.function.parameters;
        return (0, toolNames_1.documentToolIdentity)(actual)?.key === name
            && !!schema?.properties?.collectionId;
    }));
}
async function prepareDocumentSearch(history, ctl, tools) {
    if (!history.getAllFiles(ctl.client).some(file => !file.isImage()))
        return history;
    if (!hasDocumentSearch(tools)) {
        throw new Error("Document attachments are waiting in this chat (including Insert messages). Enable yuanjumay/file-search (File Search) with List Documents, Search Documents and Read Document (legacy list_documents/search_documents/read_document are also supported), then generate again. Strata cannot forward raw documents as images.");
    }
    return (0, historyDocuments_1.prepareSearchHistory)(history, ctl.client, ctl.abortSignal);
}