perf(core): narrow sandbox status imports for error helpers (#51897)

* perf(core): narrow sandbox status imports for error helpers

* fix(build): add runtime boundaries for reply understanding

Add missing lazy-load runtime shim files required by get-reply.ts.

* fix(debug): remove duplicate spacing in ingress logs

Use logIngressStage suffix spacing consistently for media and link understanding debug lines.
This commit is contained in:
Vincent Koc
2026-03-21 15:40:45 -07:00
committed by GitHub
parent d3731be2f0
commit d88c68fec1
5 changed files with 57 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ export {
isCloudflareOrHtmlErrorPage,
parseApiErrorInfo,
} from "../../shared/assistant-error-format.js";
import { formatSandboxToolPolicyBlockedMessage } from "../sandbox.js";
import { formatSandboxToolPolicyBlockedMessage } from "../sandbox/runtime-status.js";
import { stableStringify } from "../stable-stringify.js";
import {
isAuthErrorMessage,

View File

@@ -1,6 +1,9 @@
import { formatCliCommand } from "../../cli/command-format.js";
import type { OpenClawConfig } from "../../config/config.js";
import { canonicalizeMainSessionAlias, resolveAgentMainSessionKey } from "../../config/sessions.js";
import {
canonicalizeMainSessionAlias,
resolveAgentMainSessionKey,
} from "../../config/sessions/main-session.js";
import { resolveSessionAgentId } from "../agent-scope.js";
import { expandToolGroups } from "../tool-policy.js";
import { resolveSandboxConfigForAgent } from "./config.js";

View File

@@ -9,8 +9,6 @@ import { resolveAgentTimeoutMs } from "../../agents/timeout.js";
import { DEFAULT_AGENT_WORKSPACE_DIR, ensureAgentWorkspace } from "../../agents/workspace.js";
import { resolveChannelModelOverride } from "../../channels/model-overrides.js";
import { type OpenClawConfig, loadConfig } from "../../config/config.js";
import { applyLinkUnderstanding } from "../../link-understanding/apply.js";
import { applyMediaUnderstanding } from "../../media-understanding/apply.js";
import { defaultRuntime } from "../../runtime.js";
import { normalizeStringEntries } from "../../shared/string-normalization.js";
import { resolveCommandAuthorization } from "../command-auth.js";
@@ -58,6 +56,52 @@ function mergeSkillFilters(channelFilter?: string[], agentFilter?: string[]): st
return channel.filter((name) => agentSet.has(name));
}
function hasInboundMedia(ctx: MsgContext): boolean {
return Boolean(
ctx.StickerMediaIncluded ||
ctx.Sticker ||
ctx.MediaPath?.trim() ||
ctx.MediaUrl?.trim() ||
ctx.MediaPaths?.some((value) => value?.trim()) ||
ctx.MediaUrls?.some((value) => value?.trim()) ||
ctx.MediaTypes?.length,
);
}
function hasLinkCandidate(ctx: MsgContext): boolean {
const message = ctx.BodyForCommands ?? ctx.CommandBody ?? ctx.RawBody ?? ctx.Body;
if (!message) {
return false;
}
return /\bhttps?:\/\/\S+/i.test(message);
}
async function applyMediaUnderstandingIfNeeded(params: {
ctx: MsgContext;
cfg: OpenClawConfig;
agentDir?: string;
activeModel: { provider: string; model: string };
}): Promise<boolean> {
if (!hasInboundMedia(params.ctx)) {
return false;
}
const { applyMediaUnderstanding } = await import("../../media-understanding/apply.runtime.js");
await applyMediaUnderstanding(params);
return true;
}
async function applyLinkUnderstandingIfNeeded(params: {
ctx: MsgContext;
cfg: OpenClawConfig;
}): Promise<boolean> {
if (!hasLinkCandidate(params.ctx)) {
return false;
}
const { applyLinkUnderstanding } = await import("../../link-understanding/apply.runtime.js");
await applyLinkUnderstanding(params);
return true;
}
export async function getReplyFromConfig(
ctx: MsgContext,
opts?: GetReplyOptions,
@@ -143,18 +187,18 @@ export async function getReplyFromConfig(
const finalized = finalizeInboundContext(ctx);
if (!isFastTestEnv) {
await applyMediaUnderstanding({
const appliedMediaUnderstanding = await applyMediaUnderstandingIfNeeded({
ctx: finalized,
cfg,
agentDir,
activeModel: { provider, model },
});
logIngressStage("media-understanding");
await applyLinkUnderstanding({
logIngressStage("media-understanding", `applied=${appliedMediaUnderstanding ? "1" : "0"}`);
const appliedLinkUnderstanding = await applyLinkUnderstandingIfNeeded({
ctx: finalized,
cfg,
});
logIngressStage("link-understanding");
logIngressStage("link-understanding", `applied=${appliedLinkUnderstanding ? "1" : "0"}`);
}
emitPreAgentMessageHooks({
ctx: finalized,

View File

@@ -0,0 +1 @@
export { applyLinkUnderstanding } from "./apply.js";

View File

@@ -0,0 +1 @@
export { applyMediaUnderstanding } from "./apply.js";