MCPcopy
hub / github.com/Dimillian/CodexMonitor / buildConversationItem

Function buildConversationItem

src/utils/threadItems.conversion.ts:44–207  ·  view source on GitHub ↗
(
  item: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

42}
43
44export function buildConversationItem(
45 item: Record<string, unknown>,
46): ConversationItem | null {
47 const type = asString(item.type);
48 const id = asString(item.id);
49 if (!id || !type) {
50 return null;
51 }
52 if (type === "agentMessage") {
53 return null;
54 }
55 if (type === "userMessage") {
56 const content = Array.isArray(item.content) ? item.content : [];
57 const { text, images } = parseUserInputs(content as Array<Record<string, unknown>>);
58 return {
59 id,
60 kind: "message",
61 role: "user",
62 text,
63 images: images.length > 0 ? images : undefined,
64 };
65 }
66 if (type === "reasoning") {
67 const summary = asString(item.summary ?? "");
68 const content = Array.isArray(item.content)
69 ? item.content.map((entry) => asString(entry)).join("\n")
70 : asString(item.content ?? "");
71 return { id, kind: "reasoning", summary, content };
72 }
73 if (type === "plan") {
74 return {
75 id,
76 kind: "tool",
77 toolType: "plan",
78 title: "Plan",
79 detail: asString(item.status ?? ""),
80 status: asString(item.status ?? ""),
81 output: asString(item.text ?? ""),
82 };
83 }
84 if (type === "commandExecution") {
85 const command = Array.isArray(item.command)
86 ? item.command.map((part) => asString(part)).join(" ")
87 : asString(item.command ?? "");
88 const durationMs = asNumber(item.durationMs ?? item.duration_ms);
89 return {
90 id,
91 kind: "tool",
92 toolType: type,
93 title: command ? `Command: ${command}` : "Command",
94 detail: asString(item.cwd ?? ""),
95 status: asString(item.status ?? ""),
96 output: asString(item.aggregatedOutput ?? ""),
97 durationMs,
98 };
99 }
100 if (type === "fileChange") {
101 const changes = Array.isArray(item.changes) ? item.changes : [];

Callers 3

useThreadItemEventsFunction · 0.90

Calls 4

asStringFunction · 0.90
asNumberFunction · 0.90
parseCollabToolCallItemFunction · 0.90
parseUserInputsFunction · 0.85

Tested by

no test coverage detected