fix(types): narrow live thread ownership config

This commit is contained in:
Peter Steinberger
2026-04-22 21:48:56 +01:00
parent b648830632
commit aad1be102d
2 changed files with 12 additions and 5 deletions

View File

@@ -21,6 +21,10 @@ type ThreadOwnershipMessageSendingResult = { cancel: true } | undefined;
const mentionedThreads = new Map<string, number>();
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: (

View File

@@ -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();