From 4041625f06a209011fd34945f260ebfe127e8b03 Mon Sep 17 00:00:00 2001 From: Butterfly Dev Date: Tue, 7 Apr 2026 03:26:25 +0000 Subject: [PATCH] =?UTF-8?q?desktop:=20services/api.service.ts=20=E2=80=94?= =?UTF-8?q?=20HTTP=20client=20for=20REST=20endpoints=20matching=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desktop/src/app/services/api.service.ts | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 desktop/src/app/services/api.service.ts diff --git a/desktop/src/app/services/api.service.ts b/desktop/src/app/services/api.service.ts new file mode 100644 index 0000000..1aaad3c --- /dev/null +++ b/desktop/src/app/services/api.service.ts @@ -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; +} + +export interface ApiResponse { + 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> { + return this.http.get>(`${this.baseUrl}/health`); + } + + /** GET /api/sessions */ + listSessions(): Observable> { + return this.http.get>(`${this.baseUrl}/sessions`); + } + + /** POST /api/sessions */ + createSession(): Observable> { + return this.http.post>(`${this.baseUrl}/sessions`, {}); + } + + /** GET /api/sessions/:id */ + getSession(id: string): Observable> { + return this.http.get>(`${this.baseUrl}/sessions/${id}`); + } + + /** DELETE /api/sessions/:id */ + deleteSession(id: string): Observable> { + return this.http.delete>(`${this.baseUrl}/sessions/${id}`); + } + + /** POST /api/sessions/:id/hud — forward a HUD command to the agent. */ + sendHudCommand(sessionId: string, command: string, params: Record = {}): Observable> { + return this.http.post>(`${this.baseUrl}/sessions/${sessionId}/hud`, { command, params }); + } +}