返回 DeepSeek-Reasonix
remoteWorkspace.ts
根目录 / desktop / frontend / src / lib / remoteWorkspace.ts
1 /**
2 * Resolve the workspace used to open a remote Serve page.
3 *
4 * A host's last-opened workspace wins over its configured default. Fresh
5 * hosts fall back to the SSH login user's home directory, which the remote
6 * bootstrap resolves from `~` before launching Serve.
7 */
8 export function resolveRemoteWorkspace(lastWorkspace?: string, defaultWorkspace?: string): string {
9 return lastWorkspace?.trim() || defaultWorkspace?.trim() || "~";
10 }
11
12 /**
13 * Host-scoped latest-request-wins generations for remote window launches.
14 * Requests for one SSH host supersede only that host; different hosts remain
15 * independent because each opens in its own native window.
16 */
17 export class RemoteWorkspaceLaunchGate {
18 private readonly generations = new Map<string, number>();
19
20 begin(hostId: string): number {
21 const next = (this.generations.get(hostId) ?? 0) + 1;
22 this.generations.set(hostId, next);
23 return next;
24 }
25
26 isCurrent(hostId: string, generation: number): boolean {
27 return this.generations.get(hostId) === generation;
28 }
29 }
30
30 lines TYPESCRIPT