@noosphere/agent-core 0.1.0-alpha.11 → 0.1.0-alpha.13
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 +56 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +56 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -812,7 +812,13 @@ var SchedulerService = class extends import_events2.EventEmitter {
|
|
|
812
812
|
try {
|
|
813
813
|
currentInterval = BigInt(await this.router.getComputeSubscriptionInterval(sub.subscriptionId));
|
|
814
814
|
} catch (error) {
|
|
815
|
-
|
|
815
|
+
const errorMessage = error.message || "";
|
|
816
|
+
console.warn(` Could not get interval from router for subscription ${subId}:`, errorMessage);
|
|
817
|
+
if (errorMessage.includes("SubscriptionNotFound")) {
|
|
818
|
+
console.log(` Subscription ${subId} not found (cancelled), untracking...`);
|
|
819
|
+
this.untrackSubscription(sub.subscriptionId);
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
816
822
|
const intervalsSinceActive = BigInt(currentBlockTime) - sub.activeAt;
|
|
817
823
|
currentInterval = intervalsSinceActive / sub.intervalSeconds + 1n;
|
|
818
824
|
}
|
|
@@ -1440,7 +1446,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1440
1446
|
);
|
|
1441
1447
|
}
|
|
1442
1448
|
this.containerManager = new ContainerManager();
|
|
1443
|
-
this.registryManager = new import_registry.RegistryManager({
|
|
1449
|
+
this.registryManager = options.registryManager || new import_registry.RegistryManager({
|
|
1444
1450
|
autoSync: true,
|
|
1445
1451
|
// Enable automatic sync with remote registry
|
|
1446
1452
|
cacheTTL: 36e5
|
|
@@ -1480,6 +1486,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1480
1486
|
}
|
|
1481
1487
|
this.maxRetries = options.maxRetries ?? 3;
|
|
1482
1488
|
this.retryIntervalMs = options.retryIntervalMs ?? 3e4;
|
|
1489
|
+
this.containerTimeout = options.containerConfig?.timeout ?? 3e5;
|
|
1490
|
+
this.containerConnectionRetries = options.containerConfig?.connectionRetries ?? 5;
|
|
1491
|
+
this.containerConnectionRetryDelayMs = options.containerConfig?.connectionRetryDelayMs ?? 3e3;
|
|
1492
|
+
this.healthCheckIntervalMs = options.healthCheckIntervalMs ?? 3e5;
|
|
1483
1493
|
}
|
|
1484
1494
|
/**
|
|
1485
1495
|
* Initialize NoosphereAgent from config.json (RECOMMENDED)
|
|
@@ -1546,7 +1556,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1546
1556
|
async start() {
|
|
1547
1557
|
console.log("Starting Noosphere Agent...");
|
|
1548
1558
|
console.log("\u{1F4CB} Loading container registry...");
|
|
1549
|
-
|
|
1559
|
+
const existingStats = this.registryManager.getStats();
|
|
1560
|
+
if (existingStats.totalContainers === 0) {
|
|
1561
|
+
await this.registryManager.load();
|
|
1562
|
+
}
|
|
1550
1563
|
const stats = this.registryManager.getStats();
|
|
1551
1564
|
console.log(
|
|
1552
1565
|
`\u2713 Registry loaded: ${stats.totalContainers} containers, ${stats.totalVerifiers} verifiers`
|
|
@@ -1621,6 +1634,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1621
1634
|
if (this.options.getRetryableEvents && this.options.resetEventForRetry) {
|
|
1622
1635
|
this.startRetryTimer();
|
|
1623
1636
|
}
|
|
1637
|
+
this.startHealthCheck();
|
|
1624
1638
|
this.isRunning = true;
|
|
1625
1639
|
console.log("\u2713 Noosphere Agent is running");
|
|
1626
1640
|
console.log("Listening for requests...");
|
|
@@ -1637,6 +1651,38 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1637
1651
|
await this.processRetries();
|
|
1638
1652
|
}, this.retryIntervalMs);
|
|
1639
1653
|
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Start the health check timer for registry validation
|
|
1656
|
+
*/
|
|
1657
|
+
startHealthCheck() {
|
|
1658
|
+
if (this.healthCheckTimer) {
|
|
1659
|
+
clearInterval(this.healthCheckTimer);
|
|
1660
|
+
}
|
|
1661
|
+
console.log(`\u{1F3E5} Health check enabled: check every ${this.healthCheckIntervalMs / 1e3}s`);
|
|
1662
|
+
this.healthCheckTimer = setInterval(async () => {
|
|
1663
|
+
await this.performHealthCheck();
|
|
1664
|
+
}, this.healthCheckIntervalMs);
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Perform health check - verify registry has containers and reload if necessary
|
|
1668
|
+
*/
|
|
1669
|
+
async performHealthCheck() {
|
|
1670
|
+
const stats = this.registryManager.getStats();
|
|
1671
|
+
if (stats.totalContainers === 0) {
|
|
1672
|
+
console.warn("\u26A0\uFE0F Health check: 0 containers detected, attempting registry reload...");
|
|
1673
|
+
try {
|
|
1674
|
+
await this.registryManager.reload();
|
|
1675
|
+
const newStats = this.registryManager.getStats();
|
|
1676
|
+
if (newStats.totalContainers > 0) {
|
|
1677
|
+
console.log(`\u2713 Health check: Registry recovered - ${newStats.totalContainers} containers loaded`);
|
|
1678
|
+
} else {
|
|
1679
|
+
console.error("\u274C Health check: Registry reload failed - still 0 containers");
|
|
1680
|
+
}
|
|
1681
|
+
} catch (error) {
|
|
1682
|
+
console.error("\u274C Health check: Registry reload error:", error.message);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1640
1686
|
/**
|
|
1641
1687
|
* Process retryable failed events (with throttling to avoid rate limits)
|
|
1642
1688
|
*/
|
|
@@ -1823,8 +1869,9 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1823
1869
|
const result = await this.containerManager.runContainer(
|
|
1824
1870
|
container,
|
|
1825
1871
|
inputData,
|
|
1826
|
-
|
|
1827
|
-
|
|
1872
|
+
this.containerTimeout,
|
|
1873
|
+
this.containerConnectionRetries,
|
|
1874
|
+
this.containerConnectionRetryDelayMs
|
|
1828
1875
|
);
|
|
1829
1876
|
if (result.exitCode !== 0) {
|
|
1830
1877
|
console.error(` \u274C Container execution failed with exit code ${result.exitCode}`);
|
|
@@ -1919,6 +1966,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1919
1966
|
clearInterval(this.retryTimer);
|
|
1920
1967
|
this.retryTimer = void 0;
|
|
1921
1968
|
}
|
|
1969
|
+
if (this.healthCheckTimer) {
|
|
1970
|
+
clearInterval(this.healthCheckTimer);
|
|
1971
|
+
this.healthCheckTimer = void 0;
|
|
1972
|
+
}
|
|
1922
1973
|
await this.eventMonitor.stop();
|
|
1923
1974
|
this.scheduler.stop();
|
|
1924
1975
|
await this.containerManager.cleanup();
|