mirror of https://github.com/openclaw/openclaw.git
fix(media): add host media read helper
This commit is contained in:
parent
3bb02d3338
commit
fc5a2f9293
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue