Support Console/Agent "try it" page for SSE streaming - #1499
Support Console/Agent "try it" page for SSE streaming#1499RavinduWeerakoon wants to merge 2 commits into
Conversation
|
Warning Review limit reached
Next review available in: 49 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesAgent streaming chat
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AgentChat
participant fetch
participant readSSEStream
participant parseStreamChunk
AgentChat->>fetch: Send request with abort signal
fetch-->>AgentChat: Return SSE response
AgentChat->>readSSEStream: Read response body
readSSEStream-->>AgentChat: Yield event payload
AgentChat->>parseStreamChunk: Parse payload
parseStreamChunk-->>AgentChat: Return validated chunk
AgentChat->>AgentChat: Append text to assistant message
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
console/workspaces/pages/test/src/AgentTest/utils/sse.ts (2)
44-67: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winHandle CRLF event delimiters.
The event boundary search matches only
"\n\n". The SSE specification also allows"\r\n\r\n"and"\r\r". If the agent gateway emits CRLF line endings, no boundary is found during streaming. All events are then flushed as one merged payload at line 61, andparseStreamChunkreturns null for it. Normalize line endings before the boundary search.♻️ Proposed fix to normalize line endings
- buffer += decoder.decode(value, { stream: true }); + buffer += decoder.decode(value, { stream: true }).replace(/\r\n?/g, "\n"); let boundary = buffer.indexOf("\n\n");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@console/workspaces/pages/test/src/AgentTest/utils/sse.ts` around lines 44 - 67, Update the SSE parsing loop around buffer and boundary to normalize CRLF and CR line endings to LF before searching for event delimiters. Ensure "\r\n\r\n" and "\r\r" are recognized as "\n\n", while preserving the existing extractDataField and trailing-event handling.
89-106: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winValidate the elements of
content.
parseStreamChunkchecks only thatcontentis an array. A payload such as{"node":"answer","content":[null]}passes validation. The consumer inAgentChat.tsxthen readspart.type, which throws aTypeError. The catch block converts that into an error alert instead of the format hint. Validate that each element is an object.♻️ Proposed fix to validate content elements
if ( parsed && typeof parsed === "object" && typeof parsed.node === "string" && - Array.isArray(parsed.content) + Array.isArray(parsed.content) && + parsed.content.every( + (part: unknown) => typeof part === "object" && part !== null, + ) ) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@console/workspaces/pages/test/src/AgentTest/utils/sse.ts` around lines 89 - 106, Update parseStreamChunk to validate every element of parsed.content as a non-null object before returning the StreamChunk; reject the payload with null or non-object elements by returning null, while preserving the existing node and array checks.console/workspaces/pages/test/src/AgentTest/AgentChat.tsx (1)
85-86: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winAbort the active request on unmount.
abortControllerRefis aborted only by the Stop button. If the user navigates away during a stream, the fetch and the reader loop continue, andhandleStreamingResponsekeeps callingsetMessageson an unmounted component. Add a cleanup effect that aborts the controller.♻️ Proposed cleanup effect
const [isStreaming, setIsStreaming] = useState(false); const abortControllerRef = useRef<AbortController | null>(null); + + useEffect(() => { + return () => abortControllerRef.current?.abort(); + }, []);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@console/workspaces/pages/test/src/AgentTest/AgentChat.tsx` around lines 85 - 86, In the AgentChat component, add an unmount cleanup effect that checks abortControllerRef and aborts the active AbortController when the component is removed. Keep the existing Stop-button behavior unchanged and ensure the cleanup prevents the streaming request and reader loop from continuing after unmount.console/workspaces/pages/test/src/AgentTest/AgentChat.test.tsx (1)
88-91: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRestore stubbed globals after each test.
Each test replaces the global
fetchwithvi.stubGlobal. No test restores it. AddafterEach(() => vi.unstubAllGlobals())so a stub cannot leak into later tests in this file.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@console/workspaces/pages/test/src/AgentTest/AgentChat.test.tsx` around lines 88 - 91, Add an afterEach cleanup alongside the existing beforeEach in AgentChat tests to call vi.unstubAllGlobals(), ensuring fetch and any other stubbed globals are restored after every test while preserving the current mock reset behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@console/workspaces/pages/test/src/AgentTest/AgentChat.test.tsx`:
- Around line 256-258: Update the hint assertion in the AgentChat test to match
the actual streaming text configured by AgentChat.tsx, including the SSE data
structure after “Expected an SSE data:”. Remove the incorrect “line” substring
while preserving the case-insensitive waitFor assertion.
In `@console/workspaces/pages/test/src/AgentTest/AgentChat.tsx`:
- Around line 329-332: Update the fallback branch of the responseText assignment
in AgentChat so it serializes the full responseData object rather than
responseData.result, preserving the existing formatting and hint suffix. Keep
the response string path unchanged.
---
Nitpick comments:
In `@console/workspaces/pages/test/src/AgentTest/AgentChat.test.tsx`:
- Around line 88-91: Add an afterEach cleanup alongside the existing beforeEach
in AgentChat tests to call vi.unstubAllGlobals(), ensuring fetch and any other
stubbed globals are restored after every test while preserving the current mock
reset behavior.
In `@console/workspaces/pages/test/src/AgentTest/AgentChat.tsx`:
- Around line 85-86: In the AgentChat component, add an unmount cleanup effect
that checks abortControllerRef and aborts the active AbortController when the
component is removed. Keep the existing Stop-button behavior unchanged and
ensure the cleanup prevents the streaming request and reader loop from
continuing after unmount.
In `@console/workspaces/pages/test/src/AgentTest/utils/sse.ts`:
- Around line 44-67: Update the SSE parsing loop around buffer and boundary to
normalize CRLF and CR line endings to LF before searching for event delimiters.
Ensure "\r\n\r\n" and "\r\r" are recognized as "\n\n", while preserving the
existing extractDataField and trailing-event handling.
- Around line 89-106: Update parseStreamChunk to validate every element of
parsed.content as a non-null object before returning the StreamChunk; reject the
payload with null or non-object elements by returning null, while preserving the
existing node and array checks.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e3ad5d5d-bca6-4f3a-a15f-492994320e1a
📒 Files selected for processing (4)
console/workspaces/pages/test/src/AgentTest/AgentChat.test.tsxconsole/workspaces/pages/test/src/AgentTest/AgentChat.tsxconsole/workspaces/pages/test/src/AgentTest/utils/sse.test.tsconsole/workspaces/pages/test/src/AgentTest/utils/sse.ts
| @@ -0,0 +1,263 @@ | |||
| /** | |||
| * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). | |||
There was a problem hiding this comment.
Fix in the other files as well.
Purpose
The current console "Try it" page does not support interaction with SSE streaming agents. Although the response content is received successfully by the frontend the UI does not display or render the streaming output correctly. This PR tries to resolve that issue
Goals
Approach
Screen.Recording.2026-08-05.at.10.42.06.mov
when recieved response is different from the expected one
User stories
Release note
Documentation
Training
Certification
Marketing
Automation tests
Security checks
Samples
Related PRs
Migrations (if applicable)
Test environment
Learning
Fixes #1446
Summary by CodeRabbit
New Features
Bug Fixes