fix(webui): improve groupContent error detection logic

- Only treat as error when error field is set OR type is 'error' with content
- This avoids false positives from empty error markers
- While not missing real errors that only have type='error' with text
This commit is contained in:
yiliang114 2026-01-16 01:05:13 +08:00
parent e81cdbbcb1
commit c44a60f9f9

View file

@ -154,8 +154,10 @@ export const shouldShowToolCall = (kind: string): boolean =>
/**
* Group tool call content by type to avoid duplicate labels
* Note: Only treats content as error if contentObj.type === 'error'
* or if contentObj.error is explicitly set (not null/undefined)
* Error detection logic:
* - If contentObj.error is set (not null/undefined), treat as error
* - If contentObj.type === 'error' AND has content (text or error), treat as error
* This avoids false positives from empty error markers while not missing real errors
*/
export const groupContent = (content?: ToolCallContent[]): GroupedContent => {
const textOutputs: string[] = [];
@ -169,9 +171,14 @@ export const groupContent = (content?: ToolCallContent[]): GroupedContent => {
} else if (item.content) {
const contentObj = item.content;
// Only treat as error if type is explicitly 'error'
// or if error field has a truthy value (not null/undefined)
const hasError = contentObj.type === 'error' || contentObj.error != null;
// Determine if this is an error:
// 1. error field is explicitly set (not null/undefined)
// 2. type is 'error' AND has actual content (text or error field)
const hasErrorField = contentObj.error != null;
const isErrorType =
contentObj.type === 'error' &&
(contentObj.text != null || contentObj.error != null);
const hasError = hasErrorField || isErrorType;
if (hasError) {
let errorMsg = '';