@sciagent/cli 1.0.40 → 1.0.44

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": "@sciagent/cli",
3
- "version": "1.0.40",
3
+ "version": "1.0.44",
4
4
  "description": "SciAgent CLI - AI Research Assistant",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,11 +15,11 @@
15
15
  "postinstall": "node scripts/postinstall.js"
16
16
  },
17
17
  "optionalDependencies": {
18
- "@sciagent/cli-linux-x64": "1.0.33",
18
+ "@sciagent/cli-linux-x64": "1.0.44",
19
19
  "@sciagent/cli-linux-arm64": "1.0.39",
20
20
  "@sciagent/cli-darwin-x64": "1.0.39",
21
21
  "@sciagent/cli-darwin-arm64": "1.0.39",
22
- "@sciagent/cli-win32-x64": "1.0.40",
22
+ "@sciagent/cli-win32-x64": "1.0.44",
23
23
  "@sciagent/cli-win32-arm64": "1.0.39"
24
24
  },
25
25
  "keywords": [
@@ -27,7 +27,12 @@ const ARCH_MAP = {
27
27
  };
28
28
 
29
29
  // 当前版本号 - 每次发布时同步更新
30
- const CURRENT_VERSION = '1.0.40';
30
+ const CURRENT_VERSION = '1.0.44';
31
+
32
+ // Releases 服务器配置
33
+ // 优先使用环境变量,否则使用默认服务器
34
+ const RELEASE_SERVER_URL = process.env.RELEASE_SERVER_URL ||
35
+ 'https://u250924-badf-b5de25de.westc.seetacloud.com:8443';
31
36
 
32
37
  // PyPI 镜像源列表(国内优先)
33
38
  const PYPI_MIRRORS = [
@@ -179,18 +184,18 @@ function downloadFile(url, destPath, timeout = 120000) {
179
184
  });
180
185
  }
181
186
 
182
- async function getLatestSdkVersion() {
183
- // 尝试从多个镜像获取版本信息
187
+ async function getSdkDownloadInfo(platformTag) {
188
+ // 尝试从多个镜像获取版本信息和下载URL
184
189
  const mirrors = [
185
190
  'https://mirrors.cloud.tencent.com/pypi/pypi/codebuddy-agent-sdk/json',
186
191
  'https://mirrors.aliyun.com/pypi/pypi/codebuddy-agent-sdk/json',
187
- 'https://pypi.tuna.tsinghua.edu.cn/pypi/codebuddy-agent-sdk/json',
192
+ 'https://pypi.tuna.tsinghua.edu.cn/pypi/pypi/codebuddy-agent-sdk/json',
188
193
  'https://pypi.org/pypi/codebuddy-agent-sdk/json'
189
194
  ];
190
195
 
191
196
  for (const url of mirrors) {
192
197
  try {
193
- const version = await new Promise((resolve, reject) => {
198
+ const result = await new Promise((resolve, reject) => {
194
199
  const protocol = url.startsWith('https') ? https : http;
195
200
  protocol.get(url, {
196
201
  headers: { 'User-Agent': 'sciagent-cli/1.0' },
@@ -207,7 +212,7 @@ async function getLatestSdkVersion() {
207
212
  res2.on('end', () => {
208
213
  try {
209
214
  const json = JSON.parse(data);
210
- resolve(json.info.version);
215
+ resolve(json);
211
216
  } catch (e) {
212
217
  reject(new Error('Parse error'));
213
218
  }
@@ -221,7 +226,7 @@ async function getLatestSdkVersion() {
221
226
  response.on('end', () => {
222
227
  try {
223
228
  const json = JSON.parse(data);
224
- resolve(json.info.version);
229
+ resolve(json);
225
230
  } catch (e) {
226
231
  reject(new Error('Parse error'));
227
232
  }
@@ -229,13 +234,27 @@ async function getLatestSdkVersion() {
229
234
  }).on('error', reject);
230
235
  });
231
236
 
232
- if (version) return version;
237
+ if (result && result.info && result.urls) {
238
+ const version = result.info.version;
239
+ // 查找匹配平台的wheel文件
240
+ const wheelUrl = result.urls.find(u =>
241
+ u.filename && u.filename.includes(platformTag) && u.filename.endsWith('.whl')
242
+ );
243
+
244
+ if (wheelUrl) {
245
+ console.log(` 从 ${url.split('/')[2]} 获取到版本信息`);
246
+ return { version, url: wheelUrl.url, size: wheelUrl.size };
247
+ } else {
248
+ console.log(` ${url.split('/')[2]}: 未找到 ${platformTag} 平台的wheel文件`);
249
+ }
250
+ }
233
251
  } catch (e) {
252
+ console.log(` ${url.split('/')[2]}: ${e.message}`);
234
253
  // 继续尝试下一个镜像
235
254
  }
236
255
  }
237
256
 
238
- throw new Error('无法获取SDK版本信息,请检查网络连接');
257
+ throw new Error('无法获取SDK下载信息,请检查网络连接');
239
258
  }
240
259
 
241
260
  async function installCodebuddySdk() {
@@ -259,45 +278,26 @@ async function installCodebuddySdk() {
259
278
  console.log('📦 正在安装 CodeBuddy SDK...');
260
279
 
261
280
  try {
262
- // 获取最新版本
281
+ // 获取版本信息和下载URL
263
282
  console.log(' 正在获取版本信息...');
264
- const version = await getLatestSdkVersion();
265
- console.log(` 版本: ${version}`);
283
+ const sdkInfo = await getSdkDownloadInfo(platformTag);
284
+ console.log(` 版本: ${sdkInfo.version}`);
266
285
  console.log(` 平台: ${platformTag}`);
267
-
268
- // 构建 wheel 文件名
269
- const wheelFilename = `codebuddy_agent_sdk-${version}-py3-none-${platformTag}.whl`;
286
+ console.log(` 文件大小: ${(sdkInfo.size / (1024 * 1024)).toFixed(1)} MB`);
270
287
 
271
288
  // 创建临时目录
272
289
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sciagent-sdk-'));
290
+ const wheelFilename = `codebuddy_agent_sdk-${sdkInfo.version}-py3-none-${platformTag}.whl`;
273
291
  const wheelPath = path.join(tmpDir, wheelFilename);
274
292
 
275
- // 尝试从多个镜像下载
276
- let downloaded = false;
293
+ // 使用从JSON API获取的正确URL下载
277
294
  const binaryName = BINARY_NAMES[platform] || 'codebuddy-headless';
278
295
  const binDir = getCodebuddyBinDir();
279
296
  const targetPath = path.join(binDir, binaryName);
280
297
 
281
- for (const mirror of PYPI_DOWNLOAD_MIRRORS) {
282
- const downloadUrl = `${mirror}/source/c/codebuddy-agent-sdk/${wheelFilename}`;
283
-
284
- try {
285
- console.log(` 尝试下载: ${mirror.split('/')[2]}...`);
286
- await downloadFile(downloadUrl, wheelPath);
287
- downloaded = true;
288
- console.log(' ✅ 下载成功');
289
- break;
290
- } catch (e) {
291
- console.log(` ❌ ${mirror.split('/')[2]}: ${e.message}`);
292
- continue;
293
- }
294
- }
295
-
296
- if (!downloaded) {
297
- console.error('❌ 所有镜像源下载失败');
298
- console.error(' 请检查网络连接,或稍后运行 "sciagent install-sdk" 手动安装');
299
- return false;
300
- }
298
+ console.log(' 正在下载...');
299
+ await downloadFile(sdkInfo.url, wheelPath);
300
+ console.log(' ✅ 下载成功');
301
301
 
302
302
  // 提取二进制文件
303
303
  console.log(' 正在提取二进制文件...');
@@ -369,9 +369,47 @@ sys.exit(1)
369
369
  }
370
370
  }
371
371
 
372
+ async function downloadFromServer(platform, arch, version) {
373
+ const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
374
+ const downloadUrl = `${RELEASE_SERVER_URL}/api/releases/download/${platform}/${arch}/${version}`;
375
+
376
+ console.log(`\n 📥 从服务器下载: ${downloadUrl}`);
377
+
378
+ // 确定安装目录
379
+ const installDir = path.join(os.homedir(), '.sciagent', 'bin');
380
+ fs.mkdirSync(installDir, { recursive: true });
381
+
382
+ const targetPath = path.join(installDir, binName);
383
+
384
+ try {
385
+ await downloadFile(downloadUrl, targetPath, 600000); // 10 分钟超时
386
+
387
+ // 验证下载
388
+ if (fs.existsSync(targetPath)) {
389
+ const stats = fs.statSync(targetPath);
390
+ if (stats.size > 10 * 1024 * 1024) { // 至少 10MB
391
+ console.log(` ✅ 下载成功: ${targetPath} (${(stats.size / (1024 * 1024)).toFixed(1)} MB)`);
392
+
393
+ // Linux/macOS 添加执行权限
394
+ if (platform !== 'win32') {
395
+ fs.chmodSync(targetPath, 0o755);
396
+ }
397
+
398
+ return true;
399
+ }
400
+ }
401
+
402
+ console.log(` ⚠️ 下载文件验证失败`);
403
+ return false;
404
+ } catch (e) {
405
+ console.log(` ⚠️ 服务器下载失败: ${e.message}`);
406
+ return false;
407
+ }
408
+ }
409
+
372
410
  function installBinaryPackage(platform, arch) {
373
411
  // 版本回退列表:先尝试当前版本,再尝试已知存在的版本
374
- const FALLBACK_VERSIONS = [CURRENT_VERSION, '1.0.38', '1.0.36', '1.0.33'];
412
+ const FALLBACK_VERSIONS = [CURRENT_VERSION, '1.0.40', '1.0.38', '1.0.36', '1.0.33'];
375
413
 
376
414
  let npmCmd = 'npm';
377
415
  const isGlobal = process.env.npm_config_global === 'true' ||
@@ -438,23 +476,33 @@ async function main() {
438
476
  } else {
439
477
  console.log(`⚠️ Platform binary not found: ${packageName}`);
440
478
 
441
- const success = installBinaryPackage(platform, arch);
479
+ // 优先尝试从服务器下载(更快、更可靠)
480
+ console.log('');
481
+ console.log(' 尝试从服务器下载...');
482
+ const serverSuccess = await downloadFromServer(platform, arch, CURRENT_VERSION);
442
483
 
443
- if (!success) {
444
- console.error('');
445
- console.error('╔══════════════════════════════════════════════════════════╗');
446
- console.error('║ Manual Installation Required ║');
447
- console.error('╚══════════════════════════════════════════════════════════╝');
448
- console.error('');
449
- console.error(' Please run this command manually:');
450
- console.error(` npm install -g ${packageName}@${CURRENT_VERSION}`);
451
- console.error('');
452
- process.exit(1);
484
+ if (!serverSuccess) {
485
+ // 服务器下载失败,回退到 npm 包安装
486
+ console.log('');
487
+ console.log(' 回退到 npm 包安装...');
488
+ const npmSuccess = installBinaryPackage(platform, arch);
489
+
490
+ if (!npmSuccess) {
491
+ console.error('');
492
+ console.error('╔══════════════════════════════════════════════════════════╗');
493
+ console.error('║ Manual Installation Required ║');
494
+ console.error('╚══════════════════════════════════════════════════════════╝');
495
+ console.error('');
496
+ console.error(' Please run this command manually:');
497
+ console.error(` npm install -g ${packageName}@${CURRENT_VERSION}`);
498
+ console.error('');
499
+ process.exit(1);
500
+ }
453
501
  }
454
502
 
455
503
  const verifyResult = checkBinaryInstalled(platform, arch);
456
504
  if (verifyResult.installed) {
457
- console.log(`\n✅ Platform binary installed successfully: ${packageName}`);
505
+ console.log(`\n✅ Platform binary installed successfully`);
458
506
  } else {
459
507
  console.error(`\n❌ Installation verification failed. Please install manually:`);
460
508
  console.error(` npm install -g ${packageName}@${CURRENT_VERSION}`);