openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
59 lines (58 loc) • 3.45 kB
JavaScript
import { i as asOptionalObjectRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs";
import { a as maxBytesForKind } from "./constants-ChkaB-HW.mjs";
import { r as resolveChannelAccountEntry } from "./account-lookup-FhQZVFfo.mjs";
import { r as STAGED_INPUT_MAX_BYTES } from "./staged-inputs-p_W1dPfN.mjs";
import { t as MEDIA_MAX_BYTES } from "./store-zsTAVy24.mjs";
import { n as resolveChatAttachmentMaxBytes } from "./chat-attachment-policy-7g-oMINW.mjs";
//#region src/media/configured-max-bytes.ts
const MB = 1048576;
/** Native local audio/video displayed by webchat is streamed, independently of channel caps. */
const WEBCHAT_LOCAL_MEDIA_MAX_BYTES = 4096 * MB;
const TELEGRAM_DEFAULT_MEDIA_MAX_MB = 100;
/**
* Holds the largest raw image a supported model returns: Gemini "4K" at 5632x3072 is 51.9 MB as
* uncompressed RGB, which bounds an opaque PNG; transparent gpt-image output tops out at 3840x2160
* RGBA (33.2 MB). Measured Gemini 4K photo PNGs were 27-29 MiB.
*/
const GENERATED_IMAGE_DOWNLOAD_MAX_BYTES = 64 * MB;
/** Returns the configured media cap, falling back to the media-core per-kind default. */
function resolveGeneratedMediaMaxBytes(e, t) {
const n = e?.agents?.defaults?.mediaMaxMb;
return typeof n === "number" && Number.isFinite(n) && n > 0 ? Math.floor(n * MB) : maxBytesForKind(t);
}
/**
* Bounds a provider's download of generated images. Persistence re-encodes oversized images to
* the media cap, so this guards memory only and never drops below the configured cap.
*/
function resolveGeneratedImageDownloadMaxBytes(e) {
return Math.max(resolveGeneratedMediaMaxBytes(e, "image"), GENERATED_IMAGE_DOWNLOAD_MAX_BYTES);
}
/** Reads channel/account media caps from raw channel config without requiring typed account schemas. */
function resolveChannelAccountMediaMaxMb(e) {
const t = e.channel?.trim();
const n = e.accountId?.trim();
const r = t ? e.cfg.channels?.[t] : void 0;
const i = asOptionalObjectRecord(r);
const a = typeof i?.mediaMaxMb === "number" ? i.mediaMaxMb : void 0;
const o = asOptionalObjectRecord(i?.accounts);
const s = (n && t ? asOptionalObjectRecord(resolveChannelAccountEntry(o, n, t, normalizeAccountId)) : void 0)?.mediaMaxMb;
return (typeof s === "number" ? s : void 0) ?? a;
}
/** Staging follows explicit admission limits without lowering the existing floor. */
function resolveStagedInputMaxBytes(e, t, n) {
const r = resolveChannelAccountMediaMaxMb({
cfg: e,
channel: t,
accountId: n
});
const i = typeof r === "number" && Number.isFinite(r) && r > 0 ? Math.floor(r * 1024 * 1024) : 0;
return Math.min(Number.MAX_SAFE_INTEGER, Math.max(STAGED_INPUT_MAX_BYTES, resolveChatAttachmentMaxBytes(e), i));
}
/** Resolves the byte cap for staging an outbound reply's media from its configured channel/account, agent, or Telegram default. */
function resolveOutboundMediaMaxBytes(e) {
const t = resolveChannelAccountMediaMaxMb(e) ?? e.cfg.agents?.defaults?.mediaMaxMb ?? (e.channel?.trim().toLowerCase() === "telegram" ? TELEGRAM_DEFAULT_MEDIA_MAX_MB : void 0);
return typeof t === "number" && Number.isFinite(t) && t > 0 ? Math.floor(t * MB) : MEDIA_MAX_BYTES;
}
//#endregion
export { resolveOutboundMediaMaxBytes as a, resolveGeneratedMediaMaxBytes as i, resolveChannelAccountMediaMaxMb as n, resolveStagedInputMaxBytes as o, resolveGeneratedImageDownloadMaxBytes as r, WEBCHAT_LOCAL_MEDIA_MAX_BYTES as t };