Skip to content

Commit 944772e

Browse files
committed
fix forwarding context to startSession()
1 parent 46258c8 commit 944772e

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/github/copilotRemoteAgent.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,36 @@ export namespace SessionIdForPr {
7171
}
7272
}
7373

74+
type ConfirmationResult = { step: string; accepted: boolean; metadata?: CreatePromptMetadata /* | SomeOtherMetadata */ };
75+
76+
interface CreatePromptMetadata {
77+
prompt: string;
78+
history?: string;
79+
references?: ChatPromptReference[];
80+
}
81+
7482
export class CopilotRemoteAgentManager extends Disposable {
7583
async chatParticipantImpl(request: vscode.ChatRequest, context: vscode.ChatContext, stream: vscode.ChatResponseStream, token: vscode.CancellationToken) {
76-
const startSession = async (source: string) => {
84+
const startSession = async (source: string, prompt: string, history?: string, references?: readonly vscode.ChatPromptReference[]) => {
7785
/* __GDPR__
7886
"copilot.remoteagent.editor.invoke" : {
7987
"promptLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
8088
"historyLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
81-
"promptSummaryLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
82-
"historySummaryLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
89+
"referencesCount" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
8390
"source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
8491
}
8592
*/
86-
const prompt = request.prompt;
87-
const history = context.history;
88-
const promptSummary = context.chatSummary?.prompt;
89-
const historySummary = context.chatSummary?.history;
9093
this.telemetry.sendTelemetryEvent('copilot.remoteagent.editor.invoke', {
91-
promptLength: prompt.length.toString(),
92-
historyLength: history?.length.toString(),
93-
promptSummaryLength: promptSummary?.length.toString() || '0',
94-
historySummaryLength: historySummary?.length.toString() || '0',
94+
promptLength: prompt.length.toString() ?? '0',
95+
historyLength: history?.length.toString() ?? '0',
96+
referencesCount: references?.length.toString() ?? '0',
9597
source,
9698
});
9799
const result = await this.invokeRemoteAgent(
98-
promptSummary || prompt,
100+
prompt,
99101
[
100-
this.extractFileReferences(request.references),
101-
historySummary || await this.extractHistory(history)
102+
this.extractFileReferences(references),
103+
history
102104
].join('\n\n').trim(),
103105
token,
104106
false,
@@ -113,17 +115,18 @@ export class CopilotRemoteAgentManager extends Disposable {
113115
};
114116

115117
const handleConfirmationData = async () => {
116-
const results: Array<{ step: string; accepted: boolean }> = [];
117-
results.push(...(request.acceptedConfirmationData?.map(data => ({ step: data.step, accepted: true })) ?? []));
118-
results.push(...((request.rejectedConfirmationData ?? []).filter(data => !results.some(r => r.step === data.step)).map(data => ({ step: data.step, accepted: false }))));
118+
const results: ConfirmationResult[] = [];
119+
results.push(...(request.acceptedConfirmationData?.map(data => ({ step: data.step, accepted: true, metadata: data?.metadata })) ?? []));
120+
results.push(...((request.rejectedConfirmationData ?? []).filter(data => !results.some(r => r.step === data.step)).map(data => ({ step: data.step, accepted: false, metadata: data?.metadata }))));
119121
for (const data of results) {
120122
switch (data.step) {
121123
case 'create':
122124
if (!data.accepted) {
123125
stream.markdown(vscode.l10n.t('Coding agent request cancelled.'));
124126
return {};
125127
}
126-
const number = await startSession('chat');
128+
const { prompt, history, references } = data.metadata as CreatePromptMetadata;
129+
const number = await startSession('chat', prompt, history, references);
127130
if (!number) {
128131
return {};
129132
}
@@ -153,7 +156,12 @@ export class CopilotRemoteAgentManager extends Disposable {
153156

154157
if (context.chatSessionContext?.isUntitled) {
155158
/* Generate new coding agent session from an 'untitled' session */
156-
const number = await startSession('untitledChatSession');
159+
const number = await startSession(
160+
'untitledChatSession',
161+
context.chatSummary?.prompt ?? request.prompt,
162+
context.chatSummary?.history,
163+
request.references
164+
);
157165
if (!number) {
158166
return {};
159167
}
@@ -215,15 +223,20 @@ export class CopilotRemoteAgentManager extends Disposable {
215223
return { errorDetails: { message: error.message } };
216224
}
217225
} else {
218-
/* @copilot invoked from a 'normal' chat */
219-
226+
/* @copilot invoked from a 'normal' chat or 'cloud button' */
220227
stream.confirmation(
221228
vscode.l10n.t('Delegate to coding agent'),
222229
DELEGATE_MODAL_DETAILS,
223-
{ step: 'create' },
230+
{
231+
step: 'create',
232+
metadata: {
233+
prompt: context.chatSummary?.prompt ?? request.prompt,
234+
history: context.chatSummary?.history,
235+
references: request.references,
236+
}
237+
},
224238
['Delegate', 'Cancel']
225239
);
226-
227240
}
228241
}
229242

0 commit comments

Comments
 (0)