skillfree 0.1.7 → 0.1.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/scripts/commands/auth.js +62 -1
package/package.json
CHANGED
package/scripts/commands/auth.js
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
const readline = require('readline')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const os = require('os')
|
|
2
5
|
const { saveConfig, BASE_URL } = require('../lib/client')
|
|
3
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 将 apiKey 写入 ~/.openclaw/openclaw.json 的 skills.entries.skillfree
|
|
9
|
+
* 同时设置当前进程的 SKILLFREE_API_KEY 环境变量
|
|
10
|
+
*/
|
|
11
|
+
function injectToOpenclaw(apiKey) {
|
|
12
|
+
// 1. 写入 openclaw.json
|
|
13
|
+
const openclawDir = path.join(os.homedir(), '.openclaw')
|
|
14
|
+
const cfgPath = path.join(openclawDir, 'openclaw.json')
|
|
15
|
+
if (fs.existsSync(openclawDir)) {
|
|
16
|
+
let cfg = {}
|
|
17
|
+
try { cfg = JSON.parse(fs.readFileSync(cfgPath, 'utf8')) } catch {}
|
|
18
|
+
cfg.skills = cfg.skills || {}
|
|
19
|
+
cfg.skills.entries = cfg.skills.entries || {}
|
|
20
|
+
cfg.skills.entries['skillfree'] = {
|
|
21
|
+
...(cfg.skills.entries['skillfree'] || {}),
|
|
22
|
+
enabled: true,
|
|
23
|
+
apiKey,
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + '\n')
|
|
27
|
+
console.log('✅ openclaw.json 已更新,OpenClaw 下次启动自动识别 skillfree skill')
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.warn('⚠️ 无法写入 openclaw.json(权限问题?):', e.message)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 2. 写入 shell 配置文件(~/.zshrc 或 ~/.bash_profile)
|
|
34
|
+
const exportLine = `\nexport SKILLFREE_API_KEY="${apiKey}"\n`
|
|
35
|
+
const shellFiles = [
|
|
36
|
+
path.join(os.homedir(), '.zshrc'),
|
|
37
|
+
path.join(os.homedir(), '.bash_profile'),
|
|
38
|
+
]
|
|
39
|
+
let wrote = false
|
|
40
|
+
for (const f of shellFiles) {
|
|
41
|
+
if (fs.existsSync(f)) {
|
|
42
|
+
const content = fs.readFileSync(f, 'utf8')
|
|
43
|
+
if (content.includes('SKILLFREE_API_KEY')) {
|
|
44
|
+
// 替换已有行
|
|
45
|
+
const updated = content.replace(/\nexport SKILLFREE_API_KEY=.*\n?/g, exportLine)
|
|
46
|
+
fs.writeFileSync(f, updated)
|
|
47
|
+
} else {
|
|
48
|
+
fs.appendFileSync(f, exportLine)
|
|
49
|
+
}
|
|
50
|
+
console.log(`✅ ${path.basename(f)} 已写入 SKILLFREE_API_KEY`)
|
|
51
|
+
wrote = true
|
|
52
|
+
break
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!wrote) {
|
|
56
|
+
// 创建 .zshrc
|
|
57
|
+
fs.writeFileSync(shellFiles[0], `# SkillFree API Key${exportLine}`)
|
|
58
|
+
console.log('✅ ~/.zshrc 已创建并写入 SKILLFREE_API_KEY')
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
4
62
|
async function authLogin() {
|
|
5
63
|
console.log(`\n🦞 SkillFree 登录`)
|
|
6
64
|
console.log(` 控制台:${BASE_URL}/app\n`)
|
|
@@ -26,10 +84,13 @@ async function authLogin() {
|
|
|
26
84
|
if (!res.ok) throw new Error(res.status)
|
|
27
85
|
const data = await res.json()
|
|
28
86
|
saveConfig({ apiKey: key })
|
|
87
|
+
injectToOpenclaw(key)
|
|
29
88
|
console.log(` ✅\n`)
|
|
30
89
|
console.log(`🎉 登录成功!当前积分:${data.credits}`)
|
|
31
90
|
console.log(`\n快速开始:`)
|
|
32
|
-
console.log(` skillfree pilot --type chat --prompt "你好"`)
|
|
91
|
+
console.log(` skillfree pilot --type chat --model DeepSeek-V3.2-Fast --prompt "你好"`)
|
|
92
|
+
console.log(` skillfree pilot --type chat --model claude-sonnet-4-6 --prompt "你好"`)
|
|
93
|
+
console.log(` skillfree models # 查看所有可用模型`)
|
|
33
94
|
} catch (e) {
|
|
34
95
|
console.log(` ❌\nAPI Key 无效,请重新检查`)
|
|
35
96
|
process.exit(1)
|