@2api-store/activate 0.3.0 → 0.3.2
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/activate.mjs +24 -8
- package/lib/detect.mjs +2 -2
- package/lib/install.mjs +2 -2
- package/lib/render.mjs +15 -2
- package/lib/ui.mjs +2 -1
- package/package.json +1 -1
package/activate.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// 抑制 node DeprecationWarning(DEP0190 spawnSync shell 等)+ 透传子进程
|
|
3
|
+
process.removeAllListeners('warning')
|
|
4
|
+
process.env.NODE_NO_WARNINGS = '1'
|
|
2
5
|
/**
|
|
3
6
|
* @2api-store/activate — TokenShop CLI 一键激活(v0.3.0)
|
|
4
7
|
*
|
|
@@ -27,11 +30,12 @@ import {
|
|
|
27
30
|
confirm,
|
|
28
31
|
closePrompt,
|
|
29
32
|
} from './lib/prompt.mjs'
|
|
30
|
-
import { banner, ok, fail, warn, info, step, guide, plain } from './lib/ui.mjs'
|
|
33
|
+
import { banner, ok, fail, warn, info, step, guide, plain, chalk } from './lib/ui.mjs'
|
|
31
34
|
import { getCliMeta, isDefaultSelected } from './lib/platforms.mjs'
|
|
32
35
|
import { ensureInstalled } from './lib/install.mjs'
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
import { createRequire } from 'node:module'
|
|
38
|
+
const VERSION = createRequire(import.meta.url)('./package.json').version
|
|
35
39
|
const DEFAULT_API_BASE = 'https://2api.store'
|
|
36
40
|
|
|
37
41
|
// ============================================================
|
|
@@ -240,10 +244,10 @@ async function main() {
|
|
|
240
244
|
const meta = getCliMeta(c.client_type)
|
|
241
245
|
const displayName = c.display_name || c.displayName || meta?.name || `${c.platform} ${c.client_type}`
|
|
242
246
|
const installed = env.installed[c.client_type]?.path || (meta && env.installed[meta.detectBin]?.path)
|
|
243
|
-
const installMark = installed ? '✓' : '✗'
|
|
244
247
|
const primaryMark = isDefaultSelected(c.client_type) ? '' : '(独立 CLI)'
|
|
248
|
+
const nameColored = installed ? chalk.green(displayName) : chalk.gray(`${displayName} (未装)`)
|
|
245
249
|
cliItems.push({
|
|
246
|
-
label:
|
|
250
|
+
label: `${nameColored} ${chalk.dim(`[${c.platform}/${c.client_type}]`)}${primaryMark}`,
|
|
247
251
|
config: c,
|
|
248
252
|
clientType: c.client_type,
|
|
249
253
|
meta,
|
|
@@ -259,7 +263,7 @@ async function main() {
|
|
|
259
263
|
|
|
260
264
|
step('选择 CLI')
|
|
261
265
|
const selectedIdxes = await multiSelect(
|
|
262
|
-
'选择要激活的 CLI
|
|
266
|
+
'选择要激活的 CLI(绿色=已装,灰色=未装;默认选主 CLI,独立 CLI 默认不选)',
|
|
263
267
|
cliItems,
|
|
264
268
|
{ defaultSelected },
|
|
265
269
|
)
|
|
@@ -303,10 +307,22 @@ async function main() {
|
|
|
303
307
|
const modelItems = listModels(bundle.models || [])
|
|
304
308
|
let defaultModelId = ''
|
|
305
309
|
if (modelItems.length > 0) {
|
|
306
|
-
step('
|
|
307
|
-
const
|
|
310
|
+
step('选择默认模型(最新优先)')
|
|
311
|
+
const TOP_N = 10
|
|
312
|
+
const topItems = modelItems.slice(0, TOP_N)
|
|
313
|
+
const hasMore = modelItems.length > TOP_N
|
|
314
|
+
const selectItems = [
|
|
315
|
+
...topItems.map((m) => ({ label: `${m.label} (${m.id})` })),
|
|
316
|
+
...(hasMore ? [{ label: chalk.dim('其他(手动输入模型 ID)') }] : []),
|
|
317
|
+
]
|
|
308
318
|
const idx = await select('选择默认模型', selectItems, { defaultIndex: 0 })
|
|
309
|
-
|
|
319
|
+
if (hasMore && idx === topItems.length) {
|
|
320
|
+
// 手动输入
|
|
321
|
+
defaultModelId = (await ask('输入模型 ID(如 gpt-5.6-terra)')).trim()
|
|
322
|
+
if (!defaultModelId) defaultModelId = topItems[0].id
|
|
323
|
+
} else {
|
|
324
|
+
defaultModelId = topItems[idx].id
|
|
325
|
+
}
|
|
310
326
|
ok(`已选默认模型:${defaultModelId}`)
|
|
311
327
|
} else {
|
|
312
328
|
warn('服务端未返回模型列表,{{defaultModel}} 将留空')
|
package/lib/detect.mjs
CHANGED
|
@@ -62,11 +62,11 @@ function findBinary(name, isWindows) {
|
|
|
62
62
|
function getVersion(bin, isWindows) {
|
|
63
63
|
// --version 是通用约定;codex/claude/gemini/opencode/grok 都支持
|
|
64
64
|
try {
|
|
65
|
-
const result = spawnSync(bin, ['--version'], {
|
|
65
|
+
const result = spawnSync(isWindows ? `${bin}.cmd` : bin, ['--version'], {
|
|
66
66
|
encoding: 'utf8',
|
|
67
67
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
68
68
|
timeout: 5000,
|
|
69
|
-
shell:
|
|
69
|
+
// 不用 shell:true(node 22+ DEP0190);Windows 用 <bin>.cmd 直调
|
|
70
70
|
})
|
|
71
71
|
if (result.status === 0 && result.stdout) {
|
|
72
72
|
const firstLine = result.stdout.trim().split(/\r?\n/)[0]
|
package/lib/install.mjs
CHANGED
|
@@ -38,9 +38,9 @@ export function installCLI(meta, opts = {}) {
|
|
|
38
38
|
|
|
39
39
|
console.log(` 正在执行:${cmd}…`)
|
|
40
40
|
try {
|
|
41
|
-
const result = spawnSync('npm', ['install', '-g', pkg], {
|
|
41
|
+
const result = spawnSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['install', '-g', pkg], {
|
|
42
42
|
stdio: 'inherit', // npm 进度/输出直接透传到当前终端
|
|
43
|
-
shell:
|
|
43
|
+
// 不用 shell:true(node 22+ DEP0190 警告 + 安全风险);Windows 用 npm.cmd 直调
|
|
44
44
|
})
|
|
45
45
|
if (result.status === 0) {
|
|
46
46
|
return { ok: true }
|
package/lib/render.mjs
CHANGED
|
@@ -63,14 +63,20 @@ export function expandPath(p, { isWindows } = {}) {
|
|
|
63
63
|
return p
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// 模型版本解析(gpt-5.6-sol → [5,6],gpt-oss-safeguard → [0,0] 旧)用于倒序排序(最新在前)
|
|
67
|
+
function modelVersion(id) {
|
|
68
|
+
const m = String(id || '').toLowerCase().match(/(\d+)\.(\d+)/)
|
|
69
|
+
return m ? [parseInt(m[1], 10), parseInt(m[2], 10)] : [0, 0]
|
|
70
|
+
}
|
|
71
|
+
|
|
66
72
|
/**
|
|
67
|
-
* 将 models 数组规整为 {id, label}
|
|
73
|
+
* 将 models 数组规整为 {id, label} 列表,按版本倒序排序(最新在前),供选择展示用
|
|
68
74
|
* @param {Array<{id?: string, name?: string}|string>} models
|
|
69
75
|
* @returns {Array<{index: number, id: string, label: string, raw: any}>}
|
|
70
76
|
*/
|
|
71
77
|
export function listModels(models) {
|
|
72
78
|
if (!Array.isArray(models) || models.length === 0) return []
|
|
73
|
-
|
|
79
|
+
const items = models.map((m, i) => {
|
|
74
80
|
if (typeof m === 'string') {
|
|
75
81
|
return { index: i, id: m, label: m, raw: m }
|
|
76
82
|
}
|
|
@@ -78,4 +84,11 @@ export function listModels(models) {
|
|
|
78
84
|
const label = m.name || m.id || id
|
|
79
85
|
return { index: i, id, label, raw: m }
|
|
80
86
|
})
|
|
87
|
+
// 版本倒序(最新在前);同版本按 id 字母序
|
|
88
|
+
items.sort((a, b) => {
|
|
89
|
+
const va = modelVersion(a.id)
|
|
90
|
+
const vb = modelVersion(b.id)
|
|
91
|
+
return vb[0] - va[0] || vb[1] - va[1] || String(a.id).localeCompare(String(b.id))
|
|
92
|
+
})
|
|
93
|
+
return items
|
|
81
94
|
}
|
package/lib/ui.mjs
CHANGED