fix: missing tool calling info in the exported conversation JSON and MD
This commit is contained in:
@@ -83,6 +83,8 @@ const ChatBox: React.FC<ChatBoxProps> = ({ isVisible }) => {
|
|||||||
id: m.id,
|
id: m.id,
|
||||||
role: m.role,
|
role: m.role,
|
||||||
content: m.content,
|
content: m.content,
|
||||||
|
...(m.tool_calls ? { tool_calls: m.tool_calls } : {}),
|
||||||
|
...(m.tool_call_id ? { tool_call_id: m.tool_call_id } : {}),
|
||||||
timestamp: formatLocalDateTime(new Date(m.timestamp))
|
timestamp: formatLocalDateTime(new Date(m.timestamp))
|
||||||
}));
|
}));
|
||||||
const json = JSON.stringify(exportMessages, null, 2);
|
const json = JSON.stringify(exportMessages, null, 2);
|
||||||
@@ -99,15 +101,27 @@ const ChatBox: React.FC<ChatBoxProps> = ({ isVisible }) => {
|
|||||||
const res = await fetch(templateUrl);
|
const res = await fetch(templateUrl);
|
||||||
const template = await res.text();
|
const template = await res.text();
|
||||||
|
|
||||||
const sections = agentMessages
|
const sections = agentMessages.map((m) => {
|
||||||
.filter(m => m.role === 'user' || m.role === 'assistant')
|
let roleLabel: string;
|
||||||
.map((m) => {
|
if (m.role === 'assistant') roleLabel = 'Assistant';
|
||||||
const roleLabel = m.role === 'assistant' ? 'Assistant' : 'User';
|
else if (m.role === 'tool') roleLabel = 'Tool Result';
|
||||||
|
else roleLabel = 'User';
|
||||||
|
|
||||||
const ts = formatLocalDateTime(new Date(m.timestamp));
|
const ts = formatLocalDateTime(new Date(m.timestamp));
|
||||||
|
|
||||||
|
let content = m.content ?? '';
|
||||||
|
// For assistant messages with tool_calls but no text, show tool call info
|
||||||
|
if (m.role === 'assistant' && m.tool_calls && m.tool_calls.length > 0) {
|
||||||
|
const toolCallsText = m.tool_calls.map(tc =>
|
||||||
|
`**Tool call: ${tc.function.name}**\n\`\`\`json\n${tc.function.arguments}\n\`\`\``
|
||||||
|
).join('\n\n');
|
||||||
|
content = content ? `${content}\n\n${toolCallsText}` : toolCallsText;
|
||||||
|
}
|
||||||
|
|
||||||
return template
|
return template
|
||||||
.replace('{role}', roleLabel)
|
.replace('{role}', roleLabel)
|
||||||
.replace('{timestamp}', ts)
|
.replace('{timestamp}', ts)
|
||||||
.replace('{content}', m.content ?? '');
|
.replace('{content}', content);
|
||||||
});
|
});
|
||||||
|
|
||||||
const markdown = sections.join('\n');
|
const markdown = sections.join('\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user