mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
fix(whatsapp): split outbound media runtime seam
This commit is contained in:
36
extensions/whatsapp/src/outbound-media.runtime.ts
Normal file
36
extensions/whatsapp/src/outbound-media.runtime.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { loadWebMedia } from "openclaw/plugin-sdk/web-media";
|
||||
|
||||
export async function loadOutboundMediaFromUrl(
|
||||
mediaUrl: string,
|
||||
options: {
|
||||
maxBytes?: number;
|
||||
mediaAccess?: {
|
||||
localRoots?: readonly string[];
|
||||
readFile?: (filePath: string) => Promise<Buffer>;
|
||||
};
|
||||
mediaLocalRoots?: readonly string[];
|
||||
mediaReadFile?: (filePath: string) => Promise<Buffer>;
|
||||
} = {},
|
||||
) {
|
||||
const readFile = options.mediaAccess?.readFile ?? options.mediaReadFile;
|
||||
const localRoots =
|
||||
options.mediaAccess?.localRoots?.length && options.mediaAccess.localRoots.length > 0
|
||||
? options.mediaAccess.localRoots
|
||||
: options.mediaLocalRoots && options.mediaLocalRoots.length > 0
|
||||
? options.mediaLocalRoots
|
||||
: undefined;
|
||||
return await loadWebMedia(
|
||||
mediaUrl,
|
||||
readFile
|
||||
? {
|
||||
...(options.maxBytes !== undefined ? { maxBytes: options.maxBytes } : {}),
|
||||
localRoots: "any",
|
||||
readFile,
|
||||
hostReadCapability: true,
|
||||
}
|
||||
: {
|
||||
...(options.maxBytes !== undefined ? { maxBytes: options.maxBytes } : {}),
|
||||
...(localRoots ? { localRoots } : {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export type { DmPolicy, GroupPolicy } from "openclaw/plugin-sdk/config-runtime";
|
||||
import type { OpenClawConfig as RuntimeOpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
|
||||
export { type ChannelMessageActionName } from "openclaw/plugin-sdk/channel-contract";
|
||||
import { loadWebMedia } from "openclaw/plugin-sdk/web-media";
|
||||
export { loadOutboundMediaFromUrl } from "./outbound-media.runtime.js";
|
||||
export {
|
||||
resolveWhatsAppGroupRequireMention,
|
||||
resolveWhatsAppGroupToolPolicy,
|
||||
@@ -58,38 +58,3 @@ export async function monitorWebChannel(
|
||||
const { monitorWebChannel } = await loadChannelRuntime();
|
||||
return await monitorWebChannel(...args);
|
||||
}
|
||||
|
||||
export async function loadOutboundMediaFromUrl(
|
||||
mediaUrl: string,
|
||||
options: {
|
||||
maxBytes?: number;
|
||||
mediaAccess?: {
|
||||
localRoots?: readonly string[];
|
||||
readFile?: (filePath: string) => Promise<Buffer>;
|
||||
};
|
||||
mediaLocalRoots?: readonly string[];
|
||||
mediaReadFile?: (filePath: string) => Promise<Buffer>;
|
||||
} = {},
|
||||
) {
|
||||
const readFile = options.mediaAccess?.readFile ?? options.mediaReadFile;
|
||||
const localRoots =
|
||||
options.mediaAccess?.localRoots?.length && options.mediaAccess.localRoots.length > 0
|
||||
? options.mediaAccess.localRoots
|
||||
: options.mediaLocalRoots && options.mediaLocalRoots.length > 0
|
||||
? options.mediaLocalRoots
|
||||
: undefined;
|
||||
return await loadWebMedia(
|
||||
mediaUrl,
|
||||
readFile
|
||||
? {
|
||||
...(options.maxBytes !== undefined ? { maxBytes: options.maxBytes } : {}),
|
||||
localRoots: "any",
|
||||
readFile,
|
||||
hostReadCapability: true,
|
||||
}
|
||||
: {
|
||||
...(options.maxBytes !== undefined ? { maxBytes: options.maxBytes } : {}),
|
||||
...(localRoots ? { localRoots } : {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@ let setActiveWebListener: typeof import("./active-listener.js").setActiveWebList
|
||||
let resetLogger: typeof import("openclaw/plugin-sdk/runtime-env").resetLogger;
|
||||
let setLoggerOverride: typeof import("openclaw/plugin-sdk/runtime-env").setLoggerOverride;
|
||||
|
||||
vi.mock("./runtime-api.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./runtime-api.js")>("./runtime-api.js");
|
||||
vi.mock("./outbound-media.runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./outbound-media.runtime.js")>(
|
||||
"./outbound-media.runtime.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
loadOutboundMediaFromUrl: hoisted.loadOutboundMediaFromUrl,
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
resolveWhatsAppMediaMaxBytes,
|
||||
} from "./accounts.js";
|
||||
import { type ActiveWebSendOptions, requireActiveWebListener } from "./active-listener.js";
|
||||
import { loadOutboundMediaFromUrl } from "./runtime-api.js";
|
||||
import { loadOutboundMediaFromUrl } from "./outbound-media.runtime.js";
|
||||
import { markdownToWhatsApp, toWhatsappJid } from "./text-runtime.js";
|
||||
|
||||
const outboundLog = createSubsystemLogger("gateway/channels/whatsapp").child("outbound");
|
||||
|
||||
Reference in New Issue
Block a user