-
Notifications
You must be signed in to change notification settings - Fork 8
feat: [TBB] render streaming thinking blocks in chat turns (Thinking Part 3) #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ethanyhou
wants to merge
5
commits into
main
Choose a base branch
from
ethan/thinking-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e7fbefd
feat: add Thinking LSP protocol types and generateTitle request
ethanyhou f7e9bd0
feat: render streaming thinking blocks in chat turns
ethanyhou bca812e
Merge branch 'main' into ethan/thinking-ui
ethanyhou a20bb35
Address comments.
ethanyhou d1f1c74
Address comments.
ethanyhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...lot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/ThinkingBlockParseTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.ui.chat; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Unit tests for the private static parsing helpers in {@link ThinkingBlock}: {@code stripTrailingNewlines} and | ||
| * {@code parseSections}. Exercises the helpers via reflection so the production visibility stays untouched. | ||
| * | ||
| * <p>Primary goal: guard CRLF handling so a {@code \r\n}-terminated body or title boundary does not leak a stray | ||
| * {@code \r} into the rendered text. | ||
| */ | ||
| class ThinkingBlockParseTest { | ||
|
|
||
| @Test | ||
| void stripTrailingNewlines_stripsLfCrAndCrlf() throws Exception { | ||
| assertEquals("body", invokeStripTrailingNewlines("body\n")); | ||
| assertEquals("body", invokeStripTrailingNewlines("body\r")); | ||
| assertEquals("body", invokeStripTrailingNewlines("body\r\n")); | ||
| assertEquals("body", invokeStripTrailingNewlines("body\r\n\r\n")); | ||
| assertEquals("body", invokeStripTrailingNewlines("body\n\r\n")); | ||
| assertEquals("body", invokeStripTrailingNewlines("body")); | ||
| assertEquals("", invokeStripTrailingNewlines("")); | ||
| assertEquals("", invokeStripTrailingNewlines("\r\n\r\n")); | ||
| // Internal newlines and leading whitespace must survive untouched. | ||
| assertEquals(" code\n more", invokeStripTrailingNewlines(" code\n more\r\n")); | ||
| } | ||
|
|
||
| @Test | ||
| void parseSections_handlesCrlfTitleBoundary() throws Exception { | ||
| String raw = "intro body\r\n**Plan**\r\nplan body\r\n**Next**\r\nnext body\r\n"; | ||
| List<?> sections = invokeParseSections(raw); | ||
| assertEquals(3, sections.size()); | ||
|
|
||
| assertNull(title(sections.get(0))); | ||
| assertEquals("intro body", body(sections.get(0))); | ||
|
|
||
| assertEquals("Plan", title(sections.get(1))); | ||
| assertEquals("plan body", body(sections.get(1))); | ||
|
|
||
| assertEquals("Next", title(sections.get(2))); | ||
| assertEquals("next body", body(sections.get(2))); | ||
| } | ||
|
|
||
| @Test | ||
| void parseSections_handlesLfOnlyTitleBoundary() throws Exception { | ||
| // Existing LF behavior must remain unchanged. | ||
| String raw = "intro\n**Plan**\nplan body"; | ||
| List<?> sections = invokeParseSections(raw); | ||
| assertEquals(2, sections.size()); | ||
| assertNull(title(sections.get(0))); | ||
| assertEquals("intro", body(sections.get(0))); | ||
| assertEquals("Plan", title(sections.get(1))); | ||
| assertEquals("plan body", body(sections.get(1))); | ||
| } | ||
|
|
||
| private static String invokeStripTrailingNewlines(String input) throws Exception { | ||
| Method m = ThinkingBlock.class.getDeclaredMethod("stripTrailingNewlines", String.class); | ||
| m.setAccessible(true); | ||
| return (String) m.invoke(null, input); | ||
| } | ||
|
|
||
| private static List<?> invokeParseSections(String raw) throws Exception { | ||
| Method m = ThinkingBlock.class.getDeclaredMethod("parseSections", String.class); | ||
| m.setAccessible(true); | ||
| return (List<?>) m.invoke(null, raw); | ||
| } | ||
|
|
||
| private static String title(Object parsedSection) throws Exception { | ||
| Method m = parsedSection.getClass().getDeclaredMethod("title"); | ||
| m.setAccessible(true); | ||
| return (String) m.invoke(parsedSection); | ||
| } | ||
|
|
||
| private static String body(Object parsedSection) throws Exception { | ||
| Method m = parsedSection.getClass().getDeclaredMethod("body"); | ||
| m.setAccessible(true); | ||
| return (String) m.invoke(parsedSection); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q:
the thinking will be sealed when
WorkDoneProgressKind.endcomes, why do we need this logic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the mid-turn seal to kick off the title fetch and prevent subsequent thinking stream from being appended to the same block (a new block will be opened instead).
The
WorkDoneProgressKind.endseal is a safety net for turns where the mid-turn seal never fired(ex. the model only produced thinking with no renderable output), so the block doesn't stay spinning forever.