@pikecode/api-key-manager 1.3.0 → 1.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/package.json +1 -1
- package/src/commands/switch.js +27 -17
package/package.json
CHANGED
package/src/commands/switch.js
CHANGED
|
@@ -36,7 +36,14 @@ class EnvSwitcher extends BaseCommand {
|
|
|
36
36
|
this.currentPromptContext = null;
|
|
37
37
|
this.activeStatusRefresh = null;
|
|
38
38
|
this.filter = null;
|
|
39
|
-
this.filteredProviders = null;
|
|
39
|
+
this.filteredProviders = null;
|
|
40
|
+
this._refreshTimer = null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_getPageSize(itemCount) {
|
|
44
|
+
const rows = process.stdout.rows || 24;
|
|
45
|
+
const reserved = 8;
|
|
46
|
+
return Math.min(itemCount, Math.max(5, rows - reserved));
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
async validateProvider(providerName) {
|
|
@@ -296,15 +303,10 @@ class EnvSwitcher extends BaseCommand {
|
|
|
296
303
|
message: promptMessage,
|
|
297
304
|
choices,
|
|
298
305
|
default: defaultChoice,
|
|
299
|
-
pageSize:
|
|
306
|
+
pageSize: this._getPageSize(choices.length)
|
|
300
307
|
}
|
|
301
308
|
]);
|
|
302
309
|
|
|
303
|
-
// 移除 ESC 键监听
|
|
304
|
-
this.removeESCListener(escListener);
|
|
305
|
-
|
|
306
|
-
this._cancelStatusRefresh();
|
|
307
|
-
|
|
308
310
|
if (answer.provider === '__OPEN_CONFIG__') {
|
|
309
311
|
await this.openConfigFile();
|
|
310
312
|
return await this.showProviderSelection();
|
|
@@ -785,12 +787,7 @@ class EnvSwitcher extends BaseCommand {
|
|
|
785
787
|
name: 'action',
|
|
786
788
|
message: `选择供应商或操作 (总计 ${providers.length} 个):`,
|
|
787
789
|
choices,
|
|
788
|
-
pageSize:
|
|
789
|
-
}
|
|
790
|
-
]);
|
|
791
|
-
} catch (error) {
|
|
792
|
-
this.removeESCListener(escListener);
|
|
793
|
-
if (this.isEscCancelled(error)) {
|
|
790
|
+
pageSize: this._getPageSize(choices.length)
|
|
794
791
|
return;
|
|
795
792
|
}
|
|
796
793
|
throw error;
|
|
@@ -877,6 +874,10 @@ class EnvSwitcher extends BaseCommand {
|
|
|
877
874
|
|
|
878
875
|
_cancelStatusRefresh() {
|
|
879
876
|
this.activeStatusRefresh = null;
|
|
877
|
+
if (this._refreshTimer) {
|
|
878
|
+
clearTimeout(this._refreshTimer);
|
|
879
|
+
this._refreshTimer = null;
|
|
880
|
+
}
|
|
880
881
|
}
|
|
881
882
|
|
|
882
883
|
_applyStatusUpdate(providers, statusMap, error, refreshToken = null) {
|
|
@@ -908,10 +909,19 @@ class EnvSwitcher extends BaseCommand {
|
|
|
908
909
|
return;
|
|
909
910
|
}
|
|
910
911
|
|
|
911
|
-
//
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
912
|
+
// 节流:80ms 内的多次回调合并为一次 render,避免高频刷新导致 ANSI 光标错位
|
|
913
|
+
if (this._refreshTimer) {
|
|
914
|
+
clearTimeout(this._refreshTimer);
|
|
915
|
+
}
|
|
916
|
+
this._refreshTimer = setTimeout(() => {
|
|
917
|
+
this._refreshTimer = null;
|
|
918
|
+
if (this.activeStatusRefresh !== refreshToken) return;
|
|
919
|
+
const activeP = this.activePrompt?.promise?.ui?.activePrompt;
|
|
920
|
+
if (!activeP || activeP.status === 'answered') return;
|
|
921
|
+
const providers = this.filteredProviders || this.configManager.listProviders();
|
|
922
|
+
const statusMap = this.latestStatusMap || {};
|
|
923
|
+
this._refreshPromptChoices(activeP, providers, statusMap);
|
|
924
|
+
}, 80);
|
|
915
925
|
}
|
|
916
926
|
|
|
917
927
|
_refreshPromptChoices(activePrompt, providers, statusMap, options = {}) {
|