@simonyea/holysheep-cli 1.7.53 → 1.7.54
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 +1 -1
- package/src/commands/webui.js +49 -0
- package/src/index.js +12 -0
- package/src/tools/claude-process-proxy.js +37 -42
- package/src/webui/index.html +873 -0
- package/src/webui/server.js +506 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simonyea/holysheep-cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.54",
|
|
4
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",
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
const server = startServer(port)
|
|
19
|
+
|
|
20
|
+
server.on('listening', () => {
|
|
21
|
+
const url = `http://127.0.0.1:${port}`
|
|
22
|
+
console.log(chalk.green(`✓ WebUI 已启动: ${chalk.cyan.bold(url)}`))
|
|
23
|
+
console.log(chalk.gray(' 按 Ctrl+C 停止'))
|
|
24
|
+
console.log()
|
|
25
|
+
|
|
26
|
+
if (opts.open !== false) {
|
|
27
|
+
try {
|
|
28
|
+
const platform = process.platform
|
|
29
|
+
if (platform === 'darwin') execSync(`open "${url}"`)
|
|
30
|
+
else if (platform === 'win32') execSync(`start "" "${url}"`)
|
|
31
|
+
else execSync(`xdg-open "${url}"`)
|
|
32
|
+
} catch {}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
server.on('error', (err) => {
|
|
37
|
+
if (err.code === 'EADDRINUSE') {
|
|
38
|
+
console.log(chalk.red(`✗ 端口 ${port} 已被占用,请使用 --port 指定其他端口`))
|
|
39
|
+
} else {
|
|
40
|
+
console.log(chalk.red(`✗ 启动失败: ${err.message}`))
|
|
41
|
+
}
|
|
42
|
+
process.exit(1)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Keep alive
|
|
46
|
+
await new Promise(() => {})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
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('webui')
|
|
176
|
+
.alias('web')
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
|