Aspire와 github copilot 같이 쓰기

aspire 대시보드에 copilot 기능이 들어가 있군요.
vscode나 visual studio가 아니어도 copilot을 사용할 수 있는 방법이 존재하는 걸로 보입니다. :grinning_face:

개인적으로 운영 서비스에 코파일럿 붙이면 좋겠다고 생각하고 있었는데 어쩌면 가능할지도

3 Likes

아래는 깃허브 웹에서 코파일럿으로 저장소 코드 분석을 요청하여 작성한 문서입니다. aspire 대시보드의 코파일럿 기능은 비공개 api를 사용하고 디버거가 있어야 동작한다는군요.


.NET Aspire 대시보드의 GitHub Copilot 통합 방식

:pushpin: 개요

.NET Aspire 대시보드는 GitHub Copilot을 두 가지 방식으로 통합하고 있습니다:

  1. 대시보드 내장 Copilot 채팅: GHCP(GitHub Copilot Platform)를 통한 직접 통합
  2. 외부 Copilot에서 대시보드 접근: MCP(Model Context Protocol)를 통한 도구 제공

:bullseye: 방식 1: 대시보드 → Copilot (GHCP 사용)

핵심 원리

대시보드에 내장된 Copilot 채팅창은 **GHCP(GitHub Copilot Platform)**라는 비공개 엔드포인트를 사용합니다.

연결 구조

Aspire Dashboard
  ↓ (Debug Session Token 사용)
VS Code / Visual Studio (디버그 세션)
  ↓ (내부 GitHub Copilot 인증)
GHCP Endpoint (/v1, /ghcp_info)
  ↓
OpenAI GPT-4o / GPT-4o-mini

핵심 코드

1. ChatClientFactory 초기화

// src/Aspire.Dashboard/Model/Assistant/ChatClientFactory.cs

private void InitializeClientConfiguration(out Uri endpoint, out string credential, out HttpClient httpClient)
{
    // VS Code/Visual Studio 디버그 세션에서 정보 가져오기
    if (!DebugSessionHelpers.HasDebugSession(Options.DebugSession, 
        out var serverCert, out var debugSessionUri, out var token))
    {
        throw new InvalidOperationException("Debug session port is not set.");
    }

    credential = token;  // 디버그 세션 토큰 사용
    
    var uriBuilder = new UriBuilder(debugSessionUri);
    uriBuilder.Path = "/v1";  // GHCP 엔드포인트
    endpoint = uriBuilder.Uri;

    httpClient = DebugSessionHelpers.CreateHttpClient(
        debugSessionUri: null, 
        token: null, 
        cert: serverCert, 
        createHandler: null
    );
}

2. GHCP 정보 조회

public async Task<GhcpInfoResponse> GetInfoAsync(CancellationToken cancellationToken)
{
    EnsureInitialized();

    var ghcpInfoAddress = new Uri(_endpoint, "/ghcp_info");
    
    using var httpRequest = new HttpRequestMessage(HttpMethod.Get, ghcpInfoAddress);
    httpRequest.Headers.Add("Authorization", "Bearer " + _credential);

    using var httpResponse = await _httpClient.SendAsync(httpRequest, cancellationToken);
    httpResponse.EnsureSuccessStatusCode();

    var response = await httpResponse.Content.ReadFromJsonAsync<GhcpInfoResponse>(cancellationToken);
    
    // response.Models에 사용 가능한 모델 목록 포함 (gpt-4o, gpt-4o-mini 등)
    return response;
}

3. OpenAI 호환 클라이언트 생성

public IChatClient CreateClient(string model)
{
    EnsureInitialized();

    // OpenAI SDK를 사용하지만 GHCP 엔드포인트로 요청
    var innerChatClient = new OpenAI.Chat.ChatClient(
        model.ToLower(CultureInfo.InvariantCulture),
        new ApiKeyCredential(_credential),
        new()
        {
            Endpoint = _endpoint,  // GHCP 엔드포인트 (예: https://localhost:xxxxx/v1)
            Transport = new HttpClientPipelineTransport(_httpClient)
        }
    ).AsIChatClient();

    return new ChatClientBuilder(innerChatClient)
        .UseFunctionInvocation(_loggerFactory, options => options.AllowConcurrentInvocation = true)
        .UseLogging(_loggerFactory)
        .Build();
}

활성화 조건

public bool IsEnabled()
{
    // 디버그 세션이 없으면 비활성화
    if (!DebugSessionHelpers.HasDebugSession(_dashboardOptions.CurrentValue.DebugSession, 
        out _, out _, out _))
    {
        _logger.LogInformation("AI is disabled because there isn't a debug session.");
        return false;
    }

    return true;
}

주요 특징

  • :white_check_mark: 공개 API 불필요: VS Code/Visual Studio가 프록시 역할
  • :white_check_mark: OpenAI 호환: OpenAI SDK를 그대로 사용 가능
  • :white_check_mark: 자동 인증: 디버그 세션 토큰으로 자동 인증
  • :cross_mark: 디버그 세션 필수: CLI에서 실행 시 사용 불가