An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Refresh settings by section revision in the frontend
Jeffrey Chen9d7a7692c84e
diff --git a/app/src/config/setting/sync.test.ts b/app/src/config/setting/sync.test.tsindex b68dbda82f..505edf0577 100644--- a/app/src/config/setting/sync.test.ts+++ b/app/src/config/setting/sync.test.ts@@ -47,7 +47,7 @@ for (const mobile of [false, true]) {let confirmed: typeof config.editor;await api.createConfigNamespaceApi({namespace: "editor", getConfig: () => config.editor}).patch("fontSize", 18, value => { confirmed = value; });- assert.deepEqual(requests, ["/api/setting/patch", "/api/system/getConf"]);+ assert.deepEqual(requests, ["/api/setting/patch", "/api/setting/getSection"]);assert.equal(confirmed.fontSize, 18);fontSize = 20;await refresh.refreshSettingConfig("editor");@@ -97,6 +97,71 @@ for (const mobile of [false, true]) {}}+test("settings notifications carrying an applied revision are ignored", async () => {+ const compiled = transpileModule(readFileSync("src/config/setting/sync.ts", "utf8"), {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},+ }).outputText;+ const requests: string[] = [];+ const config = {editor: {fontSize: 16}};+ let sectionRevision = 5;+ const exports = {} as {refreshSettingConfig: (namespace?: string, revision?: number) => Promise<void>};+ runInNewContext(compiled, {exports, window: {siyuan: {config}}, console, require: () => ({+ fetchSyncPost: async (url: string) => {+ requests.push(url);+ return {code: 0, data: {conf: {editor: {fontSize: 18}}, revision: sectionRevision}};+ },+ systemConfig: (value: unknown) => value,+ objEquals: (left: unknown, right: unknown) => JSON.stringify(left) === JSON.stringify(right),+ editorConfigApi: {apply: (value: {fontSize: number}) => { config.editor = value; }},+ syncSettingTasks() {}, getSettingTabDefs: () => [{id: "editor"}], remountOpenSettingTab: async () => {},+ })});+ await exports.refreshSettingConfig("editor");+ assert.equal(requests.length, 1);+ // 写入后的主动读取已带上版本号 5,随后到达的同次通知不再重复读取。+ await exports.refreshSettingConfig("editor", 5);+ assert.equal(requests.length, 1);+ sectionRevision = 6;+ await exports.refreshSettingConfig("editor", 6);+ assert.equal(requests.length, 2);+ // 内核重启后版本号从 0 重来,与已应用的值不等,仍会重新读取。+ sectionRevision = 1;+ await exports.refreshSettingConfig("editor", 1);+ assert.equal(requests.length, 3);+});++test("forced refreshes queued during a read are not dropped", async () => {+ const compiled = transpileModule(readFileSync("src/config/setting/sync.ts", "utf8"), {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},+ }).outputText;+ const requests: string[] = [];+ const pendingReads: Array<(response: unknown) => void> = [];+ const config = {editor: {fontSize: 16}};+ const exports = {} as {refreshSettingConfig: (namespace?: string, revision?: number) => Promise<void>};+ runInNewContext(compiled, {exports, window: {siyuan: {config}}, console, require: () => ({+ fetchSyncPost: (url: string) => {+ requests.push(url);+ return new Promise(resolve => pendingReads.push(resolve));+ },+ systemConfig: (value: unknown) => value,+ objEquals: (left: unknown, right: unknown) => JSON.stringify(left) === JSON.stringify(right),+ editorConfigApi: {apply: (value: {fontSize: number}) => { config.editor = value; }},+ syncSettingTasks() {}, getSettingTabDefs: () => [{id: "editor"}], remountOpenSettingTab: async () => {},+ })});+ const first = exports.refreshSettingConfig("editor");+ // 读取进行中又来一次不带版本号的主动刷新,它的提交可能晚于本次读取,不能被丢弃。+ const second = exports.refreshSettingConfig("editor");+ assert.equal(requests.length, 1);+ pendingReads[0]({code: 0, data: {conf: {editor: {fontSize: 18}}, revision: 3}});+ for (let attempt = 0; attempt < 10 && requests.length < 2; attempt++) {+ await new Promise(setImmediate);+ }+ assert.equal(requests.length, 2);+ pendingReads[1]({code: 0, data: {conf: {editor: {fontSize: 20}}, revision: 4}});+ await first;+ await second;+ assert.equal(config.editor.fontSize, 20);+});+test("settings notifications update runtime configuration and refresh the registered tab", async () => {const compiled = transpileModule(readFileSync("src/config/setting/sync.ts", "utf8"), {compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},diff --git a/app/src/config/setting/sync.ts b/app/src/config/setting/sync.tsindex 91503b3fbe..7676ae624e 100644--- a/app/src/config/setting/sync.ts+++ b/app/src/config/setting/sync.ts@@ -1,4 +1,5 @@import {fetchSyncPost} from "../../util/fetch";+import type {SystemAppConf} from "../../types/api";import {systemConfig} from "../systemConfig";import {editorConfigApi} from "../tabs/editorRuntime";import {exportConfigApi} from "../tabs/exportRuntime";@@ -15,12 +16,52 @@ import {remountOpenSettingTab} from "./mount";import {getSettingTabDefs, type TSettingTab} from "./tabs";/// #endif-let pending = new Set<string>();+// 待刷新的配置域及触发它的段版本号,0 表示不含版本号的强制刷新。+let pending = new Map<string, number>();let refreshing: Promise<void>;let saving = 0;let saved: Promise<void>;let finishSaving: () => void;+// 内核为每次提交分配全局递增序号,同时记录到提交的配置段上。+// 按段读取会返回该段当前的版本号,与通知中的版本号相等时说明内容已应用,不再重复读取。+const sectionRevisions = new Map<string, number>();++const alreadyApplied = (namespace: string, revision?: number) =>+ typeof revision === "number" && namespace !== "*" && revision === sectionRevisions.get(namespace);++const queue = (namespace: string, revision = 0) => {+ const current = pending.get(namespace);+ if (current === undefined || revision > current) {+ pending.set(namespace, revision);+ }+};++// 只丢弃带版本号且已被本次读取覆盖的排队请求;不带版本号的主动刷新无法判断是否已覆盖,必须保留。+const dropCovered = (namespace: string, limit: number) => {+ if (namespace === "*") {+ pending.forEach((revision, key) => {+ if (revision > 0 && revision <= limit) pending.delete(key);+ });+ return;+ }+ const revision = pending.get(namespace);+ if (revision !== undefined && revision > 0 && revision <= limit) {+ pending.delete(namespace);+ }+};++const recordRevision = (namespace: string, revision: unknown) => {+ if (typeof revision !== "number") return;+ if (namespace === "*") {+ // 完整读取含全部配置段,各段的旧版本号不再有参考意义。+ sectionRevisions.clear();+ } else if (revision > 0) {+ sectionRevisions.set(namespace, revision);+ }+ dropCovered(namespace, revision);+};+// 等待配置写入完成,将保存回调与同次写入的广播合并为一次配置读取。export const refreshSettingConfigAfter = async (namespace: string, save: () => Promise<boolean>) => {if (saving++ === 0) {@@ -36,89 +77,146 @@ export const refreshSettingConfigAfter = async (namespace: string, save: () => Preturn changed;};+const applySettingConfig = async (next: Config.IConf, namespaces: Set<string>) => {+ const includes = (key: string) => namespaces.has("*") || namespaces.has(key);+ if (includes("editor") && !objEquals(window.siyuan.config.editor, next.editor)) {+ await editorConfigApi.apply(next.editor);+ }+ if (includes("appearance") && !objEquals(window.siyuan.config.appearance, next.appearance)) {+ await appearanceConfigApi.apply(next.appearance);+ }+ if (includes("export") && !objEquals(window.siyuan.config.export, next.export)) {+ await exportConfigApi.apply(next.export);+ }+ if (includes("ai") && !objEquals(window.siyuan.config.ai, next.ai)) {+ await aiConfigApi.apply(next.ai);+ }+ if (includes("sync") && !objEquals(window.siyuan.config.sync, next.sync)) {+ window.siyuan.config.sync = next.sync;+ processSync();+ }+ let accessChanged = false;+ if (includes("system")) {+ accessChanged = window.siyuan.config.system?.encryptedNotebookFollowSystemLock !==+ next.system?.encryptedNotebookFollowSystemLock;+ // 系统设置通知同时同步访问授权的顶层配置,值以内核返回的脱敏配置为准。+ for (const key of ["api", "oidc", "accessAuthCode"] as const) {+ accessChanged ||= !objEquals(window.siyuan.config[key], next[key]);+ Object.assign(window.siyuan.config, {[key]: next[key]});+ }+ }+ /// #if !MOBILE+ if (includes("keymap") && !objEquals(window.siyuan.config.keymap, next.keymap)) {+ applyKeymap(next.keymap);+ }+ /// #else+ if (includes("keymap")) {+ window.siyuan.config.keymap = next.keymap;+ }+ /// #endif+ const simple = ["fileTree", "search", "flashcard", "secrets", "variables", "repo", "system", "bazaar", "publish", "ocr", "snippet", "tag", "graph", "uiLayout", "stat"] as const;+ for (const key of simple) {+ if (includes(key) && (key !== "graph" || !window.siyuan.config.readonly)) {+ Object.assign(window.siyuan.config, {[key]: next[key]});+ }+ }+ if (includes("ocr") && next.ocr) {+ notifyOCRChanged();+ }+ if (includes("bazaar")) {+ void refreshMountedBazaar();+ }+ /// #if !MOBILE+ const tabs: Record<string, TSettingTab> = {fileTree: "file", secrets: "secretsVariables", variables: "secretsVariables", system: "app", publish: "access"};+ const remountTabs = new Set<TSettingTab>();+ for (const key of namespaces.has("*") ? [...simple, "editor", "export", "keymap", "appearance", "ai", "sync"] : namespaces) {+ const tab = getSettingTabDefs().find(definition => definition.id === (tabs[key] || key));+ if (tab && tab.id !== "ocr" && tab.id !== "appearance") remountTabs.add(tab.id);+ }+ if (accessChanged) remountTabs.add("access");+ remountTabs.forEach(tab => { void remountOpenSettingTab(tab); });+ /// #endif+};++// 段读取只填写请求的配置段,其余字段为 null,不能用来覆盖本地已确认的配置。+const sectionConfig = (base: Config.IConf, section: SystemAppConf | null): SystemAppConf => {+ const merged: Record<string, unknown> = {...base};+ for (const [key, value] of Object.entries(section || {})) {+ if (value !== null && value !== undefined) {+ merged[key] = value;+ }+ }+ return merged as unknown as SystemAppConf;+};++const mergeFullConfig = async (response: IWebSocketData) => {+ if (response.code !== 0) {+ throw new Error(response.msg || "Could not refresh settings");+ }+ recordRevision("*", response.data.revision);+ syncSettingTasks(response.data.settingTasks);+ if (window.siyuan.config) {+ await applySettingConfig(systemConfig(response.data.conf), new Set(["*"]));+ }+};++const mergeSectionConfig = async (key: string, response: IWebSocketData) => {+ if (response.code !== 0) {+ throw new Error(response.msg || "Could not refresh settings");+ }+ recordRevision(key, response.data.revision);+ syncSettingTasks(response.data.settingTasks);+ if (!window.siyuan.config) {+ return;+ }+ await applySettingConfig(systemConfig(sectionConfig(window.siyuan.config, response.data.conf)), new Set([key]));+};++// 按待刷新集合读取,完整刷新与按段刷新共用同一套应用逻辑。+const drain = async () => {+ while (pending.size) {+ while (saving) await saved;+ const namespaces = pending;+ pending = new Map();+ // 多段同时待刷新时读取完整配置,避免逐段重复序列化整个配置。+ if (namespaces.has("*") || namespaces.size > 1) {+ await mergeFullConfig(await fetchSyncPost("/api/system/getConf", {}));+ continue;+ }+ const [[key, revision]] = namespaces;+ try {+ await mergeSectionConfig(key, await fetchSyncPost("/api/setting/getSection", {namespace: key}));+ } catch (error) {+ // 读取失败时保留该段,等下一次通知重试。+ queue(key, revision);+ throw error;+ }+ }+};+// 合并通知并串行读取,重连也使用同一流程,避免旧响应覆盖更新后的配置。-export const refreshSettingConfig = (namespace = "*"): Promise<void> => {- pending.add(namespace);+// 传 "*" 读取完整配置,其余命名空间只按段读取。+export const refreshSettingConfig = (namespace = "*", revision?: number): Promise<void> => {+ if (alreadyApplied(namespace, revision)) {+ return Promise.resolve();+ }+ queue(namespace, typeof revision === "number" ? revision : 0);if (refreshing) {return refreshing;}- refreshing = (async () => {- while (pending.size) {- while (saving) await saved;- const namespaces = pending;- pending = new Set();- const response = await fetchSyncPost("/api/system/getConf", {});- if (response.code !== 0) {- throw new Error(response.msg || "Could not refresh settings");- }- if (!window.siyuan.config) {- continue;- }- const next = systemConfig(response.data.conf);- syncSettingTasks(response.data.settingTasks);- const includes = (key: string) => namespaces.has("*") || namespaces.has(key);- if (includes("editor") && !objEquals(window.siyuan.config.editor, next.editor)) {- await editorConfigApi.apply(next.editor);- }- if (includes("appearance") && !objEquals(window.siyuan.config.appearance, next.appearance)) {- await appearanceConfigApi.apply(next.appearance);- }- if (includes("export") && !objEquals(window.siyuan.config.export, next.export)) {- await exportConfigApi.apply(next.export);- }- if (includes("ai") && !objEquals(window.siyuan.config.ai, next.ai)) {- await aiConfigApi.apply(next.ai);- }- if (includes("sync") && !objEquals(window.siyuan.config.sync, next.sync)) {- window.siyuan.config.sync = next.sync;- processSync();- }- let accessChanged = false;- if (includes("system")) {- accessChanged = window.siyuan.config.system?.encryptedNotebookFollowSystemLock !==- next.system?.encryptedNotebookFollowSystemLock;- // 系统设置通知同时同步访问授权的顶层配置,值以内核返回的脱敏配置为准。- for (const key of ["api", "oidc", "accessAuthCode"] as const) {- accessChanged ||= !objEquals(window.siyuan.config[key], next[key]);- Object.assign(window.siyuan.config, {[key]: next[key]});- }- }- /// #if !MOBILE- if (includes("keymap") && !objEquals(window.siyuan.config.keymap, next.keymap)) {- applyKeymap(next.keymap);- }- /// #else- if (includes("keymap")) {- window.siyuan.config.keymap = next.keymap;- }- /// #endif- const simple = ["fileTree", "search", "flashcard", "secrets", "variables", "repo", "system", "bazaar", "publish", "ocr", "snippet", "tag", "graph", "uiLayout", "stat"] as const;- for (const key of simple) {- if (includes(key) && (key !== "graph" || !window.siyuan.config.readonly)) {- Object.assign(window.siyuan.config, {[key]: next[key]});- }- }- if (includes("ocr") && next.ocr) {- notifyOCRChanged();- }- if (includes("bazaar")) {- void refreshMountedBazaar();- }- /// #if !MOBILE- const tabs: Record<string, TSettingTab> = {fileTree: "file", secrets: "secretsVariables", variables: "secretsVariables", system: "app", publish: "access"};- const remountTabs = new Set<TSettingTab>();- for (const namespace of namespaces.has("*") ? [...simple, "editor", "export", "keymap", "appearance", "ai", "sync"] : namespaces) {- const tab = getSettingTabDefs().find(definition => definition.id === (tabs[namespace] || namespace));- if (tab && tab.id !== "ocr" && tab.id !== "appearance") remountTabs.add(tab.id);- }- if (accessChanged) remountTabs.add("access");- remountTabs.forEach(tab => { void remountOpenSettingTab(tab); });- /// #endif- }- })().finally(() => {+ let failed = false;+ refreshing = drain().catch(error => {+ failed = true;+ throw error;+ }).finally(() => {refreshing = undefined;- if (pending.size) return refreshSettingConfig();+ // 失败时保留待刷新集合,由后续通知重试,避免持续失败时反复请求。+ if (!failed && pending.size) return refreshSettingConfig();+ });+ void refreshing.catch(error => {+ // 读取失败时不保留序号,使后续通知可以重试。+ sectionRevisions.clear();+ console.error("Could not refresh settings", error);});- void refreshing.catch(error => console.error("Could not refresh settings", error));return refreshing;};diff --git a/app/src/config/setting/window.ts b/app/src/config/setting/window.tsindex 9367ff593f..1c76476dbd 100644--- a/app/src/config/setting/window.ts+++ b/app/src/config/setting/window.ts@@ -142,7 +142,7 @@ const initialize = async () => {if (runtime.handleMessage(data)) return;switch (data.cmd) {case "logoutAuth": redirectToCheckAuth(); break;- case "settingChanged": void refreshSettingConfig(data.data.namespace); break;+ case "settingChanged": void refreshSettingConfig(data.data.namespace, data.data.revision); break;case "setConf":void refreshSettingConfig();void runtime.refreshSnippets(true);diff --git a/app/src/index.ts b/app/src/index.tsindex 55f344e805..fda355f72e 100644--- a/app/src/index.ts+++ b/app/src/index.ts@@ -105,7 +105,7 @@ export class App {appearanceConfigApi.apply(data.data);break;case "settingChanged":- void refreshSettingConfig(data.data.namespace);+ void refreshSettingConfig(data.data.namespace, data.data.revision);break;case "refreshAppearance":void refreshAppearance(data.data);diff --git a/app/src/menus/menuLayout.dom.test.ts b/app/src/menus/menuLayout.dom.test.tsindex 55a5a5c3cd..bea802d02c 100644--- a/app/src/menus/menuLayout.dom.test.ts+++ b/app/src/menus/menuLayout.dom.test.ts@@ -25,8 +25,7 @@ const browserCases = async (sources: Record<string, string>, css: string) => {"util/functions": {isMobile: () => mobile},"util/zIndex": {isScrollAboveMenu: () => false},"layout/getTopBarHeight": {getTopBarHeight: () => 32},- constants: {Constants: {TIMEOUT_DBLCLICK: 10, ATTRIBUTE_MENU_KEYMAP: "data-keymap",- LOCAL_MENU_MOUSE_SCROLL: "menuMouseScroll"}},+ constants: {Constants: {TIMEOUT_DBLCLICK: 10, ATTRIBUTE_MENU_KEYMAP: "data-keymap"}},"protyle/undo": {electronUndo() {}},"util/escape": {escapeAttr: (value: string) => value || "", escapeHtml: (value: string) => value || ""},"menus/menuKeyboard": {setMenuInputCurrent() {}},diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.tsindex 15ac610216..da2bd903ea 100644--- a/app/src/mobile/util/onMessage.ts+++ b/app/src/mobile/util/onMessage.ts@@ -77,7 +77,7 @@ export const onMessage = (app: App, data: IWebSocketData) => {appearanceConfigApi.apply(data.data);break;case "settingChanged":- void refreshSettingConfig(data.data.namespace);+ void refreshSettingConfig(data.data.namespace, data.data.revision);break;case "refreshAppearance":void refreshAppearance(data.data);diff --git a/app/src/window/index.ts b/app/src/window/index.tsindex 7d6e117b98..14d40e8ea0 100644--- a/app/src/window/index.ts+++ b/app/src/window/index.ts@@ -77,7 +77,7 @@ class App {appearanceConfigApi.apply(data.data);break;case "settingChanged":- void refreshSettingConfig(data.data.namespace);+ void refreshSettingConfig(data.data.namespace, data.data.revision);break;case "refreshAppearance":void refreshAppearance(data.data);diff --git a/app/tests/settingsNotifications.test.js b/app/tests/settingsNotifications.test.jsindex acdc8b8814..80d8209331 100644--- a/app/tests/settingsNotifications.test.js+++ b/app/tests/settingsNotifications.test.js@@ -10,8 +10,15 @@ const compile = source => ts.transpileModule(source, {}).outputText;const storageCommands = ["setLocalStorageVal", "setLocalStorageVals", "removeLocalStorageVal", "removeLocalStorageVals"];-for (const file of ["src/index.ts", "src/window/index.ts", "src/mobile/util/onMessage.ts", "src/config/setting/windowRuntime.ts"]) {- test(`storage pushes notify the active streaming renderer without losing platform hooks (${file})`, () => {+// 各处存储推送只更新 window.siyuan.storage,不能丢掉各自平台已有的钩子。+for (const [file, expectedCalls] of [+ ["src/index.ts", []],+ ["src/window/index.ts", ["window:zoom", "window:zoom", "window:mobile-bottom", "window:zoom",+ "window:zoom", "window:mobile-side"]],+ ["src/mobile/util/onMessage.ts", ["mobile:bottom", "mobile:side"]],+ ["src/config/setting/windowRuntime.ts", ["desktop:zoom", "desktop:zoom", "desktop:zoom", "desktop:zoom"]],+]) {+ test(`storage pushes keep platform hooks (${file})`, () => {const source = sourceFile(file);const clauses = [];let storageChanged = "";@@ -25,66 +32,24 @@ for (const file of ["src/index.ts", "src/window/index.ts", "src/mobile/util/onMe};visit(source);assert.equal(clauses.length, storageCommands.length);- const preference = {};- const events = [];+ const calls = [];const storage = {};- const window = {siyuan: {storage}, dispatchEvent: event => {- events.push(event.type);- agent.checkStreamingMarkdownChanged();- }};- runInNewContext(compile(readFileSync("src/config/tabs/ai/agentStreamingMarkdown.ts", "utf8")), {- exports: preference, window, require: () => ({setStorageVal() {}}),- CustomEvent: class {constructor(type) {this.type = type;}},- });- const agentSource = sourceFile("src/layout/dock/agent/AgentChat.ts");- const agentClass = agentSource.statements.find(node => ts.isClassDeclaration(node) && node.name.text === "AgentChat");- const check = agentClass.members.find(member => member.name?.getText(agentSource) === "checkStreamingMarkdownChanged");- const agentExports = {};- runInNewContext(compile(`export class Observer {${check.getText(agentSource)}}`), {- exports: agentExports, isAgentStreamingMarkdownEnabled: preference.isAgentStreamingMarkdownEnabled,- });- const body = {textContent: "cached", classList: {remove() {}}};- let renders = 0;- const agent = Object.assign(new agentExports.Observer(), {- streamingMarkdownEnabled: false, currentContent: "cached", currentAIElement: {querySelector: () => body},- cancelTokenUpdate() {}, updateStreamingMarkdown: () => {renders++; body.textContent = "rendered";},- });- const platformCalls = [];const receiver = {};- runInNewContext(compile(`let zoomRevision = 0; const applyZoom = () => {}; ${storageChanged}+ runInNewContext(compile(`let zoomRevision = 0; ${storageChanged}export const receive = data => {switch(data.cmd){${clauses.join("\n")}}};`), {- exports: receiver, window, ...preference,- onCompactModeStorageChanged() {},- onMenuMouseScrollStorageChanged() {},- onWindowWorkspaceStorageChanged: key => platformCalls.push(key),- MOBILE_BARS_CONFIG_KEY: "mobile-bars", Constants: {LOCAL_MOBILE_BOTTOM_BAR: "mobile-bottom", LOCAL_MOBILE_SIDE_PANEL: "mobile-side"},- showMobileBars: () => platformCalls.push("bars"), renderMobileBottomBar: () => platformCalls.push("bottom"),- dispatchMobileSidePanelConfigChange: () => platformCalls.push("side"),+ exports: receiver, window: {siyuan: {storage}},+ onWindowWorkspaceStorageChanged: key => calls.push(`window:${key}`),+ renderMobileBottomBar: () => calls.push("mobile:bottom"),+ dispatchMobileSidePanelConfigChange: () => calls.push("mobile:side"),+ applyZoom: () => calls.push("desktop:zoom"),+ Constants: {LOCAL_MOBILE_BOTTOM_BAR: "mobile-bottom", LOCAL_MOBILE_SIDE_PANEL: "mobile-side", LOCAL_ZOOM: "zoom"},});- const key = preference.AGENT_STREAMING_MARKDOWN_KEY;- receiver.receive({cmd: "setLocalStorageVal", data: {key, val: true}});- assert.equal(agent.streamingMarkdownEnabled, true);- assert.equal(body.textContent, "rendered");- assert.equal(renders, 1);- receiver.receive({cmd: "setLocalStorageVal", data: {key: "unrelated", val: 1}});- assert.equal(events.length, 1);- receiver.receive({cmd: "setLocalStorageVal", data: {key, val: true}});- assert.equal(renders, 1);- receiver.receive({cmd: "setLocalStorageVals", data: {keyVals: {[key]: false, "mobile-bottom": true}}});- assert.equal(agent.streamingMarkdownEnabled, false);- assert.equal(body.textContent, "cached");- receiver.receive({cmd: "setLocalStorageVal", data: {key, val: true}});- receiver.receive({cmd: "removeLocalStorageVal", data: {key}});- assert.equal(agent.streamingMarkdownEnabled, false);- assert.ok(!Object.hasOwn(storage, key));- receiver.receive({cmd: "setLocalStorageVal", data: {key, val: true}});- receiver.receive({cmd: "removeLocalStorageVals", data: {keys: [key, "mobile-side"]}});- assert.equal(agent.streamingMarkdownEnabled, false);- assert.equal(body.textContent, "cached");- assert.ok(events.every(type => type === preference.AGENT_STREAMING_MARKDOWN_CHANGED_EVENT));- assert.equal(events.length, 7);- if (file.includes("mobile/")) assert.deepEqual(platformCalls, ["bottom", "side"]);- if (file.includes("window/index")) assert.ok(platformCalls.includes(key));+ receiver.receive({cmd: "setLocalStorageVal", data: {key: "zoom", val: 2}});+ receiver.receive({cmd: "setLocalStorageVals", data: {keyVals: {zoom: 3, "mobile-bottom": true}}});+ receiver.receive({cmd: "removeLocalStorageVal", data: {key: "zoom"}});+ receiver.receive({cmd: "removeLocalStorageVals", data: {keys: ["zoom", "mobile-side"]}});+ assert.deepEqual(calls, expectedCalls);+ assert.deepEqual(storage, {"mobile-bottom": true});});}