(line: string)
| 371 | } |
| 372 | |
| 373 | private handleLine(line: string): void { |
| 374 | if (this.protocolError) { |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | let message: Record<string, unknown> | null = null; |
| 379 | try { |
| 380 | const parsed = JSON.parse(line); |
| 381 | message = asRecord(parsed); |
| 382 | if (!message) { |
| 383 | logger.debug('[CodexAppServer] Ignoring non-object JSON from stdout', { line }); |
| 384 | return; |
| 385 | } |
| 386 | } catch (error) { |
| 387 | const protocolError = new Error('Failed to parse JSON from codex app-server'); |
| 388 | this.protocolError = protocolError; |
| 389 | logger.debug('[CodexAppServer] Failed to parse JSON line', { line, error }); |
| 390 | this.rejectAllPending(protocolError); |
| 391 | this.process?.stdin.end(); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | if (typeof message.method === 'string') { |
| 396 | const method = message.method; |
| 397 | const params = 'params' in message ? message.params : null; |
| 398 | |
| 399 | if ('id' in message && message.id !== undefined) { |
| 400 | const requestId = message.id; |
| 401 | void this.handleIncomingRequest({ |
| 402 | id: requestId, |
| 403 | method, |
| 404 | params |
| 405 | }); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | this.notificationHandler?.(method, params ?? null); |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | if ('id' in message) { |
| 414 | this.handleResponse(message as JsonRpcLiteResponse); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | private async handleIncomingRequest(request: { id: unknown; method: string; params?: unknown }): Promise<void> { |
| 419 | const responseId = typeof request.id === 'number' || typeof request.id === 'string' |
no test coverage detected