MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / parseMessage

Function parseMessage

packages/node/src/testing/ptyScenario.ts:333–369  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

331}
332
333function parseMessage(line: string): HarnessMessage | null {
334 const trimmed = line.trim();
335 if (trimmed.length === 0) return null;
336 let parsed: unknown;
337 try {
338 parsed = JSON.parse(trimmed) as unknown;
339 } catch {
340 return null;
341 }
342 if (typeof parsed !== "object" || parsed === null) return null;
343 const record = parsed as Partial<HarnessMessage>;
344 if (record.type === "ready" && typeof (record as { caps?: TerminalCaps }).caps === "object") {
345 return Object.freeze({
346 type: "ready",
347 caps: (record as { caps: TerminalCaps }).caps,
348 });
349 }
350 if (record.type === "fatal" && typeof record.detail === "string") {
351 return Object.freeze({ type: "fatal", detail: record.detail });
352 }
353 if (record.type === "engine") {
354 return Object.freeze({ type: "engine" });
355 }
356 if (record.type === "render") {
357 return Object.freeze({
358 type: "render",
359 cursor: (record as { cursor?: ScenarioCursorSnapshot | null }).cursor ?? null,
360 });
361 }
362 if (
363 record.type === "action" &&
364 typeof (record as { action?: RoutedAction }).action === "object"
365 ) {
366 return Object.freeze({ type: "action", action: (record as { action: RoutedAction }).action });
367 }
368 return null;
369}
370
371async function closeServer(server: net.Server): Promise<void> {
372 await new Promise<void>((resolve) => {

Callers 1

createControlServerFunction · 0.70

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected