| 52 | } |
| 53 | |
| 54 | async waitForReady(timeoutMs: number = 30_000): Promise<HealthResponse> { |
| 55 | const startTime = Date.now(); |
| 56 | const pollInterval = 500; |
| 57 | |
| 58 | while (Date.now() - startTime < timeoutMs) { |
| 59 | try { |
| 60 | return await this.call<HealthResponse>( |
| 61 | 'GET', |
| 62 | '/global/health', |
| 63 | undefined, |
| 64 | HEALTH_POLL_TIMEOUT_SECONDS |
| 65 | ); |
| 66 | } catch { |
| 67 | const elapsed = Date.now() - startTime; |
| 68 | if (elapsed + pollInterval >= timeoutMs) { |
| 69 | break; |
| 70 | } |
| 71 | await this.sleep(pollInterval); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | throw new KiloServerNotReadyError(`Server not ready after ${timeoutMs}ms on port ${this.port}`); |
| 76 | } |
| 77 | |
| 78 | async createSession(options?: CreateSessionOptions): Promise<Session> { |
| 79 | const session = await this.call<Session>('POST', '/session', { |