An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
import {merge} from "./util/merge";
export interface ProtyleRuntimeCapabilities {
upload?: boolean;
websocket?: boolean;
lute?: Lute;
lockedOptions?: Partial<Pick<IProtyleOptions, "hint" | "toolbar">>;
pluginExtensions?: boolean;
customBlockRender?: boolean;
// 片段内容作为列表项正文编辑,首段沿用列表输入规则。
listItemFragment?: boolean;
getTransactionOwner?: (operations: IOperation[]) => IProtyle | undefined;
sanitizeBlockDOM?: (blockDOM: string) => string;
getUnsupportedPasteBlocks?: (blockDOM: string) => string[];
richHTMLPaste?: boolean;
restoreLuteMarkdownSyntax?: (lute: Lute) => void;
}
const uploadDisabledProtyles = new WeakSet<IProtyle>();
const protyleRuntimeCapabilities = new WeakMap<IProtyle, ProtyleRuntimeCapabilities>();
export const applyProtyleLockedOptions = (options: IProtyleOptions,
lockedOptions?: ProtyleRuntimeCapabilities["lockedOptions"]) =>
lockedOptions ? merge(options, lockedOptions) as IProtyleOptions : options;
export const resolveProtyleLute = (getSharedLute: () => Lute, runtimeLute?: Lute) =>
runtimeLute || getSharedLute();
export const registerProtyleRuntimeCapabilities = (protyle: IProtyle,
capabilities: ProtyleRuntimeCapabilities) => {
protyleRuntimeCapabilities.set(protyle, capabilities);
};
export const areProtyleRuntimePluginExtensionsEnabled = (capabilities: ProtyleRuntimeCapabilities) =>
capabilities.pluginExtensions !== false;
export const areProtylePluginExtensionsEnabled = (protyle: IProtyle) =>
areProtyleRuntimePluginExtensionsEnabled(protyleRuntimeCapabilities.get(protyle) || {});
export const isProtyleCustomBlockRenderEnabled = (protyle: IProtyle) =>
protyleRuntimeCapabilities.get(protyle)?.customBlockRender !== false;
export const isProtyleListItemFragment = (protyle: IProtyle) =>
protyleRuntimeCapabilities.get(protyle)?.listItemFragment === true;
export const getProtyleTransactionOwner = (protyle: IProtyle, operations: IOperation[]) =>
protyleRuntimeCapabilities.get(protyle)?.getTransactionOwner?.(operations);
export const isProtyleListItemFirstParagraph = (protyle: IProtyle, blockElement: HTMLElement) =>
isProtyleListItemFragment(protyle) && blockElement === protyle.wysiwyg.element.firstElementChild &&
blockElement.dataset.type === "NodeParagraph";
export const getProtyleLockedToolbar = (protyle: IProtyle) =>
protyleRuntimeCapabilities.get(protyle)?.lockedOptions?.toolbar;
export const getProtyleBlockDOMSanitizer = (protyle: IProtyle) =>
protyleRuntimeCapabilities.get(protyle)?.sanitizeBlockDOM;
export const getProtyleUnsupportedPasteBlocks = (protyle: IProtyle) =>
protyleRuntimeCapabilities.get(protyle)?.getUnsupportedPasteBlocks;
export const isProtyleRichHTMLPasteEnabled = (protyle: IProtyle) =>
protyleRuntimeCapabilities.get(protyle)?.richHTMLPaste === true;
export const restoreProtyleLuteMarkdownSyntax = (protyle: IProtyle, restoreDefault: (lute: Lute) => void) => {
const restore = protyleRuntimeCapabilities.get(protyle)?.restoreLuteMarkdownSyntax || restoreDefault;
restore(protyle.lute);
};
export const getProtyleRestrictedPlainTextHTML = (value: string) => value.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(/\r\n?|\n/g, "<br>");
export const disableProtyleUpload = (protyle: IProtyle) => {
uploadDisabledProtyles.add(protyle);
};
export const isProtyleUploadDisabled = (protyle: IProtyle) => uploadDisabledProtyles.has(protyle);