imtoagent 0.2.0 → 0.2.1

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": "imtoagent",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "IM ↔ Agent 统一网关 — 飞书/Telegram/微信/企业微信对接 Claude Code/Codex/OpenCode",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,7 @@
15
15
  "README.md"
16
16
  ],
17
17
  "scripts": {
18
- "postinstall": "bun run scripts/postinstall.ts",
18
+ "postinstall": "node scripts/postinstall.cjs",
19
19
  "start": "bun run index.ts"
20
20
  },
21
21
  "dependencies": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
32
- "url": "https://github.com/YOUR_USERNAME/imtoagent.git"
32
+ "url": "git+https://github.com/YOUR_USERNAME/imtoagent.git"
33
33
  },
34
34
  "keywords": [
35
35
  "im",
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ // ================================================================
3
+ // postinstall.js — npm 安装后引导脚本
4
+ // ================================================================
5
+ // 用 Node.js 运行(不依赖 bun),兼容所有安装环境
6
+ // ================================================================
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const { execSync } = require('child_process');
11
+
12
+ const HOME = process.env.HOME || process.env.USERPROFILE || '';
13
+ const DATA_DIR = path.join(HOME, '.imtoagent');
14
+
15
+ // 检测 bun 路径
16
+ function findBun() {
17
+ // 1. PATH 中有 bun
18
+ try {
19
+ const r = execSync('which bun', { encoding: 'utf-8', timeout: 3000 }).trim();
20
+ if (r) return r;
21
+ } catch {}
22
+ // 2. 常见安装路径
23
+ const candidates = [
24
+ path.join(HOME, '.bun', 'bin', 'bun'),
25
+ '/usr/local/bin/bun',
26
+ '/opt/homebrew/bin/bun',
27
+ ];
28
+ for (const p of candidates) {
29
+ if (fs.existsSync(p)) return p;
30
+ }
31
+ return null;
32
+ }
33
+
34
+ try {
35
+ const configExists = fs.existsSync(path.join(DATA_DIR, 'config.json'));
36
+
37
+ if (configExists) {
38
+ console.log(`
39
+ ✅ imtoagent 升级成功!
40
+ 数据目录: ${DATA_DIR}
41
+ 配置文件保持不变,无需重新配置。
42
+ 运行 "imtoagent start" 启动网关。
43
+ `);
44
+ } else {
45
+ console.log(`
46
+ +----------------------------------------------------------+
47
+ | |
48
+ | 🎉 imtoagent 安装成功! |
49
+ | |
50
+ | 首次使用需要配置 IM 凭证和模型供应商 |
51
+ | |
52
+ +----------------------------------------------------------+
53
+ `);
54
+
55
+ if (process.stdin.isTTY) {
56
+ const readline = require('readline');
57
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
58
+
59
+ rl.question('是否立即运行配置向导?[Y/n]: ', (answer) => {
60
+ rl.close();
61
+ const yes = (answer || '').trim().toLowerCase();
62
+ if (yes === '' || yes === 'y' || yes === 'yes') {
63
+ const bunPath = findBun();
64
+ if (!bunPath) {
65
+ console.error('\n⚠️ bun 未安装,请先安装: https://bun.sh');
66
+ console.error(' 安装后运行: imtoagent setup\n');
67
+ process.exit(0);
68
+ }
69
+ console.log('\n🚀 启动配置向导...\n');
70
+ const pkgDir = path.resolve(__dirname, '..');
71
+ execSync(`${bunPath} bin/imtoagent setup`, {
72
+ cwd: pkgDir,
73
+ stdio: 'inherit',
74
+ env: { ...process.env },
75
+ });
76
+ } else {
77
+ console.log('\n稍后运行 "imtoagent setup" 即可开始配置。');
78
+ }
79
+ });
80
+ } else {
81
+ console.log(' 运行 "imtoagent setup" 开始配置');
82
+ console.log(' 然后运行 "imtoagent start" 启动网关\n');
83
+ }
84
+ }
85
+ } catch (e) {
86
+ // 静默失败,不影响安装
87
+ if (e.message && !e.message.includes('readline')) {
88
+ console.error(`[postinstall] 提示失败: ${e.message}`);
89
+ }
90
+ }