MCPcopy Index your code
hub / github.com/tiann/hapi / handleLine

Method handleLine

cli/src/codex/codexAppServerClient.ts:373–416  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

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'

Callers 1

handleStdoutMethod · 0.95

Calls 6

rejectAllPendingMethod · 0.95
handleIncomingRequestMethod · 0.95
handleResponseMethod · 0.95
debugMethod · 0.80
endMethod · 0.80
asRecordFunction · 0.70

Tested by

no test coverage detected