@2api-store/activate 0.4.1 → 0.4.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/lib/cmds.mjs +20 -37
- package/package.json +1 -1
package/lib/cmds.mjs
CHANGED
|
@@ -227,6 +227,18 @@ async function cmdRestore(argv) {
|
|
|
227
227
|
byTime[tsKey].push(b)
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
// 同时间组内按 origPath 去重(同 origPath 只保留 mtime 最大的)
|
|
231
|
+
for (const ts of timeOrder) {
|
|
232
|
+
const group = byTime[ts]
|
|
233
|
+
const byOrig = {}
|
|
234
|
+
for (const b of group) {
|
|
235
|
+
if (!byOrig[b.origPath] || b.mtime > byOrig[b.origPath].mtime) {
|
|
236
|
+
byOrig[b.origPath] = b
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
byTime[ts] = Object.values(byOrig).sort((a, b) => b.mtime - a.mtime)
|
|
240
|
+
}
|
|
241
|
+
|
|
230
242
|
console.log()
|
|
231
243
|
step(`选择恢复时间点(${chosenAppLabel})`)
|
|
232
244
|
const timeItems = timeOrder.map((ts) => {
|
|
@@ -464,17 +476,11 @@ async function cmdReconfig(argv) {
|
|
|
464
476
|
info('识别为:API Key 模式(不创建账号,仅重拉模板写入配置)')
|
|
465
477
|
console.log()
|
|
466
478
|
|
|
467
|
-
//
|
|
468
|
-
|
|
469
|
-
const platform = platformAnswer || null
|
|
470
|
-
if (platform) info(`平台过滤:${platform}`)
|
|
471
|
-
console.log()
|
|
472
|
-
|
|
473
|
-
// POST /cli/activate
|
|
474
|
-
step('请求激活服务(key 模式重拉模板)')
|
|
479
|
+
// POST /cli/activate — 全平台,不问平台限制
|
|
480
|
+
step('请求激活服务(全量重拉模板)')
|
|
475
481
|
let bundle
|
|
476
482
|
try {
|
|
477
|
-
bundle = await cliActivate({ credential: apiKey,
|
|
483
|
+
bundle = await cliActivate({ credential: apiKey, apiBase })
|
|
478
484
|
} catch (err) {
|
|
479
485
|
fail(`请求失败:${err.message}`)
|
|
480
486
|
if (err.statusCode) fail(` HTTP ${err.statusCode}`)
|
|
@@ -487,7 +493,7 @@ async function cmdReconfig(argv) {
|
|
|
487
493
|
if (bundle.base_url) info(`base_url:${bundle.base_url}`)
|
|
488
494
|
console.log()
|
|
489
495
|
|
|
490
|
-
// 过滤配置
|
|
496
|
+
// 过滤配置 — 按模型平台推断 + OS 过滤(与默认激活流程一致)
|
|
491
497
|
const allowedPlatforms = new Set()
|
|
492
498
|
for (const m of bundle.models || []) {
|
|
493
499
|
const id = (typeof m === 'string' ? m : m?.id || '').toLowerCase()
|
|
@@ -496,12 +502,10 @@ async function cmdReconfig(argv) {
|
|
|
496
502
|
else if (id.startsWith('gemini')) allowedPlatforms.add('gemini')
|
|
497
503
|
else if (id.startsWith('grok')) allowedPlatforms.add('grok')
|
|
498
504
|
}
|
|
499
|
-
if (platform) allowedPlatforms.add(platform)
|
|
500
505
|
|
|
501
506
|
const osConfigs = (bundle.configs || []).filter((c) => {
|
|
502
507
|
if (!c) return false
|
|
503
508
|
if (allowedPlatforms.size > 0 && !allowedPlatforms.has(c.platform)) return false
|
|
504
|
-
if (platform && c.platform !== platform) return false
|
|
505
509
|
if (env.os.isWindows) {
|
|
506
510
|
return c.os_type === 'windows' || c.os_type === 'all'
|
|
507
511
|
}
|
|
@@ -513,43 +517,22 @@ async function cmdReconfig(argv) {
|
|
|
513
517
|
return 1
|
|
514
518
|
}
|
|
515
519
|
|
|
516
|
-
//
|
|
520
|
+
// reconfig: 全选所有配置,不问 CLI 选择
|
|
517
521
|
const seen = new Set()
|
|
518
|
-
const
|
|
522
|
+
const selectedItems = []
|
|
519
523
|
for (const c of osConfigs) {
|
|
520
524
|
const key = `${c.platform}/${c.client_type}`
|
|
521
525
|
if (seen.has(key)) continue
|
|
522
526
|
seen.add(key)
|
|
523
527
|
const meta = getCliMeta(c.client_type)
|
|
524
528
|
const displayName = c.display_name || c.displayName || meta?.name || `${c.platform} ${c.client_type}`
|
|
525
|
-
|
|
526
|
-
const primaryMark = isDefaultSelected(c.client_type) ? '' : '(独立 CLI)'
|
|
527
|
-
const nameColored = installed ? chalk.green(displayName) : chalk.gray(`${displayName} (未装)`)
|
|
528
|
-
cliItems.push({
|
|
529
|
-
label: `${nameColored} ${chalk.dim(`[${c.platform}/${c.client_type}]`)}${primaryMark}`,
|
|
529
|
+
selectedItems.push({
|
|
530
530
|
config: c,
|
|
531
531
|
clientType: c.client_type,
|
|
532
532
|
meta,
|
|
533
|
-
alreadyInstalled: !!installed,
|
|
534
533
|
})
|
|
535
534
|
}
|
|
536
|
-
|
|
537
|
-
const defaultSelected = cliItems
|
|
538
|
-
.map((item, i) => ({ item, i }))
|
|
539
|
-
.filter(({ item }) => isDefaultSelected(item.clientType))
|
|
540
|
-
.map(({ i }) => i)
|
|
541
|
-
|
|
542
|
-
step('选择要重配的 CLI')
|
|
543
|
-
const selectedIdxes = await multiSelect(
|
|
544
|
-
'选择 CLI(绿色=已装,灰色=未装;默认选主 CLI)',
|
|
545
|
-
cliItems,
|
|
546
|
-
{ defaultSelected },
|
|
547
|
-
)
|
|
548
|
-
if (selectedIdxes.length === 0) {
|
|
549
|
-
plain('未选择任何 CLI,退出。')
|
|
550
|
-
return 0
|
|
551
|
-
}
|
|
552
|
-
const selectedItems = selectedIdxes.map((i) => cliItems[i])
|
|
535
|
+
ok(`将覆盖 ${selectedItems.length} 个 CLI 配置`)
|
|
553
536
|
console.log()
|
|
554
537
|
|
|
555
538
|
// 选默认模型
|