| 156 | } |
| 157 | |
| 158 | export class DaemonClient { |
| 159 | readonly baseUrl: string; |
| 160 | readonly apiPrefix: string; |
| 161 | readonly clientId: string; |
| 162 | readonly http: HttpClient; |
| 163 | |
| 164 | private readonly _wsImpl: typeof WsWebSocket; |
| 165 | private readonly _logger: ( |
| 166 | level: 'info' | 'warn' | 'error' | 'debug', |
| 167 | msg: string, |
| 168 | meta?: unknown, |
| 169 | ) => void; |
| 170 | private readonly _reportDir: string | undefined; |
| 171 | private readonly _controlAckTimeoutMs: number; |
| 172 | private _ws: WsClient | null = null; |
| 173 | private _serverHello: ServerHelloMessage['payload'] | null = null; |
| 174 | private readonly _subscribed = new Set<string>(); |
| 175 | private readonly _disposers: Array<() => void> = []; |
| 176 | |
| 177 | constructor(opts: DaemonClientOptions = {}) { |
| 178 | this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, ''); |
| 179 | this.apiPrefix = opts.apiPrefix ?? DEFAULT_API_PREFIX; |
| 180 | this.clientId = opts.clientId ?? `server-e2e-${ulid()}`; |
| 181 | this._wsImpl = opts.wsImpl ?? WsWebSocket; |
| 182 | this._logger = opts.logger ?? noopLogger; |
| 183 | this._reportDir = opts.reportDir; |
| 184 | this._controlAckTimeoutMs = opts.controlAckTimeoutMs ?? DEFAULT_CONTROL_ACK_TIMEOUT_MS; |
| 185 | this.http = new HttpClient({ |
| 186 | baseUrl: this.baseUrl, |
| 187 | apiPrefix: this.apiPrefix, |
| 188 | fetchImpl: opts.fetchImpl ?? fetch, |
| 189 | reportDir: this._reportDir, |
| 190 | }); |
| 191 | } |
| 192 | |
| 193 | // ── Probes + model catalog ───────────────────────────────────────────── |
| 194 | getAuth(): Promise<AuthSummary> { |
| 195 | return this.http.getAuth(); |
| 196 | } |
| 197 | listModels(): Promise<ListModelsResponse> { |
| 198 | return this.http.listModels(); |
| 199 | } |
| 200 | setDefaultModel(modelId: string): Promise<SetDefaultModelResponse> { |
| 201 | return this.http.setDefaultModel(modelId); |
| 202 | } |
| 203 | listProviders(): Promise<ListProvidersResponse> { |
| 204 | return this.http.listProviders(); |
| 205 | } |
| 206 | getProvider(providerId: string): Promise<ProviderCatalogItem> { |
| 207 | return this.http.getProvider(providerId); |
| 208 | } |
| 209 | |
| 210 | // ── HTTP convenience surface ──────────────────────────────────────────── |
| 211 | createSession(body: SessionCreate): Promise<Session> { |
| 212 | return this.http.createSession(body); |
| 213 | } |
| 214 | getSession(sid: string): Promise<Session> { |
| 215 | return this.http.getSession(sid); |
nothing calls this directly
no outgoing calls
no test coverage detected