/** * graph-memory DSH Web client 半侧:在 Plugins 页的 `plugins.item` 槽位注册 * 配置卡片。 * * 官方路径(dsh-settings README.zh.md + 官方设置插件 agent-loop/web-search): * 自带页面的插件在 client 半侧往 `plugins.item` 注册页面(卡片 + SettingsForm), * 字典经 `locale.register(NS)` 绑定;本部署没有已发布的客户端按 schema 自动 * 生成页面(autoGenerate 无消费者),所以必须自带页面。 * * 生命周期(官方 ui-plugin.md):资源在 apply 内注册,返回清理函数;通过 * ctx.configForms.whileServed 跟随命名空间——graph-memory 未在组合中时页面 * 不显示任何痕迹。 */ import type { Context as ClientContext } from "@deepseek-ai/cordis"; import { GraphMemoryCard } from "./GraphMemoryCard.js"; import { ENTRY_ID, en, zh, GraphMemoryCardController, type FormScope, type MirrorLike, } from "./graph-memory-controller.js"; export const inject = ["configForms", "slots", "locale"]; export const name = "@multilab/graph-memory/client"; /** 本插件持有的字典命名空间(官方设置插件惯例:settings.)。 */ const NS = "settings.graphMemory"; interface ClientCtx extends ClientContext { configForms: { whileServed( namespaces: string[], register: (served: Set) => () => void, ): () => void; get(id: string): FormScope; describe(): MirrorLike; }; slots: { inject( name: string, setup: () => () => void, ): () => void; register( options: { name: string; id: string; order: number; label: () => string; locale: string; inject: () => Record; }, component: unknown, ): () => void; }; locale: { register(ns: string, dicts: { zh: Record; en: Record }): () => void; bind(ns: string): (key: string) => string; }; } export function apply(ctx: ClientCtx): void { const t = ctx.locale.bind(NS); ctx.effect( () => ctx.locale.register(NS, { zh, en }), "graph-memory: dictionaries", ); const card = new GraphMemoryCardController( ctx.configForms.get(ENTRY_ID), ctx.configForms.describe(), ); // 先挂载投影 store 再暴露给组件(官方 SettingsFormModel.bind 同构):inject() // 的 hooks.graphMemoryCard 必须是已初始化的 store,否则组件经 slots 包装后 // 把 undefined 传给 React 19 useSyncExternalStore,WeakMap 抛 // "Invalid value used as weak map key"(此前配置页渲染崩溃的根因)。 card.bind(() => card.projection()); // 模型目录在卡片挂载时就绪(host providers/llm-models 路由;失败静默回退 // 手输文本,不阻塞配置页)。 void card.loadCatalog(); // 凭据 describe 在卡片挂载时就绪(host credential 路由;旧插件无路由 → // status:unavailable 降级,不崩溃、不报错)。 void card.loadCredentialStatus(); ctx.effect( () => () => { card.dispose(); }, "graph-memory: form subscription", ); ctx.effect( () => ctx.configForms.whileServed( [ENTRY_ID], () => ctx.slots.inject( "plugins.item", () => ctx.slots.register( { name: "plugins.item", id: "graph-memory", order: 70, label: () => t("title"), locale: NS, inject: () => card.inject(), }, GraphMemoryCard, ), ), ), "graph-memory: page", ); }