| 375 | 378 | } |
| 376 | 379 | |
| 377 | 380 | /** |
| 381 | + * Formats a message with tool invocations. |
| 382 | + * @param {ToolInvocation[]} invocations Tool invocations. |
| 383 | + * @returns {string} Formatted message with tool invocations. |
| 384 | + */ |
| 385 | + static #formatMessage(invocations) { |
| 386 | + const toolNames = invocations.map(i => i.name).join(', '); |
| 387 | + const detailsElement = document.createElement('details'); |
| 388 | + const summaryElement = document.createElement('summary'); |
| 389 | + const preElement = document.createElement('pre'); |
| 390 | + const codeElement = document.createElement('code'); |
| 391 | + codeElement.textContent = JSON.stringify(invocations, null, 2); |
| 392 | + summaryElement.textContent = `Performed tool calls: ${toolNames}`; |
| 393 | + preElement.append(codeElement); |
| 394 | + detailsElement.append(summaryElement, preElement); |
| 395 | + return detailsElement.outerHTML; |
| 396 | + } |
| 397 | + |
| 398 | + /** |
| 378 | 399 | * Saves function tool invocations to the last user chat message extra metadata. |
| 379 | 400 | * @param {ToolInvocation[]} invocations Successful tool invocations |
| 380 | 401 | */ |
| 381 | 402 | static saveFunctionToolInvocations(invocations) { |
| 382 | | - const toolNames = invocations.map(i => i.name).join(', '); |
| 383 | 403 | const message = { |
| 384 | 404 | name: systemUserName, |
| 385 | 405 | force_avatar: system_avatar, |
| 386 | 406 | is_system: true, |
| 387 | 407 | is_user: false, |
| 388 | | - mes: `Performed tool calls: ${toolNames}`, |
| 408 | + mes: ToolManager.#formatMessage(invocations), |
| 389 | 409 | extra: { |
| 390 | 410 | isSmallSys: true, |
| 391 | 411 | tool_invocations: invocations, |