65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
|
|
export interface Session {
|
|
id: string;
|
|
status: 'waiting' | 'active' | 'disconnected';
|
|
created_at: string;
|
|
display_active: boolean;
|
|
audio_active: boolean;
|
|
resolution: string | null;
|
|
metadata: Record<string, string>;
|
|
}
|
|
|
|
export interface ApiResponse<T> {
|
|
ok: boolean;
|
|
data: T | null;
|
|
error: string | null;
|
|
}
|
|
|
|
export interface HealthInfo {
|
|
status: string;
|
|
uptime_secs: number;
|
|
active_sessions: number;
|
|
connected_agents: number;
|
|
version: string;
|
|
}
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class ApiService {
|
|
private baseUrl = '/api';
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
/** GET /api/health */
|
|
getHealth(): Observable<ApiResponse<HealthInfo>> {
|
|
return this.http.get<ApiResponse<HealthInfo>>(`${this.baseUrl}/health`);
|
|
}
|
|
|
|
/** GET /api/sessions */
|
|
listSessions(): Observable<ApiResponse<Session[]>> {
|
|
return this.http.get<ApiResponse<Session[]>>(`${this.baseUrl}/sessions`);
|
|
}
|
|
|
|
/** POST /api/sessions */
|
|
createSession(): Observable<ApiResponse<Session>> {
|
|
return this.http.post<ApiResponse<Session>>(`${this.baseUrl}/sessions`, {});
|
|
}
|
|
|
|
/** GET /api/sessions/:id */
|
|
getSession(id: string): Observable<ApiResponse<Session>> {
|
|
return this.http.get<ApiResponse<Session>>(`${this.baseUrl}/sessions/${id}`);
|
|
}
|
|
|
|
/** DELETE /api/sessions/:id */
|
|
deleteSession(id: string): Observable<ApiResponse<string>> {
|
|
return this.http.delete<ApiResponse<string>>(`${this.baseUrl}/sessions/${id}`);
|
|
}
|
|
|
|
/** POST /api/sessions/:id/hud — forward a HUD command to the agent. */
|
|
sendHudCommand(sessionId: string, command: string, params: Record<string, unknown> = {}): Observable<ApiResponse<string>> {
|
|
return this.http.post<ApiResponse<string>>(`${this.baseUrl}/sessions/${sessionId}/hud`, { command, params });
|
|
}
|
|
}
|