Files
pi-agent-integrated/pi-web/lib/allowed-roots.ts

25 lines
877 B
TypeScript

// In-memory roots that should be browsable in addition to roots derived from
// persisted sessions. Stored on globalThis so Next.js hot-reload keeps them.
declare global {
var __piAllowedRootsCache: { roots: Set<string>; expiresAt: number } | undefined;
var __piAdditionalAllowedRoots: Set<string> | undefined;
}
export function normalizeSlashes(filePath: string): string {
return filePath.replace(/\\/g, "/");
}
export function getAdditionalAllowedRoots(): Set<string> {
if (!globalThis.__piAdditionalAllowedRoots) {
globalThis.__piAdditionalAllowedRoots = new Set();
}
return globalThis.__piAdditionalAllowedRoots;
}
export function allowFileRoot(root: string): void {
if (!root) return;
const normalizedRoot = normalizeSlashes(root);
getAdditionalAllowedRoots().add(normalizedRoot);
globalThis.__piAllowedRootsCache?.roots.add(normalizedRoot);
}