Skip to content

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

844 B
Raw Blame
interface IAttributeTarget {
    removeAttribute: (name: string) => void;
    setAttribute: (name: string, value: string) => void;
}

export const syncRootAttributes = (
    element: IAttributeTarget,
    managedCustomAttributes: Set<string>,
    ial: Record<string, string>,
    rootID = ""
) => {
    managedCustomAttributes.forEach(attribute => element.removeAttribute(attribute));
    managedCustomAttributes.clear();

    Object.keys(ial).forEach(attribute => {
        if (attribute.startsWith("custom-") && ial[attribute]) {
            element.setAttribute(attribute, ial[attribute]);
            managedCustomAttributes.add(attribute);
        }
    });

    const nodeID = ial.id || rootID;
    if (nodeID) {
        element.setAttribute("data-node-id", nodeID);
    } else {
        element.removeAttribute("data-node-id");
    }
};