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