From 2c907b77c63c58501b131b1026acd553baf0bf9f Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 5 Oct 2026 03:24:06 +0800 Subject: [PATCH] feat(dsh): mount the bili panel at plugins.bundle.config on the plugin detail page Register the existing origin-probe panel under the plugins.bundle.config slot so it renders between the description and the component rows on the plugin detail page (view:'page'), per #2125. Reuses the origin polling/bound-state logic already present for settings.section; the legacy entry is kept as the fallback for launcher postures where no bundle page exists. No manifest change: deliberately do NOT add dsh.client.inject for @deepseek-ai/dsh-client-ui-plugin-manager. The host ships built into dsh-web-app on 0.2.x, so the injection is redundant there; on the older 0.1.x dsh the unknown inject target stalls the client-module scanner and turns the whole web app into an endless spinner. A test locks this in: the manifest must not declare dsh.client.inject. Closes #2125 --- src/agent/dsh-native-client.ts | 20 +++-- tests/dsh-settings-ui.test.ts | 146 ++++++++++++++++++++++++++------- 2 files changed, 130 insertions(+), 36 deletions(-) diff --git a/src/agent/dsh-native-client.ts b/src/agent/dsh-native-client.ts index cc1c4f7e00..6499e704c9 100644 --- a/src/agent/dsh-native-client.ts +++ b/src/agent/dsh-native-client.ts @@ -11,13 +11,19 @@ // serves the live origin at GET /bili/origin on the dsh webserver; this // section polls that route while unresolved so the entry upgrades without a // reload or app restart. Neither source known ⇒ degrade to a hint instead of -// a dead link. +// a dead link. The same panel is mounted at two slots (#2125): settings.section +// (always present — the launcher posture has no bundle page) and +// plugins.bundle.config (keyed by package name; the plugin detail page renders +// it only when this package is installed as a profile bundle and draws the +// title itself, so that registration drops the h3). import { createElement, useEffect, useState } from "react"; type Dict = Record; -type SlotOptions = { name: string; id: string; order: number; label: () => string; locale: string }; +type SlotOptions = + | { name: string; id: string; order: number; label: () => string; locale: string } + | { name: string; key: string; locale: string }; type ClientContext = { effect: (fn: () => void | (() => void), label?: string) => void; @@ -110,7 +116,7 @@ export function apply(ctx: ClientContext): void { "bili: dictionaries", ); const t = ctx.locale.bind(NS); - const section = (): unknown => { + const panel = (titled: boolean): ((props: Record) => unknown) => () => { const [origin, setOrigin] = useState(readOrigin()); useEffect(() => { if (origin !== undefined) return; @@ -119,7 +125,7 @@ export function apply(ctx: ClientContext): void { return createElement( "div", { style: { display: "flex", flexDirection: "column", gap: 12, padding: "20px 8px" } }, - createElement("h3", { style: { margin: 0, fontSize: 16, fontWeight: 600 } }, t("title")), + titled ? createElement("h3", { style: { margin: 0, fontSize: 16, fontWeight: 600 } }, t("title")) : null, origin === undefined ? createElement("p", { style: { margin: 0, opacity: 0.7, lineHeight: 1.6 } }, t("degraded")) : createElement( @@ -147,6 +153,10 @@ export function apply(ctx: ClientContext): void { }; ctx.slots.inject( "settings.section", - () => ctx.slots.register({ name: "settings.section", id: "bili", order: 100, label: () => t("nav"), locale: NS }, section), + () => ctx.slots.register({ name: "settings.section", id: "bili", order: 100, label: () => t("nav"), locale: NS }, panel(true)), + ); + ctx.slots.inject( + "plugins.bundle.config", + () => ctx.slots.register({ name: "plugins.bundle.config", key: "billion-context", locale: NS }, panel(false)), ); } diff --git a/tests/dsh-settings-ui.test.ts b/tests/dsh-settings-ui.test.ts index 3f92a6a240..1cf537132e 100644 --- a/tests/dsh-settings-ui.test.ts +++ b/tests/dsh-settings-ui.test.ts @@ -237,7 +237,19 @@ function findButton(node: unknown): ElementNode | undefined { return undefined; } -test("#1590: client bundle registers the settings.section entry bili (wrapper id, require purity, both render branches)", async () => { +function findTag(node: unknown, type: string): ElementNode | undefined { + if (node !== null && typeof node === "object") { + const el = node as ElementNode; + if (el.type === type) return el; + for (const child of el.children ?? []) { + const hit = findTag(child, type); + if (hit !== undefined) return hit; + } + } + return undefined; +} + +test("#1590/#2125: client bundle registers the settings.section entry bili AND the plugins.bundle.config panel (wrapper id, require purity, both render branches)", async () => { const { build } = await import("esbuild"); // Reuse tsup.config.ts as the single source of truth for the wrapper // banner/footer and externals so the test cannot drift from the shipped @@ -313,13 +325,13 @@ test("#1590: client bundle registers the settings.section entry bili (wrapper id assert.deepEqual(Array.from(face.inject), ["slots", "locale"]); assert.equal(typeof face.apply, "function"); - const runApply = (): { options: Record; component: () => unknown; zh: Record; en: Record } => { + type Entry = { options: Record; component: () => unknown }; + const runApply = (): { slots: string[]; bySlot: Map; zh: Record; en: Record } => { const effects: Array<() => void> = []; const dicts: Record; en: Record }> = {}; - let slot: string | undefined; - let provide: (() => void) | undefined; - let options: Record | undefined; - let component: (() => unknown) | undefined; + const slots: string[] = []; + const bySlot = new Map(); + let current: string | undefined; face.apply({ effect: (fn: () => void, _label?: string) => effects.push(fn), locale: { @@ -330,37 +342,46 @@ test("#1590: client bundle registers the settings.section entry bili (wrapper id }, slots: { inject: (name: string, p: () => void) => { - slot = name; - provide = p; + slots.push(name); + current = name; + p(); }, register: (opts: Record, comp: () => unknown) => { - options = opts; - component = comp; + // Hook indices restart on every render (React matches hooks + // by position within a single render), so wrap the entry. + bySlot.set(current!, { options: opts, component: (): unknown => { hookIndex = 0; return comp(); } }); }, }, }); for (const eff of effects) eff(); - assert.equal(slot, "settings.section"); - provide!(); - assert.ok(options !== undefined && component !== undefined && dicts["bili"] !== undefined); - // Hook indices restart on every render (React matches hooks by - // position within a single render), so wrap the entry point. - return { options: options!, component: (): unknown => { hookIndex = 0; return component!(); }, zh: dicts["bili"].zh, en: dicts["bili"].en }; + assert.deepEqual(slots, ["settings.section", "plugins.bundle.config"]); + assert.equal(bySlot.size, 2); + assert.ok(dicts["bili"] !== undefined); + return { slots, bySlot, zh: dicts["bili"].zh, en: dicts["bili"].en }; }; sandbox.__BILI__ = { origin: "http://127.0.0.1:8787" }; const withOrigin = runApply(); - assert.equal(withOrigin.options.name, "settings.section"); - assert.equal(withOrigin.options.id, "bili"); - assert.equal(withOrigin.options.order, 100); - assert.equal(withOrigin.options.locale, "bili"); - assert.equal(typeof withOrigin.options.label, "function"); - assert.equal((withOrigin.options.label as () => string)(), "bili设置"); + const settings = withOrigin.bySlot.get("settings.section")!; + assert.equal(settings.options.name, "settings.section"); + assert.equal(settings.options.id, "bili"); + assert.equal(settings.options.order, 100); + assert.equal(settings.options.locale, "bili"); + assert.equal(typeof settings.options.label, "function"); + assert.equal((settings.options.label as () => string)(), "bili设置"); + const bundle = withOrigin.bySlot.get("plugins.bundle.config")!; + assert.equal(bundle.options.name, "plugins.bundle.config"); + assert.equal(bundle.options.key, "billion-context"); + assert.equal(bundle.options.locale, "bili"); + // Keyed slot: the host matches the key against its own package name — no + // list-slot fields may ride along. + assert.deepEqual(Object.keys(bundle.options).sort(), ["key", "locale", "name"]); assert.deepEqual(Object.keys(withOrigin.zh).sort(), Object.keys(withOrigin.en).sort()); calls.length = 0; resetHooks(); - const tree = withOrigin.component() as ElementNode; + const tree = settings.component() as ElementNode; assert.equal(tree.type, "div"); + assert.notEqual(findTag(tree, "h3"), undefined, "the settings section keeps its own title"); const button = findButton(tree); assert.ok(button !== undefined, "origin present renders the open button"); assert.equal(typeof button.props?.onClick, "function"); @@ -372,18 +393,41 @@ test("#1590: client bundle registers the settings.section entry bili (wrapper id (button.props!.onClick as () => void)(); assert.deepEqual(opened, ["http://127.0.0.1:8787/__bili/"]); + // #2125: the bundle panel reuses the probe/button/hint but drops the title + // — the plugin detail page draws it. + calls.length = 0; + resetHooks(); + const btree = bundle.component() as ElementNode; + assert.equal(btree.type, "div"); + assert.equal(findTag(btree, "h3"), undefined, "the bundle panel does not repeat the page title"); + const bButton = findButton(btree); + assert.ok(bButton !== undefined, "origin present renders the open button in the bundle panel"); + assert.equal(typeof bButton.props?.onClick, "function"); + const btexts: string[] = []; + collectText(btree, btexts); + assert.ok(btexts.some((x) => x.includes("http://127.0.0.1:8787")), `bundle button label carries the origin: ${JSON.stringify(btexts)}`); + opened.length = 0; + (bButton.props!.onClick as () => void)(); + assert.deepEqual(opened, ["http://127.0.0.1:8787/__bili/"]); + delete sandbox.__BILI__; const degraded = runApply(); calls.length = 0; resetHooks(); - const degTree = degraded.component() as ElementNode; + const degTree = degraded.bySlot.get("settings.section")!.component() as ElementNode; assert.equal(findButton(degTree), undefined); const degTexts: string[] = []; collectText(degTree, degTexts); assert.ok(degTexts.some((t) => t.includes("/acp")), `degraded hint points at /acp: ${JSON.stringify(degTexts)}`); + resetHooks(); + const degBundleTree = degraded.bySlot.get("plugins.bundle.config")!.component() as ElementNode; + assert.equal(findButton(degBundleTree), undefined, "the bundle panel degrades like the settings section"); + const degBundleTexts: string[] = []; + collectText(degBundleTree, degBundleTexts); + assert.ok(degBundleTexts.some((t) => t.includes("/acp")), "the bundle degraded hint points at /acp"); }); -test("#1809: client polls /bili/origin while unresolved — upgrades on success, stays degraded and cancels when absent", async () => { +test("#1809/#2125: client polls /bili/origin while unresolved — upgrades on success, stays degraded and cancels when absent (both slots)", async () => { const { build } = await import("esbuild"); const configs = ((await import("../tsup.config.ts")).default) as unknown as Array<{ entry: Record; @@ -409,7 +453,7 @@ test("#1809: client polls /bili/origin while unresolved — upgrades on success, const code = result.outputFiles![0].text; type Face = { inject: string[]; apply: (ctx: unknown) => void }; - const mount = (extra: Record): { component: () => unknown; resetHooks: () => void; runCleanups: () => void } => { + const mount = (extra: Record, slotName = "settings.section"): { component: () => unknown; resetHooks: () => void; runCleanups: () => void } => { const registrations: Array<{ id: string; factory: (require: (spec: string) => unknown) => unknown }> = []; const sandbox: Record = {}; sandbox.window = { __ModuleLoader__: { load: (reg: (typeof registrations)[number]) => registrations.push(reg) } }; @@ -444,7 +488,8 @@ test("#1809: client polls /bili/origin while unresolved — upgrades on success, }; const face = registrations[0].factory(requireStub) as Face; const dicts: Record; en: Record }> = {}; - let component: (() => unknown) | undefined; + const components = new Map unknown>(); + let current: string | undefined; face.apply({ effect: (fn: () => void) => fn(), locale: { @@ -454,14 +499,17 @@ test("#1809: client polls /bili/origin while unresolved — upgrades on success, bind: (ns: string) => (key: string) => dicts[ns]?.zh?.[key] ?? key, }, slots: { - inject: (_name: string, p: () => void) => p(), + inject: (name: string, p: () => void) => { + current = name; + p(); + }, register: (_opts: Record, comp: () => unknown) => { - component = comp; + components.set(current!, comp); }, }, }); - assert.ok(component !== undefined); - const bound = component; + assert.ok(components.has(slotName), `slot ${slotName} must be registered`); + const bound = components.get(slotName)!; return { // Hook indices restart on every render (React semantics). component: (): unknown => { hookIndex = 0; return bound(); }, @@ -522,4 +570,40 @@ test("#1809: client polls /bili/origin while unresolved — upgrades on success, m.runCleanups(); assert.ok(cleared >= 1, "pending retry timers are cancelled on unmount"); } + + { + // #2125: the bundle panel runs the same probe wiring through its own + // registration. + const opened: string[] = []; + const m = mount( + { + open: (url: string) => opened.push(url), + fetch: async () => ({ ok: true, json: async () => ({ origin: "http://127.0.0.1:9999" }) }), + setTimeout, + clearTimeout, + }, + "plugins.bundle.config", + ); + m.resetHooks(); + const first = m.component() as ElementNode; + assert.equal(findButton(first), undefined); + await tick(); + const second = m.component() as ElementNode; + const button = findButton(second); + assert.ok(button !== undefined, "the bundle panel upgrades on a resolved origin"); + (button.props!.onClick as () => void)(); + assert.deepEqual(opened, ["http://127.0.0.1:9999/__bili/"]); + m.runCleanups(); + } +}); + +test("#2125: the manifest declares no dsh.client.inject (pre-0.2 dsh compat)", () => { + // dsh < 0.2.x cannot resolve "@deepseek-ai/dsh-client-ui-plugin-manager" and its + // client-module scanner stalls the whole web UI on an unknown inject target. + // dsh >= 0.2.0-rc.x ships the slot host inside dsh-web-app, so no injection is + // required — re-adding it would freeze older clients into an endless spinner. + const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { + dsh?: { client?: { inject?: unknown } }; + }; + assert.equal(pkg.dsh?.client?.inject ?? null, null, "dsh.client.inject would break pre-0.2 dsh clients"); });