An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Keep tablet agent session popups open during keyboard resize https://github.com/siyuan-note/siyuan/issues/20434
Danielf094b46aaa9e
diff --git a/app/src/layout/dock/agent/AgentSessionPanel.test.ts b/app/src/layout/dock/agent/AgentSessionPanel.test.tsnew file mode 100644index 0000000000..c8b95cfc15--- /dev/null+++ b/app/src/layout/dock/agent/AgentSessionPanel.test.ts@@ -0,0 +1,64 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import {test} from "node:test";+import {runInNewContext} from "node:vm";+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";++const compiled = transpileModule(readFileSync("src/layout/dock/agent/AgentSessionPanel.ts", "utf8"), {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},+}).outputText;++for (const scenario of [+ {name: "desktop", mobile: false, phablet: false, focus: 1, closes: 1, positions: 1},+ {name: "tablet desktop layout", mobile: false, phablet: true, focus: 0, closes: 0, positions: 2},+ {name: "phone", mobile: true, phablet: true, focus: 0, closes: 0, positions: 0},+]) {+ test(`session search survives keyboard resizing on ${scenario.name}`, async () => {+ let focused = 0;+ let closes = 0;+ let positions = 0;+ const listeners = new Map<string, () => void>();+ const input = {addEventListener() {}, focus() { focused++; }};+ const list = {addEventListener() {}};+ const popup = {+ style: {},+ querySelector: (selector: string) => selector === ".b3-list" ? list : input,+ addEventListener() {},+ animate() {},+ };+ const exports = {AgentSessionPanel: undefined as unknown as new (...args: unknown[]) => {+ render: () => Promise<void>;+ renderItems: () => void;+ close: () => void;+ }};+ runInNewContext(compiled, {+ exports,+ require: (id: string) => {+ if (id === "./SessionStore") {+ return {SessionStore: {list: async () => ({sessions: [] as unknown[], total: 0})}};+ }+ if (id.endsWith("/compatibility")) return {isPhablet: () => scenario.phablet};+ if (id.endsWith("/setPosition")) return {setPosition: () => { positions++; }};+ return {};+ },+ window: {+ siyuan: {languages: {}, zIndex: 10},+ addEventListener: (type: string, handler: () => void) => listeners.set(type, handler),+ },+ document: {createElement: () => popup, body: {appendChild() {}}},+ setTimeout: () => 1,+ });+ const panel = new exports.AgentSessionPanel(+ {getBoundingClientRect: () => ({right: 400, bottom: 50, height: 30, width: 30})},+ {appendChild() {}}, () => "", () => "", {}, scenario.mobile,+ );+ panel.renderItems = () => {};+ panel.close = () => { closes++; };+ await panel.render();+ closes = 0;+ listeners.get("resize")?.();+ assert.equal(focused, scenario.focus);+ assert.equal(closes, scenario.closes);+ assert.equal(positions, scenario.positions);+ });+}diff --git a/app/src/layout/dock/agent/AgentSessionPanel.ts b/app/src/layout/dock/agent/AgentSessionPanel.tsindex 709f6e74ac..ac24a7a708 100644--- a/app/src/layout/dock/agent/AgentSessionPanel.ts+++ b/app/src/layout/dock/agent/AgentSessionPanel.ts@@ -10,6 +10,7 @@ import {useShell} from "../../../util/pathName";/// #endifimport {getHostCapabilities} from "../../../util/hostCapabilities";+import {isPhablet} from "../../../protyle/util/compatibility";export class AgentSessionPanel {private popup: HTMLElement | null = null;@@ -170,6 +171,12 @@ export class AgentSessionPanel {e.stopPropagation();});const onResize = () => {+ if (isPhablet() && this.popup) {+ // 平板软键盘改变视口时重新定位,保留会话搜索与列表。+ const btnRect = this.triggerBtn.getBoundingClientRect();+ setPosition(this.popup, btnRect.right - 280, btnRect.bottom, btnRect.height, btnRect.width);+ return;+ }this.close();};if (!this.mobile) {@@ -186,7 +193,7 @@ export class AgentSessionPanel {document.removeEventListener("click", closeOut);window.removeEventListener("resize", onResize);};- if (!this.mobile) {+ if (!this.mobile && !isPhablet()) {searchInput.focus();}} finally {