| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
| 584 | + * Groups tool names by count. |
| 585 | + * @param {string[]} toolNames Tool names |
| 586 | + * @returns {string} Grouped tool names |
| 587 | + */ |
| 588 | + static #groupToolNames(toolNames) { |
| 589 | + const toolCounts = toolNames.reduce((acc, name) => { |
| 590 | + acc[name] = (acc[name] || 0) + 1; |
| 591 | + return acc; |
| 592 | + }, {}); |
| 593 | + return Object.entries(toolCounts).map(([name, count]) => count > 1 ? `${name} (${count})` : name).join(', '); |
| 594 | + } |
| 595 | + |
| 596 | + /** |
| 584 | 597 | * Formats a message with tool invocations. |
| 585 | 598 | * @param {ToolInvocation[]} invocations Tool invocations. |
| 586 | 599 | * @returns {string} Formatted message with tool invocations. |