Thanks to visit codestin.com
Credit goes to docs.github.com

Skip to main content

원격 세션

원격 세션을 사용하면 사용자가 사용 제어 통해 GitHub 웹 및 모바일에서 Copilot 세션에 액세스할 수 있습니다. 사용하도록 설정하면 SDK는 각 세션을 Mission Control에 연결하여 링크 또는 QR 코드로 공유할 수 있는 URL을 생성합니다.

GitHub 호스팅 컴퓨팅에서 세션을 실행하려면 클라우드 세션 참조하세요.

사전 요구 사항

  • 사용자가 인증되어야 합니다(GitHub 토큰 또는 로그인한 사용자).
  • 세션의 작업 디렉터리는 GitHub 리포지토리여야 합니다.

원격 세션 활성화

항상 켜짐(클라이언트 수준)

클라이언트를 만들 때 설정합니다 remote: true . GitHub 리포지토리의 모든 세션은 자동으로 원격 URL을 가져옵니다.

TypeScript

import { CopilotClient } from "@github/copilot-sdk";

const client = new CopilotClient({ remote: true });
const session = await client.createSession({
  workingDirectory: "/path/to/github-repo",
  onPermissionRequest: async () => ({ allowed: true }),
});

session.on("session.info", (event) => {
  if (event.data.infoType === "remote") {
    console.log("Remote URL:", event.data.url);
  }
});

Python

from copilot import CopilotClient

client = CopilotClient(enable_remote_sessions=True)
session = await client.create_session(
    working_directory="/path/to/github-repo",
    on_permission_request=lambda req: {"allowed": True},
)

def on_event(event):
    if event.type == "session.info" and event.data.info_type == "remote":
        print(f"Remote URL: {event.data.url}")

session.on(on_event)

Go

client, _ := copilot.NewClient(&copilot.ClientOptions{Remote: true})
session, _ := client.CreateSession(ctx, &copilot.SessionConfig{
    WorkingDirectory: "/path/to/github-repo",
    OnPermissionRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (rpc.PermissionDecision, error) {
        return &rpc.PermissionDecisionApproveOnce{}, nil
    },
})

session.On(func(event copilot.SessionEvent) {
    if event.Type == "session.info" {
        // Check infoType and extract URL
    }
})

C#

var client = new CopilotClient(new CopilotClientOptions { Remote = true });
var session = await client.CreateSessionAsync(new SessionConfig
{
    WorkingDirectory = "/path/to/github-repo",
    OnPermissionRequest = (req, inv) =>
        Task.FromResult(PermissionDecision.ApproveOnce()),
});

session.On((SessionEvent e) =>
{
    if (e is SessionInfoEvent info && info.Data.InfoType == "remote")
    {
        Console.WriteLine($"Remote URL: {info.Data.Url}");
    }
});

러스트

use github_copilot_sdk::{Client, ClientOptions, SessionConfig};
use github_copilot_sdk::handler::PermissionResult;

let client = Client::start(
    ClientOptions::new().with_enable_remote_sessions(true)
).await?;
let session = client.create_session(
    SessionConfig::new("/path/to/github-repo")
        .with_permission_handler(|_req, _inv| async {
            Ok(PermissionResult::approve_once())
        }),
).await?;

let mut events = session.subscribe();
while let Ok(event) = events.recv().await {
    if event.event_type == "session.info" {
        // Check info_type and extract URL
    }
}

필요 시(세션별로 전환)

세션 session.rpc.remote.enable() 중간에 원격 액세스를 시작하고 중지하는 데 사용합니다session.rpc.remote.disable(). 이는 CLI의 /remote on/remote off 명령과 동일합니다.

TypeScript

const result = await session.rpc.remote.enable();
console.log("Remote URL:", result.url);

// Later: stop sharing
await session.rpc.remote.disable();

Python

result = await session.rpc.remote.enable()
print(f"Remote URL: {result.url}")

# Later: stop sharing
await session.rpc.remote.disable()

Go

result, err := session.RPC.Remote.Enable(ctx)
if result.URL != nil {
    fmt.Println("Remote URL:", *result.URL)
}

// Later: stop sharing
err = session.RPC.Remote.Disable(ctx)

C#

var result = await session.Rpc.Remote.EnableAsync();
Console.WriteLine($"Remote URL: {result.Url}");

// Later: stop sharing
await session.Rpc.Remote.DisableAsync();

러스트

let result = session.rpc().remote().enable().await?;
if let Some(url) = &result.url {
    println!("Remote URL: {url}");
}

// Later: stop sharing
session.rpc().remote().disable().await?;

QR 코드 생성

간편한 모바일 액세스를 위해 원격 URL을 QR 코드로 렌더링할 수 있습니다. SDK는 URL을 제공합니다. 기본 QR 코드 라이브러리를 사용합니다.

비고

  • remote 클라이언트 옵션은 SDK가 CLI 프로세스를 생성하는 경우에만 적용됩니다. 를 통해 cliUrl외부 서버에 연결할 때 무시됩니다.
  • 작업 디렉터리가 GitHub 리포지토리가 아닌 경우 원격 설정을 자동으로 건너뛰거나(상시 모드) 오류(주문형 모드)를 반환합니다.
  • 원격 세션에는 인증이 필요합니다. gitHubToken 또는 useLoggedInUser이(가) 구성되었는지 확인합니다.