@noosphere/agent-core 0.1.0-alpha.8 → 0.2.0-alpha.1
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 +11200 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +535 -4
- package/dist/index.d.ts +535 -4
- package/dist/index.js +11194 -129
- package/dist/index.js.map +1 -1
- package/package.json +17 -6
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,10 @@ 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';
|
|
7
|
+
import { PayloadData } from '@noosphere/contracts';
|
|
8
|
+
export { InputType, PayloadData } from '@noosphere/contracts';
|
|
6
9
|
|
|
7
10
|
interface Commitment {
|
|
8
11
|
requestId: string;
|
|
@@ -239,7 +242,10 @@ declare class ContainerManager {
|
|
|
239
242
|
private persistentContainers;
|
|
240
243
|
private containerPorts;
|
|
241
244
|
constructor();
|
|
242
|
-
runContainer(container: ContainerMetadata, input: string, timeout?: number
|
|
245
|
+
runContainer(container: ContainerMetadata, input: string, timeout?: number, // 3 minutes default
|
|
246
|
+
connectionRetries?: number, // Retry up to 5 times for connection issues
|
|
247
|
+
connectionRetryDelayMs?: number): Promise<ContainerExecutionResult>;
|
|
248
|
+
private sleep;
|
|
243
249
|
private collectContainerResult;
|
|
244
250
|
private pullImage;
|
|
245
251
|
private waitForContainer;
|
|
@@ -417,8 +423,8 @@ interface ComputeDeliveredEvent {
|
|
|
417
423
|
redundancy: number;
|
|
418
424
|
feeAmount: string;
|
|
419
425
|
feeToken: string;
|
|
420
|
-
input: string;
|
|
421
|
-
output: string;
|
|
426
|
+
input: string | PayloadData;
|
|
427
|
+
output: string | PayloadData;
|
|
422
428
|
txHash: string;
|
|
423
429
|
blockNumber: number;
|
|
424
430
|
gasUsed: bigint;
|
|
@@ -453,15 +459,29 @@ interface CheckpointData {
|
|
|
453
459
|
blockHash?: string;
|
|
454
460
|
blockTimestamp?: number;
|
|
455
461
|
}
|
|
462
|
+
interface RetryableEvent {
|
|
463
|
+
requestId: string;
|
|
464
|
+
subscriptionId: number;
|
|
465
|
+
interval: number;
|
|
466
|
+
containerId: string;
|
|
467
|
+
retryCount: number;
|
|
468
|
+
}
|
|
469
|
+
interface ContainerExecutionConfig {
|
|
470
|
+
timeout?: number;
|
|
471
|
+
connectionRetries?: number;
|
|
472
|
+
connectionRetryDelayMs?: number;
|
|
473
|
+
}
|
|
456
474
|
interface NoosphereAgentOptions {
|
|
457
475
|
config: AgentConfig;
|
|
458
476
|
routerAbi?: any[];
|
|
459
477
|
coordinatorAbi?: any[];
|
|
460
478
|
getContainer?: (containerId: string) => ContainerMetadata | undefined;
|
|
461
479
|
containers?: Map<string, ContainerMetadata>;
|
|
480
|
+
registryManager?: RegistryManager;
|
|
462
481
|
walletManager?: WalletManager;
|
|
463
482
|
paymentWallet?: string;
|
|
464
483
|
schedulerConfig?: Partial<SchedulerConfig>;
|
|
484
|
+
containerConfig?: ContainerExecutionConfig;
|
|
465
485
|
onRequestStarted?: (event: RequestStartedCallbackEvent) => void;
|
|
466
486
|
onRequestProcessing?: (requestId: string) => void;
|
|
467
487
|
onRequestSkipped?: (requestId: string, reason: string) => void;
|
|
@@ -471,6 +491,12 @@ interface NoosphereAgentOptions {
|
|
|
471
491
|
isRequestProcessed?: (requestId: string) => boolean;
|
|
472
492
|
loadCheckpoint?: () => CheckpointData | undefined;
|
|
473
493
|
saveCheckpoint?: (checkpoint: CheckpointData) => void;
|
|
494
|
+
maxRetries?: number;
|
|
495
|
+
retryIntervalMs?: number;
|
|
496
|
+
getRetryableEvents?: (maxRetries: number) => RetryableEvent[];
|
|
497
|
+
resetEventForRetry?: (requestId: string) => void;
|
|
498
|
+
healthCheckIntervalMs?: number;
|
|
499
|
+
payloadEncoder?: (content: string) => Promise<PayloadData>;
|
|
474
500
|
}
|
|
475
501
|
declare class NoosphereAgent {
|
|
476
502
|
private options;
|
|
@@ -488,6 +514,15 @@ declare class NoosphereAgent {
|
|
|
488
514
|
private paymentWallet?;
|
|
489
515
|
private isRunning;
|
|
490
516
|
private processingRequests;
|
|
517
|
+
private retryTimer?;
|
|
518
|
+
private healthCheckTimer?;
|
|
519
|
+
private maxRetries;
|
|
520
|
+
private retryIntervalMs;
|
|
521
|
+
private healthCheckIntervalMs;
|
|
522
|
+
private containerTimeout;
|
|
523
|
+
private containerConnectionRetries;
|
|
524
|
+
private containerConnectionRetryDelayMs;
|
|
525
|
+
private payloadEncoder?;
|
|
491
526
|
constructor(options: NoosphereAgentOptions);
|
|
492
527
|
/**
|
|
493
528
|
* Initialize NoosphereAgent from config.json (RECOMMENDED)
|
|
@@ -510,10 +545,34 @@ declare class NoosphereAgent {
|
|
|
510
545
|
*/
|
|
511
546
|
static fromKeystore(keystorePath: string, password: string, options: Omit<NoosphereAgentOptions, 'walletManager'>): Promise<NoosphereAgent>;
|
|
512
547
|
start(): Promise<void>;
|
|
548
|
+
/**
|
|
549
|
+
* Start the retry timer for failed requests
|
|
550
|
+
*/
|
|
551
|
+
private startRetryTimer;
|
|
552
|
+
/**
|
|
553
|
+
* Start the health check timer for registry validation
|
|
554
|
+
*/
|
|
555
|
+
private startHealthCheck;
|
|
556
|
+
/**
|
|
557
|
+
* Perform health check - verify registry has containers and reload if necessary
|
|
558
|
+
*/
|
|
559
|
+
private performHealthCheck;
|
|
560
|
+
/**
|
|
561
|
+
* Process retryable failed events (with throttling to avoid rate limits)
|
|
562
|
+
*/
|
|
563
|
+
private processRetries;
|
|
513
564
|
/**
|
|
514
565
|
* Convert registry ContainerMetadata to agent-core ContainerMetadata
|
|
515
566
|
*/
|
|
516
567
|
private convertRegistryContainer;
|
|
568
|
+
/**
|
|
569
|
+
* Get container metadata from available sources
|
|
570
|
+
* Returns undefined if container is not supported by this agent
|
|
571
|
+
*
|
|
572
|
+
* NOTE: Only checks config-defined sources (callback and containers map).
|
|
573
|
+
* Registry is NOT used here - we only process containers explicitly configured.
|
|
574
|
+
*/
|
|
575
|
+
private getContainerMetadata;
|
|
517
576
|
private handleRequest;
|
|
518
577
|
/**
|
|
519
578
|
* Self-coordination: Calculate priority and wait
|
|
@@ -543,6 +602,51 @@ declare class NoosphereAgent {
|
|
|
543
602
|
getScheduler(): SchedulerService;
|
|
544
603
|
}
|
|
545
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Utility class for PayloadData creation and encoding
|
|
607
|
+
*/
|
|
608
|
+
declare class PayloadUtils {
|
|
609
|
+
/**
|
|
610
|
+
* Create PayloadData from content with data: URI scheme (inline)
|
|
611
|
+
* Best for small payloads (<1KB)
|
|
612
|
+
* @param content - The content to embed
|
|
613
|
+
* @returns PayloadData with contentHash and data: URI
|
|
614
|
+
*/
|
|
615
|
+
static fromInlineData(content: string): PayloadData;
|
|
616
|
+
/**
|
|
617
|
+
* Create PayloadData from content with external URI
|
|
618
|
+
* Best for large payloads that are stored externally
|
|
619
|
+
* @param content - The original content (for hash computation)
|
|
620
|
+
* @param uri - The external URI (ipfs://, https://, ar://, etc.)
|
|
621
|
+
* @returns PayloadData with contentHash and URI
|
|
622
|
+
*/
|
|
623
|
+
static fromExternalUri(content: string, uri: string): PayloadData;
|
|
624
|
+
/**
|
|
625
|
+
* Create PayloadData from pre-computed hash and URI
|
|
626
|
+
* @param contentHash - Pre-computed keccak256 hash of content
|
|
627
|
+
* @param uri - The URI (empty for inline, or external URI)
|
|
628
|
+
* @returns PayloadData
|
|
629
|
+
*/
|
|
630
|
+
static fromHashAndUri(contentHash: string, uri: string): PayloadData;
|
|
631
|
+
/**
|
|
632
|
+
* Create empty PayloadData (no content)
|
|
633
|
+
* @returns PayloadData with zero hash and empty URI
|
|
634
|
+
*/
|
|
635
|
+
static empty(): PayloadData;
|
|
636
|
+
/**
|
|
637
|
+
* Compute content hash using keccak256
|
|
638
|
+
* @param content - Content string to hash
|
|
639
|
+
* @returns bytes32 hash string
|
|
640
|
+
*/
|
|
641
|
+
static computeHash(content: string): string;
|
|
642
|
+
/**
|
|
643
|
+
* Verify that content matches the hash in PayloadData
|
|
644
|
+
* @param payload - PayloadData to verify
|
|
645
|
+
* @param content - Content to verify against
|
|
646
|
+
* @returns true if content hash matches
|
|
647
|
+
*/
|
|
648
|
+
static verifyContent(payload: PayloadData, content: string): boolean;
|
|
649
|
+
}
|
|
546
650
|
declare class CommitmentUtils {
|
|
547
651
|
/**
|
|
548
652
|
* Calculate commitment hash
|
|
@@ -597,4 +701,431 @@ declare class ConfigLoader {
|
|
|
597
701
|
static getContainerConfig(config: NoosphereAgentConfig, containerId: string): NoosphereAgentConfig['containers'][0] | undefined;
|
|
598
702
|
}
|
|
599
703
|
|
|
600
|
-
|
|
704
|
+
/**
|
|
705
|
+
* Payload Storage Interface
|
|
706
|
+
*
|
|
707
|
+
* Defines the contract for storage providers that can upload/download payload data.
|
|
708
|
+
* Implementations: IpfsStorage, ArweaveStorage, HttpStorage, etc.
|
|
709
|
+
*/
|
|
710
|
+
/**
|
|
711
|
+
* Storage provider configuration
|
|
712
|
+
*/
|
|
713
|
+
interface StorageConfig {
|
|
714
|
+
/** API endpoint URL */
|
|
715
|
+
apiUrl?: string;
|
|
716
|
+
/** Gateway URL for fetching content */
|
|
717
|
+
gateway?: string;
|
|
718
|
+
/** API key for authentication */
|
|
719
|
+
apiKey?: string;
|
|
720
|
+
/** API secret for authentication */
|
|
721
|
+
apiSecret?: string;
|
|
722
|
+
/** Request timeout in milliseconds */
|
|
723
|
+
timeout?: number;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Upload result containing the URI and metadata
|
|
727
|
+
*/
|
|
728
|
+
interface UploadResult {
|
|
729
|
+
/** Full URI (e.g., "ipfs://Qm...", "ar://...") */
|
|
730
|
+
uri: string;
|
|
731
|
+
/** Content identifier (CID for IPFS, txId for Arweave) */
|
|
732
|
+
contentId: string;
|
|
733
|
+
/** Size of uploaded content in bytes */
|
|
734
|
+
size: number;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Storage provider interface
|
|
738
|
+
*/
|
|
739
|
+
interface IPayloadStorage {
|
|
740
|
+
/**
|
|
741
|
+
* Upload content to storage
|
|
742
|
+
* @param content - Content to upload (string or Buffer)
|
|
743
|
+
* @returns Upload result with URI
|
|
744
|
+
*/
|
|
745
|
+
upload(content: string | Buffer): Promise<UploadResult>;
|
|
746
|
+
/**
|
|
747
|
+
* Download content from storage
|
|
748
|
+
* @param uri - Full URI (e.g., "ipfs://Qm...")
|
|
749
|
+
* @returns Downloaded content as string
|
|
750
|
+
*/
|
|
751
|
+
download(uri: string): Promise<string>;
|
|
752
|
+
/**
|
|
753
|
+
* Check if the storage provider is configured and available
|
|
754
|
+
* @returns true if storage is ready to use
|
|
755
|
+
*/
|
|
756
|
+
isConfigured(): boolean;
|
|
757
|
+
/**
|
|
758
|
+
* Get the URI scheme this storage provider handles
|
|
759
|
+
* @returns Scheme string (e.g., "ipfs", "ar", "https")
|
|
760
|
+
*/
|
|
761
|
+
getScheme(): string;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* IPFS Storage Provider
|
|
766
|
+
*
|
|
767
|
+
* Supports both local IPFS nodes and Pinata API for pinning.
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* ```typescript
|
|
771
|
+
* // Local IPFS node
|
|
772
|
+
* const storage = new IpfsStorage({
|
|
773
|
+
* apiUrl: 'http://localhost:5001',
|
|
774
|
+
* gateway: 'http://localhost:8080/ipfs/'
|
|
775
|
+
* });
|
|
776
|
+
*
|
|
777
|
+
* // Pinata
|
|
778
|
+
* const storage = new IpfsStorage({
|
|
779
|
+
* apiUrl: 'https://api.pinata.cloud',
|
|
780
|
+
* apiKey: 'your-api-key',
|
|
781
|
+
* apiSecret: 'your-api-secret',
|
|
782
|
+
* gateway: 'https://gateway.pinata.cloud/ipfs/'
|
|
783
|
+
* });
|
|
784
|
+
*
|
|
785
|
+
* const result = await storage.upload('Hello, IPFS!');
|
|
786
|
+
* console.log(result.uri); // "ipfs://Qm..."
|
|
787
|
+
* ```
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* IPFS-specific configuration
|
|
792
|
+
*/
|
|
793
|
+
interface IpfsStorageConfig extends StorageConfig {
|
|
794
|
+
/** IPFS API URL (default: http://localhost:5001) */
|
|
795
|
+
apiUrl?: string;
|
|
796
|
+
/** IPFS Gateway URL (default: http://localhost:8080/ipfs/) */
|
|
797
|
+
gateway?: string;
|
|
798
|
+
/** Pinata API key (required for Pinata) */
|
|
799
|
+
apiKey?: string;
|
|
800
|
+
/** Pinata API secret (required for Pinata) */
|
|
801
|
+
apiSecret?: string;
|
|
802
|
+
}
|
|
803
|
+
declare class IpfsStorage implements IPayloadStorage {
|
|
804
|
+
private apiUrl;
|
|
805
|
+
private gateway;
|
|
806
|
+
private apiKey?;
|
|
807
|
+
private apiSecret?;
|
|
808
|
+
private timeout;
|
|
809
|
+
private isLocalNode;
|
|
810
|
+
constructor(config?: IpfsStorageConfig);
|
|
811
|
+
getScheme(): string;
|
|
812
|
+
isConfigured(): boolean;
|
|
813
|
+
upload(content: string | Buffer): Promise<UploadResult>;
|
|
814
|
+
private uploadToLocalNode;
|
|
815
|
+
private uploadToPinata;
|
|
816
|
+
download(uri: string): Promise<string>;
|
|
817
|
+
/**
|
|
818
|
+
* Extract CID from IPFS URI
|
|
819
|
+
*/
|
|
820
|
+
private extractCid;
|
|
821
|
+
/**
|
|
822
|
+
* Get the gateway URL for a given CID
|
|
823
|
+
*/
|
|
824
|
+
getGatewayUrl(cidOrUri: string): string;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Data URI Storage Provider
|
|
829
|
+
*
|
|
830
|
+
* Handles inline data using data: URI scheme (RFC 2397).
|
|
831
|
+
* Used for small payloads that can be embedded directly.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```typescript
|
|
835
|
+
* const storage = new DataUriStorage();
|
|
836
|
+
* const result = await storage.upload('{"action":"ping"}');
|
|
837
|
+
* console.log(result.uri);
|
|
838
|
+
* // "data:application/json;base64,eyJhY3Rpb24iOiJwaW5nIn0="
|
|
839
|
+
* ```
|
|
840
|
+
*/
|
|
841
|
+
|
|
842
|
+
interface DataUriStorageConfig {
|
|
843
|
+
/** MIME type for the data (default: application/json) */
|
|
844
|
+
mimeType?: string;
|
|
845
|
+
}
|
|
846
|
+
declare class DataUriStorage implements IPayloadStorage {
|
|
847
|
+
private mimeType;
|
|
848
|
+
constructor(config?: DataUriStorageConfig);
|
|
849
|
+
getScheme(): string;
|
|
850
|
+
isConfigured(): boolean;
|
|
851
|
+
upload(content: string | Buffer): Promise<UploadResult>;
|
|
852
|
+
download(uri: string): Promise<string>;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* HTTP/HTTPS Storage Provider
|
|
857
|
+
*
|
|
858
|
+
* Handles fetching content from HTTP/HTTPS URLs.
|
|
859
|
+
* Upload is not supported - use a dedicated storage service instead.
|
|
860
|
+
*
|
|
861
|
+
* @example
|
|
862
|
+
* ```typescript
|
|
863
|
+
* const storage = new HttpStorage();
|
|
864
|
+
* const content = await storage.download('https://api.example.com/data/123');
|
|
865
|
+
* ```
|
|
866
|
+
*/
|
|
867
|
+
|
|
868
|
+
interface HttpStorageConfig {
|
|
869
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
870
|
+
timeout?: number;
|
|
871
|
+
/** Default headers to include in requests */
|
|
872
|
+
headers?: Record<string, string>;
|
|
873
|
+
}
|
|
874
|
+
declare class HttpStorage implements IPayloadStorage {
|
|
875
|
+
private timeout;
|
|
876
|
+
private headers;
|
|
877
|
+
constructor(config?: HttpStorageConfig);
|
|
878
|
+
getScheme(): string;
|
|
879
|
+
isConfigured(): boolean;
|
|
880
|
+
upload(_content: string | Buffer): Promise<UploadResult>;
|
|
881
|
+
download(uri: string): Promise<string>;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* S3-Compatible Storage Provider
|
|
886
|
+
*
|
|
887
|
+
* Supports AWS S3, Cloudflare R2, MinIO, and other S3-compatible storage services.
|
|
888
|
+
* Uses the AWS SDK v3 for S3 operations.
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
891
|
+
* ```typescript
|
|
892
|
+
* // Cloudflare R2
|
|
893
|
+
* const storage = new S3Storage({
|
|
894
|
+
* endpoint: 'https://xxx.r2.cloudflarestorage.com',
|
|
895
|
+
* bucket: 'my-bucket',
|
|
896
|
+
* region: 'auto',
|
|
897
|
+
* accessKeyId: 'your-access-key',
|
|
898
|
+
* secretAccessKey: 'your-secret-key',
|
|
899
|
+
* publicUrlBase: 'https://pub-xxx.r2.dev'
|
|
900
|
+
* });
|
|
901
|
+
*
|
|
902
|
+
* // AWS S3
|
|
903
|
+
* const storage = new S3Storage({
|
|
904
|
+
* bucket: 'my-bucket',
|
|
905
|
+
* region: 'us-east-1',
|
|
906
|
+
* accessKeyId: 'your-access-key',
|
|
907
|
+
* secretAccessKey: 'your-secret-key',
|
|
908
|
+
* publicUrlBase: 'https://my-bucket.s3.us-east-1.amazonaws.com'
|
|
909
|
+
* });
|
|
910
|
+
*
|
|
911
|
+
* // MinIO (local)
|
|
912
|
+
* const storage = new S3Storage({
|
|
913
|
+
* endpoint: 'http://localhost:9000',
|
|
914
|
+
* bucket: 'my-bucket',
|
|
915
|
+
* region: 'us-east-1',
|
|
916
|
+
* accessKeyId: 'minioadmin',
|
|
917
|
+
* secretAccessKey: 'minioadmin',
|
|
918
|
+
* publicUrlBase: 'http://localhost:9000/my-bucket',
|
|
919
|
+
* forcePathStyle: true
|
|
920
|
+
* });
|
|
921
|
+
*
|
|
922
|
+
* const result = await storage.upload('Hello, S3!');
|
|
923
|
+
* console.log(result.uri); // "https://pub-xxx.r2.dev/abc123.json"
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* S3-compatible storage configuration
|
|
929
|
+
*/
|
|
930
|
+
interface S3StorageConfig {
|
|
931
|
+
/** S3-compatible endpoint URL (required for R2/MinIO, optional for AWS S3) */
|
|
932
|
+
endpoint?: string;
|
|
933
|
+
/** Bucket name */
|
|
934
|
+
bucket: string;
|
|
935
|
+
/** AWS region (default: 'auto' for R2, 'us-east-1' for others) */
|
|
936
|
+
region?: string;
|
|
937
|
+
/** Access key ID */
|
|
938
|
+
accessKeyId: string;
|
|
939
|
+
/** Secret access key */
|
|
940
|
+
secretAccessKey: string;
|
|
941
|
+
/**
|
|
942
|
+
* Public URL base for generating accessible URLs
|
|
943
|
+
* e.g., "https://pub-xxx.r2.dev" or "https://cdn.example.com"
|
|
944
|
+
*/
|
|
945
|
+
publicUrlBase: string;
|
|
946
|
+
/**
|
|
947
|
+
* Key prefix for organizing files
|
|
948
|
+
* e.g., "noosphere/outputs/"
|
|
949
|
+
*/
|
|
950
|
+
keyPrefix?: string;
|
|
951
|
+
/**
|
|
952
|
+
* Use path-style URLs (required for MinIO)
|
|
953
|
+
* Default: false (uses virtual-hosted style)
|
|
954
|
+
*/
|
|
955
|
+
forcePathStyle?: boolean;
|
|
956
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
957
|
+
timeout?: number;
|
|
958
|
+
/** Content type for uploaded files (default: 'application/json') */
|
|
959
|
+
contentType?: string;
|
|
960
|
+
}
|
|
961
|
+
declare class S3Storage implements IPayloadStorage {
|
|
962
|
+
private config;
|
|
963
|
+
private client;
|
|
964
|
+
private PutObjectCommandClass;
|
|
965
|
+
private initialized;
|
|
966
|
+
private initError;
|
|
967
|
+
constructor(config: S3StorageConfig);
|
|
968
|
+
/**
|
|
969
|
+
* Lazily initialize the S3 client
|
|
970
|
+
* This allows the class to be instantiated even if @aws-sdk/client-s3 is not installed
|
|
971
|
+
*/
|
|
972
|
+
private initClient;
|
|
973
|
+
getScheme(): string;
|
|
974
|
+
isConfigured(): boolean;
|
|
975
|
+
/**
|
|
976
|
+
* Generate a unique key for the content based on its hash
|
|
977
|
+
*/
|
|
978
|
+
private generateKey;
|
|
979
|
+
upload(content: string | Buffer): Promise<UploadResult>;
|
|
980
|
+
download(uri: string): Promise<string>;
|
|
981
|
+
/**
|
|
982
|
+
* Get the public URL for a given key
|
|
983
|
+
*/
|
|
984
|
+
getPublicUrl(key: string): string;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* PayloadResolver - Unified Payload Resolution
|
|
989
|
+
*
|
|
990
|
+
* Resolves PayloadData to actual content by:
|
|
991
|
+
* 1. Detecting URI scheme (data:, ipfs://, https://, ar://)
|
|
992
|
+
* 2. Fetching content from appropriate storage
|
|
993
|
+
* 3. Verifying content hash for integrity
|
|
994
|
+
*
|
|
995
|
+
* Also handles encoding output as PayloadData with automatic
|
|
996
|
+
* storage selection based on content size.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```typescript
|
|
1000
|
+
* const resolver = new PayloadResolver({
|
|
1001
|
+
* ipfs: { gateway: 'http://localhost:8080/ipfs/' },
|
|
1002
|
+
* uploadThreshold: 1024,
|
|
1003
|
+
* defaultStorage: 'ipfs'
|
|
1004
|
+
* });
|
|
1005
|
+
*
|
|
1006
|
+
* // Resolve input from PayloadData
|
|
1007
|
+
* const content = await resolver.resolve(payloadData);
|
|
1008
|
+
*
|
|
1009
|
+
* // Encode output as PayloadData (auto-uploads if large)
|
|
1010
|
+
* const outputPayload = await resolver.encode(outputContent);
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Supported URI schemes
|
|
1016
|
+
*/
|
|
1017
|
+
declare enum PayloadScheme {
|
|
1018
|
+
DATA = "data",
|
|
1019
|
+
IPFS = "ipfs",
|
|
1020
|
+
HTTPS = "https",
|
|
1021
|
+
HTTP = "http",
|
|
1022
|
+
ARWEAVE = "ar",
|
|
1023
|
+
CHAIN = "chain"
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* PayloadResolver configuration
|
|
1027
|
+
*/
|
|
1028
|
+
interface PayloadResolverConfig {
|
|
1029
|
+
/** IPFS storage configuration */
|
|
1030
|
+
ipfs?: IpfsStorageConfig;
|
|
1031
|
+
/** S3-compatible storage configuration (R2, S3, MinIO) */
|
|
1032
|
+
s3?: S3StorageConfig;
|
|
1033
|
+
/** Arweave gateway URL */
|
|
1034
|
+
arweaveGateway?: string;
|
|
1035
|
+
/** Size threshold for auto-upload (bytes, default: 1024) */
|
|
1036
|
+
uploadThreshold?: number;
|
|
1037
|
+
/** Default storage for large payloads ('ipfs' | 's3' | 'data') */
|
|
1038
|
+
defaultStorage?: 'ipfs' | 's3' | 'data';
|
|
1039
|
+
/** Request timeout in milliseconds */
|
|
1040
|
+
timeout?: number;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Resolved payload result
|
|
1044
|
+
*/
|
|
1045
|
+
interface ResolvedPayload {
|
|
1046
|
+
/** Actual content string */
|
|
1047
|
+
content: string;
|
|
1048
|
+
/** Original PayloadData */
|
|
1049
|
+
payload: PayloadData;
|
|
1050
|
+
/** Detected scheme */
|
|
1051
|
+
scheme: PayloadScheme;
|
|
1052
|
+
/** Whether content hash was verified */
|
|
1053
|
+
verified: boolean;
|
|
1054
|
+
}
|
|
1055
|
+
declare class PayloadResolver {
|
|
1056
|
+
private ipfsStorage;
|
|
1057
|
+
private s3Storage;
|
|
1058
|
+
private dataUriStorage;
|
|
1059
|
+
private httpStorage;
|
|
1060
|
+
private uploadThreshold;
|
|
1061
|
+
private defaultStorage;
|
|
1062
|
+
private arweaveGateway;
|
|
1063
|
+
constructor(config?: PayloadResolverConfig);
|
|
1064
|
+
/**
|
|
1065
|
+
* Detect URI scheme from PayloadData
|
|
1066
|
+
*/
|
|
1067
|
+
detectScheme(payload: PayloadData): PayloadScheme;
|
|
1068
|
+
/**
|
|
1069
|
+
* Resolve PayloadData to actual content
|
|
1070
|
+
*
|
|
1071
|
+
* @param payload - PayloadData to resolve
|
|
1072
|
+
* @param verifyHash - Whether to verify content hash (default: true)
|
|
1073
|
+
* @returns Resolved content and metadata
|
|
1074
|
+
*/
|
|
1075
|
+
resolve(payload: PayloadData, verifyHash?: boolean): Promise<ResolvedPayload>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Resolve Arweave URI
|
|
1078
|
+
*/
|
|
1079
|
+
private resolveArweave;
|
|
1080
|
+
/**
|
|
1081
|
+
* Encode content as PayloadData
|
|
1082
|
+
*
|
|
1083
|
+
* Automatically uploads to external storage if content exceeds threshold.
|
|
1084
|
+
*
|
|
1085
|
+
* @param content - Content to encode
|
|
1086
|
+
* @param options - Encoding options
|
|
1087
|
+
* @returns PayloadData ready for on-chain submission
|
|
1088
|
+
*/
|
|
1089
|
+
encode(content: string, options?: {
|
|
1090
|
+
forceUpload?: boolean;
|
|
1091
|
+
storage?: 'ipfs' | 's3' | 'data';
|
|
1092
|
+
}): Promise<PayloadData>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Create empty PayloadData
|
|
1095
|
+
*/
|
|
1096
|
+
createEmpty(): PayloadData;
|
|
1097
|
+
/**
|
|
1098
|
+
* Verify content matches PayloadData hash
|
|
1099
|
+
*/
|
|
1100
|
+
verifyContent(payload: PayloadData, content: string): boolean;
|
|
1101
|
+
/**
|
|
1102
|
+
* Get the configured IPFS storage instance
|
|
1103
|
+
*/
|
|
1104
|
+
getIpfsStorage(): IpfsStorage;
|
|
1105
|
+
/**
|
|
1106
|
+
* Get the configured S3 storage instance
|
|
1107
|
+
*/
|
|
1108
|
+
getS3Storage(): S3Storage | null;
|
|
1109
|
+
/**
|
|
1110
|
+
* Check if IPFS is configured
|
|
1111
|
+
*/
|
|
1112
|
+
isIpfsConfigured(): boolean;
|
|
1113
|
+
/**
|
|
1114
|
+
* Check if S3 is configured
|
|
1115
|
+
*/
|
|
1116
|
+
isS3Configured(): boolean;
|
|
1117
|
+
/**
|
|
1118
|
+
* Get the default storage type
|
|
1119
|
+
*/
|
|
1120
|
+
getDefaultStorage(): 'ipfs' | 's3' | 'data';
|
|
1121
|
+
/**
|
|
1122
|
+
* Serialize PayloadData for database storage
|
|
1123
|
+
*/
|
|
1124
|
+
serialize(payload: PayloadData): string;
|
|
1125
|
+
/**
|
|
1126
|
+
* Deserialize PayloadData from database storage
|
|
1127
|
+
*/
|
|
1128
|
+
deserialize(serialized: string): PayloadData;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
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, DataUriStorage, type DataUriStorageConfig, EventMonitor, FulfillResult, HttpStorage, type HttpStorageConfig, type IPayloadStorage, IpfsStorage, type IpfsStorageConfig, NoosphereAgent, type NoosphereAgentConfig, PayloadResolver, type PayloadResolverConfig, PayloadScheme, PayloadUtils, type Payment, type ProofVerificationRequest, RequestIdUtils, type RequestStartedCallbackEvent, type RequestStartedEvent, type ResolvedPayload, type RetryableEvent, S3Storage, type S3StorageConfig, SchedulerService, type StorageConfig, type UploadResult, type VerifierMetadata };
|