MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / formatTurnMd

Function formatTurnMd

apps/kimi-code/src/tui/utils/export-markdown.ts:131–182  ·  view source on GitHub ↗
(messages: readonly ContextMessage[], turnNumber: number)

Source from the content-addressed store, hash-verified

129}
130
131function formatTurnMd(messages: readonly ContextMessage[], turnNumber: number): string {
132 const lines: string[] = [`## Turn ${String(turnNumber)}`, ''];
133
134 const toolCallInfo = new Map<string, { name: string; hint: string }>();
135 let assistantHeaderWritten = false;
136
137 for (const msg of messages) {
138 if (isInternalMessage(msg)) continue;
139
140 if (msg.role === 'user') {
141 lines.push('### User', '');
142 for (const part of msg.content) {
143 const text = formatContentPartMd(part);
144 if (text.trim()) {
145 lines.push(text, '');
146 }
147 }
148 } else if (msg.role === 'assistant') {
149 if (!assistantHeaderWritten) {
150 lines.push('### Assistant', '');
151 assistantHeaderWritten = true;
152 }
153
154 for (const part of msg.content) {
155 const text = formatContentPartMd(part);
156 if (text.trim()) {
157 lines.push(text, '');
158 }
159 }
160
161 for (const tc of msg.toolCalls) {
162 const hint = extractToolCallHint(tc.arguments ?? '{}');
163 toolCallInfo.set(tc.id, { name: tc.name, hint });
164 lines.push(formatToolCallMd(tc), '');
165 }
166 } else if (msg.role === 'tool') {
167 const tcId = msg.toolCallId ?? '';
168 const info = toolCallInfo.get(tcId) ?? { name: 'unknown', hint: '' };
169 lines.push(formatToolResultMd(msg, info.name, info.hint), '');
170 } else if (msg.role === 'system') {
171 lines.push(`### ${msg.role.charAt(0).toUpperCase()}${msg.role.slice(1)}`, '');
172 for (const part of msg.content) {
173 const text = formatContentPartMd(part);
174 if (text.trim()) {
175 lines.push(text, '');
176 }
177 }
178 }
179 }
180
181 return lines.join('\n');
182}
183
184function buildOverview(
185 history: readonly ContextMessage[],

Callers 1

buildExportMarkdownFunction · 0.85

Calls 8

isInternalMessageFunction · 0.85
formatContentPartMdFunction · 0.85
extractToolCallHintFunction · 0.85
formatToolCallMdFunction · 0.85
formatToolResultMdFunction · 0.85
setMethod · 0.65
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected