| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| export * from './generated'; |
|
|
| |
| import { |
| client, |
| createSessionSessionsPost, |
| listSessionsSessionsGet, |
| getSessionStatusSessionsSessionIdGet, |
| startInferenceSessionsSessionIdStartPost, |
| stopInferenceSessionsSessionIdStopPost, |
| restartInferenceSessionsSessionIdRestartPost, |
| deleteSessionSessionsSessionIdDelete, |
| healthCheckHealthGet, |
| getSystemInfoDebugSystemGet, |
| debugResetSessionDebugSessionsSessionIdResetPost, |
| getSessionQueueInfoDebugSessionsSessionIdQueueGet |
| } from './generated'; |
|
|
| import type { |
| CreateSessionRequest, |
| CreateSessionResponse, |
| SessionStatusResponse |
| } from './generated'; |
|
|
| |
| |
| |
| |
| |
| |
| export class LeRobotInferenceServerClient { |
| private baseUrl: string; |
|
|
| constructor(baseUrl: string) { |
| this.baseUrl = baseUrl; |
| |
| client.setConfig({ baseUrl }); |
| } |
|
|
| |
| |
| |
| async isHealthy(): Promise<boolean> { |
| try { |
| const response = await healthCheckHealthGet(); |
| return !response.error; |
| } catch { |
| return false; |
| } |
| } |
|
|
| |
| |
| |
| async getHealth() { |
| const response = await healthCheckHealthGet(); |
| if (response.error) { |
| throw new Error(`Health check failed: ${JSON.stringify(response.error)}`); |
| } |
| return response.data; |
| } |
|
|
| |
| |
| |
| async createSession(request: CreateSessionRequest): Promise<CreateSessionResponse> { |
| const response = await createSessionSessionsPost({ |
| body: request |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to create session: ${JSON.stringify(response.error)}`); |
| } |
|
|
| return response.data!; |
| } |
|
|
| |
| |
| |
| async listSessions(): Promise<SessionStatusResponse[]> { |
| const response = await listSessionsSessionsGet(); |
| if (response.error) { |
| throw new Error(`Failed to list sessions: ${JSON.stringify(response.error)}`); |
| } |
| return response.data!; |
| } |
|
|
| |
| |
| |
| async getSessionStatus(sessionId: string): Promise<SessionStatusResponse> { |
| const response = await getSessionStatusSessionsSessionIdGet({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to get session status: ${JSON.stringify(response.error)}`); |
| } |
|
|
| return response.data!; |
| } |
|
|
| |
| |
| |
| async startInference(sessionId: string): Promise<void> { |
| const response = await startInferenceSessionsSessionIdStartPost({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to start inference: ${JSON.stringify(response.error)}`); |
| } |
| } |
|
|
| |
| |
| |
| async stopInference(sessionId: string): Promise<void> { |
| const response = await stopInferenceSessionsSessionIdStopPost({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to stop inference: ${JSON.stringify(response.error)}`); |
| } |
| } |
|
|
| |
| |
| |
| async restartInference(sessionId: string): Promise<void> { |
| const response = await restartInferenceSessionsSessionIdRestartPost({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to restart inference: ${JSON.stringify(response.error)}`); |
| } |
| } |
|
|
| |
| |
| |
| async deleteSession(sessionId: string): Promise<void> { |
| const response = await deleteSessionSessionsSessionIdDelete({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to delete session: ${JSON.stringify(response.error)}`); |
| } |
| } |
|
|
| |
| |
| |
| async waitForSessionStatus( |
| sessionId: string, |
| targetStatus: string, |
| timeoutMs: number = 30000 |
| ): Promise<SessionStatusResponse> { |
| const startTime = Date.now(); |
| |
| while (Date.now() - startTime < timeoutMs) { |
| const status = await this.getSessionStatus(sessionId); |
| if (status.status === targetStatus) { |
| return status; |
| } |
| |
| |
| await new Promise(resolve => setTimeout(resolve, 1000)); |
| } |
| |
| throw new Error(`Timeout waiting for session ${sessionId} to reach status ${targetStatus}`); |
| } |
|
|
| |
| |
| |
| async createAndStartSession(request: CreateSessionRequest): Promise<{ |
| session: CreateSessionResponse; |
| status: SessionStatusResponse; |
| }> { |
| const session = await this.createSession(request); |
| await this.startInference(request.session_id); |
| |
| |
| const status = await this.waitForSessionStatus(request.session_id, 'running'); |
| |
| return { session, status }; |
| } |
|
|
| |
| |
| |
| async getSystemInfo() { |
| const response = await getSystemInfoDebugSystemGet(); |
| if (response.error) { |
| throw new Error(`Failed to get system info: ${JSON.stringify(response.error)}`); |
| } |
| return response.data; |
| } |
|
|
| |
| |
| |
| async debugResetSession(sessionId: string): Promise<void> { |
| const response = await debugResetSessionDebugSessionsSessionIdResetPost({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to reset session: ${JSON.stringify(response.error)}`); |
| } |
| } |
|
|
| |
| |
| |
| async getSessionQueueInfo(sessionId: string) { |
| const response = await getSessionQueueInfoDebugSessionsSessionIdQueueGet({ |
| path: { session_id: sessionId } |
| }); |
|
|
| if (response.error) { |
| throw new Error(`Failed to get queue info: ${JSON.stringify(response.error)}`); |
| } |
| return response.data; |
| } |
| } |
|
|
| |
| export function createClient(baseUrl: string): LeRobotInferenceServerClient { |
| return new LeRobotInferenceServerClient(baseUrl); |
| } |
|
|
| |
| export const LeRobotAIServerClient = LeRobotInferenceServerClient; |