MCPcopy Create free account
hub / github.com/cortexkit/magic-context / convertPartToEntries

Function convertPartToEntries

packages/cli/src/commands/migrate.ts:416–452  ·  view source on GitHub ↗
(ctx: ConvertPartContext)

Source from the content-addressed store, hash-verified

414}
415
416function convertPartToEntries(ctx: ConvertPartContext): PiJson[] {
417 const part = parseJsonObject<OpenCodePartData>(ctx.row.data);
418 switch (part.type) {
419 case "step-start":
420 case "step-finish":
421 case "patch":
422 return [];
423 case "text":
424 return part.text
425 ? [makeMessageEntry(ctx.role, part.text, ctx.timestamp, ctx.parentId, ctx.usage)]
426 : [];
427 case "reasoning":
428 return part.text
429 ? [makeThinkingEntry(part.text, ctx.timestamp, ctx.parentId, ctx.usage)]
430 : [];
431 case "tool": {
432 const tool = normalizeOpenCodeTool(part);
433 const call = makeToolCallEntry(tool, ctx.timestamp, ctx.parentId, ctx.usage);
434 const result = makeToolResultEntry(tool, ctx.timestamp, call.id as string);
435 return [call, result];
436 }
437 case "file": {
438 const name = part.filename ?? part.name ?? "attachment";
439 return [
440 makeMessageEntry(
441 ctx.role,
442 `<file omitted: ${name}>`,
443 ctx.timestamp,
444 ctx.parentId,
445 ctx.usage,
446 ),
447 ];
448 }
449 default:
450 return [];
451 }
452}
453
454interface BuildEntriesResult {
455 entries: PiJson[];

Callers 1

buildPiEntriesFunction · 0.85

Calls 6

parseJsonObjectFunction · 0.85
makeMessageEntryFunction · 0.85
makeThinkingEntryFunction · 0.85
normalizeOpenCodeToolFunction · 0.85
makeToolCallEntryFunction · 0.85
makeToolResultEntryFunction · 0.85

Tested by

no test coverage detected