1import type { ScopedThreadRef } from "@t3tools/contracts";
2
3/**
4 * The server only guarantees preview tab ids are unique within one process.
5 * Desktop resources live across every connected environment, so they need a
6 * stronger identity that also changes when a server process restarts.
7 */
8export function previewRuntimeTabId(
9 threadRef: ScopedThreadRef,
10 serverEpoch: string | null,
11 tabId: string,
12): string {
13 return JSON.stringify([threadRef.environmentId, threadRef.threadId, serverEpoch, tabId]);
14}
15
16export function isCurrentPreviewRuntimeTab(
17 threadRef: ScopedThreadRef,
18 serverEpoch: string | null,
19 tabId: string,
20 runtimeTabId: string,
21): boolean {
22 return previewRuntimeTabId(threadRef, serverEpoch, tabId) === runtimeTabId;
23}