xiaozuoassistant 0.2.9 → 0.2.10

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.
Files changed (2) hide show
  1. package/bin/cli.js +70 -0
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -10,6 +10,7 @@ import { pipeline } from 'stream';
10
10
  import { promisify } from 'util';
11
11
  import * as tar from 'tar';
12
12
  import http from 'http';
13
+ import https from 'https';
13
14
  import net from 'net';
14
15
 
15
16
  const pipe = promisify(pipeline);
@@ -359,11 +360,80 @@ async function runWithSudoIfNeeded(cmd, cmdArgs, options = {}) {
359
360
  return await runCommand('sudo', [cmd, ...cmdArgs], options);
360
361
  }
361
362
 
363
+ async function getRemoteVersion(registry) {
364
+ return new Promise((resolve, reject) => {
365
+ const options = {
366
+ hostname: registry.replace('https://', ''),
367
+ path: '/xiaozuoassistant/latest',
368
+ method: 'GET',
369
+ headers: {
370
+ 'Content-Type': 'application/json'
371
+ }
372
+ };
373
+
374
+ const req = https.request(options, (res) => {
375
+ let data = '';
376
+ res.on('data', (chunk) => {
377
+ data += chunk;
378
+ });
379
+ res.on('end', () => {
380
+ try {
381
+ const info = JSON.parse(data);
382
+ resolve(info.version);
383
+ } catch (e) {
384
+ reject(new Error('Failed to parse remote version info'));
385
+ }
386
+ });
387
+ });
388
+
389
+ req.on('error', (e) => {
390
+ reject(e);
391
+ });
392
+
393
+ req.end();
394
+ });
395
+ }
396
+
397
+ function compareVersions(version1, version2) {
398
+ const v1 = version1.split('.').map(Number);
399
+ const v2 = version2.split('.').map(Number);
400
+ for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
401
+ const num1 = v1[i] || 0;
402
+ const num2 = v2[i] || 0;
403
+ if (num1 > num2) return 1;
404
+ if (num1 < num2) return -1;
405
+ }
406
+ return 0;
407
+ }
408
+
362
409
  async function updateApp() {
363
410
  const registry = getRegistry();
364
411
  const port = getPortFromConfig();
365
412
  const pidFile = getPidFilePath();
366
413
 
414
+ // Get local version
415
+ const packageJson = await import('../package.json', { assert: { type: 'json' } });
416
+ const localVersion = packageJson.default.version;
417
+ console.log(`[CLI] 当前版本: ${localVersion}`);
418
+
419
+ // Get remote version
420
+ try {
421
+ console.log(`[CLI] 检查远程版本(registry=${registry})...`);
422
+ const remoteVersion = await getRemoteVersion(registry);
423
+ console.log(`[CLI] 远程版本: ${remoteVersion}`);
424
+
425
+ // Compare versions
426
+ const comparison = compareVersions(localVersion, remoteVersion);
427
+ if (comparison >= 0) {
428
+ console.log('[CLI] ✅ 已经是最新版本,无需更新。');
429
+ process.exit(0);
430
+ }
431
+
432
+ console.log(`[CLI] 发现新版本 ${remoteVersion},开始更新...`);
433
+ } catch (e) {
434
+ console.warn('[CLI] ⚠️ 版本检查失败,继续执行更新:', e);
435
+ }
436
+
367
437
  const runningByPid = fs.existsSync(pidFile) && (() => {
368
438
  try {
369
439
  const pid = Number(fs.readFileSync(pidFile, 'utf-8').trim());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "A local-first personal AI assistant with multi-channel support and enhanced memory.",
5
5
  "author": "mantle.lau",
6
6
  "license": "MIT",