Skip to content

Commit b451a82

Browse files
authored
Merge pull request #3 from notlikejuice/codex/popraw-logikę-logowania-w-cli.tsx
Add GitHub Copilot provider
2 parents b73426c + 109cea0 commit b451a82

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

codex-cli/src/cli.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import {
4141
getApiKey as fetchApiKey,
4242
maybeRedeemCredits,
43+
fetchGithubCopilotApiKey,
4344
} from "./utils/get-api-key";
4445
import { createInputItem } from "./utils/input-utils";
4546
import { initLogger } from "./utils/logger/log";
@@ -328,7 +329,11 @@ try {
328329
}
329330

330331
if (cli.flags.login) {
331-
apiKey = await fetchApiKey(client.issuer, client.client_id);
332+
if (provider.toLowerCase() === "githubcopilot") {
333+
apiKey = await fetchGithubCopilotApiKey();
334+
} else {
335+
apiKey = await fetchApiKey(client.issuer, client.client_id);
336+
}
332337
try {
333338
const home = os.homedir();
334339
const authDir = path.join(home, ".codex");
@@ -341,7 +346,11 @@ if (cli.flags.login) {
341346
/* ignore */
342347
}
343348
} else if (!apiKey) {
344-
apiKey = await fetchApiKey(client.issuer, client.client_id);
349+
if (provider.toLowerCase() === "githubcopilot") {
350+
apiKey = await fetchGithubCopilotApiKey();
351+
} else {
352+
apiKey = await fetchApiKey(client.issuer, client.client_id);
353+
}
345354
}
346355
// Ensure the API key is available as an environment variable for legacy code
347356
process.env["OPENAI_API_KEY"] = apiKey;

codex-cli/src/utils/get-api-key.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,25 @@ export async function getApiKey(
764764
}
765765

766766
export { maybeRedeemCredits };
767+
768+
export async function fetchGithubCopilotApiKey(): Promise<string> {
769+
if (process.env["GITHUB_COPILOT_TOKEN"]) {
770+
return process.env["GITHUB_COPILOT_TOKEN"]!;
771+
}
772+
773+
const choice = await promptUserForChoice();
774+
if (choice.type === "apikey") {
775+
process.env["GITHUB_COPILOT_TOKEN"] = choice.key;
776+
return choice.key;
777+
}
778+
779+
// Sign in via GitHub is not yet supported; instruct the user
780+
// eslint-disable-next-line no-console
781+
console.error(
782+
"\n" +
783+
"GitHub OAuth login is not yet implemented for Codex. " +
784+
"Please generate a token manually and set it as GITHUB_COPILOT_TOKEN." +
785+
"\n"
786+
);
787+
process.exit(1);
788+
}

codex-cli/src/utils/providers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ export const providers: Record<
5252
baseURL: "https://conductor.arcee.ai/v1",
5353
envKey: "ARCEEAI_API_KEY",
5454
},
55+
githubcopilot: {
56+
name: "GitHubCopilot",
57+
baseURL: "https://copilot-proxy.githubusercontent.com/v1",
58+
envKey: "GITHUB_COPILOT_TOKEN",
59+
},
5560
};

0 commit comments

Comments
 (0)