Skip to content

Commit 5e46b8a

Browse files
committed
fix: show tool cals and toughts in generation order
1 parent 19d8879 commit 5e46b8a

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

custom/ConversationArea.vue

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
class="flex flex-col w-full"
3838
:class="message.role === 'user' ? 'self-end' : 'self-start'"
3939
>
40-
<ToolsGroup :toolGroup="groupToolCallParts(message)" />
4140
<template
42-
v-for="part in getParts(message)"
41+
v-for="(part, index) in getParts(message)"
4342
:key="part.type"
4443
>
4544
<Message
@@ -52,6 +51,7 @@
5251
@toggle-thoughts="() => clicks++"
5352
>
5453
</Message>
54+
<ToolsGroup v-else :toolGroup="groupToolCallParts(message, index, part)" />
5555
</template>
5656
</div>
5757
<!-- Show a placeholder message if the last message is not of type 'text' or 'reasoning' -->
@@ -154,27 +154,39 @@ const formatToolCallTextPart = ((part: IPart, currentMessage: IMessage) => {
154154
return null;
155155
});
156156
157-
const groupToolCallParts = (message: IMessage) => {
158-
const groupedParts = [];
159-
let currentToolName = null;
157+
const groupToolCallParts = (message: IMessage, currentPartIndex: number, currentPart: IPart) => {
158+
const groupedParts: { title: string; groupedTools: IPart[] }[] = [];
159+
let currentToolName: string | null = null;
160160
const parts = getParts(message);
161161
if (!parts) return [];
162162
const formatedToolParts = parts.map(part => {
163163
return formatToolCallTextPart(part as IPart, message)
164164
});
165+
const currentPartIndexInFormatedParts = formatedToolParts.findIndex(part => part?.toolInfo?.toolCallId === currentPart.data?.toolCallId);
166+
if (currentPartIndexInFormatedParts === -1) {
167+
return [];
168+
}
165169
for( const[index, part] of formatedToolParts.entries()){
166-
if(!part?.toolInfo) {
170+
if ( index < currentPartIndexInFormatedParts - 1 ) {
167171
continue;
168172
}
169-
if (part.toolInfo.toolName === currentToolName) {
170-
groupedParts[groupedParts.length - 1].groupedTools.push(part);
173+
if(!part || !part.toolInfo) {
171174
continue;
172175
}
173176
currentToolName = part.toolInfo.toolName;
174-
groupedParts.push({
175-
title: currentToolName,
176-
groupedTools: [part]
177-
});
177+
if (!groupedParts.find(group => group.title === currentToolName)) {
178+
groupedParts.push({
179+
title: currentToolName,
180+
groupedTools: []
181+
})
182+
}
183+
if( formatedToolParts[currentPartIndexInFormatedParts - 1]?.toolInfo.toolName === part.toolInfo.toolName) {
184+
continue;
185+
} else if ( formatedToolParts[currentPartIndexInFormatedParts + 1]?.toolInfo.toolName === part.toolInfo.toolName) {
186+
groupedParts[groupedParts.length - 1].groupedTools.push(formatedToolParts[currentPartIndexInFormatedParts + 1] as IPart);
187+
} else {
188+
groupedParts[groupedParts.length - 1].groupedTools.push(part);
189+
}
178190
}
179191
return groupedParts;
180192
}

custom/ToolsGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
</transition>
1717
</div>
18-
<ToolRenderer v-else :data="group.groupedTools[0]" />
18+
<ToolRenderer v-else-if="group.groupedTools.length > 0" :data="group.groupedTools[0]" />
1919
</template>
2020

2121
</template>

0 commit comments

Comments
 (0)