@simonyea/holysheep-cli 1.7.53 → 1.7.55

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.53",
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.",
3
+ "version": "1.7.55",
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",
7
7
  "claude-china",
@@ -0,0 +1,42 @@
1
+ /**
2
+ * hs webui — 启动 WebUI 本地管理面板
3
+ */
4
+ 'use strict'
5
+
6
+ const chalk = require('chalk')
7
+ const { execSync } = require('child_process')
8
+
9
+ async function webui(opts) {
10
+ const port = Number(opts.port) || 9876
11
+ const { startServer } = require('../webui/server')
12
+
13
+ console.log()
14
+ console.log(chalk.bold('🌐 HolySheep WebUI'))
15
+ console.log(chalk.gray('━'.repeat(50)))
16
+ console.log()
17
+
18
+ try {
19
+ const server = await startServer(port)
20
+ const url = `http://127.0.0.1:${port}`
21
+ console.log(chalk.green(`✓ WebUI 已启动: ${chalk.cyan.bold(url)}`))
22
+ console.log(chalk.gray(' 按 Ctrl+C 停止'))
23
+ console.log()
24
+
25
+ if (opts.open !== false) {
26
+ try {
27
+ const platform = process.platform
28
+ if (platform === 'darwin') execSync(`open "${url}"`)
29
+ else if (platform === 'win32') execSync(`start "" "${url}"`)
30
+ else execSync(`xdg-open "${url}"`)
31
+ } catch {}
32
+ }
33
+
34
+ // Keep alive
35
+ await new Promise(() => {})
36
+ } catch (err) {
37
+ console.log(chalk.red(`✗ 启动失败: ${err.message}`))
38
+ process.exit(1)
39
+ }
40
+ }
41
+
42
+ module.exports = webui
package/src/index.js CHANGED
@@ -170,6 +170,18 @@ program
170
170
  })
171
171
  })
172
172
 
173
+ // ── webui ──────────────────────────────────────────────────────────────────
174
+ program
175
+ .command('web')
176
+ .alias('webui')
177
+ .description('启动 WebUI 本地管理面板')
178
+ .option('-p, --port <port>', '指定端口', '9876')
179
+ .option('--no-open', '不自动打开浏览器')
180
+ .action(async (opts) => {
181
+ printBanner()
182
+ await require('./commands/webui')(opts)
183
+ })
184
+
173
185
  // ── claude ──────────────────────────────────────────────────────────────────
174
186
  program
175
187
  .command('claude [args...]')
@@ -113,6 +113,30 @@ function deriveNodeProxyUrl(lease) {
113
113
  return upstream.toString().replace(/\/+$/, '')
114
114
  }
115
115
 
116
+ function forwardViaNodeProxy({ nodeProxyUrl, targetUrl, clientReq, clientRes, extraHeaders = {} }) {
117
+ const upstream = new URL(nodeProxyUrl)
118
+ 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
+ ...clientReq.headers,
126
+ ...extraHeaders,
127
+ host: targetUrl.host,
128
+ connection: 'close',
129
+ },
130
+ }, (forwardRes) => {
131
+ clientRes.writeHead(forwardRes.statusCode || 502, forwardRes.headers)
132
+ forwardRes.pipe(clientRes)
133
+ resolve()
134
+ })
135
+ forwardReq.once('error', reject)
136
+ clientReq.pipe(forwardReq)
137
+ })
138
+ }
139
+
116
140
  function createConnectTunnel(proxyUrl, target, headers) {
117
141
  return new Promise((resolve, reject) => {
118
142
  const upstream = new URL(proxyUrl)
@@ -156,59 +180,30 @@ function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH }) {
156
180
 
157
181
  const doForward = async (lease) => {
158
182
  const config = readConfig(configPath)
183
+ const nodeProxyUrl = deriveNodeProxyUrl(lease)
159
184
 
160
185
  if (isDirect) {
161
186
  const crsBase = config.baseUrlAnthropic || 'https://api.holysheep.ai'
162
187
  const target = new URL(clientReq.url, crsBase)
163
- const fwdHeaders = {
164
- ...clientReq.headers,
165
- ...buildAuthHeaders(config, lease),
166
- 'x-hs-node-proxied': '1',
167
- host: target.host,
168
- }
169
- const transport = target.protocol === 'https:' ? https : http
170
- return new Promise((resolve, reject) => {
171
- const fwd = transport.request({
172
- hostname: target.hostname,
173
- port: Number(target.port || (target.protocol === 'https:' ? 443 : 80)),
174
- method: clientReq.method,
175
- path: target.pathname + target.search,
176
- headers: fwdHeaders,
177
- }, (res) => {
178
- if (res.statusCode === 401 || res.statusCode === 403) {
179
- res.resume()
180
- return reject(new Error(`Auth error ${res.statusCode}`))
181
- }
182
- clientRes.writeHead(res.statusCode || 502, res.headers)
183
- res.pipe(clientRes)
184
- resolve()
185
- })
186
- fwd.once('error', reject)
187
- clientReq.pipe(fwd)
188
+ return forwardViaNodeProxy({
189
+ nodeProxyUrl,
190
+ targetUrl: target,
191
+ clientReq,
192
+ clientRes,
193
+ extraHeaders: buildAuthHeaders(config, lease),
188
194
  })
189
195
  }
190
196
 
191
- const nodeProxyUrl = deriveNodeProxyUrl(lease)
192
197
  const headers = {
193
198
  ...buildAuthHeaders(config, lease),
194
- 'x-hs-node-proxied': '1',
195
199
  host: new URL(clientReq.url).host,
196
200
  }
197
- const upstream = new URL(nodeProxyUrl)
198
- return new Promise((resolve, reject) => {
199
- const forwardReq = http.request({
200
- host: upstream.hostname,
201
- port: Number(upstream.port || 80),
202
- method: clientReq.method,
203
- path: clientReq.url,
204
- headers: { ...clientReq.headers, ...headers, connection: 'close' },
205
- }, (forwardRes) => {
206
- clientRes.writeHead(forwardRes.statusCode || 502, forwardRes.headers)
207
- forwardRes.pipe(clientRes)
208
- resolve()
209
- })
210
- forwardReq.once('error', reject)
211
- clientReq.pipe(forwardReq)
201
+ return forwardViaNodeProxy({
202
+ nodeProxyUrl,
203
+ targetUrl: new URL(clientReq.url),
204
+ clientReq,
205
+ clientRes,
206
+ extraHeaders: headers,
212
207
  })
213
208
  }
214
209
 
@@ -12,11 +12,11 @@
12
12
  * [model_providers.holysheep]
13
13
  * name = "HolySheep"
14
14
  * base_url = "https://api.holysheep.ai/v1"
15
- * env_key = "OPENAI_API_KEY"
15
+ * api_key = "cr_xxx"
16
16
  * wire_api = "responses"
17
17
  *
18
18
  * 注意:旧的 config.json 会被 Rust Codex 忽略!
19
- * 注意:Rust Codex 当前读取 env_key,不读取自定义 api_key 字段。
19
+ * 注意:api_key 直接写入配置文件,不再写入 shell 环境变量。
20
20
  */
21
21
  const fs = require('fs')
22
22
  const path = require('path')
@@ -89,8 +89,7 @@ function isConfiguredInToml() {
89
89
  const content = readTomlConfig()
90
90
  return content.includes('model_provider = "holysheep"') &&
91
91
  content.includes('base_url') &&
92
- content.includes('holysheep.ai') &&
93
- content.includes('env_key = "OPENAI_API_KEY"')
92
+ content.includes('holysheep.ai')
94
93
  }
95
94
 
96
95
  /**
@@ -113,7 +112,7 @@ function writeTomlConfig(apiKey, baseUrlOpenAI, model) {
113
112
  `[model_providers.holysheep]`,
114
113
  `name = "HolySheep"`,
115
114
  `base_url = "${baseUrlOpenAI}"`,
116
- `env_key = "OPENAI_API_KEY"`,
115
+ `api_key = "${apiKey}"`,
117
116
  `wire_api = "responses"`,
118
117
  '',
119
118
  ].join('\n')
@@ -138,13 +137,13 @@ function writeJsonConfigIfNeeded(apiKey, baseUrlOpenAI, model) {
138
137
  jsonConfig.model_providers.holysheep = {
139
138
  name: 'HolySheep',
140
139
  base_url: baseUrlOpenAI,
141
- env_key: 'OPENAI_API_KEY',
140
+ api_key: apiKey,
142
141
  wire_api: 'responses',
143
142
  }
144
143
  jsonConfig.providers.holysheep = {
145
144
  name: 'HolySheep',
146
145
  baseURL: baseUrlOpenAI,
147
- envKey: 'OPENAI_API_KEY',
146
+ apiKey: apiKey,
148
147
  }
149
148
  fs.writeFileSync(CONFIG_FILE_JSON, JSON.stringify(jsonConfig, null, 2), 'utf8')
150
149
  } catch {}
@@ -171,7 +170,6 @@ module.exports = {
171
170
  return {
172
171
  file: CONFIG_FILE,
173
172
  hot: false,
174
- envVars: { OPENAI_API_KEY: apiKey },
175
173
  }
176
174
  },
177
175
  reset() {