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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillfree",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "๐Ÿฆž ไธ€ไธช API๏ผŒๆปก่ถณๆ‰€ๆœ‰้พ™่™พๆŠ€่ƒฝ้œ€ๆฑ‚",
5
5
  "main": "bin/skillfree.js",
6
6
  "bin": {
@@ -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) {
@@ -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
  }