mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-05 14:21:32 +00:00
fix(media): add host media read helper
This commit is contained in:
29
src/media/read-capability.ts
Normal file
29
src/media/read-capability.ts
Normal 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user