@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 +21 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -465,7 +465,7 @@ interface NoosphereAgentOptions {
|
|
|
465
465
|
onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
|
|
466
466
|
onRequestProcessing?: (requestId: string) => void;
|
|
467
467
|
onRequestSkipped?: (requestId: string, reason: string) => void;
|
|
468
|
-
onRequestFailed?: (requestId: string, error: string) => void;
|
|
468
|
+
onRequestFailed?: (requestId: string, error: string, txHash?: string) => void;
|
|
469
469
|
onComputeDelivered?: (event: ComputeDeliveredEvent) => void;
|
|
470
470
|
onCommitmentSuccess?: (event: CommitmentSuccessCallbackEvent) => void;
|
|
471
471
|
isRequestProcessed?: (requestId: string) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -465,7 +465,7 @@ interface NoosphereAgentOptions {
|
|
|
465
465
|
onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
|
|
466
466
|
onRequestProcessing?: (requestId: string) => void;
|
|
467
467
|
onRequestSkipped?: (requestId: string, reason: string) => void;
|
|
468
|
-
onRequestFailed?: (requestId: string, error: string) => void;
|
|
468
|
+
onRequestFailed?: (requestId: string, error: string, txHash?: string) => void;
|
|
469
469
|
onComputeDelivered?: (event: ComputeDeliveredEvent) => void;
|
|
470
470
|
onCommitmentSuccess?: (event: CommitmentSuccessCallbackEvent) => void;
|
|
471
471
|
isRequestProcessed?: (requestId: string) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -456,14 +456,19 @@ var ContainerManager = class {
|
|
|
456
456
|
console.log(`
|
|
457
457
|
\u{1F680} Preparing ${containers.size} containers...`);
|
|
458
458
|
const pullAndStartPromises = Array.from(containers.entries()).map(async ([id, container]) => {
|
|
459
|
+
const imageTag = `${container.image}:${container.tag || "latest"}`;
|
|
459
460
|
try {
|
|
460
|
-
const imageTag = `${container.image}:${container.tag || "latest"}`;
|
|
461
461
|
console.log(` Pulling ${imageTag}...`);
|
|
462
462
|
await this.pullImage(container.image, container.tag || "latest");
|
|
463
463
|
console.log(` \u2713 ${imageTag} ready`);
|
|
464
|
+
} catch (error) {
|
|
465
|
+
console.error(` \u274C Failed to pull ${imageTag}:`, error.message);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
try {
|
|
464
469
|
await this.startPersistentContainer(id, container);
|
|
465
470
|
} catch (error) {
|
|
466
|
-
console.error(` \u274C Failed to
|
|
471
|
+
console.error(` \u274C Failed to start ${container.name || container.image}:`, error.message);
|
|
467
472
|
}
|
|
468
473
|
});
|
|
469
474
|
await Promise.all(pullAndStartPromises);
|
|
@@ -475,21 +480,23 @@ var ContainerManager = class {
|
|
|
475
480
|
async startPersistentContainer(containerId, metadata) {
|
|
476
481
|
const containerName = `noosphere-${metadata.name}`;
|
|
477
482
|
const imageTag = `${metadata.image}:${metadata.tag || "latest"}`;
|
|
483
|
+
const existingContainer = this.docker.getContainer(containerName);
|
|
478
484
|
try {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
} else {
|
|
485
|
+
const inspect = await existingContainer.inspect();
|
|
486
|
+
if (inspect.State.Running) {
|
|
487
|
+
console.log(` \u2713 Container ${containerName} already running`);
|
|
488
|
+
this.persistentContainers.set(containerId, existingContainer);
|
|
489
|
+
return;
|
|
490
|
+
} else {
|
|
491
|
+
try {
|
|
487
492
|
await existingContainer.start();
|
|
488
493
|
console.log(` \u2713 Started existing container ${containerName}`);
|
|
489
494
|
this.persistentContainers.set(containerId, existingContainer);
|
|
490
495
|
return;
|
|
496
|
+
} catch (startErr) {
|
|
497
|
+
console.log(` Removing stopped container ${containerName} to recreate...`);
|
|
498
|
+
await existingContainer.remove({ force: true });
|
|
491
499
|
}
|
|
492
|
-
} catch (err) {
|
|
493
500
|
}
|
|
494
501
|
} catch (err) {
|
|
495
502
|
}
|
|
@@ -1627,6 +1634,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1627
1634
|
console.warn(` Could not verify interval currency:`, error.message);
|
|
1628
1635
|
}
|
|
1629
1636
|
this.scheduler.markIntervalCommitted(BigInt(event.subscriptionId), BigInt(event.interval));
|
|
1637
|
+
let sentTxHash;
|
|
1630
1638
|
try {
|
|
1631
1639
|
await this.waitForPriority(event);
|
|
1632
1640
|
if (this.options.onRequestProcessing) {
|
|
@@ -1739,6 +1747,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1739
1747
|
commitmentData,
|
|
1740
1748
|
nodeWallet
|
|
1741
1749
|
);
|
|
1750
|
+
sentTxHash = tx.hash;
|
|
1742
1751
|
console.log(` \u{1F4E4} Transaction sent: ${tx.hash}`);
|
|
1743
1752
|
const receipt = await tx.wait();
|
|
1744
1753
|
if (receipt.status === 1) {
|
|
@@ -1773,7 +1782,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1773
1782
|
}
|
|
1774
1783
|
console.error(` \u274C Error processing request:`, error);
|
|
1775
1784
|
if (this.options.onRequestFailed) {
|
|
1776
|
-
this.options.onRequestFailed(event.requestId, errorMessage);
|
|
1785
|
+
this.options.onRequestFailed(event.requestId, errorMessage, sentTxHash);
|
|
1777
1786
|
}
|
|
1778
1787
|
} finally {
|
|
1779
1788
|
this.processingRequests.delete(event.requestId);
|