import type { WorkspaceDescriptor } from "@/stores/session-store"; import { normalizeWorkspaceOpaqueId } from "@/utils/workspace-identity"; const pendingWorkspaceArchivesByServer = new Map>(); function pendingArchiveKey(input: { serverId: string; workspaceId: string }): string { return `${input.serverId.trim()}::${input.workspaceId.trim()}`; } export function markWorkspaceArchivePending(input: { serverId: string; workspaceId: string; }): void { const serverId = input.serverId.trim(); const workspaceId = normalizeWorkspaceOpaqueId(input.workspaceId); if (!serverId || !workspaceId) { return; } const archives = pendingWorkspaceArchivesByServer.get(serverId) ?? new Set(); archives.add(pendingArchiveKey({ serverId, workspaceId })); pendingWorkspaceArchivesByServer.set(serverId, archives); } export function clearWorkspaceArchivePending(input: { serverId: string; workspaceId: string; }): void { const serverId = input.serverId.trim(); const workspaceId = normalizeWorkspaceOpaqueId(input.workspaceId); if (!serverId || !workspaceId) { return; } const archives = pendingWorkspaceArchivesByServer.get(serverId); if (!archives) { return; } archives.delete(pendingArchiveKey({ serverId, workspaceId })); if (archives.size === 0) { pendingWorkspaceArchivesByServer.delete(serverId); } } export function isWorkspaceArchivePending(input: { serverId: string; workspaceId?: string | null; }): boolean { const serverId = input.serverId.trim(); const workspaceId = normalizeWorkspaceOpaqueId(input.workspaceId); if (!serverId || !workspaceId) { return false; } const archives = pendingWorkspaceArchivesByServer.get(serverId); return archives?.has(pendingArchiveKey({ serverId, workspaceId })) ?? false; } export function shouldSuppressWorkspaceForLocalArchive(input: { serverId: string; workspace: WorkspaceDescriptor; }): boolean { return isWorkspaceArchivePending({ serverId: input.serverId, workspaceId: input.workspace.id, }); }