MCPcopy Create free account
hub / github.com/anomalyco/opencode / formatPart

Function formatPart

packages/tui/src/util/transcript.ts:84–112  ·  view source on GitHub ↗
(part: Part, options: TranscriptOptions)

Source from the content-addressed store, hash-verified

82}
83
84export function formatPart(part: Part, options: TranscriptOptions): string {
85 if (part.type === "text" && !part.synthetic) {
86 return `${part.text}\n\n`
87 }
88
89 if (part.type === "reasoning") {
90 if (options.thinking) {
91 return `_Thinking:_\n\n${part.text}\n\n`
92 }
93 return ""
94 }
95
96 if (part.type === "tool") {
97 let result = `**Tool: ${part.tool}**\n`
98 if (options.toolDetails && part.state.input) {
99 result += `\n**Input:**\n\`\`\`json\n${JSON.stringify(part.state.input, null, 2)}\n\`\`\`\n`
100 }
101 if (options.toolDetails && part.state.status === "completed" && part.state.output) {
102 result += `\n**Output:**\n\`\`\`\n${part.state.output}\n\`\`\`\n`
103 }
104 if (options.toolDetails && part.state.status === "error" && part.state.error) {
105 result += `\n**Error:**\n\`\`\`\n${part.state.error}\n\`\`\`\n`
106 }
107 result += `\n`
108 return result
109 }
110
111 return ""
112}

Callers 2

transcript.test.tsFile · 0.90
formatMessageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected