skillfree 0.1.18 โ 0.1.19
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/pilot.js +4 -1
- package/scripts/lib/client.js +48 -1
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { post, postStream, get, request, getApiKey, BASE_URL } = require('../lib/client')
|
|
1
|
+
const { post, postStream, get, request, getApiKey, BASE_URL, checkCredits } = require('../lib/client')
|
|
2
2
|
const fs = require('fs')
|
|
3
3
|
const path = require('path')
|
|
4
4
|
|
|
@@ -30,6 +30,9 @@ async function pilot(flags) {
|
|
|
30
30
|
const output = flags.output || null
|
|
31
31
|
const model = flags.model || null
|
|
32
32
|
|
|
33
|
+
// โโ ็งฏๅ้ขๆฃ๏ผ< 100 ็งฏๅๆถๆฆๆชๅนถๆ็คบๅ
ๅผ๏ผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
34
|
+
await checkCredits()
|
|
35
|
+
|
|
33
36
|
// โโ CHAT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
34
37
|
if (type === 'chat') {
|
|
35
38
|
if (!output) {
|
package/scripts/lib/client.js
CHANGED
|
@@ -31,6 +31,52 @@ function getApiKey() {
|
|
|
31
31
|
return _config.apiKey || process.env.SKILLFREE_API_KEY || ''
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// โโโ ไฝ็งฏๅๆ้ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
35
|
+
const LOW_CREDITS_THRESHOLD = 100
|
|
36
|
+
|
|
37
|
+
function formatLowCreditsWarning(credits) {
|
|
38
|
+
return `
|
|
39
|
+
โ ๏ธ ็งฏๅไธ่ถณ๏ผๆ ๆณ็ปง็ปญ่ฐ็จ๏ผๅฝๅ็งฏๅ๏ผ${credits}๏ผๆไฝ้่ฆ ${LOW_CREDITS_THRESHOLD} ็งฏๅ๏ผ
|
|
40
|
+
|
|
41
|
+
๐ณ ๅ
ๅผๆต็จ๏ผ
|
|
42
|
+
1. ๆๅผๆต่งๅจ๏ผ่ฎฟ้ฎ https://skillfree.tech/app/billing
|
|
43
|
+
2. ้ๆฉๅ
ๅผๅฅ้ค๏ผๆจ่ ยฅ30 = 350็งฏๅ๏ผๆงไปทๆฏๆ้ซ๏ผ
|
|
44
|
+
3. ๅพฎไฟกๆซ็ ๆฏไป๏ผ็งฏๅ่ชๅจๅฐ่ดฆ๏ผ็บฆ 3 ็ง๏ผ
|
|
45
|
+
4. ๅ
ๅผๅ็ปง็ปญไฝฟ็จ skillfree ๅฝไปคๅณๅฏ
|
|
46
|
+
|
|
47
|
+
๐ฆ ๅฅ้คๅ่๏ผ
|
|
48
|
+
ยฅ10 โ 100 ็งฏๅ
|
|
49
|
+
ยฅ30 โ 350 ็งฏๅ๏ผๅค้ 50๏ผ
|
|
50
|
+
ยฅ100 โ 1300 ็งฏๅ๏ผๅค้ 300๏ผ
|
|
51
|
+
ยฅ300 โ 4500 ็งฏๅ๏ผๅค้ 1500๏ผ
|
|
52
|
+
|
|
53
|
+
็งฏๅๆฐธไธ่ฟๆ๏ผๆ ๆ่ดนๆ ่ฎข้
ใ`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* ไธปๅจๆฃๆฅ็งฏๅไฝ้ข๏ผไธ่ถณ LOW_CREDITS_THRESHOLD ๆถๆๅบ้่ฏฏ
|
|
58
|
+
* ไพ pilot.js ็ญๅจๅฎ้
่ฐ็จๅไธปๅจ่งฆๅ
|
|
59
|
+
*/
|
|
60
|
+
async function checkCredits() {
|
|
61
|
+
const apiKey = getApiKey()
|
|
62
|
+
if (!apiKey) return // ๆช็ปๅฝๆถๆพ่ก๏ผ็ฑ request ้็ปไธๆฅ้
|
|
63
|
+
try {
|
|
64
|
+
const res = await fetch(`${API_BASE}/balance`, {
|
|
65
|
+
headers: { 'Authorization': `Bearer ${apiKey}` },
|
|
66
|
+
})
|
|
67
|
+
if (res.ok) {
|
|
68
|
+
const data = await res.json()
|
|
69
|
+
const credits = data.credits ?? data.balance ?? 0
|
|
70
|
+
if (credits < LOW_CREDITS_THRESHOLD) {
|
|
71
|
+
throw new Error(formatLowCreditsWarning(credits))
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e.message.includes('็งฏๅไธ่ถณ')) throw e
|
|
76
|
+
// ็ฝ็ปๅคฑ่ดฅ็ญๅฟฝ็ฅ๏ผไธ้ปๅก็จๆท
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
34
80
|
// โโโ HTTP ๅทฅๅ
ท โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
35
81
|
async function request(endpoint, options = {}) {
|
|
36
82
|
const apiKey = getApiKey()
|
|
@@ -48,7 +94,7 @@ async function request(endpoint, options = {}) {
|
|
|
48
94
|
},
|
|
49
95
|
})
|
|
50
96
|
|
|
51
|
-
if (res.status === 402) throw new Error('็งฏๅไธ่ถณ๏ผ่ฏทๅๅพ https://skillfree.tech/app ๅ
ๅผ')
|
|
97
|
+
if (res.status === 402) throw new Error('็งฏๅไธ่ถณ๏ผ่ฏทๅๅพ https://skillfree.tech/app/billing ๅ
ๅผ')
|
|
52
98
|
if (res.status === 401) throw new Error('API Key ๆ ๆๆๅทฒ่ฟๆ๏ผ่ฏท้ๆฐ็ปๅฝ: skillfree auth login')
|
|
53
99
|
|
|
54
100
|
return res
|
|
@@ -89,4 +135,5 @@ module.exports = {
|
|
|
89
135
|
post,
|
|
90
136
|
postStream,
|
|
91
137
|
get,
|
|
138
|
+
checkCredits,
|
|
92
139
|
}
|