desktop: services/api.service.ts — HTTP client for REST endpoints matching backend
This commit is contained in:
parent
710560d300
commit
4041625f06
64
desktop/src/app/services/api.service.ts
Normal file
64
desktop/src/app/services/api.service.ts
Normal file
@ -0,0 +1,64 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user