@yeaft/webchat-agent 0.0.3 → 0.0.4
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/connection.js +35 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/connection.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
+
import { execSync } from 'child_process';
|
|
2
3
|
import ctx from './context.js';
|
|
3
4
|
import { encrypt, decrypt, isEncrypted, decodeKey } from './encryption.js';
|
|
4
5
|
import { handleTerminalCreate, handleTerminalInput, handleTerminalResize, handleTerminalClose } from './terminal.js';
|
|
@@ -264,6 +265,40 @@ async function handleMessage(msg) {
|
|
|
264
265
|
process.exit(1);
|
|
265
266
|
}, 500);
|
|
266
267
|
break;
|
|
268
|
+
|
|
269
|
+
case 'upgrade_agent':
|
|
270
|
+
console.log('[Agent] Upgrade requested, running npm upgrade...');
|
|
271
|
+
try {
|
|
272
|
+
const pkgName = ctx.pkgName || '@yeaft/webchat-agent';
|
|
273
|
+
execSync(`npm install -g ${pkgName}@latest`, { stdio: 'pipe' });
|
|
274
|
+
console.log('[Agent] Upgrade successful, restarting...');
|
|
275
|
+
sendToServer({ type: 'upgrade_agent_ack', success: true });
|
|
276
|
+
// Restart after upgrade (same as restart_agent)
|
|
277
|
+
setTimeout(() => {
|
|
278
|
+
for (const [, term] of ctx.terminals) {
|
|
279
|
+
if (term.pty) { try { term.pty.kill(); } catch {} }
|
|
280
|
+
if (term.timer) clearTimeout(term.timer);
|
|
281
|
+
}
|
|
282
|
+
ctx.terminals.clear();
|
|
283
|
+
for (const [, state] of ctx.conversations) {
|
|
284
|
+
if (state.abortController) state.abortController.abort();
|
|
285
|
+
if (state.inputStream) state.inputStream.done();
|
|
286
|
+
}
|
|
287
|
+
ctx.conversations.clear();
|
|
288
|
+
stopAgentHeartbeat();
|
|
289
|
+
if (ctx.ws) {
|
|
290
|
+
ctx.ws.removeAllListeners('close');
|
|
291
|
+
ctx.ws.close();
|
|
292
|
+
}
|
|
293
|
+
clearTimeout(ctx.reconnectTimer);
|
|
294
|
+
console.log('[Agent] Cleanup done, exiting for auto-restart...');
|
|
295
|
+
process.exit(1);
|
|
296
|
+
}, 500);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
console.error('[Agent] Upgrade failed:', e.message);
|
|
299
|
+
sendToServer({ type: 'upgrade_agent_ack', success: false, error: e.message });
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
267
302
|
}
|
|
268
303
|
}
|
|
269
304
|
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
16
16
|
// Load package version
|
|
17
17
|
const pkg = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf-8'));
|
|
18
18
|
ctx.agentVersion = pkg.version;
|
|
19
|
+
ctx.pkgName = pkg.name;
|
|
19
20
|
|
|
20
21
|
// 配置文件路径(向后兼容:先查当前目录 .claude-agent.json)
|
|
21
22
|
const LOCAL_CONFIG_FILE = join(process.cwd(), '.claude-agent.json');
|