skillfree 0.1.69 โ 0.1.70
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 +88 -36
package/package.json
CHANGED
package/scripts/commands/auth.js
CHANGED
|
@@ -4,36 +4,24 @@ const path = require('path')
|
|
|
4
4
|
const os = require('os')
|
|
5
5
|
const { saveConfig, BASE_URL } = require('../lib/client')
|
|
6
6
|
|
|
7
|
-
// โโ ๅนณๅฐ โ ๆ่ฝๅฎ่ฃ
่ทฏๅพๆ ๅฐ๏ผไธ postinstall.js ไฟๆไธ่ด๏ผโโโโโโโโโโโโโโโโโ
|
|
8
|
-
const PLATFORM_PATHS = {
|
|
9
|
-
openclaw: [
|
|
10
|
-
path.join(os.homedir(), '.openclaw', 'skills', 'skillfree'),
|
|
11
|
-
path.join(os.homedir(), '.agents', 'skills', 'skillfree'),
|
|
12
|
-
],
|
|
13
|
-
claude: [
|
|
14
|
-
path.join(os.homedir(), '.claude', 'skills', 'skillfree'),
|
|
15
|
-
],
|
|
16
|
-
codex: [
|
|
17
|
-
path.join(os.homedir(), '.codex', 'skills', 'skillfree'),
|
|
18
|
-
],
|
|
19
|
-
continue: [
|
|
20
|
-
path.join(os.homedir(), '.continue', 'skills', 'skillfree'),
|
|
21
|
-
],
|
|
22
|
-
cursor: [
|
|
23
|
-
path.join(os.homedir(), '.cursor', 'skills', 'skillfree'),
|
|
24
|
-
],
|
|
25
|
-
}
|
|
26
|
-
|
|
27
7
|
/**
|
|
28
|
-
* ๅฐ apiKey
|
|
8
|
+
* ๅฐ apiKey ๆณจๅ
ฅๅฐๅๅนณๅฐ้
็ฝฎ + shell ็ฏๅขๅ้
|
|
9
|
+
*
|
|
10
|
+
* ๅๅนณๅฐๆณจๅ
ฅๆนๅผ๏ผ
|
|
11
|
+
* openclaw โ ~/.openclaw/openclaw.json (skills.entries.skillfree.apiKey)
|
|
12
|
+
* hermes โ ~/.hermes/.env (SKILLFREE_API_KEY=xxx)
|
|
13
|
+
* claude โ ~/.claude/settings.json (env.SKILLFREE_API_KEY)
|
|
14
|
+
* codex โ ๆ ไธ็จ้
็ฝฎ๏ผ่ตฐ shell ็ฏๅขๅ้ๅณๅฏ
|
|
15
|
+
* ้็จ โ ~/.zshrc / ~/.bash_profile (export SKILLFREE_API_KEY=xxx)
|
|
29
16
|
*/
|
|
30
17
|
function injectToOpenclaw(apiKey) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
const HOME = os.homedir()
|
|
19
|
+
|
|
20
|
+
// โโ 1. OpenClaw: ๅๅ
ฅ openclaw.json โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
21
|
+
const openclawCfgPath = path.join(HOME, '.openclaw', 'openclaw.json')
|
|
22
|
+
if (fs.existsSync(path.join(HOME, '.openclaw')) && fs.existsSync(openclawCfgPath)) {
|
|
35
23
|
let cfg = {}
|
|
36
|
-
try { cfg = JSON.parse(fs.readFileSync(
|
|
24
|
+
try { cfg = JSON.parse(fs.readFileSync(openclawCfgPath, 'utf8')) } catch {}
|
|
37
25
|
cfg.skills = cfg.skills || {}
|
|
38
26
|
cfg.skills.entries = cfg.skills.entries || {}
|
|
39
27
|
cfg.skills.entries['skillfree'] = {
|
|
@@ -42,38 +30,102 @@ function injectToOpenclaw(apiKey) {
|
|
|
42
30
|
apiKey,
|
|
43
31
|
}
|
|
44
32
|
try {
|
|
45
|
-
fs.writeFileSync(
|
|
46
|
-
console.log('โ
openclaw.json
|
|
33
|
+
fs.writeFileSync(openclawCfgPath, JSON.stringify(cfg, null, 2) + '\n')
|
|
34
|
+
console.log('โ
[OpenClaw] openclaw.json ๅทฒๆดๆฐ')
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.warn('โ ๏ธ [OpenClaw] ๆ ๆณๅๅ
ฅ openclaw.json๏ผ', e.message)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// โโ 2. Hermes: ๅๅ
ฅ ~/.hermes/.env โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
41
|
+
const hermesDir = path.join(HOME, '.hermes')
|
|
42
|
+
if (fs.existsSync(hermesDir)) {
|
|
43
|
+
const hermesEnvPath = path.join(hermesDir, '.env')
|
|
44
|
+
_injectEnvFile(hermesEnvPath, 'SKILLFREE_API_KEY', apiKey)
|
|
45
|
+
console.log('โ
[Hermes] ~/.hermes/.env ๅทฒๅๅ
ฅ SKILLFREE_API_KEY')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// โโ 3. Claude Code: ๅๅ
ฅ ~/.claude/settings.json โโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
49
|
+
const claudeDir = path.join(HOME, '.claude')
|
|
50
|
+
if (fs.existsSync(claudeDir)) {
|
|
51
|
+
const claudeSettingsPath = path.join(claudeDir, 'settings.json')
|
|
52
|
+
let settings = {}
|
|
53
|
+
if (fs.existsSync(claudeSettingsPath)) {
|
|
54
|
+
try { settings = JSON.parse(fs.readFileSync(claudeSettingsPath, 'utf8')) } catch {}
|
|
55
|
+
}
|
|
56
|
+
settings.env = settings.env || {}
|
|
57
|
+
settings.env['SKILLFREE_API_KEY'] = apiKey
|
|
58
|
+
try {
|
|
59
|
+
fs.writeFileSync(claudeSettingsPath, JSON.stringify(settings, null, 2) + '\n')
|
|
60
|
+
console.log('โ
[Claude Code] ~/.claude/settings.json ๅทฒๅๅ
ฅ SKILLFREE_API_KEY')
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.warn('โ ๏ธ [Claude Code] ๆ ๆณๅๅ
ฅ settings.json๏ผ', e.message)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// โโ 4. Codex: ๅๅ
ฅ ~/.codex/config.json โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
67
|
+
const codexDir = path.join(HOME, '.codex')
|
|
68
|
+
if (fs.existsSync(codexDir)) {
|
|
69
|
+
const codexCfgPath = path.join(codexDir, 'config.json')
|
|
70
|
+
let cfg = {}
|
|
71
|
+
if (fs.existsSync(codexCfgPath)) {
|
|
72
|
+
try { cfg = JSON.parse(fs.readFileSync(codexCfgPath, 'utf8')) } catch {}
|
|
73
|
+
}
|
|
74
|
+
cfg.env = cfg.env || {}
|
|
75
|
+
cfg.env['SKILLFREE_API_KEY'] = apiKey
|
|
76
|
+
try {
|
|
77
|
+
fs.writeFileSync(codexCfgPath, JSON.stringify(cfg, null, 2) + '\n')
|
|
78
|
+
console.log('โ
[Codex] ~/.codex/config.json ๅทฒๅๅ
ฅ SKILLFREE_API_KEY')
|
|
47
79
|
} catch (e) {
|
|
48
|
-
console.warn('โ ๏ธ ๆ ๆณๅๅ
ฅ
|
|
80
|
+
console.warn('โ ๏ธ [Codex] ๆ ๆณๅๅ
ฅ config.json๏ผ', e.message)
|
|
49
81
|
}
|
|
50
82
|
}
|
|
51
83
|
|
|
52
|
-
//
|
|
84
|
+
// โโ 5. ้็จ๏ผๅๅ
ฅ shell ้
็ฝฎๆไปถ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
53
85
|
const exportLine = `\nexport SKILLFREE_API_KEY="${apiKey}"\n`
|
|
54
86
|
const shellFiles = [
|
|
55
|
-
path.join(
|
|
56
|
-
path.join(
|
|
87
|
+
path.join(HOME, '.zshrc'),
|
|
88
|
+
path.join(HOME, '.bash_profile'),
|
|
57
89
|
]
|
|
58
90
|
let wrote = false
|
|
59
91
|
for (const f of shellFiles) {
|
|
60
92
|
if (fs.existsSync(f)) {
|
|
61
93
|
const content = fs.readFileSync(f, 'utf8')
|
|
62
94
|
if (content.includes('SKILLFREE_API_KEY')) {
|
|
63
|
-
|
|
64
|
-
fs.writeFileSync(f, updated)
|
|
95
|
+
fs.writeFileSync(f, content.replace(/\nexport SKILLFREE_API_KEY=.*\n?/g, exportLine))
|
|
65
96
|
} else {
|
|
66
97
|
fs.appendFileSync(f, exportLine)
|
|
67
98
|
}
|
|
68
|
-
console.log(`โ
${path.basename(f)} ๅทฒๅๅ
ฅ SKILLFREE_API_KEY`)
|
|
99
|
+
console.log(`โ
[Shell] ${path.basename(f)} ๅทฒๅๅ
ฅ SKILLFREE_API_KEY`)
|
|
69
100
|
wrote = true
|
|
70
101
|
break
|
|
71
102
|
}
|
|
72
103
|
}
|
|
73
104
|
if (!wrote) {
|
|
74
105
|
fs.writeFileSync(shellFiles[0], `# SkillFree API Key${exportLine}`)
|
|
75
|
-
console.log('โ
~/.zshrc ๅทฒๅๅปบๅนถๅๅ
ฅ SKILLFREE_API_KEY')
|
|
106
|
+
console.log('โ
[Shell] ~/.zshrc ๅทฒๅๅปบๅนถๅๅ
ฅ SKILLFREE_API_KEY')
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* ๅ .env ๆไปถๆณจๅ
ฅๆๆดๆฐไธไธช KEY=value ่ก
|
|
112
|
+
*/
|
|
113
|
+
function _injectEnvFile(envPath, key, value) {
|
|
114
|
+
const line = `${key}="${value}"`
|
|
115
|
+
let content = ''
|
|
116
|
+
if (fs.existsSync(envPath)) {
|
|
117
|
+
content = fs.readFileSync(envPath, 'utf8')
|
|
118
|
+
if (content.includes(key + '=')) {
|
|
119
|
+
// ๆฟๆขๅทฒๆ่ก
|
|
120
|
+
content = content.replace(new RegExp(`^${key}=.*$`, 'm'), line)
|
|
121
|
+
} else {
|
|
122
|
+
content = content.trimEnd() + '\n' + line + '\n'
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
content = line + '\n'
|
|
76
126
|
}
|
|
127
|
+
fs.mkdirSync(path.dirname(envPath), { recursive: true })
|
|
128
|
+
fs.writeFileSync(envPath, content)
|
|
77
129
|
}
|
|
78
130
|
|
|
79
131
|
function printQuickExamples() {
|