@deinossrl/dgp-agent 1.2.5 → 1.2.7

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/index.mjs +66 -17
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -287,32 +287,29 @@ async function getPendingCommands() {
287
287
  }
288
288
 
289
289
  /**
290
- * Actualiza el estado de un comando
290
+ * Actualiza el estado de un comando via Edge Function
291
291
  */
292
292
  async function updateCommandStatus(commandId, status, result = {}, errorMessage = null) {
293
- const payload = {
294
- status,
295
- result,
296
- error_message: errorMessage,
297
- ...(status === 'running' ? { picked_up_at: new Date().toISOString() } : {}),
298
- ...(status === 'success' || status === 'failed' ? { completed_at: new Date().toISOString() } : {}),
299
- };
300
-
301
- const url = `${CONFIG.commandsUrl}?id=eq.${commandId}`;
293
+ const url = 'https://asivayhbrqennwiwttds.supabase.co/functions/v1/dgp-agent-command-update';
302
294
 
303
295
  const response = await fetch(url, {
304
- method: 'PATCH',
296
+ method: 'POST',
305
297
  headers: {
306
298
  'apikey': CONFIG.supabaseKey,
307
299
  'Authorization': `Bearer ${CONFIG.supabaseKey}`,
308
300
  'Content-Type': 'application/json',
309
- 'Prefer': 'return=minimal',
310
301
  },
311
- body: JSON.stringify(payload),
302
+ body: JSON.stringify({
303
+ commandId,
304
+ status,
305
+ result,
306
+ error_message: errorMessage,
307
+ }),
312
308
  });
313
309
 
314
310
  if (!response.ok) {
315
- throw new Error(`Failed to update command: HTTP ${response.status}`);
311
+ const text = await response.text();
312
+ throw new Error(`Failed to update command: HTTP ${response.status} - ${text}`);
316
313
  }
317
314
  }
318
315
 
@@ -443,6 +440,9 @@ async function executeCommand(command) {
443
440
  await updateCommandStatus(command.id, 'success', { status });
444
441
  return { success: true, status };
445
442
 
443
+ case 'git_commit_push':
444
+ return await executeGitCommitPush(command);
445
+
446
446
  case 'rollback':
447
447
  logError('Rollback not implemented yet');
448
448
  await updateCommandStatus(command.id, 'failed', {}, 'Rollback not implemented');
@@ -455,6 +455,53 @@ async function executeCommand(command) {
455
455
  }
456
456
  }
457
457
 
458
+ /**
459
+ * Ejecuta git add, commit y push
460
+ */
461
+ async function executeGitCommitPush(command) {
462
+ const { message, add_all } = command.params || {};
463
+
464
+ if (!message) {
465
+ await updateCommandStatus(command.id, 'failed', {}, 'Commit message is required');
466
+ return { success: false };
467
+ }
468
+
469
+ try {
470
+ // Marcar como running
471
+ await updateCommandStatus(command.id, 'running', {});
472
+
473
+ logInfo('Executing git commit + push...');
474
+
475
+ // git add
476
+ if (add_all) {
477
+ logCommand('git add .');
478
+ await shellAsync('git add .');
479
+ }
480
+
481
+ // git commit
482
+ logCommand(`git commit -m "${message}"`);
483
+ const commitResult = await shellAsync(`git commit -m "${message}"`);
484
+ logSuccess('Commit created');
485
+
486
+ // git push
487
+ const branch = shellSync('git branch --show-current').trim();
488
+ logCommand(`git push origin ${branch}`);
489
+ await shellAsync(`git push origin ${branch}`);
490
+ logSuccess('Push completed');
491
+
492
+ await updateCommandStatus(command.id, 'completed', {
493
+ commit: commitResult,
494
+ branch: branch
495
+ });
496
+
497
+ return { success: true };
498
+ } catch (error) {
499
+ logError(`Git commit/push failed: ${error.message}`);
500
+ await updateCommandStatus(command.id, 'failed', {}, error.message);
501
+ return { success: false, error: error.message };
502
+ }
503
+ }
504
+
458
505
  /**
459
506
  * Muestra el estado en consola
460
507
  */
@@ -488,7 +535,7 @@ async function runAgent(deployMode = false) {
488
535
  console.log('');
489
536
  console.log(`${colors.green}╔═══════════════════════════════════════════════════════╗${colors.reset}`);
490
537
  console.log(`${colors.green}║ DGP Agent - Despliegue-GPT Local Agent ║${colors.reset}`);
491
- console.log(`${colors.green}║ @deinossrl/dgp-agent v1.2.5 ║${colors.reset}`);
538
+ console.log(`${colors.green}║ @deinossrl/dgp-agent v1.2.7 ║${colors.reset}`);
492
539
  console.log(`${colors.green}╚═══════════════════════════════════════════════════════╝${colors.reset}`);
493
540
  console.log('');
494
541
 
@@ -604,7 +651,7 @@ async function showStatus() {
604
651
  function showHelp() {
605
652
  console.log(`
606
653
  ${colors.bold}${colors.cyan}DGP Agent - Despliegue-GPT Local Agent${colors.reset}
607
- ${colors.gray}@deinossrl/dgp-agent v1.2.5${colors.reset}
654
+ ${colors.gray}@deinossrl/dgp-agent v1.2.7${colors.reset}
608
655
 
609
656
  ${colors.bold}DESCRIPCIÓN${colors.reset}
610
657
  Agente local que reporta el estado de tu repositorio Git
@@ -652,6 +699,8 @@ ${colors.bold}REQUISITOS PARA DEPLOY${colors.reset}
652
699
  - Permisos sudo para reload nginx (vía sudoers sin password)
653
700
 
654
701
  ${colors.bold}CHANGELOG${colors.reset}
702
+ ${colors.cyan}v1.2.7${colors.reset} - Fix: update via Edge Function (401 fix)
703
+ ${colors.cyan}v1.2.6${colors.reset} - Comando git_commit_push desde la UI
655
704
  ${colors.cyan}v1.2.5${colors.reset} - Sincronización de versiones y changelog
656
705
  ${colors.cyan}v1.2.4${colors.reset} - Mejoras en ejecución async de comandos shell
657
706
  ${colors.cyan}v1.2.0${colors.reset} - Modo deploy con polling de comandos remotos
@@ -686,7 +735,7 @@ switch (command) {
686
735
  case 'version':
687
736
  case '-v':
688
737
  case '--version':
689
- console.log('@deinossrl/dgp-agent v1.2.5');
738
+ console.log('@deinossrl/dgp-agent v1.2.7');
690
739
  break;
691
740
  default:
692
741
  runAgent(false); // Status-only mode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deinossrl/dgp-agent",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Agente local para Despliegue-GPT - Reporta el estado del repositorio Git a la plataforma TenMinute IA",
5
5
  "main": "index.mjs",
6
6
  "bin": {