From aad1be102d252700d13407b412ca2d28f1524f65 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 22 Apr 2026 21:48:56 +0100 Subject: [PATCH] fix(types): narrow live thread ownership config --- extensions/thread-ownership/index.ts | 13 ++++++++++--- src/plugin-sdk/config-runtime.test.ts | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extensions/thread-ownership/index.ts b/extensions/thread-ownership/index.ts index 2e642580aee..0d1357c9a75 100644 --- a/extensions/thread-ownership/index.ts +++ b/extensions/thread-ownership/index.ts @@ -21,6 +21,10 @@ type ThreadOwnershipMessageSendingResult = { cancel: true } | undefined; const mentionedThreads = new Map(); const MENTION_TTL_MS = 5 * 60 * 1000; +function isThreadOwnershipConfig(value: unknown): value is ThreadOwnershipConfig { + return value !== null && typeof value === "object"; +} + function resolveThreadToken(value: unknown): string { return typeof value === "string" || typeof value === "number" ? String(value) : ""; } @@ -80,9 +84,12 @@ export default definePluginEntry({ register(api: OpenClawPluginApi) { const resolveCurrentState = () => { const currentConfig = api.runtime.config?.loadConfig?.() ?? api.config; - const pluginCfg = - resolvePluginConfigObject(currentConfig, "thread-ownership") || - ((api.pluginConfig ?? {}) as ThreadOwnershipConfig); + const livePluginCfg = resolvePluginConfigObject(currentConfig, "thread-ownership"); + const pluginCfg = isThreadOwnershipConfig(livePluginCfg) + ? livePluginCfg + : isThreadOwnershipConfig(api.pluginConfig) + ? api.pluginConfig + : {}; return { currentConfig, forwarderUrl: ( diff --git a/src/plugin-sdk/config-runtime.test.ts b/src/plugin-sdk/config-runtime.test.ts index f65c58b4550..50b648d6ac7 100644 --- a/src/plugin-sdk/config-runtime.test.ts +++ b/src/plugin-sdk/config-runtime.test.ts @@ -15,7 +15,7 @@ describe("resolvePluginConfigObject", () => { }, }, }, - } as OpenClawConfig; + } as unknown as OpenClawConfig; expect(resolvePluginConfigObject(config, "demo-plugin")).toEqual({ enabled: false, @@ -37,7 +37,7 @@ describe("resolvePluginConfigObject", () => { }, }, }, - } as OpenClawConfig; + } as unknown as OpenClawConfig; expect(resolvePluginConfigObject(config, "missing-plugin")).toBeUndefined(); expect(resolvePluginConfigObject(config, "demo-plugin")).toBeUndefined();