mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
25 lines
877 B
TypeScript
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);
|
|
}
|