@simonyea/holysheep-cli 1.7.19 → 1.7.21

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.19",
3
+ "version": "1.7.21",
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",
@@ -6,6 +6,19 @@ const http = require('http')
6
6
  const path = require('path')
7
7
  const os = require('os')
8
8
  const fetch = global.fetch || require('node-fetch')
9
+ const _nodeFetch = require('node-fetch')
10
+
11
+ // Windows 上 api.holysheep.ai 有 IPv6 DNS 记录,但 Windows Server 普遍未启用 IPv6。
12
+ // Node.js 默认 IPv6 优先,会导致每次请求先卡在 IPv6 连接超时再降级 IPv4,
13
+ // 超过 OpenClaw embedded agent 的 timeout 阈值,触发 "LLM request timed out"。
14
+ // 解决方案:Windows 下强制用 node-fetch + https.Agent({family:4}) 只走 IPv4。
15
+ function upstreamFetch(url, options) {
16
+ if (process.platform === 'win32' && String(url).startsWith('https://')) {
17
+ const https = require('https')
18
+ return _nodeFetch(url, { ...options, agent: new https.Agent({ family: 4 }) })
19
+ }
20
+ return fetch(url, options)
21
+ }
9
22
 
10
23
  const OPENCLAW_DIR = path.join(os.homedir(), '.openclaw')
11
24
  const BRIDGE_CONFIG_FILE = path.join(OPENCLAW_DIR, 'holysheep-bridge.json')
@@ -516,7 +529,7 @@ async function relayOpenAIRequest(requestBody, config, res) {
516
529
  ...requestBody,
517
530
  stream: requestBody.stream === true,
518
531
  }
519
- const upstream = await fetch(`${config.baseUrlOpenAI.replace(/\/+$/, '')}/chat/completions`, {
532
+ const upstream = await upstreamFetch(`${config.baseUrlOpenAI.replace(/\/+$/, '')}/chat/completions`, {
520
533
  method: 'POST',
521
534
  headers: {
522
535
  'content-type': 'application/json',
@@ -526,6 +539,18 @@ async function relayOpenAIRequest(requestBody, config, res) {
526
539
  body: JSON.stringify(upstreamBody),
527
540
  })
528
541
 
542
+ // 流式请求:直接字节透传(已是 OpenAI SSE 格式,无需转换)
543
+ if (requestBody.stream === true && upstream.ok) {
544
+ res.writeHead(200, {
545
+ 'content-type': 'text/event-stream; charset=utf-8',
546
+ 'cache-control': 'no-cache, no-transform',
547
+ connection: 'keep-alive',
548
+ })
549
+ try { await pipeStream(upstream.body, (chunk) => res.write(chunk)) } catch {}
550
+ if (!res.writableEnded) res.end()
551
+ return
552
+ }
553
+
529
554
  const text = await upstream.text()
530
555
  const parsed = parseOpenAIStreamText(text, requestBody.model)
531
556
  if (upstream.ok && parsed) {
@@ -572,7 +597,7 @@ async function relayAnthropicStream(requestBody, config, route, res) {
572
597
 
573
598
  let upstream
574
599
  try {
575
- upstream = await fetch(baseUrl, {
600
+ upstream = await upstreamFetch(baseUrl, {
576
601
  method: 'POST',
577
602
  headers: {
578
603
  'content-type': 'application/json',
@@ -695,7 +720,7 @@ async function relayAnthropicRequest(requestBody, config, route, res) {
695
720
  ? `${config.baseUrlAnthropic.replace(/\/+$/, '')}/minimax/v1/messages`
696
721
  : `${config.baseUrlAnthropic.replace(/\/+$/, '')}/v1/messages`
697
722
 
698
- const upstream = await fetch(baseUrl, {
723
+ const upstream = await upstreamFetch(baseUrl, {
699
724
  method: 'POST',
700
725
  headers: {
701
726
  'content-type': 'application/json',
@@ -203,10 +203,13 @@ function startBridge(port) {
203
203
  if (waitForBridge(port)) return true
204
204
 
205
205
  const scriptPath = path.join(__dirname, '..', 'index.js')
206
- const child = spawn(process.execPath, [scriptPath, 'openclaw-bridge', '--port', String(port)], {
207
- detached: true,
208
- stdio: 'ignore',
209
- })
206
+ // Windows: use shell+node command to avoid ERROR_FILE_NOT_FOUND with process.execPath
207
+ // (Windows Store / nvm paths can be unresolvable when spawning detached)
208
+ const spawnCmd = isWin ? 'node' : process.execPath
209
+ const spawnOpts = isWin
210
+ ? { shell: true, detached: true, stdio: 'ignore', windowsHide: true }
211
+ : { detached: true, stdio: 'ignore' }
212
+ const child = spawn(spawnCmd, [scriptPath, 'openclaw-bridge', '--port', String(port)], spawnOpts)
210
213
  child.unref()
211
214
  return waitForBridge(port)
212
215
  }