From 90c674de7558d072b8265652953b47acd976b3fb Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Thu, 12 Mar 2026 11:59:36 +0000 Subject: [PATCH] Matrix: finish main sync follow-ups --- src/infra/matrix-plugin-helper.ts | 45 ++++++++++++++++++------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/infra/matrix-plugin-helper.ts b/src/infra/matrix-plugin-helper.ts index 0e1f0c404dd..ab40287029f 100644 --- a/src/infra/matrix-plugin-helper.ts +++ b/src/infra/matrix-plugin-helper.ts @@ -107,10 +107,30 @@ function getJiti() { return jitiLoader; } -type LoadedMatrixLegacyCryptoInspectorModule = { - inspectLegacyMatrixCryptoStore?: unknown; - default?: unknown; -}; +function isObjectRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null; +} + +function resolveInspectorExport(loaded: unknown): MatrixLegacyCryptoInspector | null { + if (!isObjectRecord(loaded)) { + return null; + } + const directInspector = loaded.inspectLegacyMatrixCryptoStore; + if (typeof directInspector === "function") { + return directInspector as MatrixLegacyCryptoInspector; + } + const directDefault = loaded.default; + if (typeof directDefault === "function") { + return directDefault as MatrixLegacyCryptoInspector; + } + if (!isObjectRecord(directDefault)) { + return null; + } + const nestedInspector = directDefault.inspectLegacyMatrixCryptoStore; + return typeof nestedInspector === "function" + ? (nestedInspector as MatrixLegacyCryptoInspector) + : null; +} export async function loadMatrixLegacyCryptoInspector(params: { cfg: OpenClawConfig; @@ -134,25 +154,14 @@ export async function loadMatrixLegacyCryptoInspector(params: { } const pending = (async () => { - const loaded = await getJiti().import(helperPath); - const defaultExport = - loaded.default && typeof loaded.default === "object" - ? (loaded.default as LoadedMatrixLegacyCryptoInspectorModule) - : null; - const inspectLegacyMatrixCryptoStore = - typeof loaded?.inspectLegacyMatrixCryptoStore === "function" - ? loaded.inspectLegacyMatrixCryptoStore - : typeof loaded?.default === "function" - ? loaded.default - : typeof defaultExport?.inspectLegacyMatrixCryptoStore === "function" - ? defaultExport.inspectLegacyMatrixCryptoStore - : null; + const loaded: unknown = await getJiti().import(helperPath); + const inspectLegacyMatrixCryptoStore = resolveInspectorExport(loaded); if (!inspectLegacyMatrixCryptoStore) { throw new Error( `Matrix plugin helper at ${helperPath} does not export inspectLegacyMatrixCryptoStore(). Reinstall @openclaw/matrix and try again.`, ); } - return inspectLegacyMatrixCryptoStore as MatrixLegacyCryptoInspector; + return inspectLegacyMatrixCryptoStore; })(); inspectorCache.set(helperPath, pending); try {