Skip to content

Commit 41b1757

Browse files
authored
add additional metadata for thinking parts (#1395)
* add additional metadata for thinking parts * fix some comments, rename * cleanup
1 parent 61077cc commit 41b1757

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/extension/conversation/vscode-node/languageModelAccess.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,19 @@ export class CopilotLanguageModelWrapper extends Disposable {
448448
}
449449

450450
async provideLanguageModelResponse(endpoint: IChatEndpoint, messages: Array<vscode.LanguageModelChatMessage | vscode.LanguageModelChatMessage2>, options: vscode.ProvideLanguageModelChatResponseOptions, extensionId: string, progress: vscode.Progress<LMResponsePart>, token: vscode.CancellationToken): Promise<any> {
451+
let thinkingActive = false;
451452
const finishCallback: FinishedCallback = async (_text, index, delta): Promise<undefined> => {
453+
if (delta.thinking) {
454+
// Show thinking progress for unencrypted thinking deltas
455+
if (!isEncryptedThinkingDelta(delta.thinking)) {
456+
const text = delta.thinking.text ?? '';
457+
progress.report(new vscode.LanguageModelThinkingPart(text, delta.thinking.id, delta.thinking.metadata));
458+
thinkingActive = true;
459+
}
460+
} else if (thinkingActive) {
461+
progress.report(new vscode.LanguageModelThinkingPart('', '', { vscode_reasoning_done: true }));
462+
thinkingActive = false;
463+
}
452464
if (delta.text) {
453465
progress.report(new vscode.LanguageModelTextPart(delta.text));
454466
}
@@ -463,13 +475,6 @@ export class CopilotLanguageModelWrapper extends Disposable {
463475
}
464476
}
465477
}
466-
if (delta.thinking) {
467-
// Show thinking progress for unencrypted thinking deltas
468-
if (!isEncryptedThinkingDelta(delta.thinking)) {
469-
const text = delta.thinking.text ?? '';
470-
progress.report(new vscode.LanguageModelThinkingPart(text, delta.thinking.id, delta.thinking.metadata));
471-
}
472-
}
473478

474479
if (delta.statefulMarker) {
475480
progress.report(

src/extension/prompt/node/pseudoStartStopConversationCallback.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class PseudoStopStartResponseProcessor implements IResponseProcessor {
2727
private stagedDeltasToApply: IResponseDelta[] = [];
2828
private currentStartStop: StartStopMapping | undefined = undefined;
2929
private nonReportedDeltas: IResponseDelta[] = [];
30+
private thinkingActive: boolean = false;
3031

3132
constructor(
3233
private readonly stopStartMappings: readonly StartStopMapping[],
@@ -47,6 +48,17 @@ export class PseudoStopStartResponseProcessor implements IResponseProcessor {
4748
}
4849

4950
protected applyDeltaToProgress(delta: IResponseDelta, progress: ChatResponseStream) {
51+
if (delta.thinking) {
52+
// Don't send parts that are only encrypted content
53+
if (!isEncryptedThinkingDelta(delta.thinking) || delta.thinking.text) {
54+
progress.thinkingProgress(delta.thinking);
55+
this.thinkingActive = true;
56+
}
57+
} else if (this.thinkingActive) {
58+
progress.thinkingProgress({ id: '', text: '', metadata: { vscode_reasoning_done: true } });
59+
this.thinkingActive = false;
60+
}
61+
5062
reportCitations(delta, progress);
5163

5264
const vulnerabilities: ChatVulnerability[] | undefined = delta.codeVulnAnnotations?.map(a => ({ title: a.details.type, description: a.details.description }));
@@ -59,13 +71,6 @@ export class PseudoStopStartResponseProcessor implements IResponseProcessor {
5971
if (delta.beginToolCalls?.length) {
6072
progress.prepareToolInvocation(getContributedToolName(delta.beginToolCalls[0].name));
6173
}
62-
63-
if (delta.thinking) {
64-
// Don't send parts that are only encrypted content
65-
if (!isEncryptedThinkingDelta(delta.thinking) || delta.thinking.text) {
66-
progress.thinkingProgress(delta.thinking);
67-
}
68-
}
6974
}
7075

7176
/**
@@ -155,6 +160,7 @@ export class PseudoStopStartResponseProcessor implements IResponseProcessor {
155160
this.stagedDeltasToApply = [];
156161
this.currentStartStop = undefined;
157162
this.nonReportedDeltas = [];
163+
this.thinkingActive = false;
158164
if (delta.retryReason === 'network_error') {
159165
progress.clearToPreviousToolInvocation(ChatResponseClearToPreviousToolInvocationReason.NoReason);
160166
} else if (delta.retryReason === FilterReason.Copyright) {

0 commit comments

Comments
 (0)