@simonyea/holysheep-cli 1.7.43 → 1.7.45

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.7.43",
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.",
3
+ "version": "1.7.45",
4
+ "description": "Claude Code/Cursor/Cline API relay for China \u2014 \u00a51=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
5
5
  "keywords": [
6
6
  "openai-china",
7
7
  "claude-china",
@@ -44,16 +44,16 @@ async function runClaude(args = []) {
44
44
 
45
45
  const env = {
46
46
  ...process.env,
47
- ANTHROPIC_API_KEY: undefined, // 防止与 ANTHROPIC_AUTH_TOKEN 冲突
47
+ ANTHROPIC_API_KEY: undefined,
48
48
  ANTHROPIC_AUTH_TOKEN: apiKey,
49
- ANTHROPIC_BASE_URL: BASE_URL_ANTHROPIC,
49
+ ANTHROPIC_BASE_URL: `http://127.0.0.1:${port}`,
50
50
  CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
51
51
  HOLYSHEEP_CLAUDE_PROCESS_PROXY: '1',
52
52
  HOLYSHEEP_CLAUDE_SESSION_ID: sessionId,
53
- HTTP_PROXY: proxyUrl,
54
- HTTPS_PROXY: proxyUrl,
55
- ALL_PROXY: proxyUrl,
56
- NO_PROXY: '127.0.0.1,localhost',
53
+ HTTP_PROXY: undefined,
54
+ HTTPS_PROXY: undefined,
55
+ ALL_PROXY: undefined,
56
+ NO_PROXY: undefined,
57
57
  }
58
58
 
59
59
  const child = spawn('claude', args, {
@@ -152,8 +152,37 @@ function pipeWithCleanup(a, b) {
152
152
 
153
153
  function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH }) {
154
154
  const server = http.createServer(async (clientReq, clientRes) => {
155
+ const isDirect = !clientReq.url.startsWith('http')
156
+
155
157
  const doForward = async (lease) => {
156
158
  const config = readConfig(configPath)
159
+
160
+ if (isDirect) {
161
+ const crsBase = config.baseUrlAnthropic || 'https://api.holysheep.ai'
162
+ const target = new URL(clientReq.url, crsBase)
163
+ const fwdHeaders = { ...clientReq.headers, ...buildAuthHeaders(config, lease), 'x-hs-node-proxied': '1', host: target.host }
164
+ const transport = target.protocol === 'https:' ? https : http
165
+ return new Promise((resolve, reject) => {
166
+ const fwd = transport.request({
167
+ hostname: target.hostname,
168
+ port: Number(target.port || (target.protocol === 'https:' ? 443 : 80)),
169
+ method: clientReq.method,
170
+ path: target.pathname + target.search,
171
+ headers: fwdHeaders,
172
+ }, (res) => {
173
+ if (res.statusCode === 401 || res.statusCode === 403) {
174
+ res.resume()
175
+ return reject(new Error(`Auth error ${res.statusCode}`))
176
+ }
177
+ clientRes.writeHead(res.statusCode || 502, res.headers)
178
+ res.pipe(clientRes)
179
+ resolve()
180
+ })
181
+ fwd.once('error', reject)
182
+ clientReq.pipe(fwd)
183
+ })
184
+ }
185
+
157
186
  const nodeProxyUrl = deriveNodeProxyUrl(lease)
158
187
  const headers = {
159
188
  ...buildAuthHeaders(config, lease),
@@ -180,7 +209,6 @@ function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH }) {
180
209
  try {
181
210
  await doForward(getCachedLease(sessionId))
182
211
  } catch {
183
- // lease 失效,拿新 lease 重试一次
184
212
  try {
185
213
  const config = readConfig(configPath)
186
214
  leaseCache.delete(sessionId)