-
Notifications
You must be signed in to change notification settings - Fork 48
feat: [TBB] add Thinking LSP protocol types and generateTitle request (Thinking Part2) #156
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
Merged
Merged
Changes from 1 commit
Commits
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
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
16 changes: 16 additions & 0 deletions
16
...core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/GenerateThinkingTitleParams.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,16 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.lsp.protocol; | ||
|
|
||
| /** | ||
| * Parameters for the {@code thinking/generateTitle} request. | ||
| * | ||
| * <p>Either {@code thinkingContent} or {@code extractedTitles} should be provided depending on | ||
| * whether parsed section titles are available on the client side. | ||
| * | ||
| * @param thinkingContent the raw thinking content (used when no extracted titles are available) | ||
| * @param extractedTitles previously extracted section titles, may be {@code null} | ||
| */ | ||
| public record GenerateThinkingTitleParams(String thinkingContent, String[] extractedTitles) { | ||
| } |
12 changes: 12 additions & 0 deletions
12
...re/src/com/microsoft/copilot/eclipse/core/lsp/protocol/GenerateThinkingTitleResponse.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,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.lsp.protocol; | ||
|
|
||
| /** | ||
| * Response for the {@code thinking/generateTitle} request. | ||
| * | ||
| * @param title the title returned by the language server | ||
| */ | ||
| public record GenerateThinkingTitleResponse(String title) { | ||
| } |
15 changes: 15 additions & 0 deletions
15
...ft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/Thinking.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,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.lsp.protocol; | ||
|
|
||
| /** | ||
| * Wire-level "thinking" payload streamed from the language server inside ChatProgressValue. Each report carries a | ||
| * delta; callers accumulate the deltas across reports. | ||
| * | ||
| * @param id the (optional) identifier of the thinking block | ||
| * @param text the delta text for this report; callers should treat blank text as "no content" | ||
| * @param encrypted the (optional) encrypted form of the thinking content | ||
| */ | ||
| public record Thinking(String id, String text, String encrypted) { | ||
| } |
84 changes: 84 additions & 0 deletions
84
...eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/ThinkingTypeAdapter.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,84 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.lsp.protocol; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.JsonArray; | ||
| import com.google.gson.JsonElement; | ||
| import com.google.gson.JsonNull; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonPrimitive; | ||
| import com.google.gson.TypeAdapter; | ||
| import com.google.gson.TypeAdapterFactory; | ||
| import com.google.gson.reflect.TypeToken; | ||
| import com.google.gson.stream.JsonReader; | ||
| import com.google.gson.stream.JsonWriter; | ||
|
|
||
| /** | ||
| * TypeAdapter for {@link Thinking} that tolerates the server's mixed wire shape for | ||
| * {@code text}: it may be a string delta (e.g. {@code "text":"The"}) or an array | ||
| * (e.g. {@code "text":[]}) when the report carries only an encrypted payload, or a | ||
| * multi-fragment array of deltas. The array form is concatenated into a single string | ||
| * (or {@code null} when empty) so the rest of the UI treats the report as scalar. | ||
| */ | ||
| public class ThinkingTypeAdapter extends TypeAdapter<Thinking> { | ||
| private final TypeAdapter<Thinking> delegate; | ||
| private final TypeAdapter<JsonElement> elementAdapter; | ||
|
|
||
| /** | ||
| * Construct a new adapter that delegates to the given default adapter after the | ||
| * {@code text} field has been normalized. | ||
| * | ||
| * @param delegate the Gson-generated default adapter for {@link Thinking} | ||
| * @param elementAdapter the adapter used to read the JSON tree | ||
| */ | ||
| public ThinkingTypeAdapter(TypeAdapter<Thinking> delegate, TypeAdapter<JsonElement> elementAdapter) { | ||
| this.delegate = delegate; | ||
| this.elementAdapter = elementAdapter; | ||
| } | ||
|
|
||
| /** TypeAdapterFactory for {@link Thinking}. */ | ||
| public static final class Factory implements TypeAdapterFactory { | ||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) { | ||
| if (typeToken.getRawType() != Thinking.class) { | ||
| return null; | ||
| } | ||
| TypeAdapter<Thinking> defaultAdapter = gson.getDelegateAdapter(this, TypeToken.get(Thinking.class)); | ||
| TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); | ||
| return (TypeAdapter<T>) new ThinkingTypeAdapter(defaultAdapter, elementAdapter); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Thinking read(JsonReader in) throws IOException { | ||
| JsonElement element = elementAdapter.read(in); | ||
| if (element != null && element.isJsonObject()) { | ||
| JsonObject obj = element.getAsJsonObject(); | ||
| JsonElement text = obj.get("text"); | ||
| if (text != null && text.isJsonArray()) { | ||
| obj.add("text", flattenTextArray(text.getAsJsonArray())); | ||
| } | ||
| } | ||
| return delegate.fromJsonTree(element); | ||
| } | ||
|
|
||
| private static JsonElement flattenTextArray(JsonArray arr) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| for (JsonElement e : arr) { | ||
| if (!e.isJsonNull()) { | ||
| sb.append(e.getAsString()); | ||
| } | ||
| } | ||
| return sb.length() == 0 ? JsonNull.INSTANCE : new JsonPrimitive(sb.toString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void write(JsonWriter out, Thinking value) throws IOException { | ||
| delegate.write(out, value); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.