-
Notifications
You must be signed in to change notification settings - Fork 0
Add GitHub Copilot provider info #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,8 +39,8 @@ import { | |||||||||||
| } from "./utils/config"; | ||||||||||||
| import { | ||||||||||||
| getApiKey as fetchApiKey, | ||||||||||||
| getGithubCopilotApiKey as fetchGithubCopilotApiKey, | ||||||||||||
| maybeRedeemCredits, | ||||||||||||
| fetchGithubCopilotApiKey, | ||||||||||||
| } from "./utils/get-api-key"; | ||||||||||||
| import { createInputItem } from "./utils/input-utils"; | ||||||||||||
| import { initLogger } from "./utils/logger/log"; | ||||||||||||
|
|
@@ -117,6 +117,10 @@ const cli = meow( | |||||||||||
| $ codex "Write and run a python program that prints ASCII art" | ||||||||||||
| $ codex -q "fix build issues" | ||||||||||||
| $ codex completion bash | ||||||||||||
|
|
||||||||||||
| Supported providers: | ||||||||||||
| openai (default), openrouter, azure, gemini, ollama, mistral, | ||||||||||||
| deepseek, xai, groq, arceeai, githubcopilot | ||||||||||||
| `, | ||||||||||||
| { | ||||||||||||
| importMeta: import.meta, | ||||||||||||
|
|
@@ -323,12 +327,38 @@ try { | |||||||||||
| if (data.OPENAI_API_KEY && !expired) { | ||||||||||||
| apiKey = data.OPENAI_API_KEY; | ||||||||||||
| } | ||||||||||||
| if ( | ||||||||||||
| data.GITHUBCOPILOT_API_KEY && | ||||||||||||
| provider.toLowerCase() === "githubcopilot" | ||||||||||||
| ) { | ||||||||||||
| apiKey = data.GITHUBCOPILOT_API_KEY; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } catch { | ||||||||||||
| // ignore errors | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (cli.flags.login) { | ||||||||||||
| if (provider.toLowerCase() === "githubcopilot" && !apiKey) { | ||||||||||||
| apiKey = await fetchGithubCopilotApiKey(); | ||||||||||||
| try { | ||||||||||||
| const home = os.homedir(); | ||||||||||||
| const authDir = path.join(home, ".codex"); | ||||||||||||
| const authFile = path.join(authDir, "auth.json"); | ||||||||||||
| fs.writeFileSync( | ||||||||||||
| authFile, | ||||||||||||
| JSON.stringify( | ||||||||||||
| { | ||||||||||||
| GITHUBCOPILOT_API_KEY: apiKey, | ||||||||||||
| }, | ||||||||||||
| null, | ||||||||||||
| 2, | ||||||||||||
| ), | ||||||||||||
| "utf-8", | ||||||||||||
| ); | ||||||||||||
| } catch { | ||||||||||||
| /* ignore */ | ||||||||||||
| } | ||||||||||||
| } else if (cli.flags.login) { | ||||||||||||
|
||||||||||||
| if (provider.toLowerCase() === "githubcopilot") { | ||||||||||||
| apiKey = await fetchGithubCopilotApiKey(); | ||||||||||||
| } else { | ||||||||||||
|
|
@@ -353,7 +383,7 @@ if (cli.flags.login) { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
| // Ensure the API key is available as an environment variable for legacy code | ||||||||||||
| process.env["OPENAI_API_KEY"] = apiKey; | ||||||||||||
| process.env[`${provider.toUpperCase()}_API_KEY`] = apiKey; | ||||||||||||
|
||||||||||||
| process.env[`${provider.toUpperCase()}_API_KEY`] = apiKey; | |
| const envVarName = provider.toLowerCase() === "githubcopilot" | |
| ? "GITHUB_COPILOT_API_KEY" | |
| : `${provider.toUpperCase()}_API_KEY`; | |
| process.env[envVarName] = apiKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid blocking the event loop in async code—use
fs.promises.writeFileinstead ofwriteFileSync.