fix(media): add host media read helper

This commit is contained in:
Peter Steinberger 2026-04-01 00:08:20 +09:00
parent 3bb02d3338
commit fc5a2f9293
No known key found for this signature in database
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
import { resolvePathFromInput } from "../agents/path-policy.js";
import { resolveEffectiveToolFsRootExpansionAllowed } from "../agents/tool-fs-policy.js";
import { resolveWorkspaceRoot } from "../agents/workspace-dir.js";
import type { OpenClawConfig } from "../config/config.js";
import { readLocalFileSafely } from "../infra/fs-safe.js";
export function createAgentScopedHostMediaReadFile(params: {
cfg: OpenClawConfig;
agentId?: string;
workspaceDir?: string;
}): ((filePath: string) => Promise<Buffer>) | undefined {
if (
!resolveEffectiveToolFsRootExpansionAllowed({
cfg: params.cfg,
agentId: params.agentId,
})
) {
return undefined;
}
const inferredWorkspaceDir =
params.workspaceDir ??
(params.agentId ? resolveAgentWorkspaceDir(params.cfg, params.agentId) : undefined);
const workspaceRoot = resolveWorkspaceRoot(inferredWorkspaceDir);
return async (filePath: string) => {
const resolvedPath = resolvePathFromInput(filePath, workspaceRoot);
return (await readLocalFileSafely({ filePath: resolvedPath })).buffer;
};
}