skillfree 0.1.21 → 0.1.23

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/bin/skillfree.js CHANGED
@@ -18,6 +18,20 @@ auth
18
18
  const { authLogin } = require('../scripts/commands/auth')
19
19
  await authLogin()
20
20
  })
21
+ auth
22
+ .command('save <apiKey>')
23
+ .description('直接保存 API Key(供安装脚本调用)')
24
+ .action(async (apiKey) => {
25
+ const { authSave } = require('../scripts/commands/auth')
26
+ await authSave(apiKey)
27
+ })
28
+ auth
29
+ .command('save <apiKey>')
30
+ .description('直接保存 API Key(供安装脚本调用)')
31
+ .action(async (apiKey) => {
32
+ const { authSave } = require('../scripts/commands/auth')
33
+ await authSave(apiKey)
34
+ })
21
35
  auth
22
36
  .command('status')
23
37
  .description('查看当前登录状态和积分')
package/install.sh CHANGED
@@ -80,7 +80,7 @@ fi
80
80
  echo ""
81
81
  success "SkillFree CLI 安装完成"
82
82
 
83
- # 刷新 PATH(nvm 等工具安装后 CLI 可能还不在当前 shell 的 PATH 里)
83
+ # 刷新 PATH
84
84
  hash -r 2>/dev/null || true
85
85
  export PATH="$(npm root -g)/../bin:$PATH"
86
86
 
@@ -91,14 +91,51 @@ if ! command -v skillfree &>/dev/null; then
91
91
  exit 0
92
92
  fi
93
93
 
94
- # ── Step 3: 登录 ──────────────────────────────────────────────────────────────
94
+ # ── Step 3: 登录(从 /dev/tty 读取,兼容 curl | bash)────────────────────────
95
95
  step "[ 3 / 3 ] 登录账号"
96
96
  echo ""
97
97
  echo -e " 还没有账号?${CYAN}https://skillfree.tech/app${NC} 免费注册"
98
- echo -e " 注册后进入控制台 → API Keys → 创建一个 Key,粘贴到下方"
98
+ echo -e " 注册后进入控制台 → ${BOLD}API Keys${NC} → 创建一个 Key,粘贴到下方"
99
99
  echo ""
100
100
 
101
- skillfree auth login
101
+ API_KEY=""
102
+ while true; do
103
+ # 强制从 /dev/tty 读取,避免 curl | bash 时 stdin 被占用
104
+ printf " 请粘贴 API Key (sk-sf-...),输入 q 跳过: "
105
+ read -r API_KEY </dev/tty
106
+
107
+ if [ "$API_KEY" = "q" ] || [ -z "$API_KEY" ]; then
108
+ echo ""
109
+ warn "已跳过登录,稍后可运行 ${CYAN}skillfree auth login${NC} 完成配置"
110
+ API_KEY=""
111
+ break
112
+ fi
113
+
114
+ if [[ "$API_KEY" != sk-sf-* ]]; then
115
+ echo -e " ${RED}✗${NC} 格式不对,Key 应以 sk-sf- 开头,请重试\n"
116
+ continue
117
+ fi
118
+
119
+ # 验证 Key
120
+ printf " 验证中..."
121
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
122
+ -H "Authorization: Bearer $API_KEY" \
123
+ "https://skillfree.tech/v1/balance")
124
+
125
+ if [ "$HTTP_CODE" = "200" ]; then
126
+ echo -e " ${GREEN}✓${NC}"
127
+ break
128
+ else
129
+ echo -e " ${RED}✗${NC} (HTTP $HTTP_CODE)"
130
+ echo -e " ${RED}✗${NC} Key 无效,请检查后重试\n"
131
+ API_KEY=""
132
+ fi
133
+ done
134
+
135
+ # 有效 Key → 交给 CLI 写入配置
136
+ if [ -n "$API_KEY" ]; then
137
+ SKILLFREE_API_KEY="$API_KEY" skillfree auth save "$API_KEY"
138
+ fi
102
139
 
103
140
  # ── 完成 ──────────────────────────────────────────────────────────────────────
104
141
  echo ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillfree",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "🦞 一个 API,满足所有龙虾技能需求",
5
5
  "main": "bin/skillfree.js",
6
6
  "bin": {
@@ -112,6 +112,32 @@ async function authLogin() {
112
112
  rl.close()
113
113
  }
114
114
 
115
+ async function authSave(apiKey) {
116
+ if (!apiKey || !apiKey.startsWith('sk-sf-')) {
117
+ console.error('❌ Key 格式不正确')
118
+ process.exit(1)
119
+ }
120
+ saveConfig({ apiKey })
121
+ injectToOpenclaw(apiKey)
122
+ console.log(`\n🎉 登录成功!`)
123
+ console.log(`\n快速开始:`)
124
+ console.log(` skillfree pilot --type chat --prompt "你好"`)
125
+ console.log(` skillfree models # 查看所有可用模型`)
126
+ }
127
+
128
+ async function authSave(apiKey) {
129
+ if (!apiKey || !apiKey.startsWith('sk-sf-')) {
130
+ console.error('❌ Key 格式不正确')
131
+ process.exit(1)
132
+ }
133
+ saveConfig({ apiKey })
134
+ injectToOpenclaw(apiKey)
135
+ console.log(`\n🎉 登录成功!`)
136
+ console.log(`\n快速开始:`)
137
+ console.log(` skillfree pilot --type chat --prompt "你好"`)
138
+ console.log(` skillfree models # 查看所有可用模型`)
139
+ }
140
+
115
141
  async function authStatus() {
116
142
  const { getApiKey, BASE_URL } = require('../lib/client')
117
143
  const key = getApiKey()
@@ -132,4 +158,5 @@ async function authStatus() {
132
158
  console.log(` Key:${key.slice(0, 10)}****${key.slice(-4)}`)
133
159
  }
134
160
 
135
- module.exports = { authLogin, authStatus }
161
+ module.exports = { authLogin, authSave, authStatus }
162
+