@noosphere/agent-core 0.1.0-alpha.7 → 0.1.0-alpha.9

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/dist/index.cjs CHANGED
@@ -495,14 +495,19 @@ var ContainerManager = class {
495
495
  console.log(`
496
496
  \u{1F680} Preparing ${containers.size} containers...`);
497
497
  const pullAndStartPromises = Array.from(containers.entries()).map(async ([id, container]) => {
498
+ const imageTag = `${container.image}:${container.tag || "latest"}`;
498
499
  try {
499
- const imageTag = `${container.image}:${container.tag || "latest"}`;
500
500
  console.log(` Pulling ${imageTag}...`);
501
501
  await this.pullImage(container.image, container.tag || "latest");
502
502
  console.log(` \u2713 ${imageTag} ready`);
503
+ } catch (error) {
504
+ console.error(` \u274C Failed to pull ${imageTag}:`, error.message);
505
+ return;
506
+ }
507
+ try {
503
508
  await this.startPersistentContainer(id, container);
504
509
  } catch (error) {
505
- console.error(` \u274C Failed to prepare ${container.image}:`, error.message);
510
+ console.error(` \u274C Failed to start ${container.name || container.image}:`, error.message);
506
511
  }
507
512
  });
508
513
  await Promise.all(pullAndStartPromises);
@@ -514,21 +519,23 @@ var ContainerManager = class {
514
519
  async startPersistentContainer(containerId, metadata) {
515
520
  const containerName = `noosphere-${metadata.name}`;
516
521
  const imageTag = `${metadata.image}:${metadata.tag || "latest"}`;
522
+ const existingContainer = this.docker.getContainer(containerName);
517
523
  try {
518
- const existingContainer = this.docker.getContainer(containerName);
519
- try {
520
- const inspect = await existingContainer.inspect();
521
- if (inspect.State.Running) {
522
- console.log(` \u2713 Container ${containerName} already running`);
523
- this.persistentContainers.set(containerId, existingContainer);
524
- return;
525
- } else {
524
+ const inspect = await existingContainer.inspect();
525
+ if (inspect.State.Running) {
526
+ console.log(` \u2713 Container ${containerName} already running`);
527
+ this.persistentContainers.set(containerId, existingContainer);
528
+ return;
529
+ } else {
530
+ try {
526
531
  await existingContainer.start();
527
532
  console.log(` \u2713 Started existing container ${containerName}`);
528
533
  this.persistentContainers.set(containerId, existingContainer);
529
534
  return;
535
+ } catch (startErr) {
536
+ console.log(` Removing stopped container ${containerName} to recreate...`);
537
+ await existingContainer.remove({ force: true });
530
538
  }
531
- } catch (err) {
532
539
  }
533
540
  } catch (err) {
534
541
  }
@@ -1666,6 +1673,7 @@ var NoosphereAgent = class _NoosphereAgent {
1666
1673
  console.warn(` Could not verify interval currency:`, error.message);
1667
1674
  }
1668
1675
  this.scheduler.markIntervalCommitted(BigInt(event.subscriptionId), BigInt(event.interval));
1676
+ let sentTxHash;
1669
1677
  try {
1670
1678
  await this.waitForPriority(event);
1671
1679
  if (this.options.onRequestProcessing) {
@@ -1778,6 +1786,7 @@ var NoosphereAgent = class _NoosphereAgent {
1778
1786
  commitmentData,
1779
1787
  nodeWallet
1780
1788
  );
1789
+ sentTxHash = tx.hash;
1781
1790
  console.log(` \u{1F4E4} Transaction sent: ${tx.hash}`);
1782
1791
  const receipt = await tx.wait();
1783
1792
  if (receipt.status === 1) {
@@ -1812,7 +1821,7 @@ var NoosphereAgent = class _NoosphereAgent {
1812
1821
  }
1813
1822
  console.error(` \u274C Error processing request:`, error);
1814
1823
  if (this.options.onRequestFailed) {
1815
- this.options.onRequestFailed(event.requestId, errorMessage);
1824
+ this.options.onRequestFailed(event.requestId, errorMessage, sentTxHash);
1816
1825
  }
1817
1826
  } finally {
1818
1827
  this.processingRequests.delete(event.requestId);