@wu529778790/open-im 0.3.9 → 0.3.11

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/dist/cli.js +26 -7
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -151,11 +151,9 @@ async function startService() {
151
151
  console.log('\n请运行以下命令重新配置:\n npx @wu529778790/open-im\n');
152
152
  process.exit(1);
153
153
  }
154
- // 获取当前工作目录
155
- const currentDir = process.cwd();
156
- // 更新配置中的工作目录
157
- await updateWorkDir(currentDir);
158
- console.log(`工作目录已设置为: ${currentDir}`);
154
+ // 显示配置的工作目录(不自动更新,避免在不同目录重启时导致配置混乱)
155
+ const config = loadConfig();
156
+ console.log(`使用配置的工作目录: ${config.claudeWorkDir}`);
159
157
  // 后台启动 - 跨平台方案
160
158
  const distPath = join(__dirname, '..', 'dist', 'index.js');
161
159
  // 使用 detached 模式创建独立进程
@@ -192,8 +190,29 @@ else if (args[0] === 'restart') {
192
190
  await stopService().catch((err) => {
193
191
  console.error('停止服务时出错:', err);
194
192
  });
195
- // 等待进程完全退出
196
- await new Promise(resolve => setTimeout(resolve, 1000));
193
+ // 等待进程完全退出 AND Telegram API 释放连接(至少 3 秒)
194
+ // Telegram 需要时间释放 bot 实例,否则会出现 409 Conflict 错误
195
+ const pid = await readPid();
196
+ if (pid) {
197
+ // 持续检查直到进程真正退出(最多 15 秒)
198
+ const maxWait = 15000;
199
+ const checkInterval = 500;
200
+ let waited = 0;
201
+ while (waited < maxWait) {
202
+ if (!(await isProcessRunning(pid))) {
203
+ // 进程已退出,再等待 3 秒让 Telegram API 完全释放
204
+ const remainingWait = 3000;
205
+ console.log(`进程已退出,等待 ${remainingWait / 1000} 秒让 Telegram API 释放连接...`);
206
+ await new Promise(resolve => setTimeout(resolve, remainingWait));
207
+ break;
208
+ }
209
+ await new Promise(resolve => setTimeout(resolve, checkInterval));
210
+ waited += checkInterval;
211
+ }
212
+ if (waited >= maxWait) {
213
+ console.log('警告: 进程退出超时,继续启动...');
214
+ }
215
+ }
197
216
  console.log('\n正在重新启动服务...\n');
198
217
  await startService();
199
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",