Skip to content

Commit 1c1f139

Browse files
committed
creating from outside a chat session
1 parent ed436bc commit 1c1f139

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

src/github/copilotRemoteAgent.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ export namespace SessionIdForPr {
6969

7070
export class CopilotRemoteAgentManager extends Disposable {
7171
async chatParticipantImpl(request: vscode.ChatRequest, context: vscode.ChatContext, stream: vscode.ChatResponseStream, token: vscode.CancellationToken) {
72-
if (context.chatSessionContext?.isUntitled) {
73-
/* Generate new coding agent session from an 'untitled' session */
74-
const { prompt } = request;
75-
const { history } = context;
76-
72+
const startSession = async (prompt: string, history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>, source: string) => {
7773
/* __GDPR__
7874
"copilot.remoteagent.editor.invoke" : {
7975
"promptLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
@@ -84,9 +80,8 @@ export class CopilotRemoteAgentManager extends Disposable {
8480
this.telemetry.sendTelemetryEvent('copilot.remoteagent.editor.invoke', {
8581
promptLength: prompt.length.toString(),
8682
historyLength: history?.length.toString(),
87-
source: 'untitledChatSession',
83+
source,
8884
});
89-
9085
stream.progress(vscode.l10n.t('Delegating to coding agent'));
9186
const result = await this.invokeRemoteAgent(
9287
prompt,
@@ -100,9 +95,17 @@ export class CopilotRemoteAgentManager extends Disposable {
10095
if (result.state !== 'success') {
10196
Logger.error(`Failed to provide new chat session item: ${result.error}`, CopilotRemoteAgentManager.ID);
10297
stream.warning('Failed delegating to coding agent. Please try again later.');
98+
return;
99+
}
100+
return result.number;
101+
}
102+
103+
if (context.chatSessionContext?.isUntitled) {
104+
/* Generate new coding agent session from an 'untitled' session */
105+
const number = await startSession(request.prompt, context.history, 'untitledChatSession');
106+
if (!number) {
103107
return {};
104108
}
105-
const { number } = result;
106109
// Tell UI to the new chat session
107110
this._onDidCommitChatSession.fire({ original: context.chatSessionContext.chatSessionItem, modified: { id: String(number), label: `Pull Request ${number}` } });
108111
} else if (context.chatSessionContext) {
@@ -161,8 +164,27 @@ export class CopilotRemoteAgentManager extends Disposable {
161164
return { errorDetails: { message: error.message } };
162165
}
163166
} else {
164-
/* Not in a chat session */
165-
stream.markdown(vscode.l10n.t('Hello from the Copilot coding agent!'));
167+
/* @copilot invoked from a 'normal' chat */
168+
169+
// TODO(jospicer): Use confirmations to guide users
170+
171+
const number = await startSession(request.prompt, context.history, 'chat'); // TODO(jospicer): 'All of the chat messages so far in the current chat session. Currently, only chat messages for the current participant are included'
172+
if (!number) {
173+
return {};
174+
}
175+
const pullRequest = await this.findPullRequestById(number, true);
176+
if (!pullRequest) {
177+
stream.warning(vscode.l10n.t('Could not find the associated pull request {0} for this chat session.', number));
178+
return {};
179+
}
180+
181+
const uri = await toOpenPullRequestWebviewUri({ owner: pullRequest.remote.owner, repo: pullRequest.remote.repositoryName, pullRequestNumber: pullRequest.number });
182+
const plaintextBody = marked.parse(pullRequest.body, { renderer: new PlainTextRenderer(true), smartypants: true }).trim();
183+
184+
const card = new vscode.ChatResponsePullRequestPart(uri, pullRequest.title, plaintextBody, pullRequest.author.specialDisplayName ?? pullRequest.author.login, `#${pullRequest.number}`);
185+
stream.push(card);
186+
stream.markdown(vscode.l10n.t('GitHub Copilot coding agent has begun working on your request. Follow its progress in the associated chat and pull request.'));
187+
vscode.window.showChatSession(COPILOT_SWE_AGENT, String(number), { viewColumn: vscode.ViewColumn.Active });
166188
}
167189
}
168190

0 commit comments

Comments
 (0)