MCPcopy Create free account
hub / github.com/agent-tower/core / parseJsonSegments

Method parseJsonSegments

packages/server/src/output/codex-parser.ts:126–148  ·  view source on GitHub ↗

* 解析一行中可能包含的多个 JSON 对象 * Codex 有时会在同一行输出多个 JSON: {"type":"error",...} {"type":"turn.failed",...}

(line: string)

Source from the content-addressed store, hash-verified

124 const lines = this.buffer.split('\n');
125 this.buffer = lines.pop() || '';
126
127 for (const line of lines) {
128 const trimmed = line.trim();
129 if (!trimmed) continue;
130
131 // 收集非 JSON 行(如 ERROR 日志),用于异常退出时展示
132 if (!trimmed.startsWith('{')) {
133 this.nonJsonLines.push(stripAnsiSequences(trimmed));
134 if (DEBUG_PARSER) {
135 console.log('[CodexParser] Skipping non-JSON line:', trimmed.substring(0, 100));
136 }
137 continue;
138 }
139
140 this.parseJsonSegments(trimmed);
141 }
142 }
143
144 /**
145 * 解析一行中可能包含的多个 JSON 对象
146 * Codex 有时会在同一行输出多个 JSON: {"type":"error",...} {"type":"turn.failed",...}
147 */
148 private parseJsonSegments(line: string): void {
149 // 尝试直接解析整行
150 try {
151 const event: CodexEvent = JSON.parse(line);

Callers 2

processDataMethod · 0.95
finishMethod · 0.95

Calls 2

handleEventMethod · 0.95
extractJsonObjectsMethod · 0.95

Tested by

no test coverage detected