mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:10:58 +00:00
refactor: share channel media limit lookup
This commit is contained in:
@@ -6,6 +6,7 @@ import { assertMediaNotDataUrl, resolveSandboxedMediaSource } from "../../agents
|
||||
import { ensureSandboxWorkspaceForSession } from "../../agents/sandbox.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { logVerbose } from "../../globals.js";
|
||||
import { resolveChannelAccountMediaMaxMb } from "../../media/configured-max-bytes.js";
|
||||
import { isPassThroughRemoteMediaSource } from "../../media/media-source-url.js";
|
||||
import { resolveOutboundAttachmentFromUrl } from "../../media/outbound-attachment.js";
|
||||
import { resolveAgentScopedOutboundMediaAccess } from "../../media/read-capability.js";
|
||||
@@ -52,28 +53,8 @@ function resolveReplyMediaMaxBytes(params: {
|
||||
channel?: string;
|
||||
accountId?: string;
|
||||
}): number {
|
||||
const channelId = params.channel?.trim();
|
||||
const accountId = params.accountId?.trim();
|
||||
const channelCfg = channelId ? params.cfg.channels?.[channelId] : undefined;
|
||||
const channelObj =
|
||||
channelCfg && typeof channelCfg === "object"
|
||||
? (channelCfg as Record<string, unknown>)
|
||||
: undefined;
|
||||
const channelMediaMax =
|
||||
typeof channelObj?.mediaMaxMb === "number" ? channelObj.mediaMaxMb : undefined;
|
||||
const accountsObj =
|
||||
channelObj?.accounts && typeof channelObj.accounts === "object"
|
||||
? (channelObj.accounts as Record<string, unknown>)
|
||||
: undefined;
|
||||
const accountCfg = accountId && accountsObj ? accountsObj[accountId] : undefined;
|
||||
const accountMediaMax =
|
||||
accountCfg && typeof accountCfg === "object"
|
||||
? (accountCfg as Record<string, unknown>).mediaMaxMb
|
||||
: undefined;
|
||||
const limitMb =
|
||||
(typeof accountMediaMax === "number" ? accountMediaMax : undefined) ??
|
||||
channelMediaMax ??
|
||||
params.cfg.agents?.defaults?.mediaMaxMb;
|
||||
resolveChannelAccountMediaMaxMb(params) ?? params.cfg.agents?.defaults?.mediaMaxMb;
|
||||
return typeof limitMb === "number" && Number.isFinite(limitMb) && limitMb > 0
|
||||
? Math.floor(limitMb * 1024 * 1024)
|
||||
: MEDIA_MAX_BYTES;
|
||||
|
||||
Reference in New Issue
Block a user