@simonyea/holysheep-cli 1.2.7 → 1.2.9
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/tools/openclaw.js +53 -29
package/package.json
CHANGED
package/src/tools/openclaw.js
CHANGED
|
@@ -55,17 +55,16 @@ function buildFullConfig(existing, apiKey, baseUrlAnthropicNoV1, baseUrlOpenAI)
|
|
|
55
55
|
config.env.ANTHROPIC_API_KEY = apiKey
|
|
56
56
|
config.env.ANTHROPIC_BASE_URL = baseUrlAnthropicNoV1 // https://api.holysheep.ai
|
|
57
57
|
|
|
58
|
-
// ── 2. Auth profile
|
|
59
|
-
// openclaw
|
|
58
|
+
// ── 2. Auth profile — openclaw 官方格式(Anthropic API key)─────────
|
|
59
|
+
// 参考: docs.openclaw.ai — auth profile type=anthropic-api-key
|
|
60
60
|
if (!config.auth) config.auth = {}
|
|
61
61
|
if (!config.auth.profiles) config.auth.profiles = {}
|
|
62
62
|
config.auth.profiles.holysheep = {
|
|
63
|
-
type: 'api-key',
|
|
64
63
|
provider: 'anthropic',
|
|
65
|
-
apiKey,
|
|
64
|
+
key: apiKey,
|
|
66
65
|
baseUrl: baseUrlAnthropicNoV1,
|
|
67
66
|
}
|
|
68
|
-
|
|
67
|
+
// 不设 auth.default — openclaw 不认识这个字段
|
|
69
68
|
|
|
70
69
|
// ── 3. 默认模型 ────────────────────────────────────────────────────
|
|
71
70
|
if (!config.agents) config.agents = {}
|
|
@@ -94,10 +93,13 @@ function buildFullConfig(existing, apiKey, baseUrlAnthropicNoV1, baseUrlOpenAI)
|
|
|
94
93
|
],
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
// ── 5. Gateway
|
|
96
|
+
// ── 5. Gateway 配置(使用 openclaw 2026+ 格式)──────────────────────
|
|
98
97
|
if (!config.gateway) config.gateway = {}
|
|
99
98
|
if (!config.gateway.port) config.gateway.port = 18789
|
|
100
|
-
|
|
99
|
+
// bind 用新格式的 mode,不用 IP 字符串
|
|
100
|
+
if (!config.gateway.bind || config.gateway.bind === '127.0.0.1' || config.gateway.bind === 'localhost') {
|
|
101
|
+
config.gateway.bind = 'loopback'
|
|
102
|
+
}
|
|
101
103
|
// 生成 gateway token(若已有则不覆盖)
|
|
102
104
|
if (!config.gateway.auth) config.gateway.auth = {}
|
|
103
105
|
if (!config.gateway.auth.token) {
|
|
@@ -105,10 +107,8 @@ function buildFullConfig(existing, apiKey, baseUrlAnthropicNoV1, baseUrlOpenAI)
|
|
|
105
107
|
config.gateway.auth.mode = 'token'
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
// ── 6.
|
|
109
|
-
|
|
110
|
-
config.workspace = path.join(OPENCLAW_DIR, 'workspace')
|
|
111
|
-
}
|
|
110
|
+
// ── 6. 不写 workspace 字段(openclaw 不认识,会报 unknown key)──────
|
|
111
|
+
delete config.workspace
|
|
112
112
|
|
|
113
113
|
return config
|
|
114
114
|
}
|
|
@@ -118,7 +118,15 @@ module.exports = {
|
|
|
118
118
|
id: 'openclaw',
|
|
119
119
|
|
|
120
120
|
checkInstalled() {
|
|
121
|
-
|
|
121
|
+
if (require('../utils/which').commandExists('openclaw')) return true
|
|
122
|
+
// Windows PATH 未刷新时,用 npx 探测
|
|
123
|
+
if (process.platform === 'win32') {
|
|
124
|
+
try {
|
|
125
|
+
require('child_process').execSync('npx openclaw --version', { stdio: 'ignore', timeout: 10000 })
|
|
126
|
+
return true
|
|
127
|
+
} catch {}
|
|
128
|
+
}
|
|
129
|
+
return false
|
|
122
130
|
},
|
|
123
131
|
|
|
124
132
|
isConfigured() {
|
|
@@ -162,7 +170,12 @@ module.exports = {
|
|
|
162
170
|
getConfigPath() { return CONFIG_FILE },
|
|
163
171
|
hint: 'Gateway 已自动在后台启动,打开浏览器即可使用',
|
|
164
172
|
launchCmd: null,
|
|
165
|
-
launchNote
|
|
173
|
+
get launchNote() {
|
|
174
|
+
const isWin = process.platform === 'win32'
|
|
175
|
+
return isWin
|
|
176
|
+
? '🌐 打开浏览器访问 http://127.0.0.1:18789/\n 如无法访问请运行: npx openclaw gateway start'
|
|
177
|
+
: '🌐 打开浏览器访问 http://127.0.0.1:18789/'
|
|
178
|
+
},
|
|
166
179
|
installCmd: 'npm install -g openclaw@latest',
|
|
167
180
|
docsUrl: 'https://docs.openclaw.ai',
|
|
168
181
|
}
|
|
@@ -179,30 +192,41 @@ module.exports = {
|
|
|
179
192
|
function _initAndStartGateway() {
|
|
180
193
|
const chalk = require('chalk')
|
|
181
194
|
const isWin = process.platform === 'win32'
|
|
182
|
-
|
|
195
|
+
// Windows 刚装完 npm 包,PATH 未刷新,用 npx 兜底
|
|
196
|
+
const bin = isWin ? 'npx openclaw' : 'openclaw'
|
|
183
197
|
|
|
184
198
|
console.log(chalk.gray('\n ⚙️ 正在启动 OpenClaw Gateway...'))
|
|
185
199
|
|
|
200
|
+
// Step 0: 先 doctor --fix 修复配置兼容性问题
|
|
201
|
+
spawnSync(isWin ? 'npx' : bin,
|
|
202
|
+
isWin ? ['openclaw', 'doctor', '--fix'] : ['doctor', '--fix'],
|
|
203
|
+
{ shell: true, timeout: 15000, stdio: 'ignore' }
|
|
204
|
+
)
|
|
205
|
+
|
|
186
206
|
// Step 1: gateway start(已有 daemon 时直接生效)
|
|
187
|
-
const r1 = spawnSync(
|
|
188
|
-
|
|
189
|
-
|
|
207
|
+
const r1 = spawnSync(
|
|
208
|
+
isWin ? 'npx' : bin,
|
|
209
|
+
isWin ? ['openclaw', 'gateway', 'start'] : ['gateway', 'start'],
|
|
210
|
+
{ shell: true, timeout: 10000, stdio: 'pipe' }
|
|
211
|
+
)
|
|
190
212
|
if (r1.status === 0) {
|
|
191
213
|
console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
|
|
192
214
|
console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
|
|
193
215
|
return
|
|
194
216
|
}
|
|
195
217
|
|
|
196
|
-
// Step 2:
|
|
197
|
-
console.log(chalk.gray(' →
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const r3 = spawnSync(
|
|
204
|
-
|
|
205
|
-
|
|
218
|
+
// Step 2: 安装系统服务 + 启动
|
|
219
|
+
console.log(chalk.gray(' → 注册系统服务...'))
|
|
220
|
+
spawnSync(
|
|
221
|
+
isWin ? 'npx' : bin,
|
|
222
|
+
isWin ? ['openclaw', 'gateway', 'install'] : ['gateway', 'install'],
|
|
223
|
+
{ shell: true, timeout: 30000, stdio: 'ignore' }
|
|
224
|
+
)
|
|
225
|
+
const r3 = spawnSync(
|
|
226
|
+
isWin ? 'npx' : bin,
|
|
227
|
+
isWin ? ['openclaw', 'gateway', 'start'] : ['gateway', 'start'],
|
|
228
|
+
{ shell: true, timeout: 10000, stdio: 'pipe' }
|
|
229
|
+
)
|
|
206
230
|
if (r3.status === 0) {
|
|
207
231
|
console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
|
|
208
232
|
console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
|
|
@@ -212,10 +236,10 @@ function _initAndStartGateway() {
|
|
|
212
236
|
// Step 3: fallback — 直接后台运行进程
|
|
213
237
|
console.log(chalk.gray(' → 以守护进程模式启动...'))
|
|
214
238
|
if (isWin) {
|
|
215
|
-
// Windows: PowerShell Start-Process
|
|
239
|
+
// Windows: PowerShell Start-Process 后台运行(用 npx 兜底 PATH 未刷新)
|
|
216
240
|
spawnSync('powershell', [
|
|
217
241
|
'-NonInteractive', '-WindowStyle', 'Hidden', '-Command',
|
|
218
|
-
`Start-Process -FilePath "
|
|
242
|
+
`Start-Process -FilePath "npx" -ArgumentList "openclaw","gateway","--port","18789" -WindowStyle Hidden`
|
|
219
243
|
], { shell: false, timeout: 5000, stdio: 'ignore' })
|
|
220
244
|
} else {
|
|
221
245
|
const { spawn } = require('child_process')
|