@simonyea/holysheep-cli 1.7.74 → 1.7.76

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.7.74",
3
+ "version": "1.7.76",
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",
@@ -113,27 +113,48 @@ function deriveNodeProxyUrl(lease) {
113
113
  return upstream.toString().replace(/\/+$/, '')
114
114
  }
115
115
 
116
+ // 去掉模型 ID 中的 [1m] 后缀 — CRS 用标准模型 ID 做多账号调度
117
+ function stripModelSuffix(body) {
118
+ if (!body || !body.includes('"model"')) return body
119
+ return body.replace(/("model"\s*:\s*"claude-(?:sonnet|opus)-[\w.-]+)\[1m\](")/g, '$1$2')
120
+ }
121
+
116
122
  function forwardViaNodeProxy({ nodeProxyUrl, targetUrl, clientReq, clientRes, extraHeaders = {} }) {
117
123
  const upstream = new URL(nodeProxyUrl)
118
124
  return new Promise((resolve, reject) => {
119
- const forwardReq = http.request({
120
- host: upstream.hostname,
121
- port: Number(upstream.port || 80),
122
- method: clientReq.method,
123
- path: targetUrl.toString(),
124
- headers: {
125
+ // 读取完整 body 以便修改 model 字段
126
+ const chunks = []
127
+ clientReq.on('data', chunk => chunks.push(chunk))
128
+ clientReq.on('end', () => {
129
+ let body = Buffer.concat(chunks)
130
+ const isJson = (clientReq.headers['content-type'] || '').includes('json')
131
+ if (isJson) {
132
+ body = Buffer.from(stripModelSuffix(body.toString('utf8')))
133
+ }
134
+
135
+ const headers = {
125
136
  ...clientReq.headers,
126
137
  ...extraHeaders,
127
138
  host: targetUrl.host,
139
+ 'content-length': body.length,
128
140
  connection: 'close',
129
- },
130
- }, (forwardRes) => {
131
- clientRes.writeHead(forwardRes.statusCode || 502, forwardRes.headers)
132
- forwardRes.pipe(clientRes)
133
- resolve()
141
+ }
142
+
143
+ const forwardReq = http.request({
144
+ host: upstream.hostname,
145
+ port: Number(upstream.port || 80),
146
+ method: clientReq.method,
147
+ path: targetUrl.toString(),
148
+ headers,
149
+ }, (forwardRes) => {
150
+ clientRes.writeHead(forwardRes.statusCode || 502, forwardRes.headers)
151
+ forwardRes.pipe(clientRes)
152
+ resolve()
153
+ })
154
+ forwardReq.once('error', reject)
155
+ forwardReq.end(body)
134
156
  })
135
- forwardReq.once('error', reject)
136
- clientReq.pipe(forwardReq)
157
+ clientReq.on('error', reject)
137
158
  })
138
159
  }
139
160
 
@@ -25,9 +25,14 @@ try {
25
25
  const PROXY_HOST = parsed.hostname
26
26
  const PROXY_PORT = Number(parsed.port) || 80
27
27
  const SKIP = new Set(['127.0.0.1', '::1', 'localhost', '0.0.0.0', PROXY_HOST])
28
+ // 阻断直连 Anthropic — 强制 Claude Code 走 ANTHROPIC_BASE_URL (HTTP 路径 → proxy → CRS)
29
+ // CONNECT 隧道因 TLS SNI 不匹配无法改写目标,只能阻断
30
+ const BLOCK = new Set(['api.anthropic.com'])
28
31
 
29
32
  function shouldProxy(host, port) {
30
- return !!(port && host && !SKIP.has(host))
33
+ if (!port || !host || SKIP.has(host)) return false
34
+ if (BLOCK.has(host)) return 'block'
35
+ return true
31
36
  }
32
37
 
33
38
  // api.anthropic.com → api.holysheep.ai,让 CONNECT 隧道也走 CRS 多账号调度
@@ -82,7 +87,14 @@ net.Socket.prototype.connect = function(options) {
82
87
  const host = isObj ? String(options.host || options.hostname || '') : String(options || '')
83
88
  const port = isObj ? Number(options.port || 0) : Number(arguments[1] || 0)
84
89
 
85
- if (!shouldProxy(host, port)) return _origSocketConnect.apply(this, arguments)
90
+ const action = shouldProxy(host, port)
91
+ if (!action) return _origSocketConnect.apply(this, arguments)
92
+ if (action === 'block') {
93
+ // 阻断直连 Anthropic,触发连接失败,Claude Code 会回退到 ANTHROPIC_BASE_URL
94
+ const sock = this
95
+ process.nextTick(() => sock.destroy(new Error(`ECONNREFUSED: blocked direct connection to ${host}`)))
96
+ return sock
97
+ }
86
98
 
87
99
  const sock = this
88
100
  const proxyOpts = isObj
@@ -102,7 +114,13 @@ function proxied(options, cb) {
102
114
  const host = isObj ? String(options.host || options.hostname || 'localhost') : String(options || 'localhost')
103
115
  const port = isObj ? Number(options.port || 0) : Number(arguments[1] || 0)
104
116
 
105
- if (!shouldProxy(host, port)) return _origCreate.apply(this, arguments)
117
+ const action = shouldProxy(host, port)
118
+ if (!action) return _origCreate.apply(this, arguments)
119
+ if (action === 'block') {
120
+ const sock = new net.Socket()
121
+ process.nextTick(() => sock.destroy(new Error(`ECONNREFUSED: blocked direct connection to ${host}`)))
122
+ return sock
123
+ }
106
124
 
107
125
  const sock = _origCreate({ host: PROXY_HOST, port: PROXY_PORT })
108
126
  if (typeof cb === 'function') sock.once('connect', cb)