|
37 | 37 | class="flex flex-col w-full" |
38 | 38 | :class="message.role === 'user' ? 'self-end' : 'self-start'" |
39 | 39 | > |
40 | | - <ToolsGroup :toolGroup="groupToolCallParts(message)" /> |
41 | 40 | <template |
42 | | - v-for="part in getParts(message)" |
| 41 | + v-for="(part, index) in getParts(message)" |
43 | 42 | :key="part.type" |
44 | 43 | > |
45 | 44 | <Message |
|
52 | 51 | @toggle-thoughts="() => clicks++" |
53 | 52 | > |
54 | 53 | </Message> |
| 54 | + <ToolsGroup v-else :toolGroup="groupToolCallParts(message, index, part)" /> |
55 | 55 | </template> |
56 | 56 | </div> |
57 | 57 | <!-- 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) => { |
154 | 154 | return null; |
155 | 155 | }); |
156 | 156 |
|
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; |
160 | 160 | const parts = getParts(message); |
161 | 161 | if (!parts) return []; |
162 | 162 | const formatedToolParts = parts.map(part => { |
163 | 163 | return formatToolCallTextPart(part as IPart, message) |
164 | 164 | }); |
| 165 | + const currentPartIndexInFormatedParts = formatedToolParts.findIndex(part => part?.toolInfo?.toolCallId === currentPart.data?.toolCallId); |
| 166 | + if (currentPartIndexInFormatedParts === -1) { |
| 167 | + return []; |
| 168 | + } |
165 | 169 | for( const[index, part] of formatedToolParts.entries()){ |
166 | | - if(!part?.toolInfo) { |
| 170 | + if ( index < currentPartIndexInFormatedParts - 1 ) { |
167 | 171 | continue; |
168 | 172 | } |
169 | | - if (part.toolInfo.toolName === currentToolName) { |
170 | | - groupedParts[groupedParts.length - 1].groupedTools.push(part); |
| 173 | + if(!part || !part.toolInfo) { |
171 | 174 | continue; |
172 | 175 | } |
173 | 176 | 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 | + } |
178 | 190 | } |
179 | 191 | return groupedParts; |
180 | 192 | } |
|
0 commit comments