@sciagent/cli 1.0.79 → 1.0.81

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/bin/sciagent.js CHANGED
@@ -5,13 +5,21 @@
5
5
  * 自动识别平台并调用对应的预编译二进制文件
6
6
  */
7
7
 
8
- const { spawn } = require('child_process');
8
+ const { spawn, execSync } = require('child_process');
9
9
  const path = require('path');
10
10
  const fs = require('fs');
11
11
  const os = require('os');
12
+ const https = require('https');
13
+ const http = require('http');
12
14
 
13
15
  // 当前版本号 - 与 postinstall.js 和 package.json 保持同步
14
- const CURRENT_VERSION = '1.0.79';
16
+ const CURRENT_VERSION = '1.0.81';
17
+
18
+ // 极狐GitLab下载配置
19
+ const JIHULAB_URL = 'https://jihulab.com';
20
+ const JIHULAB_PROJECT_ID = 351778;
21
+ const JIHULAB_PACKAGE_NAME = 'sciagent';
22
+ const JIHULAB_DOWNLOAD_TOKEN = '2qxfs606HfwESUYJxtRlgm86MQp1OjVnazAK.01.101vzs2qo';
15
23
 
16
24
  // 平台和架构映射
17
25
  const PLATFORM_MAP = {
@@ -136,18 +144,86 @@ function getBinaryPath() {
136
144
  return binPath;
137
145
  }
138
146
 
139
- // 未找到二进制文件
140
- console.error(`Error: Could not find SciAgent binary for ${platform}-${arch}`);
141
- console.error(`Tried locations:`);
142
- console.error(` ${homeBinPath}`);
143
- console.error(` ${packageName}/bin/${binName} (npm package)`);
144
- console.error(` ${localPath} (dev mode)`);
145
- console.error('');
146
- console.error('Please reinstall:');
147
- console.error(' npm install -g @sciagent/cli');
147
+ // 未找到二进制文件 - 自动下载
148
+ console.log(`⚠️ SciAgent binary not found for ${platform}-${arch}`);
149
+ console.log(` Attempting to download from JiHuLab...`);
150
+
151
+ const downloaded = downloadBinary(platform, arch, CURRENT_VERSION);
152
+ if (downloaded && fs.existsSync(downloaded)) {
153
+ return downloaded;
154
+ }
155
+
156
+ console.error(`\n❌ Failed to download SciAgent binary.`);
157
+ console.error(`Please reinstall: npm install -g @sciagent/cli`);
148
158
  process.exit(1);
149
159
  }
150
160
 
161
+ /**
162
+ * 从极狐GitLab下载二进制文件
163
+ */
164
+ function downloadBinary(platform, arch, version) {
165
+ const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
166
+ const ext = platform === 'win32' ? '.exe' : '';
167
+ const filename = `sciagent-${platform}-${arch}${ext}`;
168
+
169
+ const downloadUrl = (
170
+ `${JIHULAB_URL}/api/v4/projects/${JIHULAB_PROJECT_ID}` +
171
+ `/packages/generic/${JIHULAB_PACKAGE_NAME}/${version}/${filename}` +
172
+ `?access_token=${JIHULAB_DOWNLOAD_TOKEN}`
173
+ );
174
+
175
+ const installDir = platform === 'win32'
176
+ ? path.join(process.env.LOCALAPPDATA || os.homedir(), 'sciagent', 'bin')
177
+ : path.join(os.homedir(), '.sciagent', 'bin');
178
+ fs.mkdirSync(installDir, { recursive: true });
179
+ const targetPath = path.join(installDir, binName);
180
+
181
+ console.log(` Downloading ${filename} v${version}...`);
182
+ console.log(` Target: ${targetPath}`);
183
+
184
+ try {
185
+ // 同步下载(使用curl或PowerShell)
186
+ if (platform === 'win32') {
187
+ // Windows: 使用 PowerShell 下载
188
+ const psCmd = `
189
+ $ProgressPreference = 'SilentlyContinue'
190
+ Invoke-WebRequest -Uri '${downloadUrl}' -OutFile '${targetPath}' -UseBasicParsing
191
+ `.trim();
192
+ execSync(`powershell -NoProfile -Command "${psCmd.replace(/"/g, '\\"')}"`, {
193
+ stdio: 'pipe',
194
+ timeout: 600000
195
+ });
196
+ } else {
197
+ // Linux/macOS: 使用 curl
198
+ execSync(`curl -fsSL -o '${targetPath}' '${downloadUrl}'`, {
199
+ stdio: 'pipe',
200
+ timeout: 600000
201
+ });
202
+ fs.chmodSync(targetPath, 0o755);
203
+ }
204
+
205
+ // 验证下载
206
+ if (fs.existsSync(targetPath)) {
207
+ const stats = fs.statSync(targetPath);
208
+ if (stats.size > 10 * 1024 * 1024) {
209
+ console.log(` ✅ Downloaded: ${(stats.size / (1024 * 1024)).toFixed(1)} MB`);
210
+ // 写入版本文件
211
+ fs.writeFileSync(path.join(installDir, '.version'), version);
212
+ return targetPath;
213
+ } else {
214
+ console.error(` ❌ Downloaded file too small: ${(stats.size / 1024).toFixed(0)} KB`);
215
+ try { fs.unlinkSync(targetPath); } catch (e) {}
216
+ }
217
+ }
218
+ } catch (e) {
219
+ console.error(` ❌ Download failed: ${e.message}`);
220
+ // 清理可能的部分下载
221
+ try { if (fs.existsSync(targetPath)) fs.unlinkSync(targetPath); } catch (e2) {}
222
+ }
223
+
224
+ return null;
225
+ }
226
+
151
227
  /**
152
228
  * 主函数
153
229
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sciagent/cli",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "description": "SciAgent CLI - AI Research Assistant",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,12 +15,12 @@
15
15
  "postinstall": "node scripts/postinstall.js"
16
16
  },
17
17
  "optionalDependencies": {
18
- "@sciagent/cli-linux-x64": "1.0.74",
19
- "@sciagent/cli-linux-arm64": "1.0.39",
20
- "@sciagent/cli-darwin-x64": "1.0.39",
21
- "@sciagent/cli-darwin-arm64": "1.0.39",
22
- "@sciagent/cli-win32-x64": "1.0.76",
23
- "@sciagent/cli-win32-arm64": "1.0.39"
18
+ "@sciagent/cli-linux-x64": "1.0.81",
19
+ "@sciagent/cli-linux-arm64": "1.0.81",
20
+ "@sciagent/cli-darwin-x64": "1.0.81",
21
+ "@sciagent/cli-darwin-arm64": "1.0.81",
22
+ "@sciagent/cli-win32-x64": "1.0.81",
23
+ "@sciagent/cli-win32-arm64": "1.0.81"
24
24
  },
25
25
  "keywords": [
26
26
  "ai",
@@ -27,7 +27,7 @@ const ARCH_MAP = {
27
27
  };
28
28
 
29
29
  // 当前版本号 - 每次发布时同步更新
30
- const CURRENT_VERSION = '1.0.79';
30
+ const CURRENT_VERSION = '1.0.81';
31
31
 
32
32
  // GitHub Releases 回退版本列表(当当前版本的 release 不存在时尝试)
33
33
  const GITHUB_FALLBACK_VERSIONS = ['1.0.50', '1.0.48', '1.0.46', '1.0.40', '1.0.38', '1.0.36'];
@@ -675,30 +675,29 @@ async function main() {
675
675
  } else {
676
676
  console.log(`⚠️ Platform binary not found: ${packageName}`);
677
677
 
678
- // 下载策略: 1) Releases服务器 2) 极狐GitLab 3) npm包
678
+ // 下载策略: 1) 极狐GitLab(稳定可靠) 2) Releases服务器 3) npm包
679
679
  console.log('');
680
- console.log(' 尝试从 Releases 服务器下载...');
681
- const serverSuccess = await downloadFromServer(platform, arch, CURRENT_VERSION);
680
+ console.log(' 尝试从极狐GitLab下载...');
681
+ let jihuSuccess = await downloadFromJiHuLab(platform, arch, CURRENT_VERSION);
682
682
 
683
- if (!serverSuccess) {
684
- // Releases 服务器失败,尝试极狐GitLab
685
- console.log('');
686
- console.log(' 尝试从极狐GitLab下载...');
687
-
688
- let jihuSuccess = await downloadFromJiHuLab(platform, arch, CURRENT_VERSION);
689
-
690
- // 如果当前版本失败,尝试回退版本
691
- if (!jihuSuccess) {
692
- for (const fallbackVersion of GITHUB_FALLBACK_VERSIONS) {
693
- if (fallbackVersion === CURRENT_VERSION) continue;
694
- console.log(` 尝试回退版本 v${fallbackVersion}...`);
695
- jihuSuccess = await downloadFromJiHuLab(platform, arch, fallbackVersion);
696
- if (jihuSuccess) break;
697
- }
683
+ // 如果当前版本失败,尝试回退版本
684
+ if (!jihuSuccess) {
685
+ for (const fallbackVersion of GITHUB_FALLBACK_VERSIONS) {
686
+ if (fallbackVersion === CURRENT_VERSION) continue;
687
+ console.log(` 尝试回退版本 v${fallbackVersion}...`);
688
+ jihuSuccess = await downloadFromJiHuLab(platform, arch, fallbackVersion);
689
+ if (jihuSuccess) break;
698
690
  }
691
+ }
692
+
693
+ if (!jihuSuccess) {
694
+ // 极狐GitLab 失败,尝试 Releases 服务器
695
+ console.log('');
696
+ console.log(' 尝试从 Releases 服务器下载...');
697
+ const serverSuccess = await downloadFromServer(platform, arch, CURRENT_VERSION);
699
698
 
700
- if (!jihuSuccess) {
701
- // 极狐GitLab 也失败,回退到 npm 包安装
699
+ if (!serverSuccess) {
700
+ // Releases 服务器也失败,回退到 npm 包安装
702
701
  console.log('');
703
702
  console.log(' 回退到 npm 包安装...');
704
703
  const npmSuccess = installBinaryPackage(platform, arch);