Skip to content

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

:bug: Keep agent hints visible in floating docks

Daniel86d52a915726
diff --git a/app/src/boot/globalEvent/click.ts b/app/src/boot/globalEvent/click.ts
index 4657605d2b..bb47f28a83 100644
--- a/app/src/boot/globalEvent/click.ts
+++ b/app/src/boot/globalEvent/click.ts
@@ -55,6 +55,7 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
!hasClosestByClassName(event.target, "b3-dialog--open", true) &&
!hasClosestByClassName(event.target, "b3-menu") &&
!hasClosestByClassName(event.target, "block__popover") &&
+ !hasClosestByClassName(event.target, "protyle-hint--agent-overlay") &&
!hasClosestByClassName(event.target, "dock") &&
!hasClosestByClassName(event.target, "layout--float", true)
) {
diff --git a/app/src/boot/globalEvent/mousemove.ts b/app/src/boot/globalEvent/mousemove.ts
index b9cf1838f6..1a679d2b9b 100644
--- a/app/src/boot/globalEvent/mousemove.ts
+++ b/app/src/boot/globalEvent/mousemove.ts
@@ -95,6 +95,7 @@ export const windowMouseMove = (event: MouseEvent) => {
const inDockOverlay = hasClosestByClassName(target, "b3-menu") ||
hasClosestByClassName(target, "tooltip") ||
hasClosestByClassName(target, "block__popover") ||
+ hasClosestByClassName(target, "protyle-hint--agent-overlay") ||
hasClosestByClassName(target, "b3-dialog", true);
if (event.buttons !== 0 || inDockOverlay) {
docks.forEach(dock => dock.clearDockHoverTimeout());
diff --git a/app/src/layout/dock/agent/AgentComposer.ts b/app/src/layout/dock/agent/AgentComposer.ts
index f34b2fbfd4..47a4cdeff2 100644
--- a/app/src/layout/dock/agent/AgentComposer.ts
+++ b/app/src/layout/dock/agent/AgentComposer.ts
@@ -30,6 +30,8 @@ interface ComposerHandle {
type OnChangeCallback = () => void;
+const AGENT_HINT_OVERLAY_CLASS = "protyle-hint--agent-overlay";
+
interface ComposerOptions {
initialContent?: string;
initialBlockHTML?: string;
@@ -51,9 +53,21 @@ const resetEmbedBlocks = (element: HTMLElement) => {
});
};
+const prepareAgentHint = (protyle: IProtyle) => {
+ if (protyle.hint.element.classList.contains("fn__none")) {
+ protyle.hint.element.style.zIndex = (++window.siyuan.zIndex).toString();
+ }
+};
+
+const hintAgentRef = (key: string, protyle: IProtyle, source: THintSource): IHintData[] => {
+ prepareAgentHint(protyle);
+ return hintRef(key, protyle, source);
+};
+
// / 技能菜单:异步拉取 lsSkills,选中后把技能名作为纯文本插入(value 即技能名)。
// 返回 [] 占位,数据在 fetch 回调里通过 protyle.hint.genHTML 填充(与 hintRef 异步模式一致)。
const hintSkill = (key: string, protyle: IProtyle): IHintData[] => {
+ prepareAgentHint(protyle);
protyle.hint.genLoading(protyle);
fetchPost("/api/ai/agent/lsSkills", {}, (response) => {
const rawSkills = (response && response.data) ? response.data : [];
@@ -164,16 +178,16 @@ export function mountComposer(host: HTMLElement, onSend: () => void, onChange?:
// / 技能菜单(覆盖默认的块插入菜单 hintSlash);[[ 块引用由 protyle 默认 extend 提供
extend: [{
key: "((",
- hint: hintRef,
+ hint: hintAgentRef,
}, {
key: "【【",
- hint: hintRef,
+ hint: hintAgentRef,
}, {
key: "((",
- hint: hintRef,
+ hint: hintAgentRef,
}, {
key: "[[",
- hint: hintRef,
+ hint: hintAgentRef,
}, {
key: "/",
hint: hintSkill,
@@ -188,6 +202,10 @@ export function mountComposer(host: HTMLElement, onSend: () => void, onChange?:
// 类方法(focus/insert/destroy)在 Protyle 实例上,内部数据属性在 IProtyle 上。
const p = protyle.protyle;
const wysiwyg = p.wysiwyg!;
+ const hintElement = p.hint.element;
+ // Hint 使用视口坐标定位,挂到顶层可避免受浮动 Dock 的变换坐标系和裁剪影响。
+ hintElement.classList.add(AGENT_HINT_OVERLAY_CLASS);
+ document.body.appendChild(hintElement);
wysiwyg.element.setAttribute("data-readonly", "false");
const setEmptyContent = () => {
@@ -309,6 +327,7 @@ export function mountComposer(host: HTMLElement, onSend: () => void, onChange?:
destroy: () => {
contentObserver.disconnect();
protyle.destroy();
+ hintElement.remove();
},
getSendData: () => {
const references: { id: string; title: string }[] = [];