openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
145 lines (144 loc) • 5.14 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-DItp3I4t.js";
import { r as createLazyRuntimeModule } from "./lazy-runtime-CgCh8H_K.js";
import "./http-body-D3IMwTJJ.js";
import "./mime-CVpcq9ju.js";
import "./store-Ph57PZ9P.js";
import "./fetch-BiZ7bEBv.js";
import "./media-services-By-i0Drw.js";
import "./local-roots-BphuGw-a.js";
import "./outbound-attachment-BK-r1SfK.js";
import { a as chunkText } from "./chunk-DqjJztIp.js";
import "./defaults-pXqEdm9c.js";
import "./image-runtime-BOIoCq-0.js";
import "./audio-BbEPwbmc.js";
import "./agent-media-payload-BKNVlToJ.js";
import { t as sanitizeForPlainText } from "./sanitize-text-BNoGtAII.js";
import "./qr-image-CnPhdkea.js";
import "./qr-terminal-27AasTys.js";
import { t as resolveChannelMediaMaxBytes } from "./media-limits-CQ5FqjqT.js";
import fs from "node:fs/promises";
//#region src/media/temp-files.ts
/** Best-effort temp-file cleanup helper for optional paths from media conversion flows. */
async function unlinkIfExists(filePath) {
if (!filePath) return;
try {
await fs.unlink(filePath);
} catch {}
}
//#endregion
//#region src/channels/plugins/outbound/direct-text-media.ts
/**
* Direct text/media outbound adapter helpers.
*
* Builds lightweight SDK-backed send adapters with chunking, sanitization, and media limits.
*/
function readNumberField(record, key) {
const value = record?.[key];
return typeof value === "number" ? value : void 0;
}
/**
* Resolves an account-scoped channel media byte limit.
*/
function resolveScopedChannelMediaMaxBytes(params) {
return resolveChannelMediaMaxBytes({
cfg: params.cfg,
resolveChannelLimitMb: params.resolveChannelLimitMb,
accountId: params.accountId
});
}
/**
* Builds a media byte-limit resolver for channels with `mediaMaxMb` config.
*/
function createScopedChannelMediaMaxBytesResolver(channel) {
return (params) => resolveScopedChannelMediaMaxBytes({
cfg: params.cfg,
accountId: params.accountId,
resolveChannelLimitMb: ({ cfg, accountId }) => {
const channelConfig = asOptionalRecord(cfg.channels?.[channel]);
return readNumberField(asOptionalRecord(asOptionalRecord(channelConfig?.accounts)?.[accountId]), "mediaMaxMb") ?? readNumberField(channelConfig, "mediaMaxMb");
}
});
}
/**
* Creates a channel outbound adapter backed by direct text/media send functions.
*/
function createDirectTextMediaOutbound(params) {
const sendDirect = async (sendParams) => {
const send = params.resolveSender(sendParams.deps);
const maxBytes = params.resolveMaxBytes({
cfg: sendParams.cfg,
accountId: sendParams.accountId
});
const result = await send(sendParams.to, sendParams.text, sendParams.buildOptions({
cfg: sendParams.cfg,
mediaUrl: sendParams.mediaUrl,
mediaAccess: sendParams.mediaAccess,
mediaLocalRoots: sendParams.mediaAccess?.localRoots,
mediaReadFile: sendParams.mediaAccess?.readFile,
accountId: sendParams.accountId,
replyToId: sendParams.replyToId,
maxBytes
}));
return {
channel: params.channel,
...result
};
};
const outbound = {
deliveryMode: "direct",
chunker: chunkText,
chunkerMode: "text",
textChunkLimit: 4e3,
sanitizeText: ({ text }) => sanitizeForPlainText(text),
sendPayload: async (ctx) => {
const { sendTextMediaPayload } = await import("./plugin-sdk/reply-payload.js");
return await sendTextMediaPayload({
channel: params.channel,
ctx,
adapter: outbound
});
},
sendText: async ({ cfg, to, text, accountId, deps, replyToId }) => {
return await sendDirect({
cfg,
to,
text,
accountId,
deps,
replyToId,
buildOptions: params.buildTextOptions
});
},
sendMedia: async ({ cfg, to, text, mediaUrl, mediaAccess, mediaLocalRoots, mediaReadFile, accountId, deps, replyToId }) => {
return await sendDirect({
cfg,
to,
text,
mediaUrl,
mediaAccess: mediaAccess ?? (mediaLocalRoots || mediaReadFile ? {
...mediaLocalRoots?.length ? { localRoots: mediaLocalRoots } : {},
...mediaReadFile ? { readFile: mediaReadFile } : {}
} : void 0),
accountId,
deps,
replyToId,
buildOptions: params.buildMediaOptions
});
}
};
return outbound;
}
//#endregion
//#region src/plugin-sdk/media-runtime.ts
/**
* @deprecated Broad public SDK barrel. Prefer focused media-store, media-mime,
* outbound-media, and capability runtime subpaths.
*/
const loadAudioPreflight = createLazyRuntimeModule(() => import("./audio-preflight-jy7x1Dhf.js"));
const loadMediaRunner = createLazyRuntimeModule(() => import("./runner-lLDdFCfb.js"));
/** Transcribes the first audio attachment without loading the runner during plugin registration. */
const transcribeFirstAudio = async (...args) => (await loadAudioPreflight()).transcribeFirstAudio(...args);
/** Resolves an image model through the media runner when selection is requested. */
const resolveAutoImageModel = async (...args) => (await loadMediaRunner()).resolveAutoImageModel(...args);
//#endregion
export { unlinkIfExists as a, createScopedChannelMediaMaxBytesResolver as i, transcribeFirstAudio as n, createDirectTextMediaOutbound as r, resolveAutoImageModel as t };