Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

890 B
Raw Blame
export const isDocumentBlockCountCovered = (requestSize: number, blockCount?: number) =>
    typeof blockCount === "number" && requestSize >= blockCount;

export const loadUntilDocumentBoundary = async (options: {
    isCurrent: () => boolean,
    isBoundaryLoaded: () => boolean,
    getBoundaryID: () => string | null | undefined,
    load: () => Promise<boolean>,
}) => {
    while (options.isCurrent() && !options.isBoundaryLoaded()) {
        const boundaryID = options.getBoundaryID();
        if (!await options.load()) {
            return false;
        }
        if (!options.isCurrent()) {
            return false;
        }
        if (options.isBoundaryLoaded()) {
            return true;
        }
        if (!boundaryID || options.getBoundaryID() === boundaryID) {
            return false;
        }
    }
    return options.isCurrent() && options.isBoundaryLoaded();
};