File size: 1,590 Bytes
1794757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { HttpClient } from "./http";
import type {
  CreateSessionRequest,
  LiveControlRequest,
  ResetSessionRequest,
  SourceMonitorReport,
  SessionState,
  StepSessionRequest,
  StepSessionResponse,
} from "./types";

export class SessionClient {
  constructor(private readonly http: HttpClient) {}

  async health(): Promise<{ status: string }> {
    return this.http.get<{ status: string }>("/healthz");
  }

  async createSession(request: CreateSessionRequest = {}): Promise<SessionState> {
    return this.http.post<SessionState>("/sessions", request);
  }

  async getSession(sessionId: string): Promise<SessionState> {
    return this.http.get<SessionState>(`/sessions/${sessionId}`);
  }

  async resetSession(sessionId: string, request: ResetSessionRequest = {}): Promise<SessionState> {
    return this.http.post<SessionState>(`/sessions/${sessionId}/reset`, request);
  }

  async refreshSources(sessionId: string): Promise<SessionState> {
    return this.http.post<SessionState>(`/sessions/${sessionId}/sources/refresh`, {});
  }

  async getSourceMonitor(sessionId: string): Promise<SourceMonitorReport> {
    return this.http.get<SourceMonitorReport>(`/sessions/${sessionId}/sources/monitor`);
  }

  async setLiveMode(sessionId: string, request: LiveControlRequest): Promise<SessionState> {
    return this.http.post<SessionState>(`/sessions/${sessionId}/live`, request);
  }

  async stepSession(sessionId: string, request: StepSessionRequest): Promise<StepSessionResponse> {
    return this.http.post<StepSessionResponse>(`/sessions/${sessionId}/step`, request);
  }
}