@deinossrl/dgp-agent 1.4.3 → 1.4.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/index.mjs +91 -34
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -96,9 +96,10 @@ function deleteConfigValue(key) {
|
|
|
96
96
|
const fileConfig = loadConfigFile();
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* Obtiene configuración desde la plataforma (Supabase)
|
|
99
|
+
* Obtiene configuración global desde la plataforma (Supabase)
|
|
100
|
+
* La config es compartida por todos los agentes
|
|
100
101
|
*/
|
|
101
|
-
async function fetchPlatformConfig(
|
|
102
|
+
async function fetchPlatformConfig() {
|
|
102
103
|
try {
|
|
103
104
|
const url = 'https://asivayhbrqennwiwttds.supabase.co/functions/v1/dgp-agent-config';
|
|
104
105
|
const response = await fetch(url, {
|
|
@@ -107,7 +108,7 @@ async function fetchPlatformConfig(machineId) {
|
|
|
107
108
|
'Content-Type': 'application/json',
|
|
108
109
|
'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFzaXZheWhicnFlbm53aXd0dGRzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjczMDAwOTcsImV4cCI6MjA4Mjg3NjA5N30.s3a7dR-dPkEXI7B2lUTUXU69923hhuX6meheNeo5EKA',
|
|
109
110
|
},
|
|
110
|
-
body: JSON.stringify({
|
|
111
|
+
body: JSON.stringify({}),
|
|
111
112
|
});
|
|
112
113
|
|
|
113
114
|
if (!response.ok) {
|
|
@@ -389,7 +390,7 @@ Devuelve los comandos necesarios en formato JSON.`;
|
|
|
389
390
|
}
|
|
390
391
|
|
|
391
392
|
/**
|
|
392
|
-
* Modo
|
|
393
|
+
* Modo IA - Escucha tareas de la web y las ejecuta con Claude
|
|
393
394
|
*/
|
|
394
395
|
async function runAIMode() {
|
|
395
396
|
console.log('');
|
|
@@ -399,10 +400,10 @@ async function runAIMode() {
|
|
|
399
400
|
console.log(`${colors.cyan}╚═══════════════════════════════════════════════════════╝${colors.reset}`);
|
|
400
401
|
console.log('');
|
|
401
402
|
|
|
402
|
-
// Intentar cargar config desde la plataforma si no hay API key local
|
|
403
|
+
// Intentar cargar config global desde la plataforma si no hay API key local
|
|
403
404
|
if (!CONFIG.anthropicApiKey) {
|
|
404
405
|
logInfo('Buscando configuración en la plataforma...');
|
|
405
|
-
platformConfig = await fetchPlatformConfig(
|
|
406
|
+
platformConfig = await fetchPlatformConfig();
|
|
406
407
|
|
|
407
408
|
if (platformConfig?.anthropic_api_key) {
|
|
408
409
|
CONFIG.anthropicApiKey = platformConfig.anthropic_api_key;
|
|
@@ -440,37 +441,91 @@ async function runAIMode() {
|
|
|
440
441
|
const taskArgs = process.argv.slice(3).join(' ');
|
|
441
442
|
|
|
442
443
|
if (taskArgs) {
|
|
443
|
-
// Ejecutar tarea pasada como argumento
|
|
444
|
+
// Ejecutar tarea pasada como argumento y salir
|
|
444
445
|
await executeAITask(taskArgs);
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const readline = await import('readline');
|
|
448
|
-
const rl = readline.createInterface({
|
|
449
|
-
input: process.stdin,
|
|
450
|
-
output: process.stdout,
|
|
451
|
-
});
|
|
446
|
+
process.exit(0);
|
|
447
|
+
}
|
|
452
448
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
process.exit(0);
|
|
459
|
-
}
|
|
449
|
+
// Modo escucha: polling de tareas AI desde la plataforma
|
|
450
|
+
logInfo(`Escuchando tareas desde TenMinute IA... (machine: ${CONFIG.machineId})`);
|
|
451
|
+
log('Las tareas enviadas desde la web se ejecutarán automáticamente', 'gray');
|
|
452
|
+
log('Presiona Ctrl+C para salir', 'gray');
|
|
453
|
+
console.log('');
|
|
460
454
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
455
|
+
let isProcessing = false;
|
|
456
|
+
|
|
457
|
+
const pollAITasks = async () => {
|
|
458
|
+
if (isProcessing) return; // Evitar ejecuciones simultáneas
|
|
464
459
|
|
|
465
|
-
|
|
466
|
-
|
|
460
|
+
try {
|
|
461
|
+
// Buscar comandos pendientes para esta máquina
|
|
462
|
+
const url = `${CONFIG.commandsUrl}?machine_id=eq.${CONFIG.machineId}&status=eq.pending&command=eq.ai_task&select=*&order=created_at.asc&limit=1`;
|
|
463
|
+
const response = await fetch(url, {
|
|
464
|
+
headers: {
|
|
465
|
+
'apikey': CONFIG.supabaseKey,
|
|
466
|
+
'Authorization': `Bearer ${CONFIG.supabaseKey}`,
|
|
467
|
+
},
|
|
467
468
|
});
|
|
468
|
-
};
|
|
469
469
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
470
|
+
if (!response.ok) return;
|
|
471
|
+
|
|
472
|
+
const commands = await response.json();
|
|
473
|
+
if (commands.length === 0) return;
|
|
474
|
+
|
|
475
|
+
const command = commands[0];
|
|
476
|
+
isProcessing = true;
|
|
477
|
+
|
|
478
|
+
logAI(`📥 Tarea recibida: ${command.params?.task?.substring(0, 50)}...`);
|
|
479
|
+
|
|
480
|
+
// Marcar como running
|
|
481
|
+
await updateCommandStatus(command.id, 'running', {});
|
|
482
|
+
|
|
483
|
+
// Ejecutar la tarea con AI
|
|
484
|
+
const result = await executeAITask(command.params?.task || '');
|
|
485
|
+
|
|
486
|
+
// Reportar resultado
|
|
487
|
+
if (result.success) {
|
|
488
|
+
await updateCommandStatus(command.id, 'completed', {
|
|
489
|
+
output: result.results?.map(r => r.output).join('\n'),
|
|
490
|
+
commands_executed: result.results?.length || 0,
|
|
491
|
+
});
|
|
492
|
+
logSuccess('Tarea completada y reportada a la plataforma');
|
|
493
|
+
} else {
|
|
494
|
+
await updateCommandStatus(command.id, 'failed', {}, result.error || 'Task failed');
|
|
495
|
+
logError('Tarea fallida');
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
isProcessing = false;
|
|
499
|
+
console.log('');
|
|
500
|
+
logInfo('Esperando más tareas...');
|
|
501
|
+
|
|
502
|
+
} catch (error) {
|
|
503
|
+
isProcessing = false;
|
|
504
|
+
// Silent fail para no spamear logs
|
|
505
|
+
if (!error.message.includes('42P01')) {
|
|
506
|
+
// Solo loguear si no es error de tabla inexistente
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// Poll inmediato
|
|
512
|
+
await pollAITasks();
|
|
513
|
+
|
|
514
|
+
// Polling cada N segundos
|
|
515
|
+
setInterval(pollAITasks, CONFIG.commandPollInterval * 1000);
|
|
516
|
+
|
|
517
|
+
// También reportar status periódicamente
|
|
518
|
+
const reportStatus = async () => {
|
|
519
|
+
try {
|
|
520
|
+
const status = getRepoStatus();
|
|
521
|
+
await sendStatus(status);
|
|
522
|
+
} catch (e) {
|
|
523
|
+
// Silent fail
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
await reportStatus();
|
|
528
|
+
setInterval(reportStatus, CONFIG.interval * 1000);
|
|
474
529
|
}
|
|
475
530
|
|
|
476
531
|
// ============================================
|
|
@@ -941,7 +996,7 @@ async function runAgent(deployMode = false) {
|
|
|
941
996
|
console.log('');
|
|
942
997
|
console.log(`${colors.green}╔═══════════════════════════════════════════════════════╗${colors.reset}`);
|
|
943
998
|
console.log(`${colors.green}║ DGP Agent - Despliegue-GPT Local Agent ║${colors.reset}`);
|
|
944
|
-
console.log(`${colors.green}║ @deinossrl/dgp-agent v1.4.
|
|
999
|
+
console.log(`${colors.green}║ @deinossrl/dgp-agent v1.4.5 ║${colors.reset}`);
|
|
945
1000
|
console.log(`${colors.green}╚═══════════════════════════════════════════════════════╝${colors.reset}`);
|
|
946
1001
|
console.log('');
|
|
947
1002
|
|
|
@@ -1057,7 +1112,7 @@ async function showStatus() {
|
|
|
1057
1112
|
function showHelp() {
|
|
1058
1113
|
console.log(`
|
|
1059
1114
|
${colors.bold}${colors.cyan}DGP Agent - Despliegue-GPT Local Agent${colors.reset}
|
|
1060
|
-
${colors.gray}@deinossrl/dgp-agent v1.4.
|
|
1115
|
+
${colors.gray}@deinossrl/dgp-agent v1.4.5${colors.reset}
|
|
1061
1116
|
|
|
1062
1117
|
${colors.bold}DESCRIPCIÓN${colors.reset}
|
|
1063
1118
|
Agente local que reporta el estado de tu repositorio Git
|
|
@@ -1108,6 +1163,8 @@ ${colors.bold}REQUISITOS PARA DEPLOY${colors.reset}
|
|
|
1108
1163
|
- Permisos sudo para reload nginx (vía sudoers sin password)
|
|
1109
1164
|
|
|
1110
1165
|
${colors.bold}CHANGELOG${colors.reset}
|
|
1166
|
+
${colors.cyan}v1.4.5${colors.reset} - Modo escucha: recibe tareas AI desde la web
|
|
1167
|
+
${colors.cyan}v1.4.4${colors.reset} - Config global (compartida por todos los agentes)
|
|
1111
1168
|
${colors.cyan}v1.4.3${colors.reset} - Config desde plataforma web (TenMinute IA)
|
|
1112
1169
|
${colors.cyan}v1.4.2${colors.reset} - Fix: alineación banner, config persistente
|
|
1113
1170
|
${colors.cyan}v1.3.0${colors.reset} - AI Mode: ejecuta tareas con lenguaje natural
|
|
@@ -1274,7 +1331,7 @@ switch (command) {
|
|
|
1274
1331
|
case 'version':
|
|
1275
1332
|
case '-v':
|
|
1276
1333
|
case '--version':
|
|
1277
|
-
console.log('@deinossrl/dgp-agent v1.4.
|
|
1334
|
+
console.log('@deinossrl/dgp-agent v1.4.5');
|
|
1278
1335
|
break;
|
|
1279
1336
|
case 'ai':
|
|
1280
1337
|
case '--ai':
|