@simonyea/holysheep-cli 1.7.90 → 1.7.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/tools/codex.js +29 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.7.90",
3
+ "version": "1.7.91",
4
4
  "description": "Claude Code/Cursor/Cline API relay for China — ¥1=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
5
5
  "keywords": [
6
6
  "openai-china",
@@ -26,6 +26,7 @@ const CONFIG_DIR = path.join(os.homedir(), '.codex')
26
26
  const CONFIG_FILE = path.join(CONFIG_DIR, 'config.toml')
27
27
  // 保留 JSON 兼容性(老版本 TypeScript Codex 用)
28
28
  const CONFIG_FILE_JSON = path.join(CONFIG_DIR, 'config.json')
29
+ const AUTH_FILE = path.join(CONFIG_DIR, 'auth.json')
29
30
 
30
31
  function normalizeToml(content) {
31
32
  return String(content || '').replace(/\r\n/g, '\n')
@@ -149,6 +150,28 @@ function writeJsonConfigIfNeeded(apiKey, baseUrlOpenAI, model) {
149
150
  } catch {}
150
151
  }
151
152
 
153
+ /**
154
+ * 清除 auth.json 中的 ChatGPT OAuth 认证,避免干扰 holysheep provider
155
+ * Codex RS bug: auth_mode=chatgpt 时 OAuth token 会覆盖自定义 provider 的 api_key
156
+ */
157
+ function neutralizeAuthJson() {
158
+ try {
159
+ if (!fs.existsSync(AUTH_FILE)) return
160
+
161
+ const auth = JSON.parse(fs.readFileSync(AUTH_FILE, 'utf8'))
162
+
163
+ // 只在 chatgpt 模式时处理
164
+ if (auth.auth_mode !== 'chatgpt') return
165
+
166
+ // 切换为 api-key 模式,清除 OAuth tokens
167
+ auth.auth_mode = 'api-key'
168
+ auth.OPENAI_API_KEY = null
169
+ delete auth.tokens
170
+
171
+ fs.writeFileSync(AUTH_FILE, JSON.stringify(auth, null, 2), 'utf8')
172
+ } catch {}
173
+ }
174
+
152
175
  module.exports = {
153
176
  name: 'Codex CLI',
154
177
  id: 'codex',
@@ -167,6 +190,12 @@ module.exports = {
167
190
  // 同时写 JSON(兼容旧版 TypeScript Codex)
168
191
  writeJsonConfigIfNeeded(apiKey, baseUrlOpenAI, model)
169
192
 
193
+ // 清除 auth.json 中的 ChatGPT OAuth 认证
194
+ // Codex RS 在 auth_mode=chatgpt 时会用 OAuth JWT token 做 Authorization header,
195
+ // 即使 config.toml 里设置了自定义 model_provider 的 api_key 也会被覆盖,
196
+ // 导致 holysheep 收到非 cr_ 前缀的 token 返回 401。
197
+ neutralizeAuthJson()
198
+
170
199
  return {
171
200
  file: CONFIG_FILE,
172
201
  hot: false,