sam-coder-cli 1.0.16 ā 1.0.17
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/bin/multiplayer-client.js +92 -60
- package/package.json +1 -1
|
@@ -446,26 +446,25 @@ class MultiplayerClient extends EventEmitter {
|
|
|
446
446
|
|
|
447
447
|
console.log(chalk.blue(`\nš [${this.role}] Working on: ${this.currentTask.prompt}`));
|
|
448
448
|
|
|
449
|
-
//
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
// Update progress
|
|
449
|
+
// Process the task using the completeTask method
|
|
450
|
+
const completedTask = await this.completeTask(taskId);
|
|
451
|
+
|
|
452
|
+
if (completedTask) {
|
|
453
|
+
// Task completed successfully
|
|
456
454
|
this.send({
|
|
457
455
|
type: 'task_progress',
|
|
458
456
|
sessionId: this.sessionId,
|
|
459
457
|
taskId,
|
|
460
|
-
status: '
|
|
461
|
-
progress,
|
|
458
|
+
status: 'completed',
|
|
459
|
+
progress: 100,
|
|
462
460
|
timestamp: new Date().toISOString()
|
|
463
461
|
});
|
|
462
|
+
|
|
463
|
+
console.log(chalk.green(`\nā
[${this.role}] Completed task: ${this.currentTask.prompt}`));
|
|
464
|
+
}
|
|
465
|
+
if (this.taskQueue.length > 0) {
|
|
466
|
+
this.processTaskQueue();
|
|
464
467
|
}
|
|
465
|
-
|
|
466
|
-
// Complete the task
|
|
467
|
-
await this.completeTask(taskId);
|
|
468
|
-
|
|
469
468
|
} catch (error) {
|
|
470
469
|
console.error('Error processing task:', error);
|
|
471
470
|
this.send({
|
|
@@ -477,69 +476,96 @@ class MultiplayerClient extends EventEmitter {
|
|
|
477
476
|
});
|
|
478
477
|
} finally {
|
|
479
478
|
this.currentTask = null;
|
|
480
|
-
// Process next task if available
|
|
481
|
-
if (this.taskQueue.length > 0) {
|
|
482
|
-
this.processTaskQueue();
|
|
483
|
-
}
|
|
484
479
|
}
|
|
485
480
|
}
|
|
486
481
|
|
|
487
482
|
async completeTask(taskId) {
|
|
488
483
|
const task = this.pendingTasks.get(taskId);
|
|
489
|
-
if (!task)
|
|
484
|
+
if (!task) {
|
|
485
|
+
console.error('Task not found:', taskId);
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
try {
|
|
490
|
+
// Process the task using the same logic as the normal mode
|
|
491
|
+
const { processQuery } = require('./agi-cli');
|
|
492
|
+
const result = await processQuery(task.prompt, [], this.model);
|
|
493
|
+
|
|
494
|
+
// Update task status
|
|
495
|
+
const completedTask = {
|
|
496
|
+
...task,
|
|
497
|
+
status: 'completed',
|
|
498
|
+
completedAt: new Date().toISOString(),
|
|
499
|
+
result: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
this.pendingTasks.set(taskId, completedTask);
|
|
503
|
+
this.taskResults.set(taskId, completedTask.result);
|
|
504
|
+
|
|
505
|
+
// Notify server and other clients
|
|
506
|
+
this.send({
|
|
507
|
+
type: 'task_completed',
|
|
508
|
+
sessionId: this.sessionId,
|
|
509
|
+
taskId,
|
|
510
|
+
result: completedTask.result,
|
|
511
|
+
timestamp: new Date().toISOString()
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
console.log(chalk.green(`\nā
[${this.role}] Completed: ${task.prompt}`));
|
|
515
|
+
this.emit('task_completed', completedTask);
|
|
516
|
+
|
|
517
|
+
return completedTask;
|
|
518
|
+
} catch (error) {
|
|
519
|
+
console.error('Error completing task:', error);
|
|
520
|
+
|
|
521
|
+
// Update task with error status
|
|
522
|
+
const failedTask = {
|
|
523
|
+
...task,
|
|
524
|
+
status: 'failed',
|
|
525
|
+
completedAt: new Date().toISOString(),
|
|
526
|
+
error: error.message
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
this.pendingTasks.set(taskId, failedTask);
|
|
530
|
+
this.emit('task_failed', { taskId, error: error.message });
|
|
531
|
+
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
handleTaskCompleted(data) {
|
|
537
|
+
const task = this.pendingTasks.get(data.taskId);
|
|
538
|
+
if (!task) {
|
|
539
|
+
console.error('Task not found for completion:', data.taskId);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
490
542
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
default:
|
|
504
|
-
result = `Completed: ${task.prompt}`;
|
|
543
|
+
console.log(chalk.green(`\nā
Task completed by all agents!`));
|
|
544
|
+
console.log(chalk.blue(`Task: ${task.prompt || 'Unknown task'}`));
|
|
545
|
+
|
|
546
|
+
if (data.results && data.results.length > 0) {
|
|
547
|
+
console.log(chalk.cyan('Results:'));
|
|
548
|
+
data.results.forEach(result => {
|
|
549
|
+
console.log(chalk.yellow(`- ${this.getClientName(result.clientId) || 'Unknown'}:`));
|
|
550
|
+
console.log(result.result);
|
|
551
|
+
});
|
|
552
|
+
} else if (data.result) {
|
|
553
|
+
console.log(chalk.cyan('Result:'));
|
|
554
|
+
console.log(data.result);
|
|
505
555
|
}
|
|
506
556
|
|
|
507
|
-
// Update task
|
|
557
|
+
// Update the task with the final result
|
|
508
558
|
const completedTask = {
|
|
509
559
|
...task,
|
|
510
560
|
status: 'completed',
|
|
511
561
|
completedAt: new Date().toISOString(),
|
|
512
|
-
result
|
|
562
|
+
result: data.result || 'No result provided'
|
|
513
563
|
};
|
|
514
564
|
|
|
515
|
-
this.pendingTasks.set(taskId, completedTask);
|
|
516
|
-
this.taskResults.set(taskId, result);
|
|
565
|
+
this.pendingTasks.set(data.taskId, completedTask);
|
|
566
|
+
this.taskResults.set(data.taskId, completedTask.result);
|
|
517
567
|
|
|
518
|
-
// Notify server and other clients
|
|
519
|
-
this.send({
|
|
520
|
-
type: 'task_completed',
|
|
521
|
-
sessionId: this.sessionId,
|
|
522
|
-
taskId,
|
|
523
|
-
result,
|
|
524
|
-
timestamp: new Date().toISOString()
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
console.log(chalk.green(`\nā
[${this.role}] Completed: ${task.prompt}`));
|
|
528
568
|
this.emit('task_completed', completedTask);
|
|
529
|
-
|
|
530
|
-
return completedTask;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
handleTaskCompleted(data) {
|
|
534
|
-
console.log(`\n Task completed by all agents!`);
|
|
535
|
-
console.log(`Task: ${this.tasks.get(data.taskId)?.prompt || 'Unknown task'}`);
|
|
536
|
-
console.log('Results:');
|
|
537
|
-
|
|
538
|
-
data.results.forEach(result => {
|
|
539
|
-
console.log(`- ${this.getClientName(result.clientId)}: ${result.result}`);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
this.emit('task_completed', data);
|
|
543
569
|
}
|
|
544
570
|
|
|
545
571
|
async updateWork(work) {
|
|
@@ -618,6 +644,12 @@ class MultiplayerClient extends EventEmitter {
|
|
|
618
644
|
this.ws.close();
|
|
619
645
|
}
|
|
620
646
|
}
|
|
647
|
+
|
|
648
|
+
getClientName(clientId) {
|
|
649
|
+
if (!clientId) return 'Unknown';
|
|
650
|
+
const client = this.clients.find(c => c.clientId === clientId || c.id === clientId);
|
|
651
|
+
return client ? (client.name || client.clientInfo?.name || 'Unknown') : 'Unknown';
|
|
652
|
+
}
|
|
621
653
|
}
|
|
622
654
|
|
|
623
655
|
module.exports = MultiplayerClient;
|