* Check if auto-resubmit should happen based on tool errors. * Does NOT handle retry count or quota - those are handled by the caller.
(messages: ChatMessage[])
| 70 | * Does NOT handle retry count or quota - those are handled by the caller. |
| 71 | */ |
| 72 | function hasToolErrors(messages: ChatMessage[]): boolean { |
| 73 | const lastMessage = messages[messages.length - 1] |
| 74 | if (!lastMessage || lastMessage.role !== "assistant") { |
| 75 | return false |
| 76 | } |
| 77 | |
| 78 | const toolParts = |
| 79 | (lastMessage.parts as MessagePart[] | undefined)?.filter((part) => |
| 80 | part.type?.startsWith("tool-"), |
| 81 | ) || [] |
| 82 | |
| 83 | if (toolParts.length === 0) { |
| 84 | return false |
| 85 | } |
| 86 | |
| 87 | return toolParts.some((part) => part.state === TOOL_ERROR_STATE) |
| 88 | } |
| 89 | |
| 90 | export default function ChatPanel({ |
| 91 | isVisible, |