-
Notifications
You must be signed in to change notification settings - Fork 14.2k
provider (api) 指令查询/切换模型api类型 分离OpenAl和Anthropic模型的环境变量 分离 Gemini和Anthropic环境变量 通过github action更新contributors #129
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
c9f95fc
claude-code with OpenAI mode fix
fa5329d
Merge remote main: keep OpenAI fix
21b2854
1.0.4
dfe25b1
Merge branch 'claude-code-best:main' into main
2228293026 affc826
Merge branch 'claude-code-best:main' into main
2228293026 4fa7582
Merge branch 'claude-code-best:main' into main
2228293026 7631c0f
Merge remote main and resolve conflicts
3ae973c
ReWrite
e548369
ReWrite
ad10444
Merge branch 'claude-code-best:main' into main
2228293026 b5d1dbc
provider指令切换模型类型
0c9fd37
Merge branch 'claude-code-best:main' into main
2228293026 c33d5dc
Merge branch 'claude-code-best:main' into main
2228293026 ec5dfed
fix provider指令切换模型类型
eb6fbe5
分离OpenAI和Anthropic模型的环境变量
a0141c1
ConsoleOAuthFlow格式化恢复
1e53943
修复小问题
282f2f4
删除误导注释
41f733a
验证 OAuth 流程中的 base_url 防止无效 URL
a50971f
ConsoleOAuthFlow: 添加 base_url URL 格式验证
2f95d1a
Merge branch 'claude-code-best:main' into main
2228293026 ecac0ab
Merge branch 'claude-code-best:main' into main
2228293026 1f8f90e
Merge branch 'claude-code-best:main' into main
2228293026 26245e0
Merge branch 'main' into main
2228293026 a7a9659
解决报错
6f80e96
fix: make modelType take precedence over all env vars in getAPIProvider
14dc54a
gemini模型环境变量分离 provider指令支持切换gemini
81ecd82
Test
eb62b47
e
a15340f
Merge branch 'claude-code-best:main' into main
2228293026 5bf3c93
feat: add contributors auto-update workflow
fec8ec6
fix: correct contributors link in README
7d88b4d
docs: update contributors
2228293026 767d6fa
Merge branch 'claude-code-best:main' into main
2228293026 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Update Contributors | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| schedule: | ||
| - cron: '0 0 * * *' # 每天更新一次 | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| update: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - uses: jaywcjlove/github-action-contributors@main | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| output: "contributors.svg" | ||
| repository: ${{ github.repository }} | ||
|
|
||
| - uses: stefanzweifel/git-auto-commit-action@v5 | ||
| with: | ||
| commit_message: "docs: update contributors" | ||
| file_pattern: "contributors.svg" | ||
| branch: main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import type { Command } from '../commands.js' | ||
| import type { LocalCommandCall } from '../types/command.js' | ||
| import { getAPIProvider } from '../utils/model/providers.js' | ||
| import { updateSettingsForSource } from '../utils/settings/settings.js' | ||
| import { getSettings_DEPRECATED } from '../utils/settings/settings.js' | ||
| import { applyConfigEnvironmentVariables } from '../utils/managedEnv.js' | ||
|
|
||
| function getEnvVarForProvider(provider: string): string { | ||
| switch (provider) { | ||
| case 'bedrock': | ||
| return 'CLAUDE_CODE_USE_BEDROCK' | ||
| case 'vertex': | ||
| return 'CLAUDE_CODE_USE_VERTEX' | ||
| case 'foundry': | ||
| return 'CLAUDE_CODE_USE_FOUNDRY' | ||
| case 'gemini': | ||
| return 'CLAUDE_CODE_USE_GEMINI' | ||
| default: | ||
| throw new Error(`Unknown provider: ${provider}`) | ||
| } | ||
| } | ||
|
|
||
| // Get merged env: process.env + settings.env (from userSettings) | ||
| function getMergedEnv(): Record<string, string> { | ||
| const settings = getSettings_DEPRECATED() | ||
| const merged = { ...process.env } | ||
| if (settings?.env) { | ||
| Object.assign(merged, settings.env) | ||
| } | ||
| return merged | ||
| } | ||
|
|
||
| const call: LocalCommandCall = async (args, context) => { | ||
| const arg = args.trim().toLowerCase() | ||
|
|
||
| // No argument: show current provider | ||
| if (!arg) { | ||
| const current = getAPIProvider() | ||
| return { type: 'text', value: `Current API provider: ${current}` } | ||
| } | ||
|
|
||
| // unset - clear settings, fallback to env vars | ||
| if (arg === 'unset') { | ||
| updateSettingsForSource('userSettings', { modelType: undefined }) | ||
| // Also clear all provider-specific env vars to prevent conflicts | ||
| delete process.env.CLAUDE_CODE_USE_BEDROCK | ||
| delete process.env.CLAUDE_CODE_USE_VERTEX | ||
| delete process.env.CLAUDE_CODE_USE_FOUNDRY | ||
| delete process.env.CLAUDE_CODE_USE_OPENAI | ||
| delete process.env.CLAUDE_CODE_USE_GEMINI | ||
| return { | ||
| type: 'text', | ||
| value: 'API provider cleared (will use environment variables).', | ||
| } | ||
| } | ||
|
|
||
| // Validate provider | ||
| const validProviders = [ | ||
| 'anthropic', | ||
| 'openai', | ||
| 'gemini', | ||
| 'bedrock', | ||
| 'vertex', | ||
| 'foundry', | ||
| ] | ||
| if (!validProviders.includes(arg)) { | ||
| return { | ||
| type: 'text', | ||
| value: `Invalid provider: ${arg}\nValid: ${validProviders.join(', ')}`, | ||
| } | ||
| } | ||
|
|
||
| // Check env vars when switching to openai (including settings.env) | ||
| if (arg === 'openai') { | ||
| const mergedEnv = getMergedEnv() | ||
| const hasKey = !!mergedEnv.OPENAI_API_KEY | ||
| const hasUrl = !!mergedEnv.OPENAI_BASE_URL | ||
| if (!hasKey || !hasUrl) { | ||
| updateSettingsForSource('userSettings', { modelType: 'openai' }) | ||
| const missing = [] | ||
| if (!hasKey) missing.push('OPENAI_API_KEY') | ||
| if (!hasUrl) missing.push('OPENAI_BASE_URL') | ||
| return { | ||
| type: 'text', | ||
| value: `Switched to OpenAI provider.\nWarning: Missing env vars: ${missing.join(', ')}\nConfigure them via /login or set manually.`, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check env vars when switching to gemini (including settings.env) | ||
| if (arg === 'gemini') { | ||
| const mergedEnv = getMergedEnv() | ||
| const hasKey = !!mergedEnv.GEMINI_API_KEY | ||
| // GEMINI_BASE_URL is optional (has default) | ||
| if (!hasKey) { | ||
| updateSettingsForSource('userSettings', { modelType: 'gemini' }) | ||
| return { | ||
| type: 'text', | ||
| value: `Switched to Gemini provider.\nWarning: Missing env var: GEMINI_API_KEY\nConfigure it via /login or set manually.`, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Handle different provider types | ||
| // - 'anthropic', 'openai', 'gemini' are stored in settings.json (persistent) | ||
| // - 'bedrock', 'vertex', 'foundry' are env-only (do NOT touch settings.json) | ||
| if (arg === 'anthropic' || arg === 'openai' || arg === 'gemini') { | ||
| // Clear any cloud provider env vars to avoid conflicts | ||
| delete process.env.CLAUDE_CODE_USE_BEDROCK | ||
| delete process.env.CLAUDE_CODE_USE_VERTEX | ||
| delete process.env.CLAUDE_CODE_USE_FOUNDRY | ||
| delete process.env.CLAUDE_CODE_USE_OPENAI | ||
| delete process.env.CLAUDE_CODE_USE_GEMINI | ||
| // Update settings.json | ||
| updateSettingsForSource('userSettings', { modelType: arg }) | ||
| // Ensure settings.env gets applied to process.env | ||
| applyConfigEnvironmentVariables() | ||
| return { type: 'text', value: `API provider set to ${arg}.` } | ||
| } else { | ||
| // Cloud providers: set env vars only, do NOT touch settings.json | ||
| delete process.env.CLAUDE_CODE_USE_OPENAI | ||
| delete process.env.OPENAI_API_KEY | ||
| delete process.env.OPENAI_BASE_URL | ||
| delete process.env.CLAUDE_CODE_USE_GEMINI | ||
| process.env[getEnvVarForProvider(arg)] = '1' | ||
| // Do not modify settings.json - cloud providers controlled solely by env vars | ||
| applyConfigEnvironmentVariables() | ||
| return { | ||
| type: 'text', | ||
| value: `API provider set to ${arg} (via environment variable).`, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const provider = { | ||
| type: 'local', | ||
| name: 'provider', | ||
| description: | ||
| 'Switch API provider (anthropic/openai/gemini/bedrock/vertex/foundry)', | ||
| aliases: ['api'], | ||
| argumentHint: '[anthropic|openai|gemini|bedrock|vertex|foundry|unset]', | ||
| supportsNonInteractive: true, | ||
| load: () => Promise.resolve({ call }), | ||
| } satisfies Command | ||
|
|
||
| export default provider | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.