Support rendering function calls and responses when sharing chat to markdown (#8693)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
This commit is contained in:
Rohit Ramkumar
2025-09-19 17:47:20 -04:00
committed by GitHub
parent f028913b0e
commit 5be2a9d5e2
2 changed files with 150 additions and 17 deletions

View File

@@ -280,10 +280,29 @@ export function serializeHistoryToMarkdown(history: Content[]): string {
.map((item) => {
const text =
item.parts
?.filter((m) => !!m.text)
.map((m) => m.text)
?.map((part) => {
if (part.text) {
return part.text;
}
if (part.functionCall) {
return `**Tool Command**:\n\`\`\`json\n${JSON.stringify(
part.functionCall,
null,
2,
)}\n\`\`\``;
}
if (part.functionResponse) {
return `**Tool Response**:\n\`\`\`json\n${JSON.stringify(
part.functionResponse,
null,
2,
)}\n\`\`\``;
}
return '';
})
.join('') || '';
return `**${item.role}**:\n\n${text}`;
const roleIcon = item.role === 'user' ? '🧑‍💻' : '✨';
return `${roleIcon} ## ${(item.role || 'model').toUpperCase()}\n\n${text}`;
})
.join('\n\n---\n\n');
}