mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:10:45 +00:00
fix(types): narrow live thread ownership config
This commit is contained in:
@@ -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: (
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user