From e9b635df3ddfe1f06b9421b11689a6cab28aaafd Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Tue, 14 Apr 2026 16:07:23 +0800 Subject: [PATCH] fix: require callable Baileys dispatcher --- patches/@whiskeysockets__baileys@7.0.0-rc.9.patch | 2 +- pnpm-lock.yaml | 8 ++++---- scripts/postinstall-bundled-plugins.mjs | 8 ++++++-- src/plugins/stage-bundled-plugin-runtime-deps.test.ts | 10 +++++----- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch b/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch index 49c51b1dff0..c47805f1b3d 100644 --- a/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch +++ b/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch @@ -40,7 +40,7 @@ index 0d32dfb4882dfe029ba8804772d7d89404b08e76..73809fcd1d52362aef0c35cb7416c29d + // `dispatcher` only works with Dispatcher-compatible implementations, + // so only wire it through when the object actually implements + // `dispatch`. -+ ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}), ++ ...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}), duplex: 'half', // Note: custom agents/proxy require undici Agent; omitted here. signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1d72f26a28d..758c6fc249b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,7 +29,7 @@ packageExtensionsChecksum: sha256-n+P/SQo4Pf+dHYpYn1Y6wL4cJEVoVzZ835N0OEp4TM8= patchedDependencies: '@whiskeysockets/baileys@7.0.0-rc.9': - hash: 5a0b2527947a3aabf3c7f11cd6ff61e4ba7b5a2c13516fec4cb275dc63bd0308 + hash: 23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201 path: patches/@whiskeysockets__baileys@7.0.0-rc.9.patch importers: @@ -119,7 +119,7 @@ importers: version: 7.15.0 '@whiskeysockets/baileys': specifier: 7.0.0-rc.9 - version: 7.0.0-rc.9(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5) + version: 7.0.0-rc.9(patch_hash=23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5) ajv: specifier: ^8.18.0 version: 8.18.0 @@ -1226,7 +1226,7 @@ importers: dependencies: '@whiskeysockets/baileys': specifier: 7.0.0-rc.9 - version: 7.0.0-rc.9(patch_hash=5a0b2527947a3aabf3c7f11cd6ff61e4ba7b5a2c13516fec4cb275dc63bd0308)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5) + version: 7.0.0-rc.9(patch_hash=23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5) jimp: specifier: ^1.6.1 version: 1.6.1 @@ -11428,7 +11428,7 @@ snapshots: '@wasm-audio-decoders/common': 9.0.7 optional: true - '@whiskeysockets/baileys@7.0.0-rc.9(patch_hash=5a0b2527947a3aabf3c7f11cd6ff61e4ba7b5a2c13516fec4cb275dc63bd0308)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)': + '@whiskeysockets/baileys@7.0.0-rc.9(patch_hash=23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)': dependencies: '@cacheable/node-cache': 1.7.6 '@hapi/boom': 9.1.4 diff --git a/scripts/postinstall-bundled-plugins.mjs b/scripts/postinstall-bundled-plugins.mjs index 2cf3b9acfa5..ded24ba067d 100644 --- a/scripts/postinstall-bundled-plugins.mjs +++ b/scripts/postinstall-bundled-plugins.mjs @@ -94,7 +94,7 @@ const BAILEYS_MEDIA_DISPATCHER_HEADER_REPLACEMENT = [ " // `dispatcher` only works with Dispatcher-compatible implementations,", " // so only wire it through when the object actually implements", " // `dispatch`.", - " ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),", + " ...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", ].join("\n"); const BAILEYS_MEDIA_ONCE_IMPORT_RE = /import\s+\{\s*once\s*\}\s+from\s+['"]events['"]/u; const BAILEYS_MEDIA_ASYNC_CONTEXT_RE = @@ -311,7 +311,11 @@ export function applyBaileysEncryptedStreamFinishHotfix(params = {}) { applied = true; } - if (!patchedText.includes("...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),")) { + if ( + !patchedText.includes( + "...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", + ) + ) { if (!patchedText.includes(BAILEYS_MEDIA_DISPATCHER_NEEDLE)) { return { applied: false, reason: "unexpected_content" }; } diff --git a/src/plugins/stage-bundled-plugin-runtime-deps.test.ts b/src/plugins/stage-bundled-plugin-runtime-deps.test.ts index fe570a03e7d..35d4e2f2c0c 100644 --- a/src/plugins/stage-bundled-plugin-runtime-deps.test.ts +++ b/src/plugins/stage-bundled-plugin-runtime-deps.test.ts @@ -127,7 +127,7 @@ function createBaileysMessagesMediaSource(params?: { " // `dispatcher` only works with Dispatcher-compatible implementations,", " // so only wire it through when the object actually implements", " // `dispatch`.", - " ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),", + " ...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", " duplex: 'half',", " });", ] @@ -317,7 +317,7 @@ describe("stageBundledPluginRuntimeDeps", () => { "await Promise.all([encFinishPromise, originalFinishPromise]);", ); expect(fs.readFileSync(targetPath, "utf8")).toContain( - "...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),", + "...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", ); expect(fs.readFileSync(targetPath, "utf8")).not.toContain("dispatcher: fetchAgent,"); }); @@ -351,7 +351,7 @@ describe("stageBundledPluginRuntimeDeps", () => { "await Promise.all([encFinishPromise, originalFinishPromise]);", ); expect(fs.readFileSync(targetPath, "utf8")).toContain( - "...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),", + "...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", ); }); @@ -383,7 +383,7 @@ describe("stageBundledPluginRuntimeDeps", () => { targetPath, }); expect(fs.readFileSync(targetPath, "utf8")).toContain( - "...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),", + "...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", ); expect(fs.readFileSync(targetPath, "utf8")).toContain("await encFinishPromise;"); expect(fs.readFileSync(targetPath, "utf8")).toContain("await originalFinishPromise;"); @@ -417,7 +417,7 @@ describe("stageBundledPluginRuntimeDeps", () => { expect(fs.readFileSync(targetPath, "utf8")).toContain("await encFinishPromise;"); expect(fs.readFileSync(targetPath, "utf8")).toContain("await originalFinishPromise;"); expect(fs.readFileSync(targetPath, "utf8")).toContain( - "...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),", + "...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),", ); });