MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / parseServerControl

Function parseServerControl

ui/src/components/workspace/protocol.ts:74–141  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

72// ── parser ──────────────────────────────────────────────────────────────────
73
74export function parseServerControl(text: string): ServerControlMessage | null {
75 let value: unknown;
76 try {
77 value = JSON.parse(text);
78 } catch {
79 return null;
80 }
81 if (typeof value !== 'object' || value === null) return null;
82 const v = value as Record<string, unknown>;
83 switch (v['type']) {
84 case 'attached':
85 if (
86 typeof v['wsId'] === 'string' &&
87 typeof v['sessionId'] === 'string' &&
88 typeof v['name'] === 'string' &&
89 (typeof v['agentSessionId'] === 'string' || v['agentSessionId'] === null) &&
90 typeof v['pid'] === 'number' &&
91 Array.isArray(v['command']) &&
92 v['command'].every((c) => typeof c === 'string') &&
93 typeof v['replayFromSeq'] === 'number' &&
94 typeof v['seq'] === 'number' &&
95 typeof v['scrollbackTruncated'] === 'boolean'
96 ) {
97 return {
98 type: 'attached',
99 wsId: v['wsId'],
100 sessionId: v['sessionId'],
101 name: v['name'],
102 agentSessionId: v['agentSessionId'] as string | null,
103 pid: v['pid'],
104 command: v['command'] as string[],
105 replayFromSeq: v['replayFromSeq'],
106 seq: v['seq'],
107 scrollbackTruncated: v['scrollbackTruncated'],
108 };
109 }
110 return null;
111 case 'cursor':
112 if (typeof v['seq'] === 'number') {
113 return { type: 'cursor', seq: v['seq'] };
114 }
115 return null;
116 case 'lifecycle':
117 if (v['kind'] === 'child-exit' && typeof v['code'] === 'number') {
118 return {
119 type: 'lifecycle',
120 kind: 'child-exit',
121 code: v['code'],
122 signal: typeof v['signal'] === 'number' ? v['signal'] : null,
123 };
124 }
125 if (v['kind'] === 'child-respawn' && typeof v['pid'] === 'number') {
126 return { type: 'lifecycle', kind: 'child-respawn', pid: v['pid'] };
127 }
128 return null;
129 case 'exit':
130 if (typeof v['code'] === 'number') {
131 return {

Callers 2

constructorMethod · 0.90
connectFunction · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected