@deinossrl/dgp-agent 1.4.12 → 1.4.13
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/index.mjs +56 -18
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -203,7 +203,7 @@ async function fetchPlatformConfig() {
|
|
|
203
203
|
let platformConfig = null;
|
|
204
204
|
|
|
205
205
|
// Versión y modo del agente
|
|
206
|
-
const AGENT_VERSION = '1.4.
|
|
206
|
+
const AGENT_VERSION = '1.4.13';
|
|
207
207
|
let AGENT_MODE = 'status'; // 'status' | 'deploy' | 'ai'
|
|
208
208
|
|
|
209
209
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -1231,36 +1231,74 @@ async function runAgent(deployMode = false) {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
};
|
|
1233
1233
|
|
|
1234
|
-
// Command polling cycle (
|
|
1234
|
+
// Command polling cycle - SIEMPRE escucha comandos (Web ↔ PC)
|
|
1235
|
+
let isProcessingCommand = false;
|
|
1235
1236
|
const runCommandCycle = async () => {
|
|
1237
|
+
if (isProcessingCommand) return;
|
|
1238
|
+
|
|
1236
1239
|
try {
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1240
|
+
// Buscar comandos pendientes para ESTE machine_id
|
|
1241
|
+
const url = `${CONFIG.commandsUrl}?machine_id=eq.${CONFIG.machineId}&status=eq.pending&select=*&order=created_at.asc&limit=1`;
|
|
1242
|
+
const response = await fetch(url, {
|
|
1243
|
+
headers: {
|
|
1244
|
+
'apikey': CONFIG.supabaseKey,
|
|
1245
|
+
'Authorization': `Bearer ${CONFIG.supabaseKey}`,
|
|
1246
|
+
},
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
if (!response.ok) return;
|
|
1250
|
+
|
|
1251
|
+
const commands = await response.json();
|
|
1252
|
+
if (commands.length === 0) return;
|
|
1253
|
+
|
|
1254
|
+
const command = commands[0];
|
|
1255
|
+
isProcessingCommand = true;
|
|
1256
|
+
|
|
1257
|
+
logCommand(`📥 Comando recibido: ${command.command}`);
|
|
1258
|
+
|
|
1259
|
+
// Verificar si tenemos IA disponible
|
|
1260
|
+
const useAI = !!CONFIG.anthropicApiKey;
|
|
1261
|
+
|
|
1262
|
+
if (command.command === 'ai_task' && useAI) {
|
|
1263
|
+
// Tarea AI - ejecutar con Claude
|
|
1264
|
+
await updateCommandStatus(command.id, 'running', {});
|
|
1265
|
+
const result = await executeAITask(command.params?.task || '');
|
|
1266
|
+
|
|
1267
|
+
if (result.success) {
|
|
1268
|
+
await updateCommandStatus(command.id, 'completed', {
|
|
1269
|
+
output: result.results?.map(r => r.output).join('\n'),
|
|
1270
|
+
commands_executed: result.results?.length || 0,
|
|
1271
|
+
});
|
|
1272
|
+
logSuccess('Tarea completada');
|
|
1273
|
+
} else {
|
|
1274
|
+
await updateCommandStatus(command.id, 'failed', {}, result.error || 'Task failed');
|
|
1275
|
+
logError('Tarea fallida');
|
|
1276
|
+
}
|
|
1277
|
+
} else {
|
|
1278
|
+
// Comandos git y otros
|
|
1279
|
+
await executeCommand(command, useAI);
|
|
1242
1280
|
}
|
|
1281
|
+
|
|
1282
|
+
isProcessingCommand = false;
|
|
1283
|
+
|
|
1243
1284
|
} catch (error) {
|
|
1285
|
+
isProcessingCommand = false;
|
|
1244
1286
|
// Silent fail for command polling - don't spam logs
|
|
1245
|
-
if (error.message
|
|
1246
|
-
//
|
|
1247
|
-
} else {
|
|
1248
|
-
logError(`Command poll failed: ${error.message}`);
|
|
1287
|
+
if (!error.message?.includes('42P01')) {
|
|
1288
|
+
// Solo loggear si no es error de tabla inexistente
|
|
1249
1289
|
}
|
|
1250
1290
|
}
|
|
1251
1291
|
};
|
|
1252
1292
|
|
|
1253
1293
|
// Initial run
|
|
1254
1294
|
await runStatusCycle();
|
|
1255
|
-
|
|
1256
|
-
await runCommandCycle();
|
|
1257
|
-
}
|
|
1295
|
+
await runCommandCycle();
|
|
1258
1296
|
|
|
1259
|
-
// Set intervals
|
|
1297
|
+
// Set intervals - SIEMPRE escucha comandos
|
|
1260
1298
|
setInterval(runStatusCycle, CONFIG.interval * 1000);
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1299
|
+
setInterval(runCommandCycle, CONFIG.commandPollInterval * 1000);
|
|
1300
|
+
|
|
1301
|
+
logInfo(`Escuchando comandos de la web (cada ${CONFIG.commandPollInterval}s)...`);
|
|
1264
1302
|
}
|
|
1265
1303
|
|
|
1266
1304
|
/**
|