Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ui/src/conversation-panel/core/aggregators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ const GROUP = (prev: Partial<ChatContent> = {}, chunk: Partial<ChatContent>) =>
extra: chunk.extra ?? prev.extra,
}
}

const HTML = (prev: Partial<ChatContent> = {}, chunk: Partial<ChatContent>) => {
return {
type: 'HTML',
id: chunk.id ?? prev.id,
content: (prev.content || '') + (chunk.content || ''),
workflowRunId: chunk.workflowRunId ?? prev.workflowRunId,
extra: chunk.extra ?? prev.extra,
}
}
export const aggregators = {
TEXT,
REASONING,
Expand All @@ -111,4 +119,5 @@ export const aggregators = {
FORM,
PROGRESS,
GROUP,
HTML
} as Record<string, ContentAggregator>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are my findings on this diff:

Issues / Potential Problems

  1. Type/Behavior duplication with TEXT

    • The new HTML aggregator is functionally identical to TEXT (string concatenation). If HTML chunks ever need special handling (e.g., tag balancing, <script> sanitization, or streaming partial tags), this will silently misbehave. At minimum, add a comment clarifying the intended difference from TEXT.
  2. No HTML sanitization

    • Since this produces raw HTML displayed downstream, ensure consumers render it through a sanitizer (DOMPurify or equivalent) to prevent XSS, especially since LLM output is untrusted. Just concatenating is safe at this layer, but the contract should be documented.
  3. Inconsistent ?? prev pattern

    • chunk.id ?? prev.id and chunk.workflowRunId ?? prev.workflowRunId follow the existing convention in GROUP, so consistent — OK. But note content uses || semantics (falsy fallback) while others use ??. That matches TEXT, so acceptable; just be aware empty-string vs undefined ordering.
  4. Missing trailing comma

    • HTML in aggregators lacks a trailing comma; inconsistent style with the rest of the object. Minor.
  5. Repeated boilerplate

    • The six aggregators (TEXT, REASONING, HTML, etc.) now share nearly identical merge logic. Consider extracting a concatAggregator(type) factory:
      const concatAggregator = (type: string): ContentAggregator =>
        (prev = {}, chunk = {}) => ({
          type,
          id: chunk.id ?? prev.id,
          content: (prev.content || '') + (chunk.content || ''),
          workflowRunId: chunk.workflowRunId ?? prev.workflowRunId,
          extra: chunk.extra ?? prev.extra,
        })
      Then const HTML = concatAggregator('HTML'). Reduces drift when fields change.
  6. No test coverage shown

    • Add a unit test verifying: first chunk builds state, subsequent chunks append, missing fields fall back correctly, and an unknown/garbage chunk doesn't corrupt state.
  7. Type safety on aggregators

    • as Record<string, ContentAggregator> casts away key specificity. Prefer satisfies Record<string, ContentAggregator> (TS 4.9+) or an explicit interface so misspelled keys like 'Html' are caught.

Minor

  • Diff header context (@@ ... @@) shows odd characters (,-, +const ) that appear corrupted in paste — verify the patch applies cleanly in your tooling.
  • Confirm consumers dispatch on chunk type 'HTML' case-sensitively everywhere; mismatched casing would bypass this aggregator and drop chunks.

Loading