@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.d.mts CHANGED
@@ -2,6 +2,7 @@ import { EventEmitter } from 'events';
2
2
  import { Provider, Contract } from 'ethers';
3
3
  import { WalletManager } from '@noosphere/crypto';
4
4
  export { KeystoreInfo, KeystoreManager, NoosphereKeystore, PaymentWalletInfo, WalletManager } from '@noosphere/crypto';
5
+ import { RegistryManager } from '@noosphere/registry';
5
6
  export { RegistryConfig, ContainerMetadata as RegistryContainerMetadata, RegistryManager, VerifierMetadata as RegistryVerifierMetadata } from '@noosphere/registry';
6
7
 
7
8
  interface Commitment {
@@ -463,15 +464,22 @@ interface RetryableEvent {
463
464
  containerId: string;
464
465
  retryCount: number;
465
466
  }
467
+ interface ContainerExecutionConfig {
468
+ timeout?: number;
469
+ connectionRetries?: number;
470
+ connectionRetryDelayMs?: number;
471
+ }
466
472
  interface NoosphereAgentOptions {
467
473
  config: AgentConfig;
468
474
  routerAbi?: any[];
469
475
  coordinatorAbi?: any[];
470
476
  getContainer?: (containerId: string) => ContainerMetadata | undefined;
471
477
  containers?: Map<string, ContainerMetadata>;
478
+ registryManager?: RegistryManager;
472
479
  walletManager?: WalletManager;
473
480
  paymentWallet?: string;
474
481
  schedulerConfig?: Partial<SchedulerConfig>;
482
+ containerConfig?: ContainerExecutionConfig;
475
483
  onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
476
484
  onRequestProcessing?: (requestId: string) => void;
477
485
  onRequestSkipped?: (requestId: string, reason: string) => void;
@@ -485,6 +493,7 @@ interface NoosphereAgentOptions {
485
493
  retryIntervalMs?: number;
486
494
  getRetryableEvents?: (maxRetries: number) => RetryableEvent[];
487
495
  resetEventForRetry?: (requestId: string) => void;
496
+ healthCheckIntervalMs?: number;
488
497
  }
489
498
  declare class NoosphereAgent {
490
499
  private options;
@@ -503,8 +512,13 @@ declare class NoosphereAgent {
503
512
  private isRunning;
504
513
  private processingRequests;
505
514
  private retryTimer?;
515
+ private healthCheckTimer?;
506
516
  private maxRetries;
507
517
  private retryIntervalMs;
518
+ private healthCheckIntervalMs;
519
+ private containerTimeout;
520
+ private containerConnectionRetries;
521
+ private containerConnectionRetryDelayMs;
508
522
  constructor(options: NoosphereAgentOptions);
509
523
  /**
510
524
  * Initialize NoosphereAgent from config.json (RECOMMENDED)
@@ -531,6 +545,14 @@ declare class NoosphereAgent {
531
545
  * Start the retry timer for failed requests
532
546
  */
533
547
  private startRetryTimer;
548
+ /**
549
+ * Start the health check timer for registry validation
550
+ */
551
+ private startHealthCheck;
552
+ /**
553
+ * Perform health check - verify registry has containers and reload if necessary
554
+ */
555
+ private performHealthCheck;
534
556
  /**
535
557
  * Process retryable failed events (with throttling to avoid rate limits)
536
558
  */
@@ -630,4 +652,4 @@ declare class ConfigLoader {
630
652
  static getContainerConfig(config: NoosphereAgentConfig, containerId: string): NoosphereAgentConfig['containers'][0] | undefined;
631
653
  }
632
654
 
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 };
655
+ 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
@@ -2,6 +2,7 @@ import { EventEmitter } from 'events';
2
2
  import { Provider, Contract } from 'ethers';
3
3
  import { WalletManager } from '@noosphere/crypto';
4
4
  export { KeystoreInfo, KeystoreManager, NoosphereKeystore, PaymentWalletInfo, WalletManager } from '@noosphere/crypto';
5
+ import { RegistryManager } from '@noosphere/registry';
5
6
  export { RegistryConfig, ContainerMetadata as RegistryContainerMetadata, RegistryManager, VerifierMetadata as RegistryVerifierMetadata } from '@noosphere/registry';
6
7
 
7
8
  interface Commitment {
@@ -463,15 +464,22 @@ interface RetryableEvent {
463
464
  containerId: string;
464
465
  retryCount: number;
465
466
  }
467
+ interface ContainerExecutionConfig {
468
+ timeout?: number;
469
+ connectionRetries?: number;
470
+ connectionRetryDelayMs?: number;
471
+ }
466
472
  interface NoosphereAgentOptions {
467
473
  config: AgentConfig;
468
474
  routerAbi?: any[];
469
475
  coordinatorAbi?: any[];
470
476
  getContainer?: (containerId: string) => ContainerMetadata | undefined;
471
477
  containers?: Map<string, ContainerMetadata>;
478
+ registryManager?: RegistryManager;
472
479
  walletManager?: WalletManager;
473
480
  paymentWallet?: string;
474
481
  schedulerConfig?: Partial<SchedulerConfig>;
482
+ containerConfig?: ContainerExecutionConfig;
475
483
  onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
476
484
  onRequestProcessing?: (requestId: string) => void;
477
485
  onRequestSkipped?: (requestId: string, reason: string) => void;
@@ -485,6 +493,7 @@ interface NoosphereAgentOptions {
485
493
  retryIntervalMs?: number;
486
494
  getRetryableEvents?: (maxRetries: number) => RetryableEvent[];
487
495
  resetEventForRetry?: (requestId: string) => void;
496
+ healthCheckIntervalMs?: number;
488
497
  }
489
498
  declare class NoosphereAgent {
490
499
  private options;
@@ -503,8 +512,13 @@ declare class NoosphereAgent {
503
512
  private isRunning;
504
513
  private processingRequests;
505
514
  private retryTimer?;
515
+ private healthCheckTimer?;
506
516
  private maxRetries;
507
517
  private retryIntervalMs;
518
+ private healthCheckIntervalMs;
519
+ private containerTimeout;
520
+ private containerConnectionRetries;
521
+ private containerConnectionRetryDelayMs;
508
522
  constructor(options: NoosphereAgentOptions);
509
523
  /**
510
524
  * Initialize NoosphereAgent from config.json (RECOMMENDED)
@@ -531,6 +545,14 @@ declare class NoosphereAgent {
531
545
  * Start the retry timer for failed requests
532
546
  */
533
547
  private startRetryTimer;
548
+ /**
549
+ * Start the health check timer for registry validation
550
+ */
551
+ private startHealthCheck;
552
+ /**
553
+ * Perform health check - verify registry has containers and reload if necessary
554
+ */
555
+ private performHealthCheck;
534
556
  /**
535
557
  * Process retryable failed events (with throttling to avoid rate limits)
536
558
  */
@@ -630,4 +652,4 @@ declare class ConfigLoader {
630
652
  static getContainerConfig(config: NoosphereAgentConfig, containerId: string): NoosphereAgentConfig['containers'][0] | undefined;
631
653
  }
632
654
 
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 };
655
+ 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
- console.warn(` Could not get interval from router for subscription ${subId}:`, error.message);
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
  }
@@ -1401,7 +1407,7 @@ var NoosphereAgent = class _NoosphereAgent {
1401
1407
  );
1402
1408
  }
1403
1409
  this.containerManager = new ContainerManager();
1404
- this.registryManager = new RegistryManager({
1410
+ this.registryManager = options.registryManager || new RegistryManager({
1405
1411
  autoSync: true,
1406
1412
  // Enable automatic sync with remote registry
1407
1413
  cacheTTL: 36e5
@@ -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)
@@ -1507,7 +1517,10 @@ var NoosphereAgent = class _NoosphereAgent {
1507
1517
  async start() {
1508
1518
  console.log("Starting Noosphere Agent...");
1509
1519
  console.log("\u{1F4CB} Loading container registry...");
1510
- await this.registryManager.load();
1520
+ const existingStats = this.registryManager.getStats();
1521
+ if (existingStats.totalContainers === 0) {
1522
+ await this.registryManager.load();
1523
+ }
1511
1524
  const stats = this.registryManager.getStats();
1512
1525
  console.log(
1513
1526
  `\u2713 Registry loaded: ${stats.totalContainers} containers, ${stats.totalVerifiers} verifiers`
@@ -1582,6 +1595,7 @@ var NoosphereAgent = class _NoosphereAgent {
1582
1595
  if (this.options.getRetryableEvents && this.options.resetEventForRetry) {
1583
1596
  this.startRetryTimer();
1584
1597
  }
1598
+ this.startHealthCheck();
1585
1599
  this.isRunning = true;
1586
1600
  console.log("\u2713 Noosphere Agent is running");
1587
1601
  console.log("Listening for requests...");
@@ -1598,6 +1612,38 @@ var NoosphereAgent = class _NoosphereAgent {
1598
1612
  await this.processRetries();
1599
1613
  }, this.retryIntervalMs);
1600
1614
  }
1615
+ /**
1616
+ * Start the health check timer for registry validation
1617
+ */
1618
+ startHealthCheck() {
1619
+ if (this.healthCheckTimer) {
1620
+ clearInterval(this.healthCheckTimer);
1621
+ }
1622
+ console.log(`\u{1F3E5} Health check enabled: check every ${this.healthCheckIntervalMs / 1e3}s`);
1623
+ this.healthCheckTimer = setInterval(async () => {
1624
+ await this.performHealthCheck();
1625
+ }, this.healthCheckIntervalMs);
1626
+ }
1627
+ /**
1628
+ * Perform health check - verify registry has containers and reload if necessary
1629
+ */
1630
+ async performHealthCheck() {
1631
+ const stats = this.registryManager.getStats();
1632
+ if (stats.totalContainers === 0) {
1633
+ console.warn("\u26A0\uFE0F Health check: 0 containers detected, attempting registry reload...");
1634
+ try {
1635
+ await this.registryManager.reload();
1636
+ const newStats = this.registryManager.getStats();
1637
+ if (newStats.totalContainers > 0) {
1638
+ console.log(`\u2713 Health check: Registry recovered - ${newStats.totalContainers} containers loaded`);
1639
+ } else {
1640
+ console.error("\u274C Health check: Registry reload failed - still 0 containers");
1641
+ }
1642
+ } catch (error) {
1643
+ console.error("\u274C Health check: Registry reload error:", error.message);
1644
+ }
1645
+ }
1646
+ }
1601
1647
  /**
1602
1648
  * Process retryable failed events (with throttling to avoid rate limits)
1603
1649
  */
@@ -1784,8 +1830,9 @@ var NoosphereAgent = class _NoosphereAgent {
1784
1830
  const result = await this.containerManager.runContainer(
1785
1831
  container,
1786
1832
  inputData,
1787
- 3e5
1788
- // 5 min timeout
1833
+ this.containerTimeout,
1834
+ this.containerConnectionRetries,
1835
+ this.containerConnectionRetryDelayMs
1789
1836
  );
1790
1837
  if (result.exitCode !== 0) {
1791
1838
  console.error(` \u274C Container execution failed with exit code ${result.exitCode}`);
@@ -1880,6 +1927,10 @@ var NoosphereAgent = class _NoosphereAgent {
1880
1927
  clearInterval(this.retryTimer);
1881
1928
  this.retryTimer = void 0;
1882
1929
  }
1930
+ if (this.healthCheckTimer) {
1931
+ clearInterval(this.healthCheckTimer);
1932
+ this.healthCheckTimer = void 0;
1933
+ }
1883
1934
  await this.eventMonitor.stop();
1884
1935
  this.scheduler.stop();
1885
1936
  await this.containerManager.cleanup();