Fix customization marketplace sign-in by pwang347 · Pull Request #341648 · microsoft/vscode · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/vs/platform/agentHost/node/copilot/copilotAgent.ts
29 changes: 28 additions & 1 deletion src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isObject, isStringArray } from '../../../../base/common/types.js';
import { StopWatch } from '../../../../base/common/stopwatch.js';
import { URI } from '../../../../base/common/uri.js';
import { generateUuid } from '../../../../base/common/uuid.js';
import { localize } from '../../../../nls.js';
import { IFileService } from '../../../files/common/files.js';
import { ILogService, LogLevel } from '../../../log/common/log.js';
import { AgentSession } from '../../common/agent.js';
Expand Down Expand Up @@ -794,7 +795,7 @@ export class CopilotSessionLauncher implements ICopilotSessionLauncher {
@IAgentHostSessionOpenTelemetry private readonly _sessionOpenTelemetry: IAgentHostSessionOpenTelemetry,
) { }

async createCustomizationPolicySession(client: CopilotClient, sessionId: string, workingDirectory: string, githubCredentials: CopilotGitHubSessionCredentials): Promise<CopilotSession> {
async createCustomizationPolicySession(client: CopilotClient, sessionId: string, workingDirectory: string, githubCredentials: CopilotGitHubSessionCredentials, githubHostUri: string): Promise<CopilotSession> {
const discovered = await client.rpc.mcp.discover({
workingDirectory,
includeEffectiveSource: false,
Expand Down Expand Up @@ -834,6 +835,32 @@ export class CopilotSessionLauncher implements ICopilotSessionLauncher {
},
...githubCredentials.sdkSessionOptions,
});
try {
const token = githubCredentials.token;
if (token) {
const result = await session.rpc.gitHubAuth.setCredentials({
credentials: { type: 'token', host: githubHostUri, token },
});
if (!result.success) {
throw new Error(localize('copilot.customizationPolicyAuthenticationFailed', "The customization policy session could not apply GitHub authentication."));
}
if (result.copilotUserResolved === false) {
this._logService.warn(`[Copilot] Hidden customization policy session ${session.sessionId} applied GitHub credentials without resolved Copilot user metadata`);
}
}
} catch (error) {
try {
await session.disconnect();
} catch (cleanupError) {
this._logService.debug(`[Copilot] Failed to disconnect customization policy session after authentication setup failed: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`);
}
try {
await client.deleteSession(session.sessionId);
} catch (cleanupError) {
this._logService.debug(`[Copilot] Failed to delete customization policy session after authentication setup failed: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`);
}
throw error;
}
this._logService.info('[Copilot] Created hidden customization policy session');
return session;
}
Expand Down
172 changes: 167 additions & 5 deletions src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts
Loading