@blackbox_ai/blackbox-cli 0.9.2 → 1.0.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/dist/assets/notification.mp3 +0 -0
- package/dist/package.json +2 -2
- package/dist/src/commands/voice.js +39 -34
- package/dist/src/commands/voice.js.map +1 -1
- package/dist/src/config/config.js +1 -4
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/settings.d.ts +2 -0
- package/dist/src/config/settings.js +22 -1
- package/dist/src/config/settings.js.map +1 -1
- package/dist/src/config/settingsSchema.d.ts +36 -7
- package/dist/src/config/settingsSchema.js +35 -8
- package/dist/src/config/settingsSchema.js.map +1 -1
- package/dist/src/gemini.js +25 -20
- package/dist/src/gemini.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/services/BuiltinCommandLoader.js +2 -2
- package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
- package/dist/src/services/agentExecutor.d.ts +5 -0
- package/dist/src/services/agentExecutor.js +6 -2
- package/dist/src/services/agentExecutor.js.map +1 -1
- package/dist/src/services/voiceRecordingService.d.ts +13 -1
- package/dist/src/services/voiceRecordingService.js +38 -5
- package/dist/src/services/voiceRecordingService.js.map +1 -1
- package/dist/src/ui/App.js +255 -20
- package/dist/src/ui/App.js.map +1 -1
- package/dist/src/ui/commands/agentCommand.js +134 -43
- package/dist/src/ui/commands/agentCommand.js.map +1 -1
- package/dist/src/ui/commands/modelCommand.js +15 -2
- package/dist/src/ui/commands/modelCommand.js.map +1 -1
- package/dist/src/ui/commands/quitCommand.js +5 -0
- package/dist/src/ui/commands/quitCommand.js.map +1 -1
- package/dist/src/ui/commands/subAgentsCommand.d.ts +7 -0
- package/dist/src/ui/commands/subAgentsCommand.js +32 -0
- package/dist/src/ui/commands/subAgentsCommand.js.map +1 -0
- package/dist/src/ui/commands/types.d.ts +14 -3
- package/dist/src/ui/commands/types.js.map +1 -1
- package/dist/src/ui/commands/voiceCommand.js +70 -34
- package/dist/src/ui/commands/voiceCommand.js.map +1 -1
- package/dist/src/ui/commands/voiceCommand.test.d.ts +6 -0
- package/dist/src/ui/commands/voiceCommand.test.js +131 -0
- package/dist/src/ui/commands/voiceCommand.test.js.map +1 -0
- package/dist/src/ui/components/AgentModelSelector.js +1 -1
- package/dist/src/ui/components/AgentModelSelector.js.map +1 -1
- package/dist/src/ui/components/AgentSetDialog.d.ts +15 -0
- package/dist/src/ui/components/AgentSetDialog.js +52 -0
- package/dist/src/ui/components/AgentSetDialog.js.map +1 -0
- package/dist/src/ui/components/ApiKeyInputDialog.d.ts +17 -0
- package/dist/src/ui/components/ApiKeyInputDialog.js +44 -0
- package/dist/src/ui/components/ApiKeyInputDialog.js.map +1 -0
- package/dist/src/ui/components/AuthDialog.js +32 -46
- package/dist/src/ui/components/AuthDialog.js.map +1 -1
- package/dist/src/ui/components/Footer.d.ts +6 -0
- package/dist/src/ui/components/Footer.js +17 -2
- package/dist/src/ui/components/Footer.js.map +1 -1
- package/dist/src/ui/components/GenericProviderKeyPrompt.js +1 -1
- package/dist/src/ui/components/GenericProviderKeyPrompt.js.map +1 -1
- package/dist/src/ui/components/Header.js +2 -9
- package/dist/src/ui/components/Header.js.map +1 -1
- package/dist/src/ui/components/HistoryBrowserDialog.js +2 -1
- package/dist/src/ui/components/HistoryBrowserDialog.js.map +1 -1
- package/dist/src/ui/components/InputPrompt.js +3 -1
- package/dist/src/ui/components/InputPrompt.js.map +1 -1
- package/dist/src/ui/components/MemoryUsageDisplay.js +41 -8
- package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -1
- package/dist/src/ui/components/SettingsDialog.js +4 -3
- package/dist/src/ui/components/SettingsDialog.js.map +1 -1
- package/dist/src/ui/components/SuggestionsDisplay.js +3 -2
- package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
- package/dist/src/ui/components/Tips.js +1 -1
- package/dist/src/ui/components/Tips.js.map +1 -1
- package/dist/src/ui/components/agents/SingleAgentDialog.d.ts +7 -4
- package/dist/src/ui/components/agents/SingleAgentDialog.js +135 -63
- package/dist/src/ui/components/agents/SingleAgentDialog.js.map +1 -1
- package/dist/src/ui/components/messages/DiffRenderer.js +1 -9
- package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -1
- package/dist/src/ui/components/messages/ErrorMessage.js +2 -1
- package/dist/src/ui/components/messages/ErrorMessage.js.map +1 -1
- package/dist/src/ui/components/messages/InfoMessage.js +2 -1
- package/dist/src/ui/components/messages/InfoMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolGroupMessage.js +4 -1
- package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -1
- package/dist/src/ui/components/messages/UserMessage.js +1 -2
- package/dist/src/ui/components/messages/UserMessage.js.map +1 -1
- package/dist/src/ui/components/shared/RadioButtonSelect.js +14 -4
- package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -1
- package/dist/src/ui/contexts/SessionContext.d.ts +18 -0
- package/dist/src/ui/contexts/SessionContext.js +25 -1
- package/dist/src/ui/contexts/SessionContext.js.map +1 -1
- package/dist/src/ui/hooks/slashCommandProcessor.d.ts +2 -2
- package/dist/src/ui/hooks/slashCommandProcessor.js +54 -2
- package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/useAgentCommandProcessor.d.ts +12 -2
- package/dist/src/ui/hooks/useAgentCommandProcessor.js +169 -4
- package/dist/src/ui/hooks/useAgentCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/useAuthCommand.d.ts +2 -1
- package/dist/src/ui/hooks/useAuthCommand.js +22 -2
- package/dist/src/ui/hooks/useAuthCommand.js.map +1 -1
- package/dist/src/ui/hooks/useDialogClose.d.ts +2 -0
- package/dist/src/ui/hooks/useDialogClose.js +5 -0
- package/dist/src/ui/hooks/useDialogClose.js.map +1 -1
- package/dist/src/ui/hooks/useEncryptedStream.d.ts +2 -1
- package/dist/src/ui/hooks/useEncryptedStream.js +17 -4
- package/dist/src/ui/hooks/useEncryptedStream.js.map +1 -1
- package/dist/src/ui/hooks/useGeminiStream.js +216 -21
- package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
- package/dist/src/ui/hooks/useInputBoxColor.d.ts +13 -0
- package/dist/src/ui/hooks/useInputBoxColor.js +62 -0
- package/dist/src/ui/hooks/useInputBoxColor.js.map +1 -0
- package/dist/src/ui/hooks/useMessageQueue.d.ts +7 -1
- package/dist/src/ui/hooks/useMessageQueue.js +9 -3
- package/dist/src/ui/hooks/useMessageQueue.js.map +1 -1
- package/dist/src/ui/utils/agentConversationUtils.d.ts +28 -0
- package/dist/src/ui/utils/agentConversationUtils.js +71 -0
- package/dist/src/ui/utils/agentConversationUtils.js.map +1 -0
- package/dist/src/ui/utils/colorBlend.d.ts +33 -0
- package/dist/src/ui/utils/colorBlend.js +61 -0
- package/dist/src/ui/utils/colorBlend.js.map +1 -0
- package/dist/src/ui/utils/commandUtils.d.ts +2 -1
- package/dist/src/ui/utils/commandUtils.js +14 -1
- package/dist/src/ui/utils/commandUtils.js.map +1 -1
- package/dist/src/ui/utils/commandUtils.test.js +25 -0
- package/dist/src/ui/utils/commandUtils.test.js.map +1 -1
- package/dist/src/ui/utils/terminalBackgroundDetector.d.ts +16 -0
- package/dist/src/ui/utils/terminalBackgroundDetector.js +124 -23
- package/dist/src/ui/utils/terminalBackgroundDetector.js.map +1 -1
- package/dist/src/utils/agentCommandBuilder.d.ts +16 -4
- package/dist/src/utils/agentCommandBuilder.js +66 -26
- package/dist/src/utils/agentCommandBuilder.js.map +1 -1
- package/dist/src/utils/apiKeyUtils.d.ts +47 -0
- package/dist/src/utils/apiKeyUtils.js +177 -0
- package/dist/src/utils/apiKeyUtils.js.map +1 -0
- package/dist/src/utils/backgroundUpdateCheck.js +104 -7
- package/dist/src/utils/backgroundUpdateCheck.js.map +1 -1
- package/dist/src/utils/memoryManager.d.ts +85 -0
- package/dist/src/utils/memoryManager.js +258 -0
- package/dist/src/utils/memoryManager.js.map +1 -0
- package/dist/src/utils/memoryMonitor.d.ts +89 -0
- package/dist/src/utils/memoryMonitor.js +238 -0
- package/dist/src/utils/memoryMonitor.js.map +1 -0
- package/dist/src/utils/memoryWrapper.d.ts +18 -0
- package/dist/src/utils/memoryWrapper.js +62 -0
- package/dist/src/utils/memoryWrapper.js.map +1 -0
- package/dist/src/utils/preLaunchUpdateCheck.js +17 -7
- package/dist/src/utils/preLaunchUpdateCheck.js.map +1 -1
- package/dist/src/utils/soundNotification.d.ts +15 -0
- package/dist/src/utils/soundNotification.js +138 -0
- package/dist/src/utils/soundNotification.js.map +1 -0
- package/dist/src/utils/versionStorage.d.ts +20 -0
- package/dist/src/utils/versionStorage.js +62 -0
- package/dist/src/utils/versionStorage.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Blackbox
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { SettingScope } from '../config/settings.js';
|
|
7
|
+
/**
|
|
8
|
+
* Mapping of agent types to their API key requirements
|
|
9
|
+
*/
|
|
10
|
+
export const AGENT_API_KEY_MAP = {
|
|
11
|
+
blackbox: {
|
|
12
|
+
envVarName: 'BLACKBOX_API_KEY',
|
|
13
|
+
settingsPath: 'security.auth.blackbox.apiKey',
|
|
14
|
+
displayName: 'Blackbox API Key',
|
|
15
|
+
placeholder: 'Enter your Blackbox API key...',
|
|
16
|
+
validator: (key) => key.length > 0 && !key.includes(' '),
|
|
17
|
+
description: 'Blackbox API key required for Blackbox CLI',
|
|
18
|
+
},
|
|
19
|
+
claude: {
|
|
20
|
+
envVarName: 'BLACKBOX_API_KEY', // Claude uses Blackbox API key
|
|
21
|
+
settingsPath: 'security.auth.blackbox.apiKey',
|
|
22
|
+
displayName: 'Blackbox API Key (for Claude Code)',
|
|
23
|
+
placeholder: 'Enter your Blackbox API key...',
|
|
24
|
+
validator: (key) => key.length > 0 && !key.includes(' '),
|
|
25
|
+
description: 'Blackbox API key required for Claude Code agent access',
|
|
26
|
+
},
|
|
27
|
+
codex: {
|
|
28
|
+
envVarName: 'OPENAI_API_KEY', // Primary, but can also use BLACKBOX_API_KEY
|
|
29
|
+
settingsPath: 'security.auth.openai.apiKey',
|
|
30
|
+
displayName: 'OpenAI API Key',
|
|
31
|
+
placeholder: 'sk-...',
|
|
32
|
+
validator: (key) => key.startsWith('sk-') && key.length > 20,
|
|
33
|
+
description: 'OpenAI API key required for Codex agent (or use Blackbox API key)',
|
|
34
|
+
},
|
|
35
|
+
gemini: {
|
|
36
|
+
envVarName: 'GEMINI_API_KEY',
|
|
37
|
+
settingsPath: 'security.auth.google.apiKey',
|
|
38
|
+
displayName: 'Gemini API Key',
|
|
39
|
+
placeholder: 'Enter your Gemini API key...',
|
|
40
|
+
validator: (key) => key.length > 0 && !key.includes(' '),
|
|
41
|
+
description: 'Google Gemini API key required for Gemini agent',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Check if an API key is available for the given agent type
|
|
46
|
+
* Checks both environment variables and settings
|
|
47
|
+
*/
|
|
48
|
+
export function hasApiKeyForAgent(agentType, settings) {
|
|
49
|
+
const keyInfo = AGENT_API_KEY_MAP[agentType];
|
|
50
|
+
if (!keyInfo)
|
|
51
|
+
return false;
|
|
52
|
+
// Check environment variable first
|
|
53
|
+
const envKey = process.env[keyInfo.envVarName];
|
|
54
|
+
if (envKey && keyInfo.validator(envKey)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
// For Codex, also check for BLACKBOX_API_KEY as fallback
|
|
58
|
+
if (agentType === 'codex') {
|
|
59
|
+
const blackboxKey = process.env['BLACKBOX_API_KEY'];
|
|
60
|
+
if (blackboxKey && blackboxKey.length > 0) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Check settings if available
|
|
65
|
+
if (settings) {
|
|
66
|
+
const settingsKey = getApiKeyFromSettings(agentType, settings);
|
|
67
|
+
if (settingsKey && keyInfo.validator(settingsKey)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
// For Codex, also check Blackbox key in settings as fallback
|
|
71
|
+
if (agentType === 'codex') {
|
|
72
|
+
const blackboxSettingsKey = getApiKeyFromSettings('blackbox', settings);
|
|
73
|
+
if (blackboxSettingsKey && blackboxSettingsKey.length > 0) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get API key from settings for the given agent type
|
|
82
|
+
*/
|
|
83
|
+
export function getApiKeyFromSettings(agentType, settings) {
|
|
84
|
+
const keyInfo = AGENT_API_KEY_MAP[agentType];
|
|
85
|
+
if (!keyInfo)
|
|
86
|
+
return undefined;
|
|
87
|
+
const pathParts = keyInfo.settingsPath.split('.');
|
|
88
|
+
let current = settings.merged;
|
|
89
|
+
for (const part of pathParts) {
|
|
90
|
+
if (current && typeof current === 'object' && current !== null && part in current) {
|
|
91
|
+
current = current[part];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return typeof current === 'string' ? current : undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the effective API key for an agent (env var takes precedence over settings)
|
|
101
|
+
*/
|
|
102
|
+
export function getEffectiveApiKey(agentType, settings) {
|
|
103
|
+
const keyInfo = AGENT_API_KEY_MAP[agentType];
|
|
104
|
+
if (!keyInfo)
|
|
105
|
+
return undefined;
|
|
106
|
+
// Environment variable takes precedence
|
|
107
|
+
const envKey = process.env[keyInfo.envVarName];
|
|
108
|
+
if (envKey && keyInfo.validator(envKey)) {
|
|
109
|
+
return envKey;
|
|
110
|
+
}
|
|
111
|
+
// For Codex, check BLACKBOX_API_KEY as fallback
|
|
112
|
+
if (agentType === 'codex') {
|
|
113
|
+
const blackboxKey = process.env['BLACKBOX_API_KEY'];
|
|
114
|
+
if (blackboxKey && blackboxKey.length > 0) {
|
|
115
|
+
return blackboxKey;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Fall back to settings
|
|
119
|
+
if (settings) {
|
|
120
|
+
const settingsKey = getApiKeyFromSettings(agentType, settings);
|
|
121
|
+
if (settingsKey && keyInfo.validator(settingsKey)) {
|
|
122
|
+
return settingsKey;
|
|
123
|
+
}
|
|
124
|
+
// For Codex, also check Blackbox key in settings as fallback
|
|
125
|
+
if (agentType === 'codex') {
|
|
126
|
+
const blackboxSettingsKey = getApiKeyFromSettings('blackbox', settings);
|
|
127
|
+
if (blackboxSettingsKey && blackboxSettingsKey.length > 0) {
|
|
128
|
+
return blackboxSettingsKey;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Save API key to settings for the given agent type
|
|
136
|
+
*/
|
|
137
|
+
export function saveApiKeyToSettings(agentType, apiKey, settings) {
|
|
138
|
+
const keyInfo = AGENT_API_KEY_MAP[agentType];
|
|
139
|
+
if (!keyInfo) {
|
|
140
|
+
throw new Error(`Unknown agent type: ${agentType}`);
|
|
141
|
+
}
|
|
142
|
+
if (!keyInfo.validator(apiKey)) {
|
|
143
|
+
throw new Error(`Invalid API key format for ${agentType}`);
|
|
144
|
+
}
|
|
145
|
+
// Save to the appropriate settings path
|
|
146
|
+
settings.setValue(SettingScope.User, keyInfo.settingsPath, apiKey);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get missing API key info for agents that don't have keys
|
|
150
|
+
*/
|
|
151
|
+
export function getMissingApiKeyInfo(agentTypes, settings) {
|
|
152
|
+
return agentTypes
|
|
153
|
+
.filter(agentType => !hasApiKeyForAgent(agentType, settings))
|
|
154
|
+
.map(agentType => AGENT_API_KEY_MAP[agentType])
|
|
155
|
+
.filter(Boolean);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Validate API key format for a specific agent type
|
|
159
|
+
*/
|
|
160
|
+
export function validateApiKey(agentType, apiKey) {
|
|
161
|
+
const keyInfo = AGENT_API_KEY_MAP[agentType];
|
|
162
|
+
if (!keyInfo) {
|
|
163
|
+
return { valid: false, error: `Unknown agent type: ${agentType}` };
|
|
164
|
+
}
|
|
165
|
+
if (!apiKey || apiKey.trim().length === 0) {
|
|
166
|
+
return { valid: false, error: 'API key cannot be empty' };
|
|
167
|
+
}
|
|
168
|
+
const trimmedKey = apiKey.trim();
|
|
169
|
+
if (!keyInfo.validator(trimmedKey)) {
|
|
170
|
+
if (agentType === 'codex') {
|
|
171
|
+
return { valid: false, error: 'OpenAI API key must start with "sk-" and be at least 20 characters long' };
|
|
172
|
+
}
|
|
173
|
+
return { valid: false, error: `Invalid ${keyInfo.displayName} format` };
|
|
174
|
+
}
|
|
175
|
+
return { valid: true };
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=apiKeyUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKeyUtils.js","sourceRoot":"","sources":["../../../src/utils/apiKeyUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAkC;IAC9D,QAAQ,EAAE;QACR,UAAU,EAAE,kBAAkB;QAC9B,YAAY,EAAE,+BAA+B;QAC7C,WAAW,EAAE,kBAAkB;QAC/B,WAAW,EAAE,gCAAgC;QAC7C,SAAS,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;QAChE,WAAW,EAAE,4CAA4C;KA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AAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC;IAC5D,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YAC1B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,yEAAyE,EAAE,CAAC;QAC5G,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,OAAO,CAAC,WAAW,SAAS,EAAE,CAAC;IAC1E,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -3,32 +3,122 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { getCurrentVersion, fetchLatestVersionFromAPI, getPlatformString, writePendingUpdate, } from './versionStorage.js';
|
|
6
|
+
import { getCurrentVersion, fetchLatestVersionFromAPI, getPlatformString, writePendingUpdate, shouldCheckForUpdate, writeLastCheck, } from './versionStorage.js';
|
|
7
7
|
import semver from 'semver';
|
|
8
|
+
/**
|
|
9
|
+
* Fetches the latest version with retry logic
|
|
10
|
+
* @param platform Platform string
|
|
11
|
+
* @param maxRetries Maximum number of retry attempts
|
|
12
|
+
* @param timeoutMs Timeout in milliseconds for each attempt
|
|
13
|
+
* @returns Latest version string or null if all attempts fail
|
|
14
|
+
*/
|
|
15
|
+
async function fetchLatestVersionWithRetry(platform, maxRetries = 2, timeoutMs = 7000) {
|
|
16
|
+
const debugMode = process.env['DEBUG'] === 'true';
|
|
17
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
18
|
+
try {
|
|
19
|
+
if (debugMode) {
|
|
20
|
+
console.debug(`[Update Check] Attempt ${attempt}/${maxRetries} to fetch latest version...`);
|
|
21
|
+
}
|
|
22
|
+
const latestVersion = await fetchLatestVersionFromAPI(platform, timeoutMs);
|
|
23
|
+
if (latestVersion) {
|
|
24
|
+
if (debugMode) {
|
|
25
|
+
console.debug(`[Update Check] Successfully fetched latest version: ${latestVersion}`);
|
|
26
|
+
}
|
|
27
|
+
return latestVersion;
|
|
28
|
+
}
|
|
29
|
+
if (debugMode) {
|
|
30
|
+
console.debug(`[Update Check] Attempt ${attempt} returned null, retrying...`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (debugMode) {
|
|
35
|
+
console.debug(`[Update Check] Attempt ${attempt} failed:`, error);
|
|
36
|
+
}
|
|
37
|
+
// If this is not the last attempt, wait before retrying with exponential backoff
|
|
38
|
+
if (attempt < maxRetries) {
|
|
39
|
+
const backoffMs = 1000 * Math.pow(2, attempt - 1); // 1s, 2s, 4s...
|
|
40
|
+
if (debugMode) {
|
|
41
|
+
console.debug(`[Update Check] Waiting ${backoffMs}ms before retry...`);
|
|
42
|
+
}
|
|
43
|
+
await new Promise(resolve => setTimeout(resolve, backoffMs));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (debugMode) {
|
|
48
|
+
console.debug(`[Update Check] All ${maxRetries} attempts failed`);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
8
52
|
/**
|
|
9
53
|
* Performs a background check for updates without blocking CLI startup
|
|
10
54
|
* If an update is found, it stores the information for the next CLI launch
|
|
11
55
|
*/
|
|
12
56
|
export async function backgroundUpdateCheck() {
|
|
57
|
+
const debugMode = process.env['DEBUG'] === 'true';
|
|
13
58
|
try {
|
|
59
|
+
// Check if enough time has passed since last check (default: 1 hour)
|
|
60
|
+
if (!shouldCheckForUpdate()) {
|
|
61
|
+
if (debugMode) {
|
|
62
|
+
console.debug('[Update Check] Skipping check - not enough time has passed since last check');
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (debugMode) {
|
|
67
|
+
console.debug('[Update Check] Starting background update check...');
|
|
68
|
+
}
|
|
14
69
|
// Get current and latest versions
|
|
15
70
|
const currentVersion = await getCurrentVersion();
|
|
16
71
|
if (!currentVersion) {
|
|
72
|
+
if (debugMode) {
|
|
73
|
+
console.debug('[Update Check] Could not determine current version');
|
|
74
|
+
}
|
|
75
|
+
writeLastCheck(false);
|
|
17
76
|
return;
|
|
18
77
|
}
|
|
78
|
+
if (debugMode) {
|
|
79
|
+
console.debug(`[Update Check] Current version: ${currentVersion}`);
|
|
80
|
+
}
|
|
19
81
|
const platform = getPlatformString();
|
|
20
|
-
|
|
21
|
-
|
|
82
|
+
if (debugMode) {
|
|
83
|
+
console.debug(`[Update Check] Platform: ${platform}`);
|
|
84
|
+
}
|
|
85
|
+
// Fetch latest version with retry logic (2 attempts, 7 second timeout each)
|
|
86
|
+
const latestVersion = await fetchLatestVersionWithRetry(platform, 2, 7000);
|
|
87
|
+
// If we can't fetch the latest version, record failed check
|
|
22
88
|
if (!latestVersion) {
|
|
89
|
+
if (debugMode) {
|
|
90
|
+
console.debug('[Update Check] Failed to fetch latest version after all retries');
|
|
91
|
+
}
|
|
92
|
+
writeLastCheck(false);
|
|
23
93
|
return;
|
|
24
94
|
}
|
|
95
|
+
if (debugMode) {
|
|
96
|
+
console.debug(`[Update Check] Latest version: ${latestVersion}`);
|
|
97
|
+
}
|
|
25
98
|
// Check if update is available
|
|
26
99
|
if (semver.gt(latestVersion, currentVersion)) {
|
|
100
|
+
if (debugMode) {
|
|
101
|
+
console.debug(`[Update Check] Update available: ${currentVersion} -> ${latestVersion}`);
|
|
102
|
+
}
|
|
27
103
|
// Store the pending update for next launch
|
|
28
|
-
writePendingUpdate(latestVersion);
|
|
104
|
+
const written = writePendingUpdate(latestVersion);
|
|
105
|
+
if (debugMode) {
|
|
106
|
+
console.debug(`[Update Check] Pending update ${written ? 'written' : 'failed to write'}`);
|
|
107
|
+
}
|
|
108
|
+
writeLastCheck(true);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (debugMode) {
|
|
112
|
+
console.debug('[Update Check] Already on latest version');
|
|
113
|
+
}
|
|
114
|
+
writeLastCheck(true);
|
|
29
115
|
}
|
|
30
116
|
}
|
|
31
|
-
catch (
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (debugMode) {
|
|
119
|
+
console.debug('[Update Check] Unexpected error:', error);
|
|
120
|
+
}
|
|
121
|
+
writeLastCheck(false);
|
|
32
122
|
// Silently fail - don't disrupt the CLI
|
|
33
123
|
}
|
|
34
124
|
}
|
|
@@ -37,11 +127,18 @@ export async function backgroundUpdateCheck() {
|
|
|
37
127
|
* This should be called after the CLI has started
|
|
38
128
|
*/
|
|
39
129
|
export function startBackgroundUpdateCheck() {
|
|
130
|
+
const debugMode = process.env['DEBUG'] === 'true';
|
|
131
|
+
if (debugMode) {
|
|
132
|
+
console.debug('[Update Check] Scheduling background update check...');
|
|
133
|
+
}
|
|
40
134
|
// Run the check in the background without awaiting
|
|
41
135
|
// Use setImmediate to ensure it runs after current event loop
|
|
42
136
|
setImmediate(() => {
|
|
43
|
-
backgroundUpdateCheck().catch(() => {
|
|
44
|
-
|
|
137
|
+
backgroundUpdateCheck().catch((error) => {
|
|
138
|
+
if (debugMode) {
|
|
139
|
+
console.debug('[Update Check] Background check failed:', error);
|
|
140
|
+
}
|
|
141
|
+
// Silently ignore errors in production
|
|
45
142
|
});
|
|
46
143
|
});
|
|
47
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundUpdateCheck.js","sourceRoot":"","sources":["../../../src/utils/backgroundUpdateCheck.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,
|
|
1
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AAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;QACD,cAAc,CAAC,KAAK,CAAC,CAAC;QACtB,wCAAwC;IAC1C,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;IAElD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;IACxE,CAAC;IAED,mDAAmD;IACnD,8DAA8D;IAC9D,YAAY,CAAC,GAAG,EAAE;QAChB,qBAAqB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACtC,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAClE,CAAC;YACD,uCAAuC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Config } from '@blackbox_ai/blackbox-cli-core';
|
|
7
|
+
/**
|
|
8
|
+
* Memory statistics interface
|
|
9
|
+
*/
|
|
10
|
+
export interface MemoryStats {
|
|
11
|
+
heapUsed: number;
|
|
12
|
+
heapTotal: number;
|
|
13
|
+
heapLimit: number;
|
|
14
|
+
external: number;
|
|
15
|
+
rss: number;
|
|
16
|
+
usagePercentage: number;
|
|
17
|
+
pressureLevel: 'normal' | 'warning' | 'critical' | 'emergency';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Memory cleanup callback type
|
|
21
|
+
*/
|
|
22
|
+
export type MemoryCleanupCallback = () => void | Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Memory manager class for handling memory optimization and monitoring
|
|
25
|
+
*/
|
|
26
|
+
export declare class MemoryManager {
|
|
27
|
+
private cleanupCallbacks;
|
|
28
|
+
private monitoringInterval?;
|
|
29
|
+
private lastGcTime;
|
|
30
|
+
private gcThrottleMs;
|
|
31
|
+
private config?;
|
|
32
|
+
constructor(config?: Config);
|
|
33
|
+
/**
|
|
34
|
+
* Get optimal heap size arguments for Node.js
|
|
35
|
+
*/
|
|
36
|
+
static getOptimalHeapArgs(config?: Config): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Get current memory statistics
|
|
39
|
+
*/
|
|
40
|
+
getMemoryStats(): MemoryStats;
|
|
41
|
+
/**
|
|
42
|
+
* Register a cleanup callback to be called during memory pressure
|
|
43
|
+
*/
|
|
44
|
+
registerCleanupCallback(callback: MemoryCleanupCallback): () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Force garbage collection if enough time has passed
|
|
47
|
+
*/
|
|
48
|
+
forceGarbageCollection(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Run cleanup callbacks
|
|
51
|
+
*/
|
|
52
|
+
runCleanupCallbacks(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Handle memory pressure by running cleanup and forcing GC
|
|
55
|
+
*/
|
|
56
|
+
handleMemoryPressure(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Start memory monitoring
|
|
59
|
+
*/
|
|
60
|
+
startMonitoring(intervalMs?: number): void;
|
|
61
|
+
/**
|
|
62
|
+
* Stop memory monitoring
|
|
63
|
+
*/
|
|
64
|
+
stopMonitoring(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get formatted memory usage string
|
|
67
|
+
*/
|
|
68
|
+
getFormattedMemoryUsage(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Cleanup and destroy the memory manager
|
|
71
|
+
*/
|
|
72
|
+
destroy(): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get or create the global memory manager
|
|
76
|
+
*/
|
|
77
|
+
export declare function getMemoryManager(config?: Config): MemoryManager;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize memory management with optimal settings
|
|
80
|
+
*/
|
|
81
|
+
export declare function initializeMemoryManagement(config?: Config): MemoryManager;
|
|
82
|
+
/**
|
|
83
|
+
* Utility function to create a memory-aware cleanup callback
|
|
84
|
+
*/
|
|
85
|
+
export declare function createMemoryCleanupCallback(cleanupFn: () => void | Promise<void>, description?: string): MemoryCleanupCallback;
|