(event)
| 423 | } |
| 424 | |
| 425 | function handleAgentEvent(event) { |
| 426 | ensureAssistantMessageForEvent(event); |
| 427 | if (!currentAssistantMsg) return; |
| 428 | |
| 429 | if ( |
| 430 | ["text_delta", "thinking_delta", "tool_start", "tool_end"].includes( |
| 431 | event.type |
| 432 | ) |
| 433 | ) { |
| 434 | hideLoadingIndicator(); |
| 435 | } |
| 436 | |
| 437 | switch (event.type) { |
| 438 | case "agent_start": |
| 439 | case "message_start": |
| 440 | showLoadingIndicator(); |
| 441 | break; |
| 442 | |
| 443 | case "agent_end": |
| 444 | case "message_end": |
| 445 | hideLoadingIndicator(); |
| 446 | break; |
| 447 | |
| 448 | case "thinking_delta": |
| 449 | const thinkingBlock = getOrCreateThinkingBlock(); |
| 450 | thinkingBlock.dataset.mdContent += event.delta; |
| 451 | const contentEl = thinkingBlock.querySelector(".thinking-content"); |
| 452 | if (typeof window.marked !== "undefined") { |
| 453 | contentEl.innerHTML = renderMarkdown(thinkingBlock.dataset.mdContent); |
| 454 | } else { |
| 455 | contentEl.textContent = thinkingBlock.dataset.mdContent; |
| 456 | } |
| 457 | scrollToBottom(); |
| 458 | break; |
| 459 | |
| 460 | case "text_delta": |
| 461 | const textBlock = getOrCreateTextBlock(); |
| 462 | textBlock.dataset.mdContent += event.delta; |
| 463 | if (typeof window.marked !== "undefined") { |
| 464 | textBlock.innerHTML = renderMarkdown(textBlock.dataset.mdContent); |
| 465 | } else { |
| 466 | textBlock.textContent = textBlock.dataset.mdContent; |
| 467 | } |
| 468 | scrollToBottom(); |
| 469 | break; |
| 470 | |
| 471 | case "tool_start": |
| 472 | if (event.toolName === "send_file") { |
| 473 | queueSendFileToolCall(event.toolCallId, event.toolInput); |
| 474 | scrollToBottom(); |
| 475 | showLoadingIndicator(); |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | const toolCard = document.createElement("div"); |
| 480 | toolCard.className = "tool-card running collapsed"; |
| 481 | const safeInput = |
| 482 | typeof event.toolInput === "string" |
no test coverage detected