mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-07 07:58:36 +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;
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ChannelId, ChannelMessageActionName } from "../../channels/plugins
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { createRootScopedReadFile } from "../../infra/fs-safe.js";
|
||||
import { basenameFromMediaSource } from "../../infra/local-file-access.js";
|
||||
import { resolveChannelAccountMediaMaxMb } from "../../media/configured-max-bytes.js";
|
||||
import {
|
||||
buildOutboundMediaLoadOptions,
|
||||
resolveOutboundMediaAccess,
|
||||
@@ -117,28 +118,9 @@ function resolveAttachmentMaxBytes(params: {
|
||||
channel: ChannelId;
|
||||
accountId?: string | null;
|
||||
}): number | undefined {
|
||||
const accountId = typeof params.accountId === "string" ? params.accountId.trim() : "";
|
||||
const channelCfg = params.cfg.channels?.[params.channel];
|
||||
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;
|
||||
// Priority: account-specific > channel-level > global default
|
||||
const limitMb =
|
||||
(typeof accountMediaMax === "number" ? accountMediaMax : undefined) ??
|
||||
channelMediaMax ??
|
||||
params.cfg.agents?.defaults?.mediaMaxMb;
|
||||
resolveChannelAccountMediaMaxMb(params) ?? params.cfg.agents?.defaults?.mediaMaxMb;
|
||||
return typeof limitMb === "number" ? limitMb * 1024 * 1024 : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,3 +9,29 @@ export function resolveConfiguredMediaMaxBytes(cfg?: OpenClawConfig): number | u
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveChannelAccountMediaMaxMb(params: {
|
||||
cfg: OpenClawConfig;
|
||||
channel?: string | null;
|
||||
accountId?: string | null;
|
||||
}): number | undefined {
|
||||
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;
|
||||
return (typeof accountMediaMax === "number" ? accountMediaMax : undefined) ?? channelMediaMax;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user