@noosphere/agent-core 0.1.0-alpha.11 → 0.1.0-alpha.12
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 +51 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +51 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -463,6 +463,11 @@ interface RetryableEvent {
|
|
|
463
463
|
containerId: string;
|
|
464
464
|
retryCount: number;
|
|
465
465
|
}
|
|
466
|
+
interface ContainerExecutionConfig {
|
|
467
|
+
timeout?: number;
|
|
468
|
+
connectionRetries?: number;
|
|
469
|
+
connectionRetryDelayMs?: number;
|
|
470
|
+
}
|
|
466
471
|
interface NoosphereAgentOptions {
|
|
467
472
|
config: AgentConfig;
|
|
468
473
|
routerAbi?: any[];
|
|
@@ -472,6 +477,7 @@ interface NoosphereAgentOptions {
|
|
|
472
477
|
walletManager?: WalletManager;
|
|
473
478
|
paymentWallet?: string;
|
|
474
479
|
schedulerConfig?: Partial<SchedulerConfig>;
|
|
480
|
+
containerConfig?: ContainerExecutionConfig;
|
|
475
481
|
onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
|
|
476
482
|
onRequestProcessing?: (requestId: string) => void;
|
|
477
483
|
onRequestSkipped?: (requestId: string, reason: string) => void;
|
|
@@ -485,6 +491,7 @@ interface NoosphereAgentOptions {
|
|
|
485
491
|
retryIntervalMs?: number;
|
|
486
492
|
getRetryableEvents?: (maxRetries: number) => RetryableEvent[];
|
|
487
493
|
resetEventForRetry?: (requestId: string) => void;
|
|
494
|
+
healthCheckIntervalMs?: number;
|
|
488
495
|
}
|
|
489
496
|
declare class NoosphereAgent {
|
|
490
497
|
private options;
|
|
@@ -503,8 +510,13 @@ declare class NoosphereAgent {
|
|
|
503
510
|
private isRunning;
|
|
504
511
|
private processingRequests;
|
|
505
512
|
private retryTimer?;
|
|
513
|
+
private healthCheckTimer?;
|
|
506
514
|
private maxRetries;
|
|
507
515
|
private retryIntervalMs;
|
|
516
|
+
private healthCheckIntervalMs;
|
|
517
|
+
private containerTimeout;
|
|
518
|
+
private containerConnectionRetries;
|
|
519
|
+
private containerConnectionRetryDelayMs;
|
|
508
520
|
constructor(options: NoosphereAgentOptions);
|
|
509
521
|
/**
|
|
510
522
|
* Initialize NoosphereAgent from config.json (RECOMMENDED)
|
|
@@ -531,6 +543,14 @@ declare class NoosphereAgent {
|
|
|
531
543
|
* Start the retry timer for failed requests
|
|
532
544
|
*/
|
|
533
545
|
private startRetryTimer;
|
|
546
|
+
/**
|
|
547
|
+
* Start the health check timer for registry validation
|
|
548
|
+
*/
|
|
549
|
+
private startHealthCheck;
|
|
550
|
+
/**
|
|
551
|
+
* Perform health check - verify registry has containers and reload if necessary
|
|
552
|
+
*/
|
|
553
|
+
private performHealthCheck;
|
|
534
554
|
/**
|
|
535
555
|
* Process retryable failed events (with throttling to avoid rate limits)
|
|
536
556
|
*/
|
|
@@ -630,4 +650,4 @@ declare class ConfigLoader {
|
|
|
630
650
|
static getContainerConfig(config: NoosphereAgentConfig, containerId: string): NoosphereAgentConfig['containers'][0] | undefined;
|
|
631
651
|
}
|
|
632
652
|
|
|
633
|
-
export { type AgentConfig, type CheckpointData$1 as CheckpointData, type Commitment, type CommitmentSuccessCallbackEvent, type CommitmentSuccessEvent, CommitmentUtils, type ComputeDeliveredEvent, type ComputeSubscription, ConfigLoader, type ContainerConfig, ContainerManager, type ContainerMetadata, EventMonitor, FulfillResult, NoosphereAgent, type NoosphereAgentConfig, type Payment, type ProofVerificationRequest, RequestIdUtils, type RequestStartedCallbackEvent, type RequestStartedEvent, type RetryableEvent, SchedulerService, type VerifierMetadata };
|
|
653
|
+
export { type AgentConfig, type CheckpointData$1 as CheckpointData, type Commitment, type CommitmentSuccessCallbackEvent, type CommitmentSuccessEvent, CommitmentUtils, type ComputeDeliveredEvent, type ComputeSubscription, ConfigLoader, type ContainerConfig, type ContainerExecutionConfig, ContainerManager, type ContainerMetadata, EventMonitor, FulfillResult, NoosphereAgent, type NoosphereAgentConfig, type Payment, type ProofVerificationRequest, RequestIdUtils, type RequestStartedCallbackEvent, type RequestStartedEvent, type RetryableEvent, SchedulerService, type VerifierMetadata };
|
package/dist/index.d.ts
CHANGED
|
@@ -463,6 +463,11 @@ interface RetryableEvent {
|
|
|
463
463
|
containerId: string;
|
|
464
464
|
retryCount: number;
|
|
465
465
|
}
|
|
466
|
+
interface ContainerExecutionConfig {
|
|
467
|
+
timeout?: number;
|
|
468
|
+
connectionRetries?: number;
|
|
469
|
+
connectionRetryDelayMs?: number;
|
|
470
|
+
}
|
|
466
471
|
interface NoosphereAgentOptions {
|
|
467
472
|
config: AgentConfig;
|
|
468
473
|
routerAbi?: any[];
|
|
@@ -472,6 +477,7 @@ interface NoosphereAgentOptions {
|
|
|
472
477
|
walletManager?: WalletManager;
|
|
473
478
|
paymentWallet?: string;
|
|
474
479
|
schedulerConfig?: Partial<SchedulerConfig>;
|
|
480
|
+
containerConfig?: ContainerExecutionConfig;
|
|
475
481
|
onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
|
|
476
482
|
onRequestProcessing?: (requestId: string) => void;
|
|
477
483
|
onRequestSkipped?: (requestId: string, reason: string) => void;
|
|
@@ -485,6 +491,7 @@ interface NoosphereAgentOptions {
|
|
|
485
491
|
retryIntervalMs?: number;
|
|
486
492
|
getRetryableEvents?: (maxRetries: number) => RetryableEvent[];
|
|
487
493
|
resetEventForRetry?: (requestId: string) => void;
|
|
494
|
+
healthCheckIntervalMs?: number;
|
|
488
495
|
}
|
|
489
496
|
declare class NoosphereAgent {
|
|
490
497
|
private options;
|
|
@@ -503,8 +510,13 @@ declare class NoosphereAgent {
|
|
|
503
510
|
private isRunning;
|
|
504
511
|
private processingRequests;
|
|
505
512
|
private retryTimer?;
|
|
513
|
+
private healthCheckTimer?;
|
|
506
514
|
private maxRetries;
|
|
507
515
|
private retryIntervalMs;
|
|
516
|
+
private healthCheckIntervalMs;
|
|
517
|
+
private containerTimeout;
|
|
518
|
+
private containerConnectionRetries;
|
|
519
|
+
private containerConnectionRetryDelayMs;
|
|
508
520
|
constructor(options: NoosphereAgentOptions);
|
|
509
521
|
/**
|
|
510
522
|
* Initialize NoosphereAgent from config.json (RECOMMENDED)
|
|
@@ -531,6 +543,14 @@ declare class NoosphereAgent {
|
|
|
531
543
|
* Start the retry timer for failed requests
|
|
532
544
|
*/
|
|
533
545
|
private startRetryTimer;
|
|
546
|
+
/**
|
|
547
|
+
* Start the health check timer for registry validation
|
|
548
|
+
*/
|
|
549
|
+
private startHealthCheck;
|
|
550
|
+
/**
|
|
551
|
+
* Perform health check - verify registry has containers and reload if necessary
|
|
552
|
+
*/
|
|
553
|
+
private performHealthCheck;
|
|
534
554
|
/**
|
|
535
555
|
* Process retryable failed events (with throttling to avoid rate limits)
|
|
536
556
|
*/
|
|
@@ -630,4 +650,4 @@ declare class ConfigLoader {
|
|
|
630
650
|
static getContainerConfig(config: NoosphereAgentConfig, containerId: string): NoosphereAgentConfig['containers'][0] | undefined;
|
|
631
651
|
}
|
|
632
652
|
|
|
633
|
-
export { type AgentConfig, type CheckpointData$1 as CheckpointData, type Commitment, type CommitmentSuccessCallbackEvent, type CommitmentSuccessEvent, CommitmentUtils, type ComputeDeliveredEvent, type ComputeSubscription, ConfigLoader, type ContainerConfig, ContainerManager, type ContainerMetadata, EventMonitor, FulfillResult, NoosphereAgent, type NoosphereAgentConfig, type Payment, type ProofVerificationRequest, RequestIdUtils, type RequestStartedCallbackEvent, type RequestStartedEvent, type RetryableEvent, SchedulerService, type VerifierMetadata };
|
|
653
|
+
export { type AgentConfig, type CheckpointData$1 as CheckpointData, type Commitment, type CommitmentSuccessCallbackEvent, type CommitmentSuccessEvent, CommitmentUtils, type ComputeDeliveredEvent, type ComputeSubscription, ConfigLoader, type ContainerConfig, type ContainerExecutionConfig, ContainerManager, type ContainerMetadata, EventMonitor, FulfillResult, NoosphereAgent, type NoosphereAgentConfig, type Payment, type ProofVerificationRequest, RequestIdUtils, type RequestStartedCallbackEvent, type RequestStartedEvent, type RetryableEvent, SchedulerService, type VerifierMetadata };
|
package/dist/index.js
CHANGED
|
@@ -773,7 +773,13 @@ var SchedulerService = class extends EventEmitter2 {
|
|
|
773
773
|
try {
|
|
774
774
|
currentInterval = BigInt(await this.router.getComputeSubscriptionInterval(sub.subscriptionId));
|
|
775
775
|
} catch (error) {
|
|
776
|
-
|
|
776
|
+
const errorMessage = error.message || "";
|
|
777
|
+
console.warn(` Could not get interval from router for subscription ${subId}:`, errorMessage);
|
|
778
|
+
if (errorMessage.includes("SubscriptionNotFound")) {
|
|
779
|
+
console.log(` Subscription ${subId} not found (cancelled), untracking...`);
|
|
780
|
+
this.untrackSubscription(sub.subscriptionId);
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
777
783
|
const intervalsSinceActive = BigInt(currentBlockTime) - sub.activeAt;
|
|
778
784
|
currentInterval = intervalsSinceActive / sub.intervalSeconds + 1n;
|
|
779
785
|
}
|
|
@@ -1441,6 +1447,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1441
1447
|
}
|
|
1442
1448
|
this.maxRetries = options.maxRetries ?? 3;
|
|
1443
1449
|
this.retryIntervalMs = options.retryIntervalMs ?? 3e4;
|
|
1450
|
+
this.containerTimeout = options.containerConfig?.timeout ?? 3e5;
|
|
1451
|
+
this.containerConnectionRetries = options.containerConfig?.connectionRetries ?? 5;
|
|
1452
|
+
this.containerConnectionRetryDelayMs = options.containerConfig?.connectionRetryDelayMs ?? 3e3;
|
|
1453
|
+
this.healthCheckIntervalMs = options.healthCheckIntervalMs ?? 3e5;
|
|
1444
1454
|
}
|
|
1445
1455
|
/**
|
|
1446
1456
|
* Initialize NoosphereAgent from config.json (RECOMMENDED)
|
|
@@ -1582,6 +1592,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1582
1592
|
if (this.options.getRetryableEvents && this.options.resetEventForRetry) {
|
|
1583
1593
|
this.startRetryTimer();
|
|
1584
1594
|
}
|
|
1595
|
+
this.startHealthCheck();
|
|
1585
1596
|
this.isRunning = true;
|
|
1586
1597
|
console.log("\u2713 Noosphere Agent is running");
|
|
1587
1598
|
console.log("Listening for requests...");
|
|
@@ -1598,6 +1609,38 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1598
1609
|
await this.processRetries();
|
|
1599
1610
|
}, this.retryIntervalMs);
|
|
1600
1611
|
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Start the health check timer for registry validation
|
|
1614
|
+
*/
|
|
1615
|
+
startHealthCheck() {
|
|
1616
|
+
if (this.healthCheckTimer) {
|
|
1617
|
+
clearInterval(this.healthCheckTimer);
|
|
1618
|
+
}
|
|
1619
|
+
console.log(`\u{1F3E5} Health check enabled: check every ${this.healthCheckIntervalMs / 1e3}s`);
|
|
1620
|
+
this.healthCheckTimer = setInterval(async () => {
|
|
1621
|
+
await this.performHealthCheck();
|
|
1622
|
+
}, this.healthCheckIntervalMs);
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* Perform health check - verify registry has containers and reload if necessary
|
|
1626
|
+
*/
|
|
1627
|
+
async performHealthCheck() {
|
|
1628
|
+
const stats = this.registryManager.getStats();
|
|
1629
|
+
if (stats.totalContainers === 0) {
|
|
1630
|
+
console.warn("\u26A0\uFE0F Health check: 0 containers detected, attempting registry reload...");
|
|
1631
|
+
try {
|
|
1632
|
+
await this.registryManager.reload();
|
|
1633
|
+
const newStats = this.registryManager.getStats();
|
|
1634
|
+
if (newStats.totalContainers > 0) {
|
|
1635
|
+
console.log(`\u2713 Health check: Registry recovered - ${newStats.totalContainers} containers loaded`);
|
|
1636
|
+
} else {
|
|
1637
|
+
console.error("\u274C Health check: Registry reload failed - still 0 containers");
|
|
1638
|
+
}
|
|
1639
|
+
} catch (error) {
|
|
1640
|
+
console.error("\u274C Health check: Registry reload error:", error.message);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1601
1644
|
/**
|
|
1602
1645
|
* Process retryable failed events (with throttling to avoid rate limits)
|
|
1603
1646
|
*/
|
|
@@ -1784,8 +1827,9 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1784
1827
|
const result = await this.containerManager.runContainer(
|
|
1785
1828
|
container,
|
|
1786
1829
|
inputData,
|
|
1787
|
-
|
|
1788
|
-
|
|
1830
|
+
this.containerTimeout,
|
|
1831
|
+
this.containerConnectionRetries,
|
|
1832
|
+
this.containerConnectionRetryDelayMs
|
|
1789
1833
|
);
|
|
1790
1834
|
if (result.exitCode !== 0) {
|
|
1791
1835
|
console.error(` \u274C Container execution failed with exit code ${result.exitCode}`);
|
|
@@ -1880,6 +1924,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1880
1924
|
clearInterval(this.retryTimer);
|
|
1881
1925
|
this.retryTimer = void 0;
|
|
1882
1926
|
}
|
|
1927
|
+
if (this.healthCheckTimer) {
|
|
1928
|
+
clearInterval(this.healthCheckTimer);
|
|
1929
|
+
this.healthCheckTimer = void 0;
|
|
1930
|
+
}
|
|
1883
1931
|
await this.eventMonitor.stop();
|
|
1884
1932
|
this.scheduler.stop();
|
|
1885
1933
|
await this.containerManager.cleanup();
|