MCPcopy Create free account
hub / github.com/Nimrobo/superdense / extractOpenCodePart

Function extractOpenCodePart

packages/core/src/adapters/opencode.ts:302–336  ·  view source on GitHub ↗
(row: OpenCodePartRow)

Source from the content-addressed store, hash-verified

300}
301
302function* extractOpenCodePart(row: OpenCodePartRow): Generator<TranscriptEvent> {
303 const data = safeJsonParse(row.part_data);
304 if (!data || typeof data !== 'object') return;
305 const role = isTranscriptRole(row.message_role) ? row.message_role : undefined;
306 const ts = row.part_time ?? row.message_time;
307
308 if (data.type === 'text' && typeof data.text === 'string' && data.text.trim()) {
309 yield { ts, kind: 'text', role, text: data.text, raw: data };
310 return;
311 }
312
313 if (data.type !== 'tool') return;
314 const callId = typeof data.callID === 'string' ? data.callID : row.part_id;
315 const state = data.state;
316 yield {
317 ts,
318 kind: 'tool_call',
319 role: role ?? 'assistant',
320 toolCallId: callId,
321 toolName: typeof data.tool === 'string' ? data.tool : undefined,
322 inputText: stringifyValue(state?.input ?? {}),
323 raw: data,
324 };
325
326 if (shouldEmitToolResult(state)) {
327 yield {
328 ts,
329 kind: 'tool_result',
330 role: role ?? 'assistant',
331 toolCallId: callId,
332 text: resultText(state) ?? '',
333 raw: data,
334 };
335 }
336}

Callers 1

iterOpenCodeEventsFunction · 0.85

Calls 5

shouldEmitToolResultFunction · 0.85
resultTextFunction · 0.85
safeJsonParseFunction · 0.70
isTranscriptRoleFunction · 0.70
stringifyValueFunction · 0.70

Tested by

no test coverage detected