| 383 | 383 | * @returns {string} Formatted message with tool invocations. |
| 384 | 384 | */ |
| 385 | 385 | static #formatMessage(invocations) { |
| 386 | | - const toolNames = invocations.map(i => i.name).join(', '); |
| 386 | + const tryParse = (x) => { try { return JSON.parse(x); } catch { return x; } }; |
| 387 | + const data = structuredClone(invocations); |
| 387 | 388 | const detailsElement = document.createElement('details'); |
| 388 | 389 | const summaryElement = document.createElement('summary'); |
| 389 | 390 | const preElement = document.createElement('pre'); |
| 390 | 391 | const codeElement = document.createElement('code'); |
| 391 | | - codeElement.textContent = JSON.stringify(invocations, null, 2); |
| 392 | + codeElement.classList.add('language-json'); |
| 393 | + data.forEach(i => i.parameters = tryParse(i.parameters)); |
| 394 | + codeElement.textContent = JSON.stringify(data, null, 2); |
| 395 | + const toolNames = data.map(i => i.name).join(', '); |
| 392 | 396 | summaryElement.textContent = `Performed tool calls: ${toolNames}`; |
| 393 | 397 | preElement.append(codeElement); |
| 394 | 398 | detailsElement.append(summaryElement, preElement); |