@yeaft/webchat-agent 0.0.4 → 0.0.5
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 +10 -2
- package/package.json +1 -1
package/connection.js
CHANGED
|
@@ -267,12 +267,20 @@ async function handleMessage(msg) {
|
|
|
267
267
|
break;
|
|
268
268
|
|
|
269
269
|
case 'upgrade_agent':
|
|
270
|
-
console.log('[Agent] Upgrade requested,
|
|
270
|
+
console.log('[Agent] Upgrade requested, checking for updates...');
|
|
271
271
|
try {
|
|
272
272
|
const pkgName = ctx.pkgName || '@yeaft/webchat-agent';
|
|
273
|
+
// Check latest version before installing
|
|
274
|
+
const latestVersion = execSync(`npm view ${pkgName} version`, { stdio: 'pipe' }).toString().trim();
|
|
275
|
+
if (latestVersion === ctx.agentVersion) {
|
|
276
|
+
console.log(`[Agent] Already at latest version (${ctx.agentVersion}), skipping upgrade.`);
|
|
277
|
+
sendToServer({ type: 'upgrade_agent_ack', success: true, alreadyLatest: true, version: ctx.agentVersion });
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
console.log(`[Agent] Upgrading from ${ctx.agentVersion} to ${latestVersion}...`);
|
|
273
281
|
execSync(`npm install -g ${pkgName}@latest`, { stdio: 'pipe' });
|
|
274
282
|
console.log('[Agent] Upgrade successful, restarting...');
|
|
275
|
-
sendToServer({ type: 'upgrade_agent_ack', success: true });
|
|
283
|
+
sendToServer({ type: 'upgrade_agent_ack', success: true, version: latestVersion });
|
|
276
284
|
// Restart after upgrade (same as restart_agent)
|
|
277
285
|
setTimeout(() => {
|
|
278
286
|
for (const [, term] of ctx.terminals) {
|