{"meta":{"title":"既定のセットアップ (バンドルされた CLI)","intro":"Node.js SDK と .NET SDK には、依存関係として Copilot CLI が含まれています。アプリには必要なものがすべて付属しており、追加のインストールや構成は必要ありません。","product":"GitHub Copilot","breadcrumbs":[{"href":"/ja/copilot","title":"GitHub Copilot"},{"href":"/ja/copilot/how-tos","title":"方法"},{"href":"/ja/copilot/how-tos/copilot-sdk","title":"Copilot SDK"},{"href":"/ja/copilot/how-tos/copilot-sdk/setup","title":"Copilot SDK を設定する"},{"href":"/ja/copilot/how-tos/copilot-sdk/setup/bundled-cli","title":"バンドルされた CLI"}],"documentType":"article"},"body":"# 既定のセットアップ (バンドルされた CLI)\n\nNode.js SDK と .NET SDK には、依存関係として Copilot CLI が含まれています。アプリには必要なものがすべて付属しており、追加のインストールや構成は必要ありません。\n\n<!-- markdownlint-disable GHD046 GHD005 -->\n\n<!-- Suppressed: GHD046 (outdated release terminology), GHD005 (hardcoded data variable) -->\n\nPython SDK では、インストール後に 1 回限りのダウンロード手順が推奨されます。\n\n```bash\npython -m copilot download-runtime\n```\n\nこれにより、一致するランタイムがダウンロードされ、ローカルにキャッシュされます。 この手順をスキップすると、SDK は最初にフォールバックとして使用したときに自動的にダウンロードを試みます。\n\n**次の場合に最適です。** ほとんどのアプリケーション (デスクトップ アプリ、スタンドアロン ツール、CLI ユーティリティ、プロトタイプなど)。\n\n## どのように機能するのか\n\nSDK をインストールすると、Copilot ランタイムが自動的に (Node.js、.NET)、または `python -m copilot download-runtime` (Python) 経由でダウンロードされます。 SDK は、それを子プロセスとして開始し、stdio 経由で通信します。 構成する必要がある追加の情報はありません。\n\n![図: 説明されたプロセスを示すフローチャート。](/assets/images/help/copilot/copilot-sdk/setup-bundled-cli-diagram-0.png)\n\n**主な特性:**\n\n* CLI バイナリは SDK に含まれています。個別のインストールは必要ありません\n* SDK は、互換性を確保するために CLI バージョンを管理します\n* ユーザーはアプリを使用して認証します (または env vars/BYOK を使用します)\n* セッションは自分のマシンでユーザーごとに管理されます\n\n## 簡単スタート\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nimport { CopilotClient } from \"@github/copilot-sdk\";\n\nconst client = new CopilotClient();\n\nconst session = await client.createSession({ model: \"gpt-5.4\" });\nconst response = await session.sendAndWait({ prompt: \"Hello!\" });\nconsole.log(response?.data.content);\n\nawait client.stop();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n```python\nfrom copilot import CopilotClient\nfrom copilot.session import PermissionHandler\n\nclient = CopilotClient()\nawait client.start()\n\nsession = await client.create_session(on_permission_request=PermissionHandler.approve_all, model=\"gpt-5.4\")\nresponse = await session.send_and_wait(\"Hello!\")\nprint(response.data.content)\n\nawait client.stop()\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"go\" data-label=\"Go\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Go</div>\n\n> \\[!NOTE]\n> Node.js、Python、.NETとは異なり、Go SDK には CLI は自動依存関係として含まれません。 明示的なパスがない`NewClient(nil)`は、使用可能な場合は埋め込み CLI を使用し、`PATH`の`copilot`にフォールバックします。 CLI を埋め込むには、ビルド時に [bundler ツール](https://github.com/github/copilot-sdk/tree/main/go/README.md#distributing-your-application-with-an-embedded-github-copilot-cli) を実行します。\n> `COPILOT_CLI_PATH`を設定したり、既存のバイナリで`Connection`をポイントしたりすることもできます。 詳しくは、「[ローカル CLI のセットアップ](/ja/copilot/how-tos/copilot-sdk/setup/local-cli)」をご覧ください。\n\n```golang\nclient := copilot.NewClient(nil)\nif err := client.Start(ctx); err != nil {\n    log.Fatal(err)\n}\ndefer client.Stop()\n\nsession, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: \"gpt-5.4\"})\nresponse, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: \"Hello!\"})\nif d, ok := response.Data.(*copilot.AssistantMessageData); ok {\n    fmt.Println(d.Content)\n}\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n```csharp\nawait using var client = new CopilotClient();\nawait using var session = await client.CreateSessionAsync(\n    new SessionConfig { Model = \"gpt-5.4\" });\n\nvar response = await session.SendAndWaitAsync(\n    new MessageOptions { Prompt = \"Hello!\" });\nConsole.WriteLine(response?.Data.Content);\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n> \\[!NOTE]\n> Java SDK は、Copilot CLI をバンドルまたは埋め込むことはありません。 CLI を個別にインストールし、`PATH`で`copilot`を使用できるようにするか、`setCliPath(...)`でその場所を設定します (または、`setCliUrl(...)`を使用して実行中の CLI サーバーに接続します)。\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\n\nvar client = new CopilotClient(new CopilotClientOptions()\n    // Point to the CLI binary installed on the system\n    .setCliPath(\"/path/to/vendor/copilot\")\n);\nclient.start().get();\n\nvar session = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\nvar response = session.sendAndWait(new MessageOptions()\n    .setPrompt(\"Hello!\")).get();\nSystem.out.println(response.getData().content());\n\nclient.stop().get();\n```\n\n</div>\n\n</div>\n\n## 認証の戦略\n\nユーザーの認証方法を決定する必要があります。 一般的なパターンを次に示します。\n\n![図: 説明されたプロセスを示すフローチャート。](/assets/images/help/copilot/copilot-sdk/setup-bundled-cli-diagram-1.png)\n\n### オプション A: ユーザーのサインイン資格情報 (最も簡単)\n\nユーザーは CLI に 1 回サインインし、アプリはこれらの資格情報を使用します。 追加のコードは必要ありません。これが既定の動作です。\n\n```typescript\nconst client = new CopilotClient();\n// Default: uses signed-in user credentials\n```\n\n### オプション B: 環境変数を使用したトークン\n\nトークンを設定する手順をアプリに配布するか、プログラムで設定します。\n\n```typescript\nconst client = new CopilotClient({\n    env: {\n        COPILOT_GITHUB_TOKEN: getUserToken(),  // Your app provides the token\n    },\n});\n```\n\n### オプション C: BYOK (GitHub認証は必要ありません)\n\n独自のモデル プロバイダー キーを管理する場合、ユーザーはGitHubアカウントをまったく必要としません。\n\n```typescript\nconst client = new CopilotClient();\n\nconst session = await client.createSession({\n    model: \"gpt-5.4\",\n    provider: {\n        type: \"openai\",\n        baseUrl: \"https://api.openai.com/v1\",\n        apiKey: process.env.OPENAI_API_KEY,\n    },\n});\n```\n\n詳細については、 **[BYOK (独自のキーを持ち込む)](/ja/copilot/how-tos/copilot-sdk/auth/byok)** を参照してください。\n\n## セッション管理\n\nアプリでは通常、ユーザーが会話を再開できるように、名前付きセッションが必要です。\n\n```typescript\nconst client = new CopilotClient();\n\n// Create a session tied to the user's project\nconst sessionId = `project-${projectName}`;\nconst session = await client.createSession({\n    sessionId,\n    model: \"gpt-5.4\",\n});\n\n// User closes app...\n// Later, resume where they left off\nconst resumed = await client.resumeSession(sessionId);\n```\n\nセッション状態は `~/.copilot/session-state/{sessionId}/`で保持されます。\n\n## 次に進むタイミング\n\n| 必要                                                                           | 次のガイドへ |\n| ---------------------------------------------------------------------------- | ------ |\n| GitHub アカウントを使用してサインインするユーザー                                                 |        |\n| [GitHub OAuth のセットアップ](/ja/copilot/how-tos/copilot-sdk/setup/github-oauth)   |        |\n| ユーザー マシンではなくサーバーで実行する                                                        |        |\n| [バックエンド サービスのセットアップ](/ja/copilot/how-tos/copilot-sdk/setup/backend-services) |        |\n| 独自のモデル キーを使用する                                                               |        |\n| [BYOK (独自のキーを持ち込む)](/ja/copilot/how-tos/copilot-sdk/auth/byok)               |        |\n\n## 次のステップ\n\n* **[BYOK (独自のキーを持ち込む)](/ja/copilot/how-tos/copilot-sdk/auth/byok)**: 独自のモデル プロバイダー キーを使用する\n* **[セッションの再開と永続化](/ja/copilot/how-tos/copilot-sdk/features/session-persistence)**: 高度なセッション管理\n* **[初めてのCopilot搭載アプリを構築する](/ja/copilot/how-tos/copilot-sdk/getting-started)**: 完全なアプリをビルドする"}