feat: support basic file presenting

This commit is contained in:
Henry Li
2026-01-16 22:35:20 +08:00
parent 4b69aed47b
commit f9853f037c
4 changed files with 102 additions and 4 deletions

View File

@@ -46,9 +46,14 @@ export function groupMessages<T>(
messageIndex === messages.length - 1 &&
isLoading)
) {
// Assistant messages without any content are folded into the previous group
// Normally, these are tool calls (with or without thinking)
currentGroup.push(message);
if (message.tool_calls?.[0]?.name === "present_files") {
yieldCurrentGroup();
currentGroup.push(message);
} else {
// Assistant messages without any content are folded into the previous group
// Normally, these are tool calls (with or without thinking)
currentGroup.push(message);
}
} else {
// Assistant messages with content (text or images) are shown as a group if they have content
// No matter whether it has tool calls or not
@@ -144,6 +149,25 @@ export function hasToolCalls(message: Message) {
);
}
export function hasPresentFiles(message: Message) {
return (
message.type === "ai" && message.tool_calls?.[0]?.name === "present_files"
);
}
export function extractPresentFilesFromMessage(message: Message) {
if (message.type !== "ai" || !hasPresentFiles(message)) {
return [];
}
const files = [];
for (const toolCall of message.tool_calls ?? []) {
if (toolCall.name === "present_files") {
files.push(...(toolCall.args.filepaths as string[]));
}
}
return files;
}
export function findToolCallResult(toolCallId: string, messages: Message[]) {
for (const message of messages) {
if (message.type === "tool" && message.tool_call_id === toolCallId) {