Files
openclaw/src/media/local-roots.ts
2026-02-17 13:36:48 +09:00

40 lines
1.2 KiB
TypeScript

import os from "node:os";
import path from "node:path";
import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolveStateDir } from "../config/paths.js";
function buildMediaLocalRoots(stateDir: string): string[] {
const resolvedStateDir = path.resolve(stateDir);
return [
os.tmpdir(),
path.join(resolvedStateDir, "media"),
path.join(resolvedStateDir, "agents"),
path.join(resolvedStateDir, "workspace"),
path.join(resolvedStateDir, "sandboxes"),
];
}
export function getDefaultMediaLocalRoots(): readonly string[] {
return buildMediaLocalRoots(resolveStateDir());
}
export function getAgentScopedMediaLocalRoots(
cfg: OpenClawConfig,
agentId?: string,
): readonly string[] {
const roots = buildMediaLocalRoots(resolveStateDir());
if (!agentId?.trim()) {
return roots;
}
const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
if (!workspaceDir) {
return roots;
}
const normalizedWorkspaceDir = path.resolve(workspaceDir);
if (!roots.includes(normalizedWorkspaceDir)) {
roots.push(normalizedWorkspaceDir);
}
return roots;
}