holosphere 2.0.0-alpha8 → 2.0.0-alpha9
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/CHANGELOG.md +446 -0
- package/FEATURES.md +431 -0
- package/LICENSE +29 -166
- package/LICENSE-AGPL.md +180 -0
- package/dist/cdn/holosphere.min.js +55 -0
- package/dist/cdn/holosphere.min.js.map +1 -0
- package/dist/cjs/holosphere.cjs +1 -1
- package/dist/esm/holosphere.js +1 -1
- package/dist/{index-CKffQDmQ.cjs → index-DDGt_V9o.cjs} +2 -2
- package/dist/{index-CKffQDmQ.cjs.map → index-DDGt_V9o.cjs.map} +1 -1
- package/dist/{index-4XHHKe6S.js → index-DJXftyvB.js} +1905 -337
- package/dist/index-DJXftyvB.js.map +1 -0
- package/dist/{index-Dz5kOZMI.cjs → index-DMbdcMtK.cjs} +17 -4
- package/dist/index-DMbdcMtK.cjs.map +1 -0
- package/dist/{index-BjP1TXGz.js → index-DeZ1xz_s.js} +2 -2
- package/dist/{index-BjP1TXGz.js.map → index-DeZ1xz_s.js.map} +1 -1
- package/dist/{indexeddb-storage-lExjjFlV.js → indexeddb-storage-BFt6hMeF.js} +48 -4
- package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
- package/dist/{indexeddb-storage-DD7EFBVc.cjs → indexeddb-storage-BK5tv4Sh.cjs} +2 -2
- package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
- package/dist/{memory-storage-C68adso2.js → memory-storage-C9HuoL2E.js} +44 -4
- package/dist/memory-storage-C9HuoL2E.js.map +1 -0
- package/dist/{memory-storage-DD_6yyXT.cjs → memory-storage-Dao7jfYG.cjs} +2 -2
- package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
- package/dist/{secp256k1-DYELiqgx.cjs → secp256k1-BbKzbLtD.cjs} +2 -2
- package/dist/{secp256k1-DYELiqgx.cjs.map → secp256k1-BbKzbLtD.cjs.map} +1 -1
- package/dist/{secp256k1-OM8siPyy.js → secp256k1-CreY7Pcl.js} +2 -2
- package/dist/{secp256k1-OM8siPyy.js.map → secp256k1-CreY7Pcl.js.map} +1 -1
- package/docs/api/ai_aggregation.js.html +333 -0
- package/docs/api/ai_breakdown.js.html +524 -0
- package/docs/api/ai_classifier.js.html +231 -0
- package/docs/api/ai_council.js.html +246 -0
- package/docs/api/ai_embeddings.js.html +304 -0
- package/docs/api/ai_federation-ai.js.html +338 -0
- package/docs/api/ai_h3-ai.js.html +970 -0
- package/docs/api/ai_index.js.html +124 -0
- package/docs/api/ai_json-ops.js.html +241 -0
- package/docs/api/ai_llm-service.js.html +239 -0
- package/docs/api/ai_nl-query.js.html +236 -0
- package/docs/api/ai_relationships.js.html +367 -0
- package/docs/api/ai_schema-extractor.js.html +235 -0
- package/docs/api/ai_spatial.js.html +307 -0
- package/docs/api/ai_tts.js.html +214 -0
- package/docs/api/content_social-protocols.js.html +180 -0
- package/docs/api/core_holosphere.js.html +757 -0
- package/docs/api/crypto_nostr-utils.js.html +306 -0
- package/docs/api/crypto_secp256k1.js.html +267 -0
- package/docs/api/data/search.json +1 -0
- package/docs/api/federation_discovery.js.html +337 -0
- package/docs/api/federation_handshake.js.html +478 -0
- package/docs/api/federation_hologram.js.html +1053 -0
- package/docs/api/federation_registry.js.html +389 -0
- package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/api/global.html +3 -0
- package/docs/api/hierarchical_upcast.js.html +128 -0
- package/docs/api/index.html +265 -0
- package/docs/api/index.js.html +1868 -0
- package/docs/api/lib_ai-methods.js.html +660 -0
- package/docs/api/lib_contract-methods.js.html +445 -0
- package/docs/api/lib_errors.js.html +56 -0
- package/docs/api/lib_federation-methods.js.html +348 -0
- package/docs/api/lib_index.js.html +33 -0
- package/docs/api/module-ai.html +5 -0
- package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
- package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
- package/docs/api/module-ai_aggregation.html +3 -0
- package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
- package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
- package/docs/api/module-ai_breakdown.html +3 -0
- package/docs/api/module-ai_classifier-Classifier.html +6 -0
- package/docs/api/module-ai_classifier.Classifier.html +3 -0
- package/docs/api/module-ai_classifier.html +3 -0
- package/docs/api/module-ai_council-Council.html +6 -0
- package/docs/api/module-ai_council.Council.html +3 -0
- package/docs/api/module-ai_council.html +3 -0
- package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
- package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
- package/docs/api/module-ai_embeddings.html +3 -0
- package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
- package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
- package/docs/api/module-ai_federation-ai.html +3 -0
- package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
- package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
- package/docs/api/module-ai_h3-ai.html +3 -0
- package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
- package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
- package/docs/api/module-ai_json-ops.html +3 -0
- package/docs/api/module-ai_llm-service-LLMService.html +5 -0
- package/docs/api/module-ai_llm-service.LLMService.html +3 -0
- package/docs/api/module-ai_llm-service.html +3 -0
- package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
- package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
- package/docs/api/module-ai_nl-query.html +3 -0
- package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
- package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
- package/docs/api/module-ai_relationships.html +3 -0
- package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
- package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
- package/docs/api/module-ai_schema-extractor.html +3 -0
- package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
- package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
- package/docs/api/module-ai_spatial.html +3 -0
- package/docs/api/module-ai_tts-TTS.html +5 -0
- package/docs/api/module-ai_tts.TTS.html +3 -0
- package/docs/api/module-ai_tts.html +3 -0
- package/docs/api/module-content_social-protocols.html +3 -0
- package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
- package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
- package/docs/api/module-core_holosphere.html +3 -0
- package/docs/api/module-crypto_nostr-utils.html +3 -0
- package/docs/api/module-crypto_secp256k1.html +3 -0
- package/docs/api/module-federation_hologram.html +3 -0
- package/docs/api/module-hierarchical_upcast.html +3 -0
- package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
- package/docs/api/module-holosphere.html +3 -0
- package/docs/api/module-lib_ai-methods.html +3 -0
- package/docs/api/module-lib_contract-methods.html +3 -0
- package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
- package/docs/api/module-lib_errors-ValidationError.html +3 -0
- package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
- package/docs/api/module-lib_errors.ValidationError.html +3 -0
- package/docs/api/module-lib_errors.html +3 -0
- package/docs/api/module-lib_federation-methods.html +3 -0
- package/docs/api/module-lib_index.html +3 -0
- package/docs/api/module-schema_validator-ValidationError.html +3 -0
- package/docs/api/module-schema_validator.ValidationError.html +3 -0
- package/docs/api/module-schema_validator.html +3 -0
- package/docs/api/module-spatial_h3-operations.html +4 -0
- package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
- package/docs/api/module-storage_backend-factory.html +3 -0
- package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
- package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
- package/docs/api/module-storage_backend-interface.html +3 -0
- package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
- package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
- package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
- package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
- package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
- package/docs/api/module-storage_backends_activitypub_server.html +3 -0
- package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
- package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
- package/docs/api/module-storage_backends_gundb-backend.html +3 -0
- package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
- package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
- package/docs/api/module-storage_backends_nostr-backend.html +3 -0
- package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
- package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
- package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage.html +3 -0
- package/docs/api/module-storage_global-tables.html +3 -0
- package/docs/api/module-storage_gun-async.html +3 -0
- package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
- package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
- package/docs/api/module-storage_gun-auth.html +3 -0
- package/docs/api/module-storage_gun-federation.html +3 -0
- package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
- package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
- package/docs/api/module-storage_gun-references.html +3 -0
- package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
- package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
- package/docs/api/module-storage_gun-schema.html +3 -0
- package/docs/api/module-storage_gun-wrapper.html +11 -0
- package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
- package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
- package/docs/api/module-storage_indexeddb-storage.html +3 -0
- package/docs/api/module-storage_key-storage-simple.html +3 -0
- package/docs/api/module-storage_key-storage.html +4 -0
- package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
- package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
- package/docs/api/module-storage_memory-storage.html +3 -0
- package/docs/api/module-storage_migration-MigrationTool.html +6 -0
- package/docs/api/module-storage_migration.MigrationTool.html +3 -0
- package/docs/api/module-storage_migration.html +3 -0
- package/docs/api/module-storage_nostr-async.html +18 -0
- package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
- package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
- package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
- package/docs/api/module-storage_nostr-client.html +6 -0
- package/docs/api/module-storage_nostr-wrapper.html +3 -0
- package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
- package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
- package/docs/api/module-storage_outbox-queue.html +3 -0
- package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
- package/docs/api/module-storage_persistent-storage.html +4 -0
- package/docs/api/module-storage_sync-service-SyncService.html +5 -0
- package/docs/api/module-storage_sync-service.SyncService.html +3 -0
- package/docs/api/module-storage_sync-service.html +3 -0
- package/docs/api/module-storage_unified-storage.html +3 -0
- package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
- package/docs/api/module-subscriptions_manager.html +3 -0
- package/docs/api/schema_validator.js.html +113 -0
- package/docs/api/scripts/core.js +726 -0
- package/docs/api/scripts/core.min.js +23 -0
- package/docs/api/scripts/resize.js +90 -0
- package/docs/api/scripts/search.js +265 -0
- package/docs/api/scripts/search.min.js +6 -0
- package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/api/scripts/third-party/fuse.js +9 -0
- package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/api/scripts/third-party/hljs-original.js +5171 -0
- package/docs/api/scripts/third-party/hljs.js +1 -0
- package/docs/api/scripts/third-party/popper.js +5 -0
- package/docs/api/scripts/third-party/tippy.js +1 -0
- package/docs/api/scripts/third-party/tocbot.js +672 -0
- package/docs/api/scripts/third-party/tocbot.min.js +1 -0
- package/docs/api/spatial_h3-operations.js.html +129 -0
- package/docs/api/storage_backend-factory.js.html +133 -0
- package/docs/api/storage_backend-interface.js.html +164 -0
- package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
- package/docs/api/storage_backends_activitypub_server.js.html +678 -0
- package/docs/api/storage_backends_gundb-backend.js.html +878 -0
- package/docs/api/storage_backends_nostr-backend.js.html +254 -0
- package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
- package/docs/api/storage_filesystem-storage.js.html +207 -0
- package/docs/api/storage_global-tables.js.html +116 -0
- package/docs/api/storage_gun-async.js.html +344 -0
- package/docs/api/storage_gun-auth.js.html +376 -0
- package/docs/api/storage_gun-federation.js.html +788 -0
- package/docs/api/storage_gun-references.js.html +212 -0
- package/docs/api/storage_gun-schema.js.html +309 -0
- package/docs/api/storage_gun-wrapper.js.html +645 -0
- package/docs/api/storage_indexeddb-storage.js.html +224 -0
- package/docs/api/storage_key-storage-simple.js.html +102 -0
- package/docs/api/storage_key-storage.js.html +171 -0
- package/docs/api/storage_memory-storage.js.html +128 -0
- package/docs/api/storage_migration.js.html +354 -0
- package/docs/api/storage_nostr-async.js.html +1076 -0
- package/docs/api/storage_nostr-client.js.html +1598 -0
- package/docs/api/storage_nostr-wrapper.js.html +218 -0
- package/docs/api/storage_outbox-queue.js.html +248 -0
- package/docs/api/storage_persistent-storage.js.html +160 -0
- package/docs/api/storage_sync-service.js.html +201 -0
- package/docs/api/storage_unified-storage.js.html +157 -0
- package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/api/subscriptions_manager.js.html +162 -0
- package/jsdoc.json +26 -0
- package/package.json +14 -3
- package/src/ai/aggregation.js +13 -2
- package/src/ai/breakdown.js +12 -2
- package/src/ai/classifier.js +14 -3
- package/src/ai/council.js +22 -7
- package/src/ai/embeddings.js +37 -15
- package/src/ai/federation-ai.js +13 -2
- package/src/ai/h3-ai.js +14 -2
- package/src/ai/index.js +16 -7
- package/src/ai/json-ops.js +18 -5
- package/src/ai/llm-service.js +62 -31
- package/src/ai/nl-query.js +12 -2
- package/src/ai/relationships.js +13 -2
- package/src/ai/schema-extractor.js +24 -10
- package/src/ai/spatial.js +13 -2
- package/src/ai/tts.js +25 -8
- package/src/content/social-protocols.js +34 -25
- package/src/contracts/chain-manager.js +68 -40
- package/src/contracts/deployer.js +70 -42
- package/src/contracts/event-listener.js +61 -29
- package/src/contracts/holon-contracts.js +46 -31
- package/src/contracts/index.js +5 -6
- package/src/contracts/networks.js +19 -14
- package/src/contracts/operations.js +58 -41
- package/src/contracts/queries.js +54 -20
- package/src/core/holosphere.js +35 -6
- package/src/crypto/nostr-utils.js +82 -76
- package/src/crypto/secp256k1.js +7 -2
- package/src/federation/handshake.js +7 -7
- package/src/federation/hologram.js +9 -1
- package/src/hierarchical/upcast.js +34 -20
- package/src/index.js +655 -5
- package/src/lib/ai-methods.js +352 -3
- package/src/lib/contract-methods.js +152 -3
- package/src/lib/errors.js +31 -1
- package/src/lib/federation-methods.js +110 -3
- package/src/lib/index.js +9 -5
- package/src/schema/validator.js +22 -3
- package/src/spatial/h3-operations.js +17 -1
- package/src/storage/backend-factory.js +7 -2
- package/src/storage/backend-interface.js +21 -2
- package/src/storage/backends/activitypub/server.js +25 -3
- package/src/storage/backends/activitypub-backend.js +25 -2
- package/src/storage/backends/gundb-backend.js +29 -2
- package/src/storage/backends/nostr-backend.js +116 -1
- package/src/storage/filesystem-storage-browser.js +42 -2
- package/src/storage/filesystem-storage.js +72 -5
- package/src/storage/global-tables.js +7 -2
- package/src/storage/gun-async.js +20 -11
- package/src/storage/gun-auth.js +15 -4
- package/src/storage/gun-federation.js +14 -5
- package/src/storage/gun-references.js +16 -5
- package/src/storage/gun-schema.js +25 -10
- package/src/storage/gun-wrapper.js +99 -36
- package/src/storage/indexeddb-storage.js +65 -4
- package/src/storage/key-storage-simple.js +32 -9
- package/src/storage/key-storage.js +45 -13
- package/src/storage/memory-storage.js +65 -4
- package/src/storage/migration.js +20 -7
- package/src/storage/nostr-async.js +157 -67
- package/src/storage/nostr-client.js +173 -49
- package/src/storage/nostr-wrapper.js +6 -2
- package/src/storage/outbox-queue.js +55 -18
- package/src/storage/persistent-storage.js +56 -13
- package/src/storage/sync-service.js +51 -17
- package/src/storage/unified-storage.js +7 -2
- package/src/subscriptions/manager.js +33 -16
- package/dist/index-4XHHKe6S.js.map +0 -1
- package/dist/index-Dz5kOZMI.cjs.map +0 -1
- package/dist/indexeddb-storage-DD7EFBVc.cjs.map +0 -1
- package/dist/indexeddb-storage-lExjjFlV.js.map +0 -1
- package/dist/memory-storage-C68adso2.js.map +0 -1
- package/dist/memory-storage-DD_6yyXT.cjs.map +0 -1
- /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
- /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
|
@@ -4,12 +4,14 @@ import { latLngToCell, getResolution, cellToParent, cellToChildren, isValidCell
|
|
|
4
4
|
import Ajv from "ajv";
|
|
5
5
|
class OutboxQueue {
|
|
6
6
|
/**
|
|
7
|
+
* Create a new OutboxQueue.
|
|
8
|
+
*
|
|
7
9
|
* @param {Object} persistentStorage - Storage adapter (IndexedDB/FileSystem)
|
|
8
|
-
* @param {Object} options - Configuration options
|
|
9
|
-
* @param {number} options.maxRetries - Max retry attempts
|
|
10
|
-
* @param {number} options.baseDelay - Base delay in ms
|
|
11
|
-
* @param {number} options.maxDelay - Max delay cap in ms (
|
|
12
|
-
* @param {number} options.failedTTL - TTL for failed events in ms (
|
|
10
|
+
* @param {Object} [options={}] - Configuration options
|
|
11
|
+
* @param {number} [options.maxRetries=5] - Max retry attempts
|
|
12
|
+
* @param {number} [options.baseDelay=1000] - Base delay in ms
|
|
13
|
+
* @param {number} [options.maxDelay=60000] - Max delay cap in ms (1 minute)
|
|
14
|
+
* @param {number} [options.failedTTL=86400000] - TTL for failed events in ms (24 hours)
|
|
13
15
|
*/
|
|
14
16
|
constructor(persistentStorage, options = {}) {
|
|
15
17
|
this.storage = persistentStorage;
|
|
@@ -20,10 +22,11 @@ class OutboxQueue {
|
|
|
20
22
|
this.failedTTL = options.failedTTL || 24 * 60 * 60 * 1e3;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
|
-
* Add an event to the outbox queue
|
|
25
|
+
* Add an event to the outbox queue.
|
|
26
|
+
*
|
|
24
27
|
* @param {Object} event - Signed Nostr event
|
|
25
28
|
* @param {string[]} relays - Target relay URLs
|
|
26
|
-
* @returns {Promise<Object>} Queue entry
|
|
29
|
+
* @returns {Promise<Object>} Queue entry with metadata
|
|
27
30
|
*/
|
|
28
31
|
async enqueue(event, relays) {
|
|
29
32
|
const entry = {
|
|
@@ -41,9 +44,13 @@ class OutboxQueue {
|
|
|
41
44
|
return entry;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
|
-
* Mark an event as sent
|
|
47
|
+
* Mark an event as sent.
|
|
48
|
+
*
|
|
49
|
+
* Removes from queue if at least one relay accepted, otherwise schedules retry.
|
|
50
|
+
*
|
|
45
51
|
* @param {string} eventId - Event ID
|
|
46
52
|
* @param {string[]} successfulRelays - Relays that accepted the event
|
|
53
|
+
* @returns {Promise<void>}
|
|
47
54
|
*/
|
|
48
55
|
async markSent(eventId, successfulRelays) {
|
|
49
56
|
const key = `${this.queuePrefix}${eventId}`;
|
|
@@ -56,8 +63,14 @@ class OutboxQueue {
|
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
/**
|
|
59
|
-
* Schedule a retry with exponential backoff
|
|
66
|
+
* Schedule a retry with exponential backoff.
|
|
67
|
+
*
|
|
68
|
+
* Uses exponential backoff with jitter. Marks as failed if max retries exceeded.
|
|
69
|
+
*
|
|
60
70
|
* @private
|
|
71
|
+
* @param {string} key - Storage key
|
|
72
|
+
* @param {Object} entry - Queue entry
|
|
73
|
+
* @returns {Promise<void>}
|
|
61
74
|
*/
|
|
62
75
|
async _scheduleRetry(key, entry) {
|
|
63
76
|
entry.retries++;
|
|
@@ -75,7 +88,8 @@ class OutboxQueue {
|
|
|
75
88
|
await this.storage.put(key, entry);
|
|
76
89
|
}
|
|
77
90
|
/**
|
|
78
|
-
* Get all pending events ready for retry
|
|
91
|
+
* Get all pending events ready for retry.
|
|
92
|
+
*
|
|
79
93
|
* @returns {Promise<Object[]>} Pending queue entries sorted by creation time
|
|
80
94
|
*/
|
|
81
95
|
async getPendingEvents() {
|
|
@@ -84,7 +98,8 @@ class OutboxQueue {
|
|
|
84
98
|
return allEntries.filter((e) => e && e.status === "pending" && e.nextRetryAt <= now).sort((a, b2) => a.createdAt - b2.createdAt);
|
|
85
99
|
}
|
|
86
100
|
/**
|
|
87
|
-
* Get all failed events (exceeded max retries)
|
|
101
|
+
* Get all failed events (exceeded max retries).
|
|
102
|
+
*
|
|
88
103
|
* @returns {Promise<Object[]>} Failed queue entries
|
|
89
104
|
*/
|
|
90
105
|
async getFailedEvents() {
|
|
@@ -92,8 +107,9 @@ class OutboxQueue {
|
|
|
92
107
|
return allEntries.filter((e) => e && e.status === "failed");
|
|
93
108
|
}
|
|
94
109
|
/**
|
|
95
|
-
* Get queue statistics
|
|
96
|
-
*
|
|
110
|
+
* Get queue statistics.
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<Object>} Stats object with total, pending, failed counts and oldest timestamps
|
|
97
113
|
*/
|
|
98
114
|
async getStats() {
|
|
99
115
|
const allEntries = await this.storage.getAll(this.queuePrefix);
|
|
@@ -121,8 +137,9 @@ class OutboxQueue {
|
|
|
121
137
|
return stats;
|
|
122
138
|
}
|
|
123
139
|
/**
|
|
124
|
-
* Purge failed events older than maxAge
|
|
125
|
-
*
|
|
140
|
+
* Purge failed events older than maxAge.
|
|
141
|
+
*
|
|
142
|
+
* @param {number} [maxAge] - Max age in ms (defaults to failedTTL)
|
|
126
143
|
* @returns {Promise<number>} Number of entries purged
|
|
127
144
|
*/
|
|
128
145
|
async purgeOldFailed(maxAge = this.failedTTL) {
|
|
@@ -138,7 +155,8 @@ class OutboxQueue {
|
|
|
138
155
|
return purged;
|
|
139
156
|
}
|
|
140
157
|
/**
|
|
141
|
-
* Clear all entries from the queue
|
|
158
|
+
* Clear all entries from the queue.
|
|
159
|
+
*
|
|
142
160
|
* @returns {Promise<number>} Number of entries cleared
|
|
143
161
|
*/
|
|
144
162
|
async clear() {
|
|
@@ -153,7 +171,10 @@ class OutboxQueue {
|
|
|
153
171
|
return cleared;
|
|
154
172
|
}
|
|
155
173
|
/**
|
|
156
|
-
* Manually retry a failed event
|
|
174
|
+
* Manually retry a failed event.
|
|
175
|
+
*
|
|
176
|
+
* Resets retry counter and status to allow manual retry of a failed event.
|
|
177
|
+
*
|
|
157
178
|
* @param {string} eventId - Event ID to retry
|
|
158
179
|
* @returns {Promise<Object|null>} Updated entry or null if not found
|
|
159
180
|
*/
|
|
@@ -173,10 +194,12 @@ class OutboxQueue {
|
|
|
173
194
|
}
|
|
174
195
|
class SyncService {
|
|
175
196
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* @param {
|
|
179
|
-
* @param {
|
|
197
|
+
* Create a new SyncService.
|
|
198
|
+
*
|
|
199
|
+
* @param {Object} client - NostrClient instance with outboxQueue
|
|
200
|
+
* @param {Object} [options={}] - Configuration options
|
|
201
|
+
* @param {number} [options.interval=10000] - Sync interval in ms (10 seconds)
|
|
202
|
+
* @param {boolean} [options.autoStart=false] - Start automatically
|
|
180
203
|
*/
|
|
181
204
|
constructor(client, options = {}) {
|
|
182
205
|
this.client = client;
|
|
@@ -189,7 +212,9 @@ class SyncService {
|
|
|
189
212
|
}
|
|
190
213
|
}
|
|
191
214
|
/**
|
|
192
|
-
* Start the background sync service
|
|
215
|
+
* Start the background sync service.
|
|
216
|
+
*
|
|
217
|
+
* @returns {void}
|
|
193
218
|
*/
|
|
194
219
|
start() {
|
|
195
220
|
if (this.running) return;
|
|
@@ -197,7 +222,9 @@ class SyncService {
|
|
|
197
222
|
this._scheduleNextRun();
|
|
198
223
|
}
|
|
199
224
|
/**
|
|
200
|
-
* Stop the background sync service
|
|
225
|
+
* Stop the background sync service.
|
|
226
|
+
*
|
|
227
|
+
* @returns {void}
|
|
201
228
|
*/
|
|
202
229
|
stop() {
|
|
203
230
|
this.running = false;
|
|
@@ -207,22 +234,28 @@ class SyncService {
|
|
|
207
234
|
}
|
|
208
235
|
}
|
|
209
236
|
/**
|
|
210
|
-
* Check if the service is running
|
|
211
|
-
*
|
|
237
|
+
* Check if the service is running.
|
|
238
|
+
*
|
|
239
|
+
* @returns {boolean} True if service is running
|
|
212
240
|
*/
|
|
213
241
|
isRunning() {
|
|
214
242
|
return this.running;
|
|
215
243
|
}
|
|
216
244
|
/**
|
|
217
|
-
* Force an immediate sync
|
|
218
|
-
*
|
|
245
|
+
* Force an immediate sync.
|
|
246
|
+
*
|
|
247
|
+
* Useful for testing or manual trigger.
|
|
248
|
+
*
|
|
249
|
+
* @returns {Promise<Object>} Sync result with processed, succeeded, failed, purged counts
|
|
219
250
|
*/
|
|
220
251
|
async syncNow() {
|
|
221
252
|
return this._processOutbox();
|
|
222
253
|
}
|
|
223
254
|
/**
|
|
224
|
-
* Schedule the next run
|
|
255
|
+
* Schedule the next run.
|
|
256
|
+
*
|
|
225
257
|
* @private
|
|
258
|
+
* @returns {void}
|
|
226
259
|
*/
|
|
227
260
|
_scheduleNextRun() {
|
|
228
261
|
if (!this.running) return;
|
|
@@ -231,8 +264,10 @@ class SyncService {
|
|
|
231
264
|
}, this.interval);
|
|
232
265
|
}
|
|
233
266
|
/**
|
|
234
|
-
* Main loop iteration
|
|
267
|
+
* Main loop iteration.
|
|
268
|
+
*
|
|
235
269
|
* @private
|
|
270
|
+
* @returns {Promise<void>}
|
|
236
271
|
*/
|
|
237
272
|
async _runLoop() {
|
|
238
273
|
if (!this.running) return;
|
|
@@ -244,9 +279,12 @@ class SyncService {
|
|
|
244
279
|
this._scheduleNextRun();
|
|
245
280
|
}
|
|
246
281
|
/**
|
|
247
|
-
* Process pending events in the outbox
|
|
282
|
+
* Process pending events in the outbox.
|
|
283
|
+
*
|
|
284
|
+
* Retries pending events and purges old failed events.
|
|
285
|
+
*
|
|
248
286
|
* @private
|
|
249
|
-
* @returns {Promise<Object>} Processing result
|
|
287
|
+
* @returns {Promise<Object>} Processing result with counts
|
|
250
288
|
*/
|
|
251
289
|
async _processOutbox() {
|
|
252
290
|
if (this._processing) {
|
|
@@ -285,8 +323,9 @@ class SyncService {
|
|
|
285
323
|
return result;
|
|
286
324
|
}
|
|
287
325
|
/**
|
|
288
|
-
* Get sync service statistics
|
|
289
|
-
*
|
|
326
|
+
* Get sync service statistics.
|
|
327
|
+
*
|
|
328
|
+
* @returns {Promise<Object>} Stats including running status, interval, and queue status
|
|
290
329
|
*/
|
|
291
330
|
async getStats() {
|
|
292
331
|
const stats = {
|
|
@@ -302,56 +341,77 @@ class SyncService {
|
|
|
302
341
|
}
|
|
303
342
|
class PersistentStorage {
|
|
304
343
|
/**
|
|
305
|
-
* Initialize storage
|
|
344
|
+
* Initialize storage with namespace.
|
|
345
|
+
*
|
|
346
|
+
* @abstract
|
|
306
347
|
* @param {string} namespace - Storage namespace (appName)
|
|
307
348
|
* @returns {Promise<void>}
|
|
349
|
+
* @throws {Error} Must be implemented by subclass
|
|
308
350
|
*/
|
|
309
351
|
async init(namespace) {
|
|
310
352
|
throw new Error("init() must be implemented by subclass");
|
|
311
353
|
}
|
|
312
354
|
/**
|
|
313
|
-
* Store event
|
|
355
|
+
* Store event.
|
|
356
|
+
*
|
|
357
|
+
* @abstract
|
|
314
358
|
* @param {string} key - Event ID or d-tag
|
|
315
359
|
* @param {Object} event - Nostr event
|
|
316
360
|
* @returns {Promise<void>}
|
|
361
|
+
* @throws {Error} Must be implemented by subclass
|
|
317
362
|
*/
|
|
318
363
|
async put(key, event) {
|
|
319
364
|
throw new Error("put() must be implemented by subclass");
|
|
320
365
|
}
|
|
321
366
|
/**
|
|
322
|
-
* Retrieve event
|
|
367
|
+
* Retrieve event.
|
|
368
|
+
*
|
|
369
|
+
* @abstract
|
|
323
370
|
* @param {string} key - Event ID or d-tag
|
|
324
371
|
* @returns {Promise<Object|null>} Event or null
|
|
372
|
+
* @throws {Error} Must be implemented by subclass
|
|
325
373
|
*/
|
|
326
374
|
async get(key) {
|
|
327
375
|
throw new Error("get() must be implemented by subclass");
|
|
328
376
|
}
|
|
329
377
|
/**
|
|
330
|
-
* Get all events matching prefix
|
|
378
|
+
* Get all events matching prefix.
|
|
379
|
+
*
|
|
380
|
+
* @abstract
|
|
331
381
|
* @param {string} prefix - Key prefix
|
|
332
382
|
* @returns {Promise<any[]>} Array of events
|
|
383
|
+
* @throws {Error} Must be implemented by subclass
|
|
333
384
|
*/
|
|
334
385
|
async getAll(prefix) {
|
|
335
386
|
throw new Error("getAll() must be implemented by subclass");
|
|
336
387
|
}
|
|
337
388
|
/**
|
|
338
|
-
* Delete event
|
|
389
|
+
* Delete event.
|
|
390
|
+
*
|
|
391
|
+
* @abstract
|
|
339
392
|
* @param {string} key - Event ID or d-tag
|
|
340
393
|
* @returns {Promise<void>}
|
|
394
|
+
* @throws {Error} Must be implemented by subclass
|
|
341
395
|
*/
|
|
342
396
|
async delete(key) {
|
|
343
397
|
throw new Error("delete() must be implemented by subclass");
|
|
344
398
|
}
|
|
345
399
|
/**
|
|
346
|
-
* Clear all data in namespace
|
|
400
|
+
* Clear all data in namespace.
|
|
401
|
+
*
|
|
402
|
+
* @abstract
|
|
347
403
|
* @returns {Promise<void>}
|
|
404
|
+
* @throws {Error} Must be implemented by subclass
|
|
348
405
|
*/
|
|
349
406
|
async clear() {
|
|
350
407
|
throw new Error("clear() must be implemented by subclass");
|
|
351
408
|
}
|
|
352
409
|
/**
|
|
353
|
-
* Close storage
|
|
410
|
+
* Close storage connection.
|
|
411
|
+
*
|
|
412
|
+
* @abstract
|
|
354
413
|
* @returns {Promise<void>}
|
|
414
|
+
* @throws {Error} Must be implemented by subclass
|
|
355
415
|
*/
|
|
356
416
|
async close() {
|
|
357
417
|
throw new Error("close() must be implemented by subclass");
|
|
@@ -361,12 +421,12 @@ async function createPersistentStorage(namespace, options = {}) {
|
|
|
361
421
|
const isBrowser = typeof window !== "undefined" && typeof window.indexedDB !== "undefined";
|
|
362
422
|
typeof process !== "undefined" && process.versions && void 0;
|
|
363
423
|
if (isBrowser) {
|
|
364
|
-
const { IndexedDBStorage } = await import("./indexeddb-storage-
|
|
424
|
+
const { IndexedDBStorage } = await import("./indexeddb-storage-BFt6hMeF.js");
|
|
365
425
|
const storage = new IndexedDBStorage();
|
|
366
426
|
await storage.init(namespace);
|
|
367
427
|
return storage;
|
|
368
428
|
} else {
|
|
369
|
-
const { MemoryStorage } = await import("./memory-storage-
|
|
429
|
+
const { MemoryStorage } = await import("./memory-storage-C9HuoL2E.js");
|
|
370
430
|
const storage = new MemoryStorage();
|
|
371
431
|
await storage.init(namespace);
|
|
372
432
|
return storage;
|
|
@@ -393,10 +453,21 @@ const WRITE_DEBOUNCE_MS = 500;
|
|
|
393
453
|
const authorSubscriptions = /* @__PURE__ */ new Map();
|
|
394
454
|
const AUTHOR_SUB_INIT_TIMEOUT = 5e3;
|
|
395
455
|
class LRUCache {
|
|
456
|
+
/**
|
|
457
|
+
* Create a new LRU cache.
|
|
458
|
+
*
|
|
459
|
+
* @param {number} [maxSize=500] - Maximum number of entries
|
|
460
|
+
*/
|
|
396
461
|
constructor(maxSize = 500) {
|
|
397
462
|
this.maxSize = maxSize;
|
|
398
463
|
this.cache = /* @__PURE__ */ new Map();
|
|
399
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Get an entry from the cache.
|
|
467
|
+
*
|
|
468
|
+
* @param {string} key - Cache key
|
|
469
|
+
* @returns {*} Cached value or undefined
|
|
470
|
+
*/
|
|
400
471
|
get(key) {
|
|
401
472
|
if (!this.cache.has(key)) return void 0;
|
|
402
473
|
const value = this.cache.get(key);
|
|
@@ -457,13 +528,20 @@ function ensureWebSocket() {
|
|
|
457
528
|
}
|
|
458
529
|
class NostrClient {
|
|
459
530
|
/**
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
* @param {
|
|
463
|
-
* @param {
|
|
464
|
-
* @param {
|
|
465
|
-
* @param {
|
|
466
|
-
* @param {boolean} config.
|
|
531
|
+
* Create a new NostrClient.
|
|
532
|
+
*
|
|
533
|
+
* @param {Object} [config={}] - Configuration options
|
|
534
|
+
* @param {string[]} [config.relays=[]] - Array of relay URLs
|
|
535
|
+
* @param {string} [config.privateKey] - Private key for signing (hex format)
|
|
536
|
+
* @param {boolean} [config.enableReconnect=true] - Auto-reconnect on disconnect
|
|
537
|
+
* @param {boolean} [config.enablePing=true] - Auto-ping relays
|
|
538
|
+
* @param {string} [config.appName] - Application name for storage namespace
|
|
539
|
+
* @param {boolean} [config.persistence=true] - Enable persistent storage
|
|
540
|
+
* @param {number} [config.cacheSize=500] - Maximum cache size
|
|
541
|
+
* @param {number} [config.persistBatchMs=100] - Batch persist writes within this window
|
|
542
|
+
* @param {boolean} [config.backgroundSync=true] - Enable background sync service
|
|
543
|
+
* @param {string} [config.dataDir] - Data directory for persistent storage
|
|
544
|
+
* @throws {Error} If relays is not an array
|
|
467
545
|
*/
|
|
468
546
|
constructor(config = {}) {
|
|
469
547
|
if (config.relays && !Array.isArray(config.relays)) {
|
|
@@ -483,8 +561,10 @@ class NostrClient {
|
|
|
483
561
|
this._initReady = this._initialize();
|
|
484
562
|
}
|
|
485
563
|
/**
|
|
486
|
-
* Initialize WebSocket polyfill and pool
|
|
564
|
+
* Initialize WebSocket polyfill and pool.
|
|
565
|
+
*
|
|
487
566
|
* @private
|
|
567
|
+
* @returns {Promise<void>}
|
|
488
568
|
*/
|
|
489
569
|
async _initialize() {
|
|
490
570
|
await ensureWebSocket();
|
|
@@ -673,13 +753,21 @@ class NostrClient {
|
|
|
673
753
|
return Array.from(bytes2).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
674
754
|
}
|
|
675
755
|
/**
|
|
676
|
-
* Publish event to relays
|
|
677
|
-
*
|
|
756
|
+
* Publish event to relays.
|
|
757
|
+
*
|
|
758
|
+
* Supports debouncing for replaceable events (kind 30000-39999) to avoid rapid updates.
|
|
759
|
+
*
|
|
678
760
|
* @param {Object} event - Unsigned event object
|
|
679
|
-
* @param {Object} options - Publish options
|
|
680
|
-
* @param {boolean} options.waitForRelays - Wait for relay confirmation
|
|
681
|
-
* @param {boolean} options.debounce - Debounce rapid writes to same d-tag
|
|
761
|
+
* @param {Object} [options={}] - Publish options
|
|
762
|
+
* @param {boolean} [options.waitForRelays=false] - Wait for relay confirmation
|
|
763
|
+
* @param {boolean} [options.debounce=true] - Debounce rapid writes to same d-tag
|
|
682
764
|
* @returns {Promise<Object>} Signed event with relay publish results
|
|
765
|
+
* @example
|
|
766
|
+
* const result = await client.publish({
|
|
767
|
+
* kind: 30000,
|
|
768
|
+
* tags: [['d', 'mypath']],
|
|
769
|
+
* content: JSON.stringify({ name: 'Test' })
|
|
770
|
+
* });
|
|
683
771
|
*/
|
|
684
772
|
async publish(event, options = {}) {
|
|
685
773
|
await this._initReady;
|
|
@@ -792,14 +880,22 @@ class NostrClient {
|
|
|
792
880
|
return { successful, failed, results: formattedResults };
|
|
793
881
|
}
|
|
794
882
|
/**
|
|
795
|
-
* Query events from relays
|
|
796
|
-
*
|
|
883
|
+
* Query events from relays.
|
|
884
|
+
*
|
|
885
|
+
* Uses long-lived subscription for cache updates - avoids polling.
|
|
886
|
+
*
|
|
797
887
|
* @param {Object} filter - Nostr filter object
|
|
798
|
-
* @param {Object} options - Query options
|
|
799
|
-
* @param {number} options.timeout - Query timeout in ms (
|
|
800
|
-
* @param {boolean} options.localFirst - Return local cache immediately, refresh in background
|
|
801
|
-
* @param {boolean} options.forceRelay - Force relay query even if subscription cache is available
|
|
888
|
+
* @param {Object} [options={}] - Query options
|
|
889
|
+
* @param {number} [options.timeout=30000] - Query timeout in ms (set to 0 for no timeout)
|
|
890
|
+
* @param {boolean} [options.localFirst=true] - Return local cache immediately, refresh in background
|
|
891
|
+
* @param {boolean} [options.forceRelay=false] - Force relay query even if subscription cache is available
|
|
802
892
|
* @returns {Promise<Array>} Array of events
|
|
893
|
+
* @example
|
|
894
|
+
* const events = await client.query({
|
|
895
|
+
* kinds: [30000],
|
|
896
|
+
* authors: [client.publicKey],
|
|
897
|
+
* '#d': ['mypath']
|
|
898
|
+
* });
|
|
803
899
|
*/
|
|
804
900
|
async query(filter, options = {}) {
|
|
805
901
|
await this._initReady;
|
|
@@ -1082,12 +1178,21 @@ class NostrClient {
|
|
|
1082
1178
|
return event.id;
|
|
1083
1179
|
}
|
|
1084
1180
|
/**
|
|
1085
|
-
* Subscribe to events
|
|
1086
|
-
*
|
|
1181
|
+
* Subscribe to events.
|
|
1182
|
+
*
|
|
1183
|
+
* Uses subscription deduplication to avoid creating multiple identical subscriptions.
|
|
1184
|
+
*
|
|
1087
1185
|
* @param {Object} filter - Nostr filter object
|
|
1088
1186
|
* @param {Function} onEvent - Callback for each event
|
|
1089
|
-
* @param {Object} options - Subscription options
|
|
1090
|
-
* @
|
|
1187
|
+
* @param {Object} [options={}] - Subscription options
|
|
1188
|
+
* @param {Function} [options.onEOSE] - Callback when End Of Stored Events is received
|
|
1189
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method and id
|
|
1190
|
+
* @example
|
|
1191
|
+
* const sub = await client.subscribe(
|
|
1192
|
+
* { kinds: [30000], authors: [client.publicKey] },
|
|
1193
|
+
* (event) => console.log('Event:', event)
|
|
1194
|
+
* );
|
|
1195
|
+
* // Later: sub.unsubscribe();
|
|
1091
1196
|
*/
|
|
1092
1197
|
async subscribe(filter, onEvent, options = {}) {
|
|
1093
1198
|
await this._initReady;
|
|
@@ -1382,9 +1487,11 @@ class NostrClient {
|
|
|
1382
1487
|
}
|
|
1383
1488
|
}
|
|
1384
1489
|
/**
|
|
1385
|
-
* Close all connections and subscriptions
|
|
1386
|
-
*
|
|
1387
|
-
* @param {
|
|
1490
|
+
* Close all connections and subscriptions.
|
|
1491
|
+
*
|
|
1492
|
+
* @param {Object} [options={}] - Close options
|
|
1493
|
+
* @param {boolean} [options.flush=true] - Flush pending writes before closing
|
|
1494
|
+
* @returns {Promise<void>}
|
|
1388
1495
|
*/
|
|
1389
1496
|
async close(options = {}) {
|
|
1390
1497
|
const shouldFlush = options.flush !== false;
|
|
@@ -2443,6 +2550,12 @@ async function updateFederatedMessages(backend, originalChatId, messageId, updat
|
|
|
2443
2550
|
}
|
|
2444
2551
|
}
|
|
2445
2552
|
class StorageBackend {
|
|
2553
|
+
/**
|
|
2554
|
+
* Creates a new StorageBackend instance.
|
|
2555
|
+
*
|
|
2556
|
+
* @param {Object} config - Backend-specific configuration
|
|
2557
|
+
* @throws {Error} If instantiated directly (abstract class)
|
|
2558
|
+
*/
|
|
2446
2559
|
constructor(config) {
|
|
2447
2560
|
if (new.target === StorageBackend) {
|
|
2448
2561
|
throw new Error("StorageBackend is abstract and cannot be instantiated directly");
|
|
@@ -2569,7 +2682,8 @@ class StorageBackend {
|
|
|
2569
2682
|
}
|
|
2570
2683
|
class GunReferenceHandler {
|
|
2571
2684
|
/**
|
|
2572
|
-
* Create a new reference handler
|
|
2685
|
+
* Create a new reference handler.
|
|
2686
|
+
*
|
|
2573
2687
|
* @param {string} appname - Application namespace
|
|
2574
2688
|
*/
|
|
2575
2689
|
constructor(appname) {
|
|
@@ -2712,7 +2826,8 @@ class GunReferenceHandler {
|
|
|
2712
2826
|
}
|
|
2713
2827
|
class GunAuth {
|
|
2714
2828
|
/**
|
|
2715
|
-
* Create a new authentication handler
|
|
2829
|
+
* Create a new authentication handler.
|
|
2830
|
+
*
|
|
2716
2831
|
* @param {Object} gun - Gun instance
|
|
2717
2832
|
* @param {string} appname - Application namespace
|
|
2718
2833
|
*/
|
|
@@ -3007,10 +3122,11 @@ const META_SCHEMA = {
|
|
|
3007
3122
|
};
|
|
3008
3123
|
class GunSchemaValidator {
|
|
3009
3124
|
/**
|
|
3010
|
-
* Create a new schema validator
|
|
3011
|
-
*
|
|
3012
|
-
* @param {
|
|
3013
|
-
* @param {
|
|
3125
|
+
* Create a new schema validator.
|
|
3126
|
+
*
|
|
3127
|
+
* @param {Object} [options={}] - Validator options
|
|
3128
|
+
* @param {boolean} [options.strict=false] - Whether to enforce strict validation
|
|
3129
|
+
* @param {number} [options.cacheMaxAge=3600000] - Schema cache TTL in ms (1 hour)
|
|
3014
3130
|
*/
|
|
3015
3131
|
constructor(options = {}) {
|
|
3016
3132
|
this.strict = options.strict || false;
|
|
@@ -3217,6 +3333,18 @@ class GunSchemaValidator {
|
|
|
3217
3333
|
}
|
|
3218
3334
|
}
|
|
3219
3335
|
class GunDBBackend extends StorageBackend {
|
|
3336
|
+
/**
|
|
3337
|
+
* Create a new GunDB backend instance.
|
|
3338
|
+
* @param {Object} config - Backend configuration
|
|
3339
|
+
* @param {string} [config.appName='holosphere'] - Application namespace
|
|
3340
|
+
* @param {string[]} [config.peers=[]] - Array of peer URLs
|
|
3341
|
+
* @param {boolean} [config.radisk=true] - Enable radisk persistence
|
|
3342
|
+
* @param {boolean} [config.localStorage=true] - Enable localStorage
|
|
3343
|
+
* @param {string} [config.dataDir='radata'] - Data directory for Node.js
|
|
3344
|
+
* @param {string} [config.privateKey] - Optional existing private key
|
|
3345
|
+
* @param {string} [config.publicKey] - Optional existing public key
|
|
3346
|
+
* @param {boolean} [config.strict=false] - Enable strict schema validation
|
|
3347
|
+
*/
|
|
3220
3348
|
constructor(config) {
|
|
3221
3349
|
super(config);
|
|
3222
3350
|
this.gun = null;
|
|
@@ -3889,6 +4017,7 @@ const scripts = {
|
|
|
3889
4017
|
build: "vite build",
|
|
3890
4018
|
"build:cdn": "vite build --config vite.config.cdn.js",
|
|
3891
4019
|
"build:all": "npm run build && npm run build:cdn",
|
|
4020
|
+
docs: "jsdoc -c jsdoc.json",
|
|
3892
4021
|
test: "vitest run",
|
|
3893
4022
|
"test:watch": "vitest",
|
|
3894
4023
|
"test:coverage": "vitest run --coverage",
|
|
@@ -3909,8 +4038,16 @@ const keywords = [
|
|
|
3909
4038
|
"erc20",
|
|
3910
4039
|
"fractal"
|
|
3911
4040
|
];
|
|
3912
|
-
const author = "";
|
|
3913
|
-
const license = "
|
|
4041
|
+
const author = "Roberto Valenti";
|
|
4042
|
+
const license = "AGPL-3.0-or-later";
|
|
4043
|
+
const repository = {
|
|
4044
|
+
type: "git",
|
|
4045
|
+
url: "https://github.com/liminalvillage/holosphere2.git"
|
|
4046
|
+
};
|
|
4047
|
+
const homepage = "https://github.com/liminalvillage/holosphere2#readme";
|
|
4048
|
+
const bugs = {
|
|
4049
|
+
url: "https://github.com/liminalvillage/holosphere2/issues"
|
|
4050
|
+
};
|
|
3914
4051
|
const dependencies = {
|
|
3915
4052
|
"@noble/curves": "^1.3.0",
|
|
3916
4053
|
ajv: "^8.12.0",
|
|
@@ -3927,7 +4064,9 @@ const optionalDependencies = {
|
|
|
3927
4064
|
};
|
|
3928
4065
|
const devDependencies = {
|
|
3929
4066
|
"@vitest/coverage-v8": "^1.3.0",
|
|
4067
|
+
"clean-jsdoc-theme": "^4.3.0",
|
|
3930
4068
|
eslint: "^8.57.0",
|
|
4069
|
+
jsdoc: "^4.0.4",
|
|
3931
4070
|
prettier: "^3.2.5",
|
|
3932
4071
|
terser: "^5.44.0",
|
|
3933
4072
|
vite: "^5.1.0",
|
|
@@ -3951,6 +4090,9 @@ const pkg = {
|
|
|
3951
4090
|
keywords,
|
|
3952
4091
|
author,
|
|
3953
4092
|
license,
|
|
4093
|
+
repository,
|
|
4094
|
+
homepage,
|
|
4095
|
+
bugs,
|
|
3954
4096
|
dependencies,
|
|
3955
4097
|
optionalDependencies,
|
|
3956
4098
|
devDependencies,
|
|
@@ -4536,7 +4678,10 @@ let HoloSphere$1 = class HoloSphere {
|
|
|
4536
4678
|
// LIFECYCLE
|
|
4537
4679
|
// ============================================================================
|
|
4538
4680
|
/**
|
|
4539
|
-
*
|
|
4681
|
+
* Closes the backend and cleans up resources.
|
|
4682
|
+
* Should be called when done using the HoloSphere instance.
|
|
4683
|
+
*
|
|
4684
|
+
* @returns {void}
|
|
4540
4685
|
*/
|
|
4541
4686
|
close() {
|
|
4542
4687
|
if (this._backend) {
|
|
@@ -4641,7 +4786,7 @@ async function nostrGet(client, path, kind2 = 3e4, options = {}) {
|
|
|
4641
4786
|
else {
|
|
4642
4787
|
try {
|
|
4643
4788
|
const data = JSON.parse(persistedEvent.content);
|
|
4644
|
-
if (data._deleted) {
|
|
4789
|
+
if (!data || data._deleted) {
|
|
4645
4790
|
return null;
|
|
4646
4791
|
}
|
|
4647
4792
|
if (options.includeAuthor) {
|
|
@@ -4694,7 +4839,7 @@ async function _executeNostrGet(client, path, kind2, authors, timeout, options)
|
|
|
4694
4839
|
const event = authoredEvents.sort((a, b2) => b2.created_at - a.created_at)[0];
|
|
4695
4840
|
try {
|
|
4696
4841
|
const data = JSON.parse(event.content);
|
|
4697
|
-
if (data._deleted) {
|
|
4842
|
+
if (!data || data._deleted) {
|
|
4698
4843
|
return null;
|
|
4699
4844
|
}
|
|
4700
4845
|
if (options.includeAuthor) {
|
|
@@ -4723,7 +4868,7 @@ async function nostrGetAll(client, pathPrefix, kind2 = 3e4, options = {}) {
|
|
|
4723
4868
|
if (!existing || event.created_at > existing.created_at) {
|
|
4724
4869
|
try {
|
|
4725
4870
|
const data = JSON.parse(event.content);
|
|
4726
|
-
if (data._deleted) {
|
|
4871
|
+
if (!data || data._deleted) {
|
|
4727
4872
|
byPath.delete(path);
|
|
4728
4873
|
continue;
|
|
4729
4874
|
}
|
|
@@ -4781,7 +4926,7 @@ async function _executeNostrGetAll(client, pathPrefix, kind2, authors, timeout,
|
|
|
4781
4926
|
if (!existing || event.created_at > existing.created_at) {
|
|
4782
4927
|
try {
|
|
4783
4928
|
const data = JSON.parse(event.content);
|
|
4784
|
-
if (data._deleted) {
|
|
4929
|
+
if (!data || data._deleted) {
|
|
4785
4930
|
byPath.delete(dTag);
|
|
4786
4931
|
continue;
|
|
4787
4932
|
}
|
|
@@ -4993,7 +5138,7 @@ function nostrSubscribe(client, path, callback, options = {}) {
|
|
|
4993
5138
|
}
|
|
4994
5139
|
try {
|
|
4995
5140
|
const data = JSON.parse(event.content);
|
|
4996
|
-
if (data._deleted) {
|
|
5141
|
+
if (!data || data._deleted) {
|
|
4997
5142
|
return;
|
|
4998
5143
|
}
|
|
4999
5144
|
for (const cb of callbacks) {
|
|
@@ -5075,7 +5220,7 @@ async function nostrSubscribeMany(client, pathPrefix, callback, options = {}) {
|
|
|
5075
5220
|
if (dTag && dTag.startsWith(pathPrefix)) {
|
|
5076
5221
|
try {
|
|
5077
5222
|
const data = JSON.parse(event.content);
|
|
5078
|
-
if (data._deleted) {
|
|
5223
|
+
if (!data || data._deleted) {
|
|
5079
5224
|
return;
|
|
5080
5225
|
}
|
|
5081
5226
|
acceptedCount++;
|
|
@@ -5346,6 +5491,12 @@ const ajv = new Ajv({ allErrors: true, strict: false });
|
|
|
5346
5491
|
const schemaCache = /* @__PURE__ */ new Map();
|
|
5347
5492
|
const CACHE_TTL = 36e5;
|
|
5348
5493
|
let ValidationError$1 = class ValidationError extends Error {
|
|
5494
|
+
/**
|
|
5495
|
+
* Creates a new ValidationError.
|
|
5496
|
+
*
|
|
5497
|
+
* @param {string} message - Error message
|
|
5498
|
+
* @param {Array} [errors=[]] - Array of Ajv error objects
|
|
5499
|
+
*/
|
|
5349
5500
|
constructor(message, errors = []) {
|
|
5350
5501
|
super(message);
|
|
5351
5502
|
this.name = "ValidationError";
|
|
@@ -5794,7 +5945,7 @@ const sha256 = sha256$1;
|
|
|
5794
5945
|
let secp256k1 = null;
|
|
5795
5946
|
async function loadCrypto() {
|
|
5796
5947
|
if (!secp256k1) {
|
|
5797
|
-
const module2 = await import("./secp256k1-
|
|
5948
|
+
const module2 = await import("./secp256k1-CreY7Pcl.js");
|
|
5798
5949
|
secp256k1 = module2.secp256k1;
|
|
5799
5950
|
}
|
|
5800
5951
|
return secp256k1;
|
|
@@ -7309,17 +7460,23 @@ async function createSubscription(client, path, callback, options = {}) {
|
|
|
7309
7460
|
};
|
|
7310
7461
|
}
|
|
7311
7462
|
class SubscriptionRegistry {
|
|
7463
|
+
/**
|
|
7464
|
+
* Create a new subscription registry.
|
|
7465
|
+
*/
|
|
7312
7466
|
constructor() {
|
|
7313
7467
|
this.subscriptions = /* @__PURE__ */ new Map();
|
|
7314
7468
|
}
|
|
7315
7469
|
/**
|
|
7316
|
-
* Register a subscription
|
|
7470
|
+
* Register a subscription by ID.
|
|
7471
|
+
* @param {string} id - Unique subscription identifier
|
|
7472
|
+
* @param {Object} subscription - Subscription object with unsubscribe method
|
|
7317
7473
|
*/
|
|
7318
7474
|
register(id2, subscription) {
|
|
7319
7475
|
this.subscriptions.set(id2, subscription);
|
|
7320
7476
|
}
|
|
7321
7477
|
/**
|
|
7322
|
-
* Unregister a subscription
|
|
7478
|
+
* Unregister and unsubscribe a subscription by ID.
|
|
7479
|
+
* @param {string} id - Subscription identifier to remove
|
|
7323
7480
|
*/
|
|
7324
7481
|
unregister(id2) {
|
|
7325
7482
|
const subscription = this.subscriptions.get(id2);
|
|
@@ -7329,7 +7486,7 @@ class SubscriptionRegistry {
|
|
|
7329
7486
|
}
|
|
7330
7487
|
}
|
|
7331
7488
|
/**
|
|
7332
|
-
* Unsubscribe all
|
|
7489
|
+
* Unsubscribe all registered subscriptions and clear the registry.
|
|
7333
7490
|
*/
|
|
7334
7491
|
unsubscribeAll() {
|
|
7335
7492
|
for (const [id2, subscription] of this.subscriptions) {
|
|
@@ -7338,7 +7495,8 @@ class SubscriptionRegistry {
|
|
|
7338
7495
|
this.subscriptions.clear();
|
|
7339
7496
|
}
|
|
7340
7497
|
/**
|
|
7341
|
-
* Get active
|
|
7498
|
+
* Get the count of active subscriptions.
|
|
7499
|
+
* @returns {number} Number of active subscriptions
|
|
7342
7500
|
*/
|
|
7343
7501
|
count() {
|
|
7344
7502
|
return this.subscriptions.size;
|
|
@@ -13472,11 +13630,16 @@ class LLMService {
|
|
|
13472
13630
|
this.temperature = options.temperature || 0.7;
|
|
13473
13631
|
}
|
|
13474
13632
|
/**
|
|
13475
|
-
* Send a message to the LLM
|
|
13476
|
-
*
|
|
13477
|
-
* @param {string}
|
|
13478
|
-
* @param {
|
|
13633
|
+
* Send a single-turn message to the LLM with system and user prompts.
|
|
13634
|
+
*
|
|
13635
|
+
* @param {string} systemPrompt - System prompt defining role and behavior
|
|
13636
|
+
* @param {string} userMessage - User message content
|
|
13637
|
+
* @param {Object} [options={}] - Override options
|
|
13638
|
+
* @param {string} [options.model] - Override model
|
|
13639
|
+
* @param {number} [options.maxTokens] - Override max tokens
|
|
13640
|
+
* @param {number} [options.temperature] - Override temperature
|
|
13479
13641
|
* @returns {Promise<string>} Response content
|
|
13642
|
+
* @throws {Error} If LLM request fails
|
|
13480
13643
|
*/
|
|
13481
13644
|
async sendMessage(systemPrompt, userMessage, options = {}) {
|
|
13482
13645
|
try {
|
|
@@ -13495,10 +13658,15 @@ class LLMService {
|
|
|
13495
13658
|
}
|
|
13496
13659
|
}
|
|
13497
13660
|
/**
|
|
13498
|
-
* Send multiple messages
|
|
13499
|
-
*
|
|
13500
|
-
* @param {
|
|
13661
|
+
* Send multiple messages in a conversation format.
|
|
13662
|
+
*
|
|
13663
|
+
* @param {Array<{role: string, content: string}>} messages - Array of message objects with role and content
|
|
13664
|
+
* @param {Object} [options={}] - Override options
|
|
13665
|
+
* @param {string} [options.model] - Override model
|
|
13666
|
+
* @param {number} [options.maxTokens] - Override max tokens
|
|
13667
|
+
* @param {number} [options.temperature] - Override temperature
|
|
13501
13668
|
* @returns {Promise<string>} Response content
|
|
13669
|
+
* @throws {Error} If LLM chat fails
|
|
13502
13670
|
*/
|
|
13503
13671
|
async chat(messages, options = {}) {
|
|
13504
13672
|
try {
|
|
@@ -13514,30 +13682,36 @@ class LLMService {
|
|
|
13514
13682
|
}
|
|
13515
13683
|
}
|
|
13516
13684
|
/**
|
|
13517
|
-
*
|
|
13685
|
+
* Generate a concise summary of text while preserving key information.
|
|
13686
|
+
*
|
|
13518
13687
|
* @param {string} text - Text to summarize
|
|
13519
|
-
* @param {Object} options -
|
|
13520
|
-
* @
|
|
13688
|
+
* @param {Object} [options={}] - Summarization options
|
|
13689
|
+
* @param {number} [options.maxLength] - Maximum word count for summary
|
|
13690
|
+
* @param {string} [options.style] - Summary style (e.g., 'bullet points', 'executive summary')
|
|
13691
|
+
* @returns {Promise<string>} Summary text
|
|
13521
13692
|
*/
|
|
13522
13693
|
async summarize(text, options = {}) {
|
|
13523
13694
|
const systemPrompt = `You are a helpful assistant that summarizes text concisely while preserving key information. Keep summaries clear and focused.${options.maxLength ? ` Keep the summary under ${options.maxLength} words.` : ""}${options.style ? ` Style: ${options.style}.` : ""}`;
|
|
13524
13695
|
return this.sendMessage(systemPrompt, text, { temperature: 0.5 });
|
|
13525
13696
|
}
|
|
13526
13697
|
/**
|
|
13527
|
-
* Analyze text from a specific perspective
|
|
13698
|
+
* Analyze text from a specific perspective or aspect.
|
|
13699
|
+
*
|
|
13528
13700
|
* @param {string} text - Text to analyze
|
|
13529
|
-
* @param {string} aspect -
|
|
13530
|
-
* @returns {Promise<string>}
|
|
13701
|
+
* @param {string} aspect - Analysis aspect (e.g., 'sentiment', 'themes', 'tone', 'bias')
|
|
13702
|
+
* @returns {Promise<string>} Structured analysis
|
|
13531
13703
|
*/
|
|
13532
13704
|
async analyze(text, aspect) {
|
|
13533
13705
|
const systemPrompt = `You are an expert analyst. Analyze the following text from the perspective of "${aspect}". Provide a clear, structured analysis.`;
|
|
13534
13706
|
return this.sendMessage(systemPrompt, text, { temperature: 0.3 });
|
|
13535
13707
|
}
|
|
13536
13708
|
/**
|
|
13537
|
-
* Extract
|
|
13709
|
+
* Extract key words and phrases from text.
|
|
13710
|
+
*
|
|
13538
13711
|
* @param {string} text - Text to extract keywords from
|
|
13539
|
-
* @param {number} maxKeywords - Maximum keywords
|
|
13540
|
-
* @returns {Promise<string[]>} Array of
|
|
13712
|
+
* @param {number} [maxKeywords=10] - Maximum number of keywords to extract
|
|
13713
|
+
* @returns {Promise<string[]>} Array of keyword strings
|
|
13714
|
+
* @throws {Error} If JSON parsing fails after retry attempts
|
|
13541
13715
|
*/
|
|
13542
13716
|
async extractKeywords(text, maxKeywords = 10) {
|
|
13543
13717
|
const systemPrompt = `Extract the ${maxKeywords} most important keywords or key phrases from the text. Return ONLY a JSON array of strings, nothing else. Example: ["keyword1", "keyword2"]`;
|
|
@@ -13553,10 +13727,11 @@ class LLMService {
|
|
|
13553
13727
|
}
|
|
13554
13728
|
}
|
|
13555
13729
|
/**
|
|
13556
|
-
* Categorize text into
|
|
13730
|
+
* Categorize text into one of the provided categories with confidence score.
|
|
13731
|
+
*
|
|
13557
13732
|
* @param {string} text - Text to categorize
|
|
13558
|
-
* @param {string[]} categories - Available
|
|
13559
|
-
* @returns {Promise<{category: string, confidence: number, reasoning: string}>}
|
|
13733
|
+
* @param {string[]} categories - Available category options
|
|
13734
|
+
* @returns {Promise<{category: string, confidence: number, reasoning: string}>} Categorization result
|
|
13560
13735
|
*/
|
|
13561
13736
|
async categorize(text, categories) {
|
|
13562
13737
|
const systemPrompt = `Categorize the following text into one of these categories: ${categories.join(", ")}.
|
|
@@ -13573,9 +13748,10 @@ Return ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.
|
|
|
13573
13748
|
}
|
|
13574
13749
|
}
|
|
13575
13750
|
/**
|
|
13576
|
-
* Translate text to target language
|
|
13751
|
+
* Translate text to a target language.
|
|
13752
|
+
*
|
|
13577
13753
|
* @param {string} text - Text to translate
|
|
13578
|
-
* @param {string} targetLanguage - Target language
|
|
13754
|
+
* @param {string} targetLanguage - Target language name (e.g., 'Spanish', 'French')
|
|
13579
13755
|
* @returns {Promise<string>} Translated text
|
|
13580
13756
|
*/
|
|
13581
13757
|
async translate(text, targetLanguage) {
|
|
@@ -13583,10 +13759,11 @@ Return ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.
|
|
|
13583
13759
|
return this.sendMessage(systemPrompt, text, { temperature: 0.3 });
|
|
13584
13760
|
}
|
|
13585
13761
|
/**
|
|
13586
|
-
* Generate questions about content
|
|
13762
|
+
* Generate insightful questions about the content.
|
|
13763
|
+
*
|
|
13587
13764
|
* @param {string} text - Text to generate questions about
|
|
13588
|
-
* @param {number} count - Number of questions
|
|
13589
|
-
* @returns {Promise<string[]>} Array of
|
|
13765
|
+
* @param {number} [count=5] - Number of questions to generate
|
|
13766
|
+
* @returns {Promise<string[]>} Array of question strings
|
|
13590
13767
|
*/
|
|
13591
13768
|
async generateQuestions(text, count = 5) {
|
|
13592
13769
|
const systemPrompt = `Generate ${count} insightful questions about the following text. Return ONLY a JSON array of question strings, nothing else. Example: ["Question 1?", "Question 2?"]`;
|
|
@@ -13602,11 +13779,15 @@ Return ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.
|
|
|
13602
13779
|
}
|
|
13603
13780
|
}
|
|
13604
13781
|
/**
|
|
13605
|
-
* Get JSON response from LLM
|
|
13606
|
-
*
|
|
13782
|
+
* Get a structured JSON response from the LLM with automatic parsing.
|
|
13783
|
+
* Attempts to extract JSON from response even if surrounded by additional text.
|
|
13784
|
+
*
|
|
13785
|
+
* @param {string} systemPrompt - System prompt (JSON instruction will be appended)
|
|
13607
13786
|
* @param {string} userMessage - User message
|
|
13608
|
-
* @param {Object} options -
|
|
13609
|
-
* @
|
|
13787
|
+
* @param {Object} [options={}] - Request options
|
|
13788
|
+
* @param {number} [options.temperature=0.2] - Temperature (defaults to 0.2 for structured output)
|
|
13789
|
+
* @returns {Promise<Object>} Parsed JSON object
|
|
13790
|
+
* @throws {Error} If JSON parsing fails completely
|
|
13610
13791
|
*/
|
|
13611
13792
|
async getJSON(systemPrompt, userMessage, options = {}) {
|
|
13612
13793
|
const response = await this.sendMessage(
|
|
@@ -13633,10 +13814,13 @@ class SchemaExtractor {
|
|
|
13633
13814
|
this.llm = llmService;
|
|
13634
13815
|
}
|
|
13635
13816
|
/**
|
|
13636
|
-
* Extract data from text
|
|
13637
|
-
*
|
|
13638
|
-
*
|
|
13639
|
-
* @param {
|
|
13817
|
+
* Extract structured data from text according to a JSON schema.
|
|
13818
|
+
* Uses LLM to intelligently parse unstructured text and map to schema fields.
|
|
13819
|
+
*
|
|
13820
|
+
* @param {string} text - Unstructured text to extract from
|
|
13821
|
+
* @param {Object} schema - JSON schema defining target structure
|
|
13822
|
+
* @param {Object} [options={}] - Extraction options
|
|
13823
|
+
* @param {number} [options.maxTokens=2000] - Maximum tokens for response
|
|
13640
13824
|
* @returns {Promise<Object>} Extracted data conforming to schema
|
|
13641
13825
|
*/
|
|
13642
13826
|
async extractToSchema(text, schema, options = {}) {
|
|
@@ -13753,10 +13937,12 @@ Return JSON with ONLY the missing fields that you can extract. Do not modify exi
|
|
|
13753
13937
|
return missing;
|
|
13754
13938
|
}
|
|
13755
13939
|
/**
|
|
13756
|
-
* Validate extracted data against schema
|
|
13757
|
-
*
|
|
13758
|
-
*
|
|
13759
|
-
* @
|
|
13940
|
+
* Validate extracted data against a JSON schema.
|
|
13941
|
+
* Performs basic type checking and required field validation.
|
|
13942
|
+
*
|
|
13943
|
+
* @param {Object} data - Extracted data to validate
|
|
13944
|
+
* @param {Object} schema - JSON schema to validate against
|
|
13945
|
+
* @returns {{valid: boolean, errors: string[]}} Validation result with error list
|
|
13760
13946
|
*/
|
|
13761
13947
|
validateExtraction(data, schema) {
|
|
13762
13948
|
const errors = [];
|
|
@@ -13813,11 +13999,14 @@ class JSONOps {
|
|
|
13813
13999
|
this.llm = llmService;
|
|
13814
14000
|
}
|
|
13815
14001
|
/**
|
|
13816
|
-
* Semantically merge two JSON objects
|
|
14002
|
+
* Semantically merge two JSON objects with intelligent deduplication.
|
|
14003
|
+
* Combines information from both objects, resolving conflicts semantically.
|
|
14004
|
+
*
|
|
13817
14005
|
* @param {Object} obj1 - First object
|
|
13818
14006
|
* @param {Object} obj2 - Second object
|
|
13819
|
-
* @param {Object} options - Merge options
|
|
13820
|
-
* @
|
|
14007
|
+
* @param {Object} [options={}] - Merge options
|
|
14008
|
+
* @param {boolean} [options.preferSecond=false] - Prefer second object's values in conflicts
|
|
14009
|
+
* @returns {Promise<Object>} Merged object with combined information
|
|
13821
14010
|
*/
|
|
13822
14011
|
async add(obj1, obj2, options = {}) {
|
|
13823
14012
|
const systemPrompt = `You are a JSON merge expert. Semantically merge these two JSON objects.
|
|
@@ -14016,9 +14205,11 @@ class Embeddings2 {
|
|
|
14016
14205
|
this.holosphere = holosphere;
|
|
14017
14206
|
}
|
|
14018
14207
|
/**
|
|
14019
|
-
* Generate embedding for text
|
|
14208
|
+
* Generate a vector embedding for the given text.
|
|
14209
|
+
*
|
|
14020
14210
|
* @param {string} text - Text to embed
|
|
14021
|
-
* @returns {Promise<number[]>} Embedding vector
|
|
14211
|
+
* @returns {Promise<number[]>} Embedding vector (1536 dimensions by default)
|
|
14212
|
+
* @throws {Error} If embedding generation fails
|
|
14022
14213
|
*/
|
|
14023
14214
|
async embed(text) {
|
|
14024
14215
|
try {
|
|
@@ -14048,10 +14239,13 @@ class Embeddings2 {
|
|
|
14048
14239
|
}
|
|
14049
14240
|
}
|
|
14050
14241
|
/**
|
|
14051
|
-
* Calculate cosine similarity between two vectors
|
|
14052
|
-
*
|
|
14053
|
-
*
|
|
14054
|
-
* @
|
|
14242
|
+
* Calculate cosine similarity between two embedding vectors.
|
|
14243
|
+
* Returns a score between -1 and 1, where 1 indicates identical vectors.
|
|
14244
|
+
*
|
|
14245
|
+
* @param {number[]} vec1 - First embedding vector
|
|
14246
|
+
* @param {number[]} vec2 - Second embedding vector
|
|
14247
|
+
* @returns {number} Similarity score (0-1 for normalized vectors)
|
|
14248
|
+
* @throws {Error} If vectors have different lengths
|
|
14055
14249
|
*/
|
|
14056
14250
|
cosineSimilarity(vec1, vec2) {
|
|
14057
14251
|
if (vec1.length !== vec2.length) {
|
|
@@ -14094,12 +14288,17 @@ class Embeddings2 {
|
|
|
14094
14288
|
return itemWithEmbedding;
|
|
14095
14289
|
}
|
|
14096
14290
|
/**
|
|
14097
|
-
*
|
|
14098
|
-
*
|
|
14291
|
+
* Perform semantic search within a holon/lens using vector similarity.
|
|
14292
|
+
* Returns items ranked by semantic similarity to the query.
|
|
14293
|
+
*
|
|
14294
|
+
* @param {string} query - Natural language search query
|
|
14099
14295
|
* @param {string} holon - Holon identifier
|
|
14100
14296
|
* @param {string} lens - Lens name
|
|
14101
|
-
* @param {Object} options - Search options
|
|
14102
|
-
* @
|
|
14297
|
+
* @param {Object} [options={}] - Search options
|
|
14298
|
+
* @param {number} [options.limit=10] - Maximum results to return
|
|
14299
|
+
* @param {number} [options.threshold=0.5] - Minimum similarity score (0-1)
|
|
14300
|
+
* @returns {Promise<Array<{item: Object, similarity: number}>>} Results ranked by similarity descending
|
|
14301
|
+
* @throws {Error} If HoloSphere instance not configured
|
|
14103
14302
|
*/
|
|
14104
14303
|
async semanticSearch(query, holon, lens, options = {}) {
|
|
14105
14304
|
if (!this.holosphere) {
|
|
@@ -14137,10 +14336,12 @@ class Embeddings2 {
|
|
|
14137
14336
|
return this.semanticSearch(text, holon, lens, options);
|
|
14138
14337
|
}
|
|
14139
14338
|
/**
|
|
14140
|
-
* Cluster items by semantic similarity
|
|
14339
|
+
* Cluster items by semantic similarity using k-means algorithm.
|
|
14340
|
+
* Automatically generates embeddings for items that don't have them.
|
|
14341
|
+
*
|
|
14141
14342
|
* @param {Object[]} items - Items to cluster
|
|
14142
|
-
* @param {number} numClusters -
|
|
14143
|
-
* @returns {Promise<Object[][]>}
|
|
14343
|
+
* @param {number} [numClusters=5] - Target number of clusters
|
|
14344
|
+
* @returns {Promise<Object[][]>} Array of clusters, each containing related items
|
|
14144
14345
|
*/
|
|
14145
14346
|
async cluster(items, numClusters = 5) {
|
|
14146
14347
|
const itemsWithEmbeddings = await Promise.all(
|
|
@@ -14246,10 +14447,14 @@ class Council {
|
|
|
14246
14447
|
return DEFAULT_PERSPECTIVES;
|
|
14247
14448
|
}
|
|
14248
14449
|
/**
|
|
14249
|
-
* Ask a question to the council
|
|
14250
|
-
*
|
|
14251
|
-
* @param {
|
|
14252
|
-
* @
|
|
14450
|
+
* Ask a question to the council and receive diverse perspective responses.
|
|
14451
|
+
*
|
|
14452
|
+
* @param {string} question - Question to ask the council
|
|
14453
|
+
* @param {Object} [options={}] - Options
|
|
14454
|
+
* @param {boolean} [options.parallel=true] - Query perspectives in parallel or sequentially
|
|
14455
|
+
* @param {boolean} [options.includeSummary=true] - Generate a synthesis summary
|
|
14456
|
+
* @param {Array} [options.perspectives] - Override default perspectives
|
|
14457
|
+
* @returns {Promise<{question: string, perspectives: Array, summary: string, timestamp: number}>} Council responses
|
|
14253
14458
|
*/
|
|
14254
14459
|
async ask(question, options = {}) {
|
|
14255
14460
|
const { parallel = true, includeSummary = true } = options;
|
|
@@ -14416,10 +14621,16 @@ class TTS {
|
|
|
14416
14621
|
this.defaultModel = MODELS.TTS_1;
|
|
14417
14622
|
}
|
|
14418
14623
|
/**
|
|
14419
|
-
* Convert text to speech
|
|
14420
|
-
*
|
|
14421
|
-
* @param {
|
|
14422
|
-
* @
|
|
14624
|
+
* Convert text to speech audio.
|
|
14625
|
+
*
|
|
14626
|
+
* @param {string} text - Text to convert to speech
|
|
14627
|
+
* @param {Object} [options={}] - TTS generation options
|
|
14628
|
+
* @param {string} [options.voice] - Voice to use (from VOICES enum)
|
|
14629
|
+
* @param {string} [options.model] - Model to use (from MODELS enum)
|
|
14630
|
+
* @param {number} [options.speed=1.0] - Speech speed (0.25 to 4.0)
|
|
14631
|
+
* @param {string} [options.responseFormat='mp3'] - Audio format (mp3, opus, aac, flac)
|
|
14632
|
+
* @returns {Promise<Buffer>} Audio buffer
|
|
14633
|
+
* @throws {Error} If TTS generation fails
|
|
14423
14634
|
*/
|
|
14424
14635
|
async speak(text, options = {}) {
|
|
14425
14636
|
const {
|
|
@@ -14763,7 +14974,7 @@ class Classifier {
|
|
|
14763
14974
|
}
|
|
14764
14975
|
/**
|
|
14765
14976
|
* Register multiple lenses
|
|
14766
|
-
* @param {Object
|
|
14977
|
+
* @param {Object.<string, Object>} lenses - Map of lens names to config objects with description and optional schema
|
|
14767
14978
|
*/
|
|
14768
14979
|
registerLenses(lenses) {
|
|
14769
14980
|
for (const [name2, config] of Object.entries(lenses)) {
|
|
@@ -17430,6 +17641,10 @@ const networks = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
17430
17641
|
listNetworks
|
|
17431
17642
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17432
17643
|
class ChainManager {
|
|
17644
|
+
/**
|
|
17645
|
+
* Create a new ChainManager instance.
|
|
17646
|
+
* @param {Object} [config={}] - Configuration options
|
|
17647
|
+
*/
|
|
17433
17648
|
constructor(config = {}) {
|
|
17434
17649
|
this.config = config;
|
|
17435
17650
|
this.provider = null;
|
|
@@ -17440,22 +17655,24 @@ class ChainManager {
|
|
|
17440
17655
|
this._initialized = false;
|
|
17441
17656
|
}
|
|
17442
17657
|
/**
|
|
17443
|
-
* Initialize ethers.js (lazy load)
|
|
17658
|
+
* Initialize ethers.js library (lazy load).
|
|
17444
17659
|
* @private
|
|
17660
|
+
* @returns {Promise<Object>} Ethers.js module
|
|
17445
17661
|
*/
|
|
17446
17662
|
async _loadEthers() {
|
|
17447
17663
|
if (!this.ethers) {
|
|
17448
|
-
const ethersModule = await import("./index-
|
|
17664
|
+
const ethersModule = await import("./index-DeZ1xz_s.js");
|
|
17449
17665
|
this.ethers = ethersModule;
|
|
17450
17666
|
}
|
|
17451
17667
|
return this.ethers;
|
|
17452
17668
|
}
|
|
17453
17669
|
/**
|
|
17454
|
-
* Connect to a network
|
|
17670
|
+
* Connect to a network using RPC provider.
|
|
17455
17671
|
* @param {string} networkName - Network name (e.g., 'sepolia', 'polygon')
|
|
17456
17672
|
* @param {string} [privateKey] - Private key for signing transactions
|
|
17457
17673
|
* @param {string} [rpcUrl] - Custom RPC URL (overrides default)
|
|
17458
|
-
* @returns {Promise<{provider, signer, network}>}
|
|
17674
|
+
* @returns {Promise<{provider: Object, signer: Object|null, network: Object, networkName: string, config: Object}>} Connection details
|
|
17675
|
+
* @throws {Error} If network is unsupported and no custom RPC URL provided
|
|
17459
17676
|
*/
|
|
17460
17677
|
async connect(networkName, privateKey, rpcUrl) {
|
|
17461
17678
|
const ethers = await this._loadEthers();
|
|
@@ -17485,9 +17702,10 @@ class ChainManager {
|
|
|
17485
17702
|
};
|
|
17486
17703
|
}
|
|
17487
17704
|
/**
|
|
17488
|
-
* Connect using browser wallet (MetaMask, etc.)
|
|
17705
|
+
* Connect using browser wallet (MetaMask, etc.).
|
|
17489
17706
|
* @param {string} [networkName] - Optionally switch to this network
|
|
17490
|
-
* @returns {Promise<{provider, signer, network, address}>}
|
|
17707
|
+
* @returns {Promise<{provider: Object, signer: Object, network: Object, address: string}>} Connection details including user address
|
|
17708
|
+
* @throws {Error} If no browser wallet is detected
|
|
17491
17709
|
*/
|
|
17492
17710
|
async connectBrowser(networkName) {
|
|
17493
17711
|
const ethers = await this._loadEthers();
|
|
@@ -17514,8 +17732,11 @@ class ChainManager {
|
|
|
17514
17732
|
};
|
|
17515
17733
|
}
|
|
17516
17734
|
/**
|
|
17517
|
-
* Switch to a different network (browser wallet only)
|
|
17735
|
+
* Switch to a different network (browser wallet only).
|
|
17736
|
+
* Adds the network to the wallet if it doesn't exist.
|
|
17518
17737
|
* @param {string} networkName - Target network name
|
|
17738
|
+
* @returns {Promise<void>}
|
|
17739
|
+
* @throws {Error} If not using a browser wallet or network is unknown
|
|
17519
17740
|
*/
|
|
17520
17741
|
async switchNetwork(networkName) {
|
|
17521
17742
|
if (typeof window === "undefined" || !window.ethereum) {
|
|
@@ -17554,16 +17775,18 @@ class ChainManager {
|
|
|
17554
17775
|
this.networkName = networkName;
|
|
17555
17776
|
}
|
|
17556
17777
|
/**
|
|
17557
|
-
* Get the current provider
|
|
17558
|
-
* @returns {
|
|
17778
|
+
* Get the current provider.
|
|
17779
|
+
* @returns {Object} Ethers.js provider instance
|
|
17780
|
+
* @throws {Error} If not initialized
|
|
17559
17781
|
*/
|
|
17560
17782
|
getProvider() {
|
|
17561
17783
|
this._requireInitialized();
|
|
17562
17784
|
return this.provider;
|
|
17563
17785
|
}
|
|
17564
17786
|
/**
|
|
17565
|
-
* Get the current signer
|
|
17566
|
-
* @returns {
|
|
17787
|
+
* Get the current signer.
|
|
17788
|
+
* @returns {Object} Ethers.js signer instance
|
|
17789
|
+
* @throws {Error} If not initialized or no signer available
|
|
17567
17790
|
*/
|
|
17568
17791
|
getSigner() {
|
|
17569
17792
|
this._requireInitialized();
|
|
@@ -17573,17 +17796,19 @@ class ChainManager {
|
|
|
17573
17796
|
return this.signer;
|
|
17574
17797
|
}
|
|
17575
17798
|
/**
|
|
17576
|
-
* Get the connected address
|
|
17577
|
-
* @returns {Promise<string>}
|
|
17799
|
+
* Get the connected wallet address.
|
|
17800
|
+
* @returns {Promise<string>} Ethereum address
|
|
17801
|
+
* @throws {Error} If no signer available
|
|
17578
17802
|
*/
|
|
17579
17803
|
async getAddress() {
|
|
17580
17804
|
const signer = this.getSigner();
|
|
17581
17805
|
return signer.getAddress();
|
|
17582
17806
|
}
|
|
17583
17807
|
/**
|
|
17584
|
-
* Get ETH balance of an address
|
|
17808
|
+
* Get ETH balance of an address.
|
|
17585
17809
|
* @param {string} [address] - Address to check (defaults to signer)
|
|
17586
|
-
* @returns {Promise<string>} Balance in ETH
|
|
17810
|
+
* @returns {Promise<string>} Balance in ETH as decimal string
|
|
17811
|
+
* @throws {Error} If not initialized or no address/signer available
|
|
17587
17812
|
*/
|
|
17588
17813
|
async getBalance(address) {
|
|
17589
17814
|
this._requireInitialized();
|
|
@@ -17596,25 +17821,27 @@ class ChainManager {
|
|
|
17596
17821
|
return ethers.formatEther(balance);
|
|
17597
17822
|
}
|
|
17598
17823
|
/**
|
|
17599
|
-
* Get current network configuration
|
|
17600
|
-
* @returns {Object}
|
|
17824
|
+
* Get current network configuration.
|
|
17825
|
+
* @returns {Object} Network configuration object
|
|
17826
|
+
* @throws {Error} If not initialized
|
|
17601
17827
|
*/
|
|
17602
17828
|
getNetworkConfig() {
|
|
17603
17829
|
this._requireInitialized();
|
|
17604
17830
|
return getNetwork(this.networkName);
|
|
17605
17831
|
}
|
|
17606
17832
|
/**
|
|
17607
|
-
* Get current chain ID
|
|
17608
|
-
* @returns {number}
|
|
17833
|
+
* Get current chain ID.
|
|
17834
|
+
* @returns {number} Chain ID as number
|
|
17835
|
+
* @throws {Error} If not initialized
|
|
17609
17836
|
*/
|
|
17610
17837
|
getChainId() {
|
|
17611
17838
|
this._requireInitialized();
|
|
17612
17839
|
return Number(this.network.chainId);
|
|
17613
17840
|
}
|
|
17614
17841
|
/**
|
|
17615
|
-
* Check if connected to the expected network
|
|
17842
|
+
* Check if connected to the expected network.
|
|
17616
17843
|
* @param {string} expectedNetwork - Expected network name
|
|
17617
|
-
* @returns {boolean}
|
|
17844
|
+
* @returns {boolean} True if on expected network
|
|
17618
17845
|
*/
|
|
17619
17846
|
isOnNetwork(expectedNetwork) {
|
|
17620
17847
|
if (!this._initialized) return false;
|
|
@@ -17623,11 +17850,12 @@ class ChainManager {
|
|
|
17623
17850
|
return this.getChainId() === expected.chainId;
|
|
17624
17851
|
}
|
|
17625
17852
|
/**
|
|
17626
|
-
* Create a contract instance
|
|
17853
|
+
* Create a contract instance.
|
|
17627
17854
|
* @param {string} address - Contract address
|
|
17628
17855
|
* @param {Array} abi - Contract ABI
|
|
17629
17856
|
* @param {boolean} [useSigner=true] - Use signer for write operations
|
|
17630
|
-
* @returns {Contract
|
|
17857
|
+
* @returns {Promise<Object>} Ethers.js Contract instance
|
|
17858
|
+
* @throws {Error} If not initialized
|
|
17631
17859
|
*/
|
|
17632
17860
|
async getContract(address, abi2, useSigner = true) {
|
|
17633
17861
|
this._requireInitialized();
|
|
@@ -17636,11 +17864,12 @@ class ChainManager {
|
|
|
17636
17864
|
return new ethers.Contract(address, abi2, signerOrProvider);
|
|
17637
17865
|
}
|
|
17638
17866
|
/**
|
|
17639
|
-
* Deploy a contract
|
|
17867
|
+
* Deploy a contract.
|
|
17640
17868
|
* @param {Array} abi - Contract ABI
|
|
17641
17869
|
* @param {string} bytecode - Contract bytecode
|
|
17642
17870
|
* @param {Array} [constructorArgs=[]] - Constructor arguments
|
|
17643
|
-
* @returns {Promise<{contract, address, deployTx}>}
|
|
17871
|
+
* @returns {Promise<{contract: Object, address: string, deployTx: Object, txHash: string}>} Deployment details
|
|
17872
|
+
* @throws {Error} If not initialized or no signer available
|
|
17644
17873
|
*/
|
|
17645
17874
|
async deployContract(abi2, bytecode2, constructorArgs = []) {
|
|
17646
17875
|
this._requireInitialized();
|
|
@@ -17661,27 +17890,30 @@ class ChainManager {
|
|
|
17661
17890
|
};
|
|
17662
17891
|
}
|
|
17663
17892
|
/**
|
|
17664
|
-
* Wait for a transaction to be mined
|
|
17893
|
+
* Wait for a transaction to be mined.
|
|
17665
17894
|
* @param {string} txHash - Transaction hash
|
|
17666
17895
|
* @param {number} [confirmations=1] - Number of confirmations to wait for
|
|
17667
|
-
* @returns {Promise<
|
|
17896
|
+
* @returns {Promise<Object>} Transaction receipt
|
|
17897
|
+
* @throws {Error} If not initialized
|
|
17668
17898
|
*/
|
|
17669
17899
|
async waitForTransaction(txHash, confirmations = 1) {
|
|
17670
17900
|
this._requireInitialized();
|
|
17671
17901
|
return this.provider.waitForTransaction(txHash, confirmations);
|
|
17672
17902
|
}
|
|
17673
17903
|
/**
|
|
17674
|
-
* Estimate gas for a transaction
|
|
17904
|
+
* Estimate gas for a transaction.
|
|
17675
17905
|
* @param {Object} tx - Transaction object
|
|
17676
|
-
* @returns {Promise<bigint>}
|
|
17906
|
+
* @returns {Promise<bigint>} Estimated gas amount
|
|
17907
|
+
* @throws {Error} If not initialized
|
|
17677
17908
|
*/
|
|
17678
17909
|
async estimateGas(tx) {
|
|
17679
17910
|
this._requireInitialized();
|
|
17680
17911
|
return this.provider.estimateGas(tx);
|
|
17681
17912
|
}
|
|
17682
17913
|
/**
|
|
17683
|
-
* Get current gas price
|
|
17684
|
-
* @returns {Promise<{gasPrice: string, maxFeePerGas: string, maxPriorityFeePerGas: string}>}
|
|
17914
|
+
* Get current gas price and fee data.
|
|
17915
|
+
* @returns {Promise<{gasPrice: string|null, maxFeePerGas: string|null, maxPriorityFeePerGas: string|null}>} Fee data in gwei
|
|
17916
|
+
* @throws {Error} If not initialized
|
|
17685
17917
|
*/
|
|
17686
17918
|
async getGasPrice() {
|
|
17687
17919
|
this._requireInitialized();
|
|
@@ -17694,28 +17926,29 @@ class ChainManager {
|
|
|
17694
17926
|
};
|
|
17695
17927
|
}
|
|
17696
17928
|
/**
|
|
17697
|
-
* Parse units (e.g., ETH to wei)
|
|
17929
|
+
* Parse units (e.g., ETH to wei).
|
|
17698
17930
|
* @param {string|number} value - Value to parse
|
|
17699
17931
|
* @param {string|number} [unit='ether'] - Unit name or decimals
|
|
17700
|
-
* @returns {bigint}
|
|
17932
|
+
* @returns {Promise<bigint>} Parsed value as bigint
|
|
17701
17933
|
*/
|
|
17702
17934
|
async parseUnits(value, unit = "ether") {
|
|
17703
17935
|
const ethers = await this._loadEthers();
|
|
17704
17936
|
return ethers.parseUnits(value.toString(), unit);
|
|
17705
17937
|
}
|
|
17706
17938
|
/**
|
|
17707
|
-
* Format units (e.g., wei to ETH)
|
|
17939
|
+
* Format units (e.g., wei to ETH).
|
|
17708
17940
|
* @param {bigint|string} value - Value to format
|
|
17709
17941
|
* @param {string|number} [unit='ether'] - Unit name or decimals
|
|
17710
|
-
* @returns {string}
|
|
17942
|
+
* @returns {Promise<string>} Formatted value as decimal string
|
|
17711
17943
|
*/
|
|
17712
17944
|
async formatUnits(value, unit = "ether") {
|
|
17713
17945
|
const ethers = await this._loadEthers();
|
|
17714
17946
|
return ethers.formatUnits(value, unit);
|
|
17715
17947
|
}
|
|
17716
17948
|
/**
|
|
17717
|
-
* Check if manager is initialized
|
|
17949
|
+
* Check if manager is initialized.
|
|
17718
17950
|
* @private
|
|
17951
|
+
* @throws {Error} If not initialized
|
|
17719
17952
|
*/
|
|
17720
17953
|
_requireInitialized() {
|
|
17721
17954
|
if (!this._initialized) {
|
|
@@ -17723,14 +17956,14 @@ class ChainManager {
|
|
|
17723
17956
|
}
|
|
17724
17957
|
}
|
|
17725
17958
|
/**
|
|
17726
|
-
* Check if connected
|
|
17727
|
-
* @returns {boolean}
|
|
17959
|
+
* Check if connected to a network.
|
|
17960
|
+
* @returns {boolean} True if connected
|
|
17728
17961
|
*/
|
|
17729
17962
|
isConnected() {
|
|
17730
17963
|
return this._initialized && this.provider !== null;
|
|
17731
17964
|
}
|
|
17732
17965
|
/**
|
|
17733
|
-
* Disconnect and clean up
|
|
17966
|
+
* Disconnect and clean up resources.
|
|
17734
17967
|
*/
|
|
17735
17968
|
disconnect() {
|
|
17736
17969
|
this.provider = null;
|
|
@@ -26203,31 +26436,36 @@ const ABIs = {
|
|
|
26203
26436
|
TestToken: TestTokenABI
|
|
26204
26437
|
};
|
|
26205
26438
|
class ContractDeployer {
|
|
26439
|
+
/**
|
|
26440
|
+
* Create a new ContractDeployer instance.
|
|
26441
|
+
* @param {ChainManager} chainManager - Chain manager instance
|
|
26442
|
+
*/
|
|
26206
26443
|
constructor(chainManager) {
|
|
26207
26444
|
this.chainManager = chainManager;
|
|
26208
26445
|
this.deployedContracts = {};
|
|
26209
26446
|
this.ethers = null;
|
|
26210
26447
|
}
|
|
26211
26448
|
/**
|
|
26212
|
-
* Load ethers
|
|
26449
|
+
* Load ethers.js library.
|
|
26213
26450
|
* @private
|
|
26451
|
+
* @returns {Promise<Object>} Ethers.js module
|
|
26214
26452
|
*/
|
|
26215
26453
|
async _loadEthers() {
|
|
26216
26454
|
if (!this.ethers) {
|
|
26217
|
-
this.ethers = await import("./index-
|
|
26455
|
+
this.ethers = await import("./index-DeZ1xz_s.js");
|
|
26218
26456
|
}
|
|
26219
26457
|
return this.ethers;
|
|
26220
26458
|
}
|
|
26221
26459
|
/**
|
|
26222
|
-
* 1-CLICK DEPLOY: Deploy entire Holosphere contract infrastructure
|
|
26223
|
-
* Deploys
|
|
26224
|
-
*
|
|
26225
|
-
* @param {Object} options - Deployment options
|
|
26460
|
+
* 1-CLICK DEPLOY: Deploy entire Holosphere contract infrastructure.
|
|
26461
|
+
* Deploys all factories, Holons registry, and optional TestToken.
|
|
26462
|
+
* @param {Object} [options={}] - Deployment options
|
|
26226
26463
|
* @param {string} [options.botAddress] - Bot address for managed operations (defaults to deployer)
|
|
26227
26464
|
* @param {string} [options.testTokenSupply='1000000'] - Initial supply for test token (in whole tokens)
|
|
26228
26465
|
* @param {boolean} [options.deployTestToken=true] - Whether to deploy test token
|
|
26229
|
-
* @param {Function} [options.onProgress] - Callback for deployment progress
|
|
26230
|
-
* @returns {Promise<Object>}
|
|
26466
|
+
* @param {Function} [options.onProgress] - Callback for deployment progress updates
|
|
26467
|
+
* @returns {Promise<Object>} Deployment details including contract addresses, explorer URLs, and metadata
|
|
26468
|
+
* @throws {Error} If deployment fails
|
|
26231
26469
|
*/
|
|
26232
26470
|
async deployAll(options = {}) {
|
|
26233
26471
|
const ethers = await this._loadEthers();
|
|
@@ -26326,12 +26564,16 @@ class ContractDeployer {
|
|
|
26326
26564
|
}
|
|
26327
26565
|
}
|
|
26328
26566
|
/**
|
|
26329
|
-
* Deploy a Splitter contract for
|
|
26567
|
+
* Deploy a Splitter contract for fractal ownership distribution.
|
|
26330
26568
|
* @param {string} holonId - Holon identifier
|
|
26331
26569
|
* @param {string} name - Contract display name
|
|
26332
26570
|
* @param {number} [splitPercentage=70] - Internal/External split (e.g., 70 = 70% internal, 30% external)
|
|
26333
|
-
* @param {Object} [options] - Additional options
|
|
26334
|
-
* @
|
|
26571
|
+
* @param {Object} [options={}] - Additional deployment options
|
|
26572
|
+
* @param {string} [options.creatorUserId] - Creator user ID (defaults to holonId)
|
|
26573
|
+
* @param {string} [options.managedFactory] - Managed factory address
|
|
26574
|
+
* @param {string} [options.zonedFactory] - Zoned factory address
|
|
26575
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, holonId: string, type: string, splitPercentage: number}>} Deployment details
|
|
26576
|
+
* @throws {Error} If factories not deployed
|
|
26335
26577
|
*/
|
|
26336
26578
|
async deploySplitter(holonId, name2, splitPercentage = 70, options = {}) {
|
|
26337
26579
|
const signer = this.chainManager.getSigner();
|
|
@@ -26358,10 +26600,11 @@ class ContractDeployer {
|
|
|
26358
26600
|
};
|
|
26359
26601
|
}
|
|
26360
26602
|
/**
|
|
26361
|
-
* Deploy a Managed contract
|
|
26603
|
+
* Deploy a Managed contract for appreciation-based distribution.
|
|
26362
26604
|
* @param {string} name - Contract name
|
|
26363
|
-
* @param {Object} [options] - Additional options
|
|
26364
|
-
* @
|
|
26605
|
+
* @param {Object} [options={}] - Additional deployment options
|
|
26606
|
+
* @param {string} [options.botAddress] - Bot address for managing appreciation (defaults to deployer)
|
|
26607
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, type: string}>} Deployment details
|
|
26365
26608
|
*/
|
|
26366
26609
|
async deployManaged(name2, options = {}) {
|
|
26367
26610
|
const signer = this.chainManager.getSigner();
|
|
@@ -26378,11 +26621,13 @@ class ContractDeployer {
|
|
|
26378
26621
|
};
|
|
26379
26622
|
}
|
|
26380
26623
|
/**
|
|
26381
|
-
* Deploy a Zoned contract
|
|
26624
|
+
* Deploy a Zoned contract for tier-based distribution.
|
|
26382
26625
|
* @param {string} name - Contract name
|
|
26383
26626
|
* @param {number} [nZones=6] - Number of zones
|
|
26384
|
-
* @param {Object} [options] - Additional options
|
|
26385
|
-
* @
|
|
26627
|
+
* @param {Object} [options={}] - Additional deployment options
|
|
26628
|
+
* @param {string} [options.botAddress] - Bot address for managing zones (defaults to deployer)
|
|
26629
|
+
* @param {string} [options.creatorUserId] - Creator user ID (defaults to 'creator')
|
|
26630
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, type: string, nZones: number}>} Deployment details
|
|
26386
26631
|
*/
|
|
26387
26632
|
async deployZoned(name2, nZones = 6, options = {}) {
|
|
26388
26633
|
const signer = this.chainManager.getSigner();
|
|
@@ -26401,11 +26646,11 @@ class ContractDeployer {
|
|
|
26401
26646
|
};
|
|
26402
26647
|
}
|
|
26403
26648
|
/**
|
|
26404
|
-
* Deploy an Appreciative contract
|
|
26649
|
+
* Deploy an Appreciative contract for peer-to-peer appreciation.
|
|
26405
26650
|
* @param {string} name - Contract name
|
|
26406
26651
|
* @param {string} creatorUserId - Creator's user ID
|
|
26407
|
-
* @param {Object} [options] - Additional options
|
|
26408
|
-
* @returns {Promise<{contract, address, txHash}>}
|
|
26652
|
+
* @param {Object} [options={}] - Additional deployment options
|
|
26653
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, type: string}>} Deployment details
|
|
26409
26654
|
*/
|
|
26410
26655
|
async deployAppreciative(name2, creatorUserId, options = {}) {
|
|
26411
26656
|
const signer = this.chainManager.getSigner();
|
|
@@ -26421,13 +26666,15 @@ class ContractDeployer {
|
|
|
26421
26666
|
};
|
|
26422
26667
|
}
|
|
26423
26668
|
/**
|
|
26424
|
-
* Deploy a Bundle contract
|
|
26425
|
-
* This is the simplest way to deploy a holon - no registry needed
|
|
26669
|
+
* Deploy a Bundle contract for 2-way split with steepness-based zone decay.
|
|
26670
|
+
* This is the simplest way to deploy a holon - no registry needed.
|
|
26426
26671
|
* @param {string} name - Contract name
|
|
26427
|
-
* @param {
|
|
26672
|
+
* @param {bigint|string} [steepness] - Steepness factor (e.g., 0.5e18 = 50% decay, defaults to 0.5e18)
|
|
26428
26673
|
* @param {number} [nZones=6] - Number of zones
|
|
26429
|
-
* @param {Object} [options] - Additional options
|
|
26430
|
-
* @
|
|
26674
|
+
* @param {Object} [options={}] - Additional deployment options
|
|
26675
|
+
* @param {string} [options.creatorUserId] - Creator user ID (defaults to 'creator')
|
|
26676
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, type: string, steepness: bigint, nZones: number, creatorUserId: string, name: string}>} Deployment details
|
|
26677
|
+
* @throws {Error} If bytecode is not available
|
|
26431
26678
|
*/
|
|
26432
26679
|
async deployBundle(name2, steepness, nZones = 6, options = {}) {
|
|
26433
26680
|
const ethers = await this._loadEthers();
|
|
@@ -26455,12 +26702,14 @@ class ContractDeployer {
|
|
|
26455
26702
|
};
|
|
26456
26703
|
}
|
|
26457
26704
|
/**
|
|
26458
|
-
* Deploy a Bundle contract directly (simplified 1-click deployment)
|
|
26459
|
-
* No registry needed - just deploys and returns the address
|
|
26705
|
+
* Deploy a Bundle contract directly (simplified 1-click deployment).
|
|
26706
|
+
* No registry needed - just deploys and returns the address.
|
|
26460
26707
|
* @param {string} holonId - Unique identifier for the holon
|
|
26461
26708
|
* @param {string} name - Display name for the holon
|
|
26462
|
-
* @param {Object} [options] -
|
|
26463
|
-
* @
|
|
26709
|
+
* @param {Object} [options={}] - Deployment options
|
|
26710
|
+
* @param {bigint|string} [options.steepness] - Steepness factor
|
|
26711
|
+
* @param {number} [options.nZones=6] - Number of zones
|
|
26712
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, type: string, steepness: bigint, nZones: number, creatorUserId: string, name: string}>} Deployment details
|
|
26464
26713
|
*/
|
|
26465
26714
|
async deployBundleDirect(holonId, name2, options = {}) {
|
|
26466
26715
|
const steepness = options.steepness;
|
|
@@ -26471,9 +26720,9 @@ class ContractDeployer {
|
|
|
26471
26720
|
});
|
|
26472
26721
|
}
|
|
26473
26722
|
/**
|
|
26474
|
-
* Deploy a TestToken
|
|
26723
|
+
* Deploy a TestToken ERC20 for testing.
|
|
26475
26724
|
* @param {string} [initialSupply='1000000'] - Initial supply in whole tokens
|
|
26476
|
-
* @returns {Promise<{contract, address, txHash}>}
|
|
26725
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, type: string, initialSupply: string}>} Deployment details
|
|
26477
26726
|
*/
|
|
26478
26727
|
async deployTestToken(initialSupply = "1000000") {
|
|
26479
26728
|
const ethers = await this._loadEthers();
|
|
@@ -26490,11 +26739,12 @@ class ContractDeployer {
|
|
|
26490
26739
|
};
|
|
26491
26740
|
}
|
|
26492
26741
|
/**
|
|
26493
|
-
* Create a holon bundle through the Holons registry
|
|
26742
|
+
* Create a holon bundle through the Holons registry.
|
|
26494
26743
|
* @param {string} creatorUserId - Creator's user ID
|
|
26495
26744
|
* @param {string} name - Bundle name
|
|
26496
26745
|
* @param {number} [parameter=70] - Split parameter
|
|
26497
|
-
* @returns {Promise<{address, txHash}>}
|
|
26746
|
+
* @returns {Promise<{address: string, txHash: string, name: string, creatorUserId: string}>} Created holon details
|
|
26747
|
+
* @throws {Error} If Holons registry not deployed
|
|
26498
26748
|
*/
|
|
26499
26749
|
async createHolonBundle(creatorUserId, name2, parameter = 70) {
|
|
26500
26750
|
if (!this.deployedContracts.holons) {
|
|
@@ -26523,10 +26773,11 @@ class ContractDeployer {
|
|
|
26523
26773
|
};
|
|
26524
26774
|
}
|
|
26525
26775
|
/**
|
|
26526
|
-
* Get contract instance by address
|
|
26776
|
+
* Get contract instance by address and type.
|
|
26527
26777
|
* @param {string} address - Contract address
|
|
26528
|
-
* @param {string} type - Contract type (Splitter, Managed, Zoned,
|
|
26529
|
-
* @returns {Promise<
|
|
26778
|
+
* @param {string} type - Contract type (Splitter, Managed, Zoned, Appreciative, Bundle, Holons, TestToken)
|
|
26779
|
+
* @returns {Promise<Object>} Ethers.js Contract instance
|
|
26780
|
+
* @throws {Error} If unknown contract type
|
|
26530
26781
|
*/
|
|
26531
26782
|
async getContract(address, type2) {
|
|
26532
26783
|
const abi2 = ABIs[type2];
|
|
@@ -26536,22 +26787,26 @@ class ContractDeployer {
|
|
|
26536
26787
|
return this.chainManager.getContract(address, abi2.abi);
|
|
26537
26788
|
}
|
|
26538
26789
|
/**
|
|
26539
|
-
* Get deployed contract addresses
|
|
26540
|
-
* @returns {Object}
|
|
26790
|
+
* Get deployed contract addresses.
|
|
26791
|
+
* @returns {Object} Map of contract names to addresses
|
|
26541
26792
|
*/
|
|
26542
26793
|
getDeployedAddresses() {
|
|
26543
26794
|
return { ...this.deployedContracts };
|
|
26544
26795
|
}
|
|
26545
26796
|
/**
|
|
26546
|
-
* Load previously deployed
|
|
26547
|
-
* @param {Object} addresses -
|
|
26797
|
+
* Load previously deployed contract addresses.
|
|
26798
|
+
* @param {Object} addresses - Map of contract names to addresses
|
|
26548
26799
|
*/
|
|
26549
26800
|
loadDeployedAddresses(addresses) {
|
|
26550
26801
|
this.deployedContracts = { ...addresses };
|
|
26551
26802
|
}
|
|
26552
26803
|
/**
|
|
26553
|
-
* Internal
|
|
26804
|
+
* Internal helper to deploy a contract.
|
|
26554
26805
|
* @private
|
|
26806
|
+
* @param {Array} abi - Contract ABI
|
|
26807
|
+
* @param {string} bytecode - Contract bytecode
|
|
26808
|
+
* @param {Array} constructorArgs - Constructor arguments
|
|
26809
|
+
* @returns {Promise<{contract: Object, address: string, txHash: string, explorerUrl: string|null}>} Deployment result
|
|
26555
26810
|
*/
|
|
26556
26811
|
async _deployContract(abi2, bytecode2, constructorArgs) {
|
|
26557
26812
|
const result = await this.chainManager.deployContract(abi2, bytecode2, constructorArgs);
|
|
@@ -26564,6 +26819,12 @@ class ContractDeployer {
|
|
|
26564
26819
|
}
|
|
26565
26820
|
}
|
|
26566
26821
|
class ContractOperations {
|
|
26822
|
+
/**
|
|
26823
|
+
* Create a new ContractOperations instance.
|
|
26824
|
+
* @param {Object} contract - Ethers.js Contract instance
|
|
26825
|
+
* @param {string} type - Contract type (Splitter, Managed, Zoned, Appreciative, Bundle)
|
|
26826
|
+
* @param {ChainManager} chainManager - Chain manager instance
|
|
26827
|
+
*/
|
|
26567
26828
|
constructor(contract, type2, chainManager) {
|
|
26568
26829
|
this.contract = contract;
|
|
26569
26830
|
this.type = type2;
|
|
@@ -26571,12 +26832,13 @@ class ContractOperations {
|
|
|
26571
26832
|
this.ethers = null;
|
|
26572
26833
|
}
|
|
26573
26834
|
/**
|
|
26574
|
-
* Load ethers dynamically
|
|
26835
|
+
* Load ethers.js library dynamically.
|
|
26575
26836
|
* @private
|
|
26837
|
+
* @returns {Promise<Object>} Ethers.js module
|
|
26576
26838
|
*/
|
|
26577
26839
|
async _loadEthers() {
|
|
26578
26840
|
if (!this.ethers) {
|
|
26579
|
-
this.ethers = await import("./index-
|
|
26841
|
+
this.ethers = await import("./index-DeZ1xz_s.js");
|
|
26580
26842
|
}
|
|
26581
26843
|
return this.ethers;
|
|
26582
26844
|
}
|
|
@@ -26584,9 +26846,9 @@ class ContractOperations {
|
|
|
26584
26846
|
// MEMBER MANAGEMENT
|
|
26585
26847
|
// ========================================================================
|
|
26586
26848
|
/**
|
|
26587
|
-
* Add a single member to the contract
|
|
26849
|
+
* Add a single member to the contract.
|
|
26588
26850
|
* @param {string} userId - User identifier (string-based, e.g., 'alice', 'telegram_12345')
|
|
26589
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
26851
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
26590
26852
|
*/
|
|
26591
26853
|
async addMember(userId) {
|
|
26592
26854
|
const tx = await this.contract.addMember(userId);
|
|
@@ -26594,9 +26856,9 @@ class ContractOperations {
|
|
|
26594
26856
|
return { txHash: receipt.hash, receipt };
|
|
26595
26857
|
}
|
|
26596
26858
|
/**
|
|
26597
|
-
* Add multiple members at once (batch operation)
|
|
26859
|
+
* Add multiple members at once (batch operation).
|
|
26598
26860
|
* @param {string[]} userIds - Array of user identifiers
|
|
26599
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
26861
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
26600
26862
|
*/
|
|
26601
26863
|
async addMembers(userIds) {
|
|
26602
26864
|
const tx = await this.contract.addMembers(userIds);
|
|
@@ -26604,8 +26866,8 @@ class ContractOperations {
|
|
|
26604
26866
|
return { txHash: receipt.hash, receipt };
|
|
26605
26867
|
}
|
|
26606
26868
|
/**
|
|
26607
|
-
* Get all member user IDs
|
|
26608
|
-
* @returns {Promise<string[]>}
|
|
26869
|
+
* Get all member user IDs.
|
|
26870
|
+
* @returns {Promise<string[]>} Array of user IDs
|
|
26609
26871
|
*/
|
|
26610
26872
|
async getMembers() {
|
|
26611
26873
|
await this.contract.userIds();
|
|
@@ -26627,9 +26889,9 @@ class ContractOperations {
|
|
|
26627
26889
|
}
|
|
26628
26890
|
}
|
|
26629
26891
|
/**
|
|
26630
|
-
* Check if a user is a member
|
|
26892
|
+
* Check if a user is a member.
|
|
26631
26893
|
* @param {string} userId - User identifier
|
|
26632
|
-
* @returns {Promise<boolean>}
|
|
26894
|
+
* @returns {Promise<boolean>} True if user is a member
|
|
26633
26895
|
*/
|
|
26634
26896
|
async isMember(userId) {
|
|
26635
26897
|
try {
|
|
@@ -26642,7 +26904,7 @@ class ContractOperations {
|
|
|
26642
26904
|
}
|
|
26643
26905
|
}
|
|
26644
26906
|
/**
|
|
26645
|
-
* Get the address associated with a user ID
|
|
26907
|
+
* Get the Ethereum address associated with a user ID.
|
|
26646
26908
|
* @param {string} userId - User identifier
|
|
26647
26909
|
* @returns {Promise<string>} Ethereum address (or zero address if not set)
|
|
26648
26910
|
*/
|
|
@@ -26653,10 +26915,10 @@ class ContractOperations {
|
|
|
26653
26915
|
// FUND DISTRIBUTION
|
|
26654
26916
|
// ========================================================================
|
|
26655
26917
|
/**
|
|
26656
|
-
* Trigger reward distribution for ERC20 tokens
|
|
26918
|
+
* Trigger reward distribution for ERC20 tokens.
|
|
26657
26919
|
* @param {string} tokenAddress - ERC20 token contract address
|
|
26658
26920
|
* @param {string|bigint} amount - Amount in wei (or token's smallest unit)
|
|
26659
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
26921
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
26660
26922
|
*/
|
|
26661
26923
|
async reward(tokenAddress, amount) {
|
|
26662
26924
|
const ethers = await this._loadEthers();
|
|
@@ -26666,9 +26928,9 @@ class ContractOperations {
|
|
|
26666
26928
|
return { txHash: receipt.hash, receipt };
|
|
26667
26929
|
}
|
|
26668
26930
|
/**
|
|
26669
|
-
* Trigger reward distribution for ETH
|
|
26931
|
+
* Trigger reward distribution for ETH.
|
|
26670
26932
|
* @param {string} amount - Amount in ETH (e.g., '1.5' for 1.5 ETH)
|
|
26671
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
26933
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
26672
26934
|
*/
|
|
26673
26935
|
async rewardEth(amount) {
|
|
26674
26936
|
const ethers = await this._loadEthers();
|
|
@@ -26682,9 +26944,9 @@ class ContractOperations {
|
|
|
26682
26944
|
return { txHash: receipt.hash, receipt };
|
|
26683
26945
|
}
|
|
26684
26946
|
/**
|
|
26685
|
-
* Send ETH directly to contract (triggers receive/fallback)
|
|
26947
|
+
* Send ETH directly to contract (triggers receive/fallback).
|
|
26686
26948
|
* @param {string} amount - Amount in ETH
|
|
26687
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
26949
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
26688
26950
|
*/
|
|
26689
26951
|
async sendEth(amount) {
|
|
26690
26952
|
const ethers = await this._loadEthers();
|
|
@@ -26698,10 +26960,10 @@ class ContractOperations {
|
|
|
26698
26960
|
return { txHash: receipt.hash, receipt };
|
|
26699
26961
|
}
|
|
26700
26962
|
/**
|
|
26701
|
-
* Claim accumulated rewards for a user
|
|
26963
|
+
* Claim accumulated rewards for a user.
|
|
26702
26964
|
* @param {string} userId - User identifier
|
|
26703
26965
|
* @param {string} beneficiaryAddress - Ethereum address to receive funds
|
|
26704
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
26966
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
26705
26967
|
*/
|
|
26706
26968
|
async claim(userId, beneficiaryAddress) {
|
|
26707
26969
|
const tx = await this.contract.claim(userId, beneficiaryAddress);
|
|
@@ -26709,9 +26971,9 @@ class ContractOperations {
|
|
|
26709
26971
|
return { txHash: receipt.hash, receipt };
|
|
26710
26972
|
}
|
|
26711
26973
|
/**
|
|
26712
|
-
* Get ETH balance for a user
|
|
26974
|
+
* Get ETH balance for a user.
|
|
26713
26975
|
* @param {string} userId - User identifier
|
|
26714
|
-
* @returns {Promise<string>} Balance in ETH
|
|
26976
|
+
* @returns {Promise<string>} Balance in ETH as decimal string
|
|
26715
26977
|
*/
|
|
26716
26978
|
async getEthBalance(userId) {
|
|
26717
26979
|
const ethers = await this._loadEthers();
|
|
@@ -26719,10 +26981,10 @@ class ContractOperations {
|
|
|
26719
26981
|
return ethers.formatEther(balance);
|
|
26720
26982
|
}
|
|
26721
26983
|
/**
|
|
26722
|
-
* Get ERC20 token balance for a user
|
|
26984
|
+
* Get ERC20 token balance for a user.
|
|
26723
26985
|
* @param {string} userId - User identifier
|
|
26724
26986
|
* @param {string} tokenAddress - ERC20 token address
|
|
26725
|
-
* @returns {Promise<string>} Balance in tokens (18 decimals assumed)
|
|
26987
|
+
* @returns {Promise<string>} Balance in tokens (18 decimals assumed) as decimal string
|
|
26726
26988
|
*/
|
|
26727
26989
|
async getTokenBalance(userId, tokenAddress) {
|
|
26728
26990
|
const ethers = await this._loadEthers();
|
|
@@ -26730,17 +26992,17 @@ class ContractOperations {
|
|
|
26730
26992
|
return ethers.formatUnits(balance, 18);
|
|
26731
26993
|
}
|
|
26732
26994
|
/**
|
|
26733
|
-
* Check if user has already claimed
|
|
26995
|
+
* Check if user has already claimed rewards.
|
|
26734
26996
|
* @param {string} userId - User identifier
|
|
26735
|
-
* @returns {Promise<boolean>}
|
|
26997
|
+
* @returns {Promise<boolean>} True if user has claimed
|
|
26736
26998
|
*/
|
|
26737
26999
|
async hasClaimed(userId) {
|
|
26738
27000
|
return this.contract.hasClaimed(userId);
|
|
26739
27001
|
}
|
|
26740
27002
|
/**
|
|
26741
|
-
* Get total deposited amount for a token
|
|
27003
|
+
* Get total deposited amount for a token.
|
|
26742
27004
|
* @param {string} tokenAddress - Token address (use zero address for ETH)
|
|
26743
|
-
* @returns {Promise<string>}
|
|
27005
|
+
* @returns {Promise<string>} Total deposited as decimal string
|
|
26744
27006
|
*/
|
|
26745
27007
|
async getTotalDeposited(tokenAddress) {
|
|
26746
27008
|
const ethers = await this._loadEthers();
|
|
@@ -26751,10 +27013,11 @@ class ContractOperations {
|
|
|
26751
27013
|
// SPLITTER OPERATIONS
|
|
26752
27014
|
// ========================================================================
|
|
26753
27015
|
/**
|
|
26754
|
-
* Set the internal/external split percentages (Splitter only)
|
|
27016
|
+
* Set the internal/external split percentages (Splitter only).
|
|
26755
27017
|
* @param {number} internalPct - Internal percentage (0-100)
|
|
26756
27018
|
* @param {number} externalPct - External percentage (0-100, must sum to 100 with internal)
|
|
26757
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
27019
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
27020
|
+
* @throws {Error} If percentages don't sum to 100 or not a Splitter contract
|
|
26758
27021
|
*/
|
|
26759
27022
|
async setContractSplit(internalPct, externalPct) {
|
|
26760
27023
|
this._requireType(["Splitter"]);
|
|
@@ -26766,8 +27029,9 @@ class ContractOperations {
|
|
|
26766
27029
|
return { txHash: receipt.hash, receipt };
|
|
26767
27030
|
}
|
|
26768
27031
|
/**
|
|
26769
|
-
* Get current split percentages (Splitter only)
|
|
26770
|
-
* @returns {Promise<{internal: number, external: number}>}
|
|
27032
|
+
* Get current split percentages (Splitter only).
|
|
27033
|
+
* @returns {Promise<{internal: number, external: number}>} Split percentages
|
|
27034
|
+
* @throws {Error} If not a Splitter contract
|
|
26771
27035
|
*/
|
|
26772
27036
|
async getContractSplit() {
|
|
26773
27037
|
this._requireType(["Splitter"]);
|
|
@@ -27127,8 +27391,10 @@ class ContractOperations {
|
|
|
27127
27391
|
// UTILITIES
|
|
27128
27392
|
// ========================================================================
|
|
27129
27393
|
/**
|
|
27130
|
-
* Require specific contract type(s)
|
|
27394
|
+
* Require specific contract type(s).
|
|
27131
27395
|
* @private
|
|
27396
|
+
* @param {string[]} allowedTypes - Array of allowed contract types
|
|
27397
|
+
* @throws {Error} If contract type doesn't match
|
|
27132
27398
|
*/
|
|
27133
27399
|
_requireType(allowedTypes) {
|
|
27134
27400
|
if (!allowedTypes.includes(this.type)) {
|
|
@@ -27136,26 +27402,26 @@ class ContractOperations {
|
|
|
27136
27402
|
}
|
|
27137
27403
|
}
|
|
27138
27404
|
/**
|
|
27139
|
-
* Get raw contract instance for advanced usage
|
|
27140
|
-
* @returns {Contract
|
|
27405
|
+
* Get raw contract instance for advanced usage.
|
|
27406
|
+
* @returns {Object} Ethers.js Contract instance
|
|
27141
27407
|
*/
|
|
27142
27408
|
getRawContract() {
|
|
27143
27409
|
return this.contract;
|
|
27144
27410
|
}
|
|
27145
27411
|
/**
|
|
27146
|
-
* Execute a raw contract call
|
|
27412
|
+
* Execute a raw contract call.
|
|
27147
27413
|
* @param {string} method - Method name
|
|
27148
|
-
* @param {
|
|
27149
|
-
* @returns {Promise
|
|
27414
|
+
* @param {...*} args - Method arguments
|
|
27415
|
+
* @returns {Promise<*>} Method return value
|
|
27150
27416
|
*/
|
|
27151
27417
|
async call(method, ...args) {
|
|
27152
27418
|
return this.contract[method](...args);
|
|
27153
27419
|
}
|
|
27154
27420
|
/**
|
|
27155
|
-
* Execute a raw contract transaction
|
|
27421
|
+
* Execute a raw contract transaction.
|
|
27156
27422
|
* @param {string} method - Method name
|
|
27157
|
-
* @param {
|
|
27158
|
-
* @returns {Promise<{txHash, receipt}>}
|
|
27423
|
+
* @param {...*} args - Method arguments
|
|
27424
|
+
* @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
|
|
27159
27425
|
*/
|
|
27160
27426
|
async send(method, ...args) {
|
|
27161
27427
|
const tx = await this.contract[method](...args);
|
|
@@ -27164,6 +27430,11 @@ class ContractOperations {
|
|
|
27164
27430
|
}
|
|
27165
27431
|
}
|
|
27166
27432
|
class HolonContracts {
|
|
27433
|
+
/**
|
|
27434
|
+
* Create a new HolonContracts instance.
|
|
27435
|
+
* @param {ChainManager} chainManager - Chain manager instance
|
|
27436
|
+
* @param {ContractDeployer} [deployer] - Contract deployer instance (auto-created if not provided)
|
|
27437
|
+
*/
|
|
27167
27438
|
constructor(chainManager, deployer) {
|
|
27168
27439
|
this.chainManager = chainManager;
|
|
27169
27440
|
this.deployer = deployer || new ContractDeployer(chainManager);
|
|
@@ -27171,18 +27442,19 @@ class HolonContracts {
|
|
|
27171
27442
|
this.storage = null;
|
|
27172
27443
|
}
|
|
27173
27444
|
/**
|
|
27174
|
-
* Set storage adapter for persisting holon-contract mappings
|
|
27175
|
-
* @param {Object} storage - Storage adapter with get/set methods
|
|
27445
|
+
* Set storage adapter for persisting holon-contract mappings.
|
|
27446
|
+
* @param {Object} storage - Storage adapter with get/set/delete methods
|
|
27176
27447
|
*/
|
|
27177
27448
|
setStorage(storage) {
|
|
27178
27449
|
this.storage = storage;
|
|
27179
27450
|
}
|
|
27180
27451
|
/**
|
|
27181
|
-
* Deploy a new contract for a holon
|
|
27452
|
+
* Deploy a new contract for a holon.
|
|
27182
27453
|
* @param {string} holonId - Holon identifier
|
|
27183
27454
|
* @param {string} [type='Splitter'] - Contract type (Splitter, Managed, Zoned, Appreciative, Bundle)
|
|
27184
|
-
* @param {Object} [options] - Deployment options
|
|
27185
|
-
* @returns {Promise<{contract, address, operations}>}
|
|
27455
|
+
* @param {Object} [options={}] - Deployment options (varies by contract type)
|
|
27456
|
+
* @returns {Promise<{contract: Object, address: string, operations: ContractOperations, txHash: string, type: string}>} Deployment details
|
|
27457
|
+
* @throws {Error} If holon already has a contract
|
|
27186
27458
|
*/
|
|
27187
27459
|
async deploy(holonId, type2 = "Splitter", options = {}) {
|
|
27188
27460
|
if (this.holonContracts.has(holonId)) {
|
|
@@ -27241,11 +27513,12 @@ class HolonContracts {
|
|
|
27241
27513
|
};
|
|
27242
27514
|
}
|
|
27243
27515
|
/**
|
|
27244
|
-
* Link a holon to an existing contract
|
|
27516
|
+
* Link a holon to an existing deployed contract.
|
|
27245
27517
|
* @param {string} holonId - Holon identifier
|
|
27246
27518
|
* @param {string} contractAddress - Existing contract address
|
|
27247
27519
|
* @param {string} [type='Splitter'] - Contract type
|
|
27248
|
-
* @returns {Promise<{contract, address, operations}>}
|
|
27520
|
+
* @returns {Promise<{contract: Object, address: string, operations: ContractOperations, type: string}>} Link details
|
|
27521
|
+
* @throws {Error} If holon already has a contract or contract is invalid
|
|
27249
27522
|
*/
|
|
27250
27523
|
async link(holonId, contractAddress, type2 = "Splitter") {
|
|
27251
27524
|
if (this.holonContracts.has(holonId)) {
|
|
@@ -27280,9 +27553,9 @@ class HolonContracts {
|
|
|
27280
27553
|
};
|
|
27281
27554
|
}
|
|
27282
27555
|
/**
|
|
27283
|
-
* Unlink a holon from its contract
|
|
27556
|
+
* Unlink a holon from its contract.
|
|
27284
27557
|
* @param {string} holonId - Holon identifier
|
|
27285
|
-
* @returns {boolean} True if unlinked, false if no contract was linked
|
|
27558
|
+
* @returns {Promise<boolean>} True if unlinked, false if no contract was linked
|
|
27286
27559
|
*/
|
|
27287
27560
|
async unlink(holonId) {
|
|
27288
27561
|
if (!this.holonContracts.has(holonId)) {
|
|
@@ -27295,52 +27568,52 @@ class HolonContracts {
|
|
|
27295
27568
|
return true;
|
|
27296
27569
|
}
|
|
27297
27570
|
/**
|
|
27298
|
-
* Get contract for a holon
|
|
27571
|
+
* Get contract instance for a holon.
|
|
27299
27572
|
* @param {string} holonId - Holon identifier
|
|
27300
|
-
* @returns {
|
|
27573
|
+
* @returns {Object|null} Ethers.js Contract instance or null if not found
|
|
27301
27574
|
*/
|
|
27302
27575
|
getContract(holonId) {
|
|
27303
27576
|
const data = this.holonContracts.get(holonId);
|
|
27304
27577
|
return data?.contract || null;
|
|
27305
27578
|
}
|
|
27306
27579
|
/**
|
|
27307
|
-
* Get contract address for a holon
|
|
27580
|
+
* Get contract address for a holon.
|
|
27308
27581
|
* @param {string} holonId - Holon identifier
|
|
27309
|
-
* @returns {string|null}
|
|
27582
|
+
* @returns {string|null} Contract address or null if not found
|
|
27310
27583
|
*/
|
|
27311
27584
|
getAddress(holonId) {
|
|
27312
27585
|
const data = this.holonContracts.get(holonId);
|
|
27313
27586
|
return data?.address || null;
|
|
27314
27587
|
}
|
|
27315
27588
|
/**
|
|
27316
|
-
* Get operations wrapper for a holon
|
|
27589
|
+
* Get operations wrapper for a holon.
|
|
27317
27590
|
* @param {string} holonId - Holon identifier
|
|
27318
|
-
* @returns {ContractOperations|null}
|
|
27591
|
+
* @returns {ContractOperations|null} Operations wrapper or null if not found
|
|
27319
27592
|
*/
|
|
27320
27593
|
getOperations(holonId) {
|
|
27321
27594
|
const data = this.holonContracts.get(holonId);
|
|
27322
27595
|
return data?.operations || null;
|
|
27323
27596
|
}
|
|
27324
27597
|
/**
|
|
27325
|
-
* Get contract type for a holon
|
|
27598
|
+
* Get contract type for a holon.
|
|
27326
27599
|
* @param {string} holonId - Holon identifier
|
|
27327
|
-
* @returns {string|null}
|
|
27600
|
+
* @returns {string|null} Contract type or null if not found
|
|
27328
27601
|
*/
|
|
27329
27602
|
getType(holonId) {
|
|
27330
27603
|
const data = this.holonContracts.get(holonId);
|
|
27331
27604
|
return data?.type || null;
|
|
27332
27605
|
}
|
|
27333
27606
|
/**
|
|
27334
|
-
* Check if a holon has a contract
|
|
27607
|
+
* Check if a holon has a linked contract.
|
|
27335
27608
|
* @param {string} holonId - Holon identifier
|
|
27336
|
-
* @returns {boolean}
|
|
27609
|
+
* @returns {boolean} True if holon has a contract
|
|
27337
27610
|
*/
|
|
27338
27611
|
hasContract(holonId) {
|
|
27339
27612
|
return this.holonContracts.has(holonId);
|
|
27340
27613
|
}
|
|
27341
27614
|
/**
|
|
27342
|
-
* Get all holon-contract mappings
|
|
27343
|
-
* @returns {Array<{holonId, address, type}>}
|
|
27615
|
+
* Get all holon-contract mappings.
|
|
27616
|
+
* @returns {Array<{holonId: string, address: string, type: string, deployedAt?: string, linkedAt?: string}>} Array of mappings
|
|
27344
27617
|
*/
|
|
27345
27618
|
listAll() {
|
|
27346
27619
|
const result = [];
|
|
@@ -27356,9 +27629,9 @@ class HolonContracts {
|
|
|
27356
27629
|
return result;
|
|
27357
27630
|
}
|
|
27358
27631
|
/**
|
|
27359
|
-
* Get holons by contract type
|
|
27632
|
+
* Get holons by contract type.
|
|
27360
27633
|
* @param {string} type - Contract type
|
|
27361
|
-
* @returns {Array<{holonId, address}>}
|
|
27634
|
+
* @returns {Array<{holonId: string, address: string}>} Array of holons with matching type
|
|
27362
27635
|
*/
|
|
27363
27636
|
getByType(type2) {
|
|
27364
27637
|
const result = [];
|
|
@@ -27373,8 +27646,8 @@ class HolonContracts {
|
|
|
27373
27646
|
return result;
|
|
27374
27647
|
}
|
|
27375
27648
|
/**
|
|
27376
|
-
* Load holon-contract mappings from storage
|
|
27377
|
-
* @returns {Promise<number>} Number of mappings loaded
|
|
27649
|
+
* Load holon-contract mappings from storage.
|
|
27650
|
+
* @returns {Promise<number>} Number of mappings successfully loaded
|
|
27378
27651
|
*/
|
|
27379
27652
|
async loadFromStorage() {
|
|
27380
27653
|
if (!this.storage) {
|
|
@@ -27405,8 +27678,10 @@ class HolonContracts {
|
|
|
27405
27678
|
return loaded;
|
|
27406
27679
|
}
|
|
27407
27680
|
/**
|
|
27408
|
-
* Save a holon-contract mapping to storage
|
|
27681
|
+
* Save a holon-contract mapping to storage.
|
|
27409
27682
|
* @private
|
|
27683
|
+
* @param {string} holonId - Holon identifier
|
|
27684
|
+
* @param {Object} data - Holon contract data
|
|
27410
27685
|
*/
|
|
27411
27686
|
async _saveMapping(holonId, data) {
|
|
27412
27687
|
if (!this.storage) return;
|
|
@@ -27425,10 +27700,10 @@ class HolonContracts {
|
|
|
27425
27700
|
}
|
|
27426
27701
|
}
|
|
27427
27702
|
/**
|
|
27428
|
-
* Get required holon operations
|
|
27703
|
+
* Get required holon operations, throwing if not linked.
|
|
27429
27704
|
* @param {string} holonId - Holon identifier
|
|
27430
|
-
* @returns {ContractOperations}
|
|
27431
|
-
* @throws {Error} If holon has no contract
|
|
27705
|
+
* @returns {ContractOperations} Operations wrapper
|
|
27706
|
+
* @throws {Error} If holon has no linked contract
|
|
27432
27707
|
*/
|
|
27433
27708
|
requireOperations(holonId) {
|
|
27434
27709
|
const ops = this.getOperations(holonId);
|
|
@@ -27462,6 +27737,10 @@ const SANKEY_EVENTS = {
|
|
|
27462
27737
|
ContractSplitConfigured: "ContractSplitConfigured"
|
|
27463
27738
|
};
|
|
27464
27739
|
class EventListener {
|
|
27740
|
+
/**
|
|
27741
|
+
* Create a new EventListener instance.
|
|
27742
|
+
* @param {ChainManager} chainManager - Chain manager instance
|
|
27743
|
+
*/
|
|
27465
27744
|
constructor(chainManager) {
|
|
27466
27745
|
this.chainManager = chainManager;
|
|
27467
27746
|
this.listeners = /* @__PURE__ */ new Map();
|
|
@@ -27470,10 +27749,10 @@ class EventListener {
|
|
|
27470
27749
|
this.sankeyLinks = [];
|
|
27471
27750
|
}
|
|
27472
27751
|
/**
|
|
27473
|
-
* Start listening to all Sankey-relevant events on a contract
|
|
27474
|
-
* @param {string} contractAddress -
|
|
27752
|
+
* Start listening to all Sankey-relevant events on a contract.
|
|
27753
|
+
* @param {string} contractAddress - Contract address
|
|
27475
27754
|
* @param {string} holonId - Human-readable holon identifier
|
|
27476
|
-
* @param {Object} contract -
|
|
27755
|
+
* @param {Object} contract - Ethers.js contract instance
|
|
27477
27756
|
*/
|
|
27478
27757
|
async listenToContract(contractAddress, holonId, contract) {
|
|
27479
27758
|
const eventFilters = [
|
|
@@ -27502,7 +27781,8 @@ class EventListener {
|
|
|
27502
27781
|
this.listeners.set(contractAddress, { contract, holonId });
|
|
27503
27782
|
}
|
|
27504
27783
|
/**
|
|
27505
|
-
* Stop listening to a contract
|
|
27784
|
+
* Stop listening to a specific contract.
|
|
27785
|
+
* @param {string} contractAddress - Contract address
|
|
27506
27786
|
*/
|
|
27507
27787
|
stopListening(contractAddress) {
|
|
27508
27788
|
const listener = this.listeners.get(contractAddress);
|
|
@@ -27512,7 +27792,7 @@ class EventListener {
|
|
|
27512
27792
|
}
|
|
27513
27793
|
}
|
|
27514
27794
|
/**
|
|
27515
|
-
* Stop all listeners
|
|
27795
|
+
* Stop all active listeners.
|
|
27516
27796
|
*/
|
|
27517
27797
|
stopAll() {
|
|
27518
27798
|
for (const [address, listener] of this.listeners) {
|
|
@@ -27521,7 +27801,12 @@ class EventListener {
|
|
|
27521
27801
|
this.listeners.clear();
|
|
27522
27802
|
}
|
|
27523
27803
|
/**
|
|
27524
|
-
* Handle incoming event and transform to Sankey data
|
|
27804
|
+
* Handle incoming event and transform to Sankey data.
|
|
27805
|
+
* @private
|
|
27806
|
+
* @param {string} eventName - Event name
|
|
27807
|
+
* @param {Array} args - Event arguments
|
|
27808
|
+
* @param {string} contractAddress - Contract address
|
|
27809
|
+
* @param {string} holonId - Holon identifier
|
|
27525
27810
|
*/
|
|
27526
27811
|
_handleEvent(eventName, args, contractAddress, holonId) {
|
|
27527
27812
|
const event = args[args.length - 1];
|
|
@@ -27542,7 +27827,11 @@ class EventListener {
|
|
|
27542
27827
|
}
|
|
27543
27828
|
}
|
|
27544
27829
|
/**
|
|
27545
|
-
* Parse event data based on event type
|
|
27830
|
+
* Parse event data based on event type.
|
|
27831
|
+
* @private
|
|
27832
|
+
* @param {string} eventName - Event name
|
|
27833
|
+
* @param {Array} args - Event arguments
|
|
27834
|
+
* @returns {Object} Parsed event data
|
|
27546
27835
|
*/
|
|
27547
27836
|
_parseEventData(eventName, args) {
|
|
27548
27837
|
switch (eventName) {
|
|
@@ -27635,7 +27924,9 @@ class EventListener {
|
|
|
27635
27924
|
}
|
|
27636
27925
|
}
|
|
27637
27926
|
/**
|
|
27638
|
-
* Update Sankey nodes and links based on event
|
|
27927
|
+
* Update Sankey nodes and links based on event.
|
|
27928
|
+
* @private
|
|
27929
|
+
* @param {Object} event - Parsed event object
|
|
27639
27930
|
*/
|
|
27640
27931
|
_updateSankeyData(event) {
|
|
27641
27932
|
const { type: type2, data } = event;
|
|
@@ -27697,7 +27988,11 @@ class EventListener {
|
|
|
27697
27988
|
}
|
|
27698
27989
|
}
|
|
27699
27990
|
/**
|
|
27700
|
-
* Ensure a node exists in the Sankey graph
|
|
27991
|
+
* Ensure a node exists in the Sankey graph.
|
|
27992
|
+
* @private
|
|
27993
|
+
* @param {string} id - Node ID
|
|
27994
|
+
* @param {string} type - Node type (external, contract, user, wallet)
|
|
27995
|
+
* @param {string} label - Display label
|
|
27701
27996
|
*/
|
|
27702
27997
|
_ensureNode(id2, type2, label) {
|
|
27703
27998
|
if (!this.sankeyNodes.has(id2)) {
|
|
@@ -27705,9 +28000,13 @@ class EventListener {
|
|
|
27705
28000
|
}
|
|
27706
28001
|
}
|
|
27707
28002
|
/**
|
|
27708
|
-
* Get Sankey-compatible data for visualization
|
|
27709
|
-
* @param {Object} options - Filter options
|
|
27710
|
-
* @
|
|
28003
|
+
* Get Sankey-compatible data for visualization.
|
|
28004
|
+
* @param {Object} [options={}] - Filter options
|
|
28005
|
+
* @param {string} [options.tokenAddress] - Filter by token address
|
|
28006
|
+
* @param {number} [options.fromBlock] - Filter from block number
|
|
28007
|
+
* @param {number} [options.toBlock] - Filter to block number
|
|
28008
|
+
* @param {string} [options.minValue] - Minimum value to include
|
|
28009
|
+
* @returns {Object} Sankey data with nodes and links arrays
|
|
27711
28010
|
*/
|
|
27712
28011
|
getSankeyData(options = {}) {
|
|
27713
28012
|
const { tokenAddress, fromBlock, toBlock, minValue } = options;
|
|
@@ -27750,8 +28049,8 @@ class EventListener {
|
|
|
27750
28049
|
};
|
|
27751
28050
|
}
|
|
27752
28051
|
/**
|
|
27753
|
-
* Get aggregated flow summary
|
|
27754
|
-
* @returns {Object} Summary
|
|
28052
|
+
* Get aggregated flow summary statistics.
|
|
28053
|
+
* @returns {Object} Summary with inflow/outflow totals and distribution breakdown
|
|
27755
28054
|
*/
|
|
27756
28055
|
getFlowSummary() {
|
|
27757
28056
|
const summary = {
|
|
@@ -27787,10 +28086,13 @@ class EventListener {
|
|
|
27787
28086
|
};
|
|
27788
28087
|
}
|
|
27789
28088
|
/**
|
|
27790
|
-
* Query historical events from blockchain
|
|
27791
|
-
* @param {Object} contract -
|
|
28089
|
+
* Query historical events from blockchain.
|
|
28090
|
+
* @param {Object} contract - Ethers.js contract instance
|
|
27792
28091
|
* @param {string} eventName - Event name to query
|
|
27793
|
-
* @param {Object} options -
|
|
28092
|
+
* @param {Object} [options={}] - Query options
|
|
28093
|
+
* @param {number} [options.fromBlock=0] - Starting block number
|
|
28094
|
+
* @param {number|string} [options.toBlock='latest'] - Ending block number
|
|
28095
|
+
* @returns {Promise<Array>} Array of parsed events
|
|
27794
28096
|
*/
|
|
27795
28097
|
async queryPastEvents(contract, eventName, options = {}) {
|
|
27796
28098
|
const { fromBlock = 0, toBlock = "latest" } = options;
|
|
@@ -27811,10 +28113,11 @@ class EventListener {
|
|
|
27811
28113
|
}
|
|
27812
28114
|
}
|
|
27813
28115
|
/**
|
|
27814
|
-
* Build Sankey data from historical events
|
|
27815
|
-
* @param {Object} contract -
|
|
28116
|
+
* Build Sankey data from historical blockchain events.
|
|
28117
|
+
* @param {Object} contract - Ethers.js contract instance
|
|
27816
28118
|
* @param {string} holonId - Holon identifier
|
|
27817
|
-
* @param {Object} options - Query options
|
|
28119
|
+
* @param {Object} [options={}] - Query options (fromBlock, toBlock)
|
|
28120
|
+
* @returns {Promise<Object>} Sankey data with nodes and links
|
|
27818
28121
|
*/
|
|
27819
28122
|
async buildFromHistory(contract, holonId, options = {}) {
|
|
27820
28123
|
const eventTypes = [
|
|
@@ -27836,7 +28139,7 @@ class EventListener {
|
|
|
27836
28139
|
return this.getSankeyData();
|
|
27837
28140
|
}
|
|
27838
28141
|
/**
|
|
27839
|
-
* Clear all stored data
|
|
28142
|
+
* Clear all stored event data.
|
|
27840
28143
|
*/
|
|
27841
28144
|
clear() {
|
|
27842
28145
|
this.eventHistory = [];
|
|
@@ -27844,7 +28147,8 @@ class EventListener {
|
|
|
27844
28147
|
this.sankeyLinks = [];
|
|
27845
28148
|
}
|
|
27846
28149
|
/**
|
|
27847
|
-
* Export data for persistence
|
|
28150
|
+
* Export data for persistence.
|
|
28151
|
+
* @returns {Object} Serializable event data
|
|
27848
28152
|
*/
|
|
27849
28153
|
export() {
|
|
27850
28154
|
return {
|
|
@@ -27857,7 +28161,8 @@ class EventListener {
|
|
|
27857
28161
|
};
|
|
27858
28162
|
}
|
|
27859
28163
|
/**
|
|
27860
|
-
* Import previously exported data
|
|
28164
|
+
* Import previously exported data.
|
|
28165
|
+
* @param {Object} data - Previously exported data
|
|
27861
28166
|
*/
|
|
27862
28167
|
import(data) {
|
|
27863
28168
|
this.eventHistory = data.events || [];
|
|
@@ -35834,16 +36139,18 @@ function formatEthNumber(wei) {
|
|
|
35834
36139
|
}
|
|
35835
36140
|
class ContractQueries {
|
|
35836
36141
|
/**
|
|
35837
|
-
*
|
|
36142
|
+
* Create a new ContractQueries instance.
|
|
36143
|
+
* @param {Object} provider - Ethers.js provider instance
|
|
35838
36144
|
*/
|
|
35839
36145
|
constructor(provider) {
|
|
35840
36146
|
this.provider = provider;
|
|
35841
36147
|
}
|
|
35842
36148
|
/**
|
|
35843
|
-
* Get a contract instance with the appropriate ABI
|
|
36149
|
+
* Get a contract instance with the appropriate ABI.
|
|
35844
36150
|
* @param {string} address - Contract address
|
|
35845
|
-
* @param {string} flavor - Contract flavor (Splitter, Managed, Zoned, Appreciative, Bundle)
|
|
35846
|
-
* @returns {
|
|
36151
|
+
* @param {string} flavor - Contract flavor (Splitter, Managed, Zoned, Appreciative, Bundle, Holons)
|
|
36152
|
+
* @returns {Object} Ethers.js Contract instance
|
|
36153
|
+
* @throws {Error} If unknown contract flavor
|
|
35847
36154
|
*/
|
|
35848
36155
|
getContract(address, flavor) {
|
|
35849
36156
|
const abi2 = ContractABIs[flavor];
|
|
@@ -35853,9 +36160,9 @@ class ContractQueries {
|
|
|
35853
36160
|
return new Contract(address, abi2, this.provider);
|
|
35854
36161
|
}
|
|
35855
36162
|
/**
|
|
35856
|
-
* Auto-detect contract flavor by calling flavor()
|
|
36163
|
+
* Auto-detect contract flavor by calling flavor() method.
|
|
35857
36164
|
* @param {string} address - Contract address
|
|
35858
|
-
* @returns {Promise<string>} Contract flavor
|
|
36165
|
+
* @returns {Promise<string>} Contract flavor or 'Unknown'
|
|
35859
36166
|
*/
|
|
35860
36167
|
async detectFlavor(address) {
|
|
35861
36168
|
const minAbi = [
|
|
@@ -35871,7 +36178,10 @@ class ContractQueries {
|
|
|
35871
36178
|
}
|
|
35872
36179
|
// ==================== COMMON QUERIES ====================
|
|
35873
36180
|
/**
|
|
35874
|
-
* Get basic contract
|
|
36181
|
+
* Get basic contract information.
|
|
36182
|
+
* @param {string} address - Contract address
|
|
36183
|
+
* @param {string} flavor - Contract flavor
|
|
36184
|
+
* @returns {Promise<{address: string, name: string, flavor: string, version: string, creator: string, memberCount: number}>} Contract info
|
|
35875
36185
|
*/
|
|
35876
36186
|
async getContractInfo(address, flavor) {
|
|
35877
36187
|
const contract = this.getContract(address, flavor);
|
|
@@ -35892,7 +36202,10 @@ class ContractQueries {
|
|
|
35892
36202
|
};
|
|
35893
36203
|
}
|
|
35894
36204
|
/**
|
|
35895
|
-
* Get all
|
|
36205
|
+
* Get all member user IDs.
|
|
36206
|
+
* @param {string} address - Contract address
|
|
36207
|
+
* @param {string} flavor - Contract flavor
|
|
36208
|
+
* @returns {Promise<string[]>} Array of user IDs
|
|
35896
36209
|
*/
|
|
35897
36210
|
async getMembers(address, flavor) {
|
|
35898
36211
|
const contract = this.getContract(address, flavor);
|
|
@@ -35905,7 +36218,11 @@ class ContractQueries {
|
|
|
35905
36218
|
return members;
|
|
35906
36219
|
}
|
|
35907
36220
|
/**
|
|
35908
|
-
* Get user's ETH balance
|
|
36221
|
+
* Get user's ETH balance in the contract.
|
|
36222
|
+
* @param {string} address - Contract address
|
|
36223
|
+
* @param {string} flavor - Contract flavor
|
|
36224
|
+
* @param {string} userId - User identifier
|
|
36225
|
+
* @returns {Promise<{wei: string, eth: number}>} Balance in wei and ETH
|
|
35909
36226
|
*/
|
|
35910
36227
|
async getUserEthBalance(address, flavor, userId) {
|
|
35911
36228
|
const contract = this.getContract(address, flavor);
|
|
@@ -35916,7 +36233,12 @@ class ContractQueries {
|
|
|
35916
36233
|
};
|
|
35917
36234
|
}
|
|
35918
36235
|
/**
|
|
35919
|
-
* Get user's token balance
|
|
36236
|
+
* Get user's ERC20 token balance in the contract.
|
|
36237
|
+
* @param {string} address - Contract address
|
|
36238
|
+
* @param {string} flavor - Contract flavor
|
|
36239
|
+
* @param {string} userId - User identifier
|
|
36240
|
+
* @param {string} tokenAddress - ERC20 token address
|
|
36241
|
+
* @returns {Promise<{wei: string, formatted: number}>} Token balance
|
|
35920
36242
|
*/
|
|
35921
36243
|
async getUserTokenBalance(address, flavor, userId, tokenAddress) {
|
|
35922
36244
|
const contract = this.getContract(address, flavor);
|
|
@@ -35927,7 +36249,11 @@ class ContractQueries {
|
|
|
35927
36249
|
};
|
|
35928
36250
|
}
|
|
35929
36251
|
/**
|
|
35930
|
-
* Get total deposited for a token
|
|
36252
|
+
* Get total deposited amount for a token.
|
|
36253
|
+
* @param {string} address - Contract address
|
|
36254
|
+
* @param {string} flavor - Contract flavor
|
|
36255
|
+
* @param {string} [tokenAddress] - Token address (defaults to ETH/zero address)
|
|
36256
|
+
* @returns {Promise<{wei: string, formatted: number}>} Total deposited
|
|
35931
36257
|
*/
|
|
35932
36258
|
async getTotalDeposited(address, flavor, tokenAddress) {
|
|
35933
36259
|
const contract = this.getContract(address, flavor);
|
|
@@ -35939,7 +36265,11 @@ class ContractQueries {
|
|
|
35939
36265
|
};
|
|
35940
36266
|
}
|
|
35941
36267
|
/**
|
|
35942
|
-
* Check if user has claimed
|
|
36268
|
+
* Check if user has claimed their rewards.
|
|
36269
|
+
* @param {string} address - Contract address
|
|
36270
|
+
* @param {string} flavor - Contract flavor
|
|
36271
|
+
* @param {string} userId - User identifier
|
|
36272
|
+
* @returns {Promise<boolean>} True if claimed
|
|
35943
36273
|
*/
|
|
35944
36274
|
async hasClaimed(address, flavor, userId) {
|
|
35945
36275
|
const contract = this.getContract(address, flavor);
|
|
@@ -36272,7 +36602,9 @@ class ContractQueries {
|
|
|
36272
36602
|
}
|
|
36273
36603
|
// ==================== FULL SNAPSHOT ====================
|
|
36274
36604
|
/**
|
|
36275
|
-
* Get complete contract state snapshot
|
|
36605
|
+
* Get complete contract state snapshot including all members and configuration.
|
|
36606
|
+
* @param {string} address - Contract address
|
|
36607
|
+
* @returns {Promise<Object>} Complete contract state
|
|
36276
36608
|
*/
|
|
36277
36609
|
async getFullSnapshot(address) {
|
|
36278
36610
|
const flavor = await this.detectFlavor(address);
|
|
@@ -36325,37 +36657,89 @@ class ContractQueries {
|
|
|
36325
36657
|
}
|
|
36326
36658
|
function withAIMethods(Base) {
|
|
36327
36659
|
return class extends Base {
|
|
36660
|
+
/**
|
|
36661
|
+
* Internal method to ensure AI services are initialized.
|
|
36662
|
+
* @private
|
|
36663
|
+
* @throws {Error} If AI services are not initialized
|
|
36664
|
+
*/
|
|
36328
36665
|
_requireAI() {
|
|
36329
36666
|
if (!this._ai) {
|
|
36330
36667
|
throw new Error("AI services not initialized. Provide openaiKey in config.");
|
|
36331
36668
|
}
|
|
36332
36669
|
}
|
|
36333
36670
|
// --- Core LLM Methods ---
|
|
36671
|
+
/**
|
|
36672
|
+
* Summarize text using AI.
|
|
36673
|
+
* @param {string} text - Text content to summarize
|
|
36674
|
+
* @param {Object} [options={}] - Summarization options (model, maxLength, etc.)
|
|
36675
|
+
* @returns {Promise<string>} Generated summary
|
|
36676
|
+
*/
|
|
36334
36677
|
async summarize(text, options = {}) {
|
|
36335
36678
|
this._requireAI();
|
|
36336
36679
|
return this._ai.llm.summarize(text, options);
|
|
36337
36680
|
}
|
|
36681
|
+
/**
|
|
36682
|
+
* Analyze text for a specific aspect using AI.
|
|
36683
|
+
* @param {string} text - Text content to analyze
|
|
36684
|
+
* @param {string} aspect - Aspect to analyze (e.g., 'sentiment', 'tone', 'themes')
|
|
36685
|
+
* @param {Object} [options={}] - Analysis options
|
|
36686
|
+
* @returns {Promise<string>} Analysis result
|
|
36687
|
+
*/
|
|
36338
36688
|
async analyze(text, aspect, options = {}) {
|
|
36339
36689
|
this._requireAI();
|
|
36340
36690
|
return this._ai.llm.analyze(text, aspect, options);
|
|
36341
36691
|
}
|
|
36692
|
+
/**
|
|
36693
|
+
* Extract keywords from text using AI.
|
|
36694
|
+
* @param {string} text - Text content to process
|
|
36695
|
+
* @param {Object} [options={}] - Extraction options (count, focus, etc.)
|
|
36696
|
+
* @returns {Promise<string[]>} Array of extracted keywords
|
|
36697
|
+
*/
|
|
36342
36698
|
async extractKeywords(text, options = {}) {
|
|
36343
36699
|
this._requireAI();
|
|
36344
36700
|
return this._ai.llm.extractKeywords(text, options);
|
|
36345
36701
|
}
|
|
36702
|
+
/**
|
|
36703
|
+
* Categorize text into one of the provided categories.
|
|
36704
|
+
* @param {string} text - Text content to categorize
|
|
36705
|
+
* @param {string[]} categories - Array of possible categories
|
|
36706
|
+
* @param {Object} [options={}] - Categorization options
|
|
36707
|
+
* @returns {Promise<string>} Selected category
|
|
36708
|
+
*/
|
|
36346
36709
|
async categorize(text, categories, options = {}) {
|
|
36347
36710
|
this._requireAI();
|
|
36348
36711
|
return this._ai.llm.categorize(text, categories, options);
|
|
36349
36712
|
}
|
|
36713
|
+
/**
|
|
36714
|
+
* Translate text to target language using AI.
|
|
36715
|
+
* @param {string} text - Text to translate
|
|
36716
|
+
* @param {string} targetLanguage - Target language (e.g., 'Spanish', 'French')
|
|
36717
|
+
* @param {Object} [options={}] - Translation options
|
|
36718
|
+
* @returns {Promise<string>} Translated text
|
|
36719
|
+
*/
|
|
36350
36720
|
async translate(text, targetLanguage, options = {}) {
|
|
36351
36721
|
this._requireAI();
|
|
36352
36722
|
return this._ai.llm.translate(text, targetLanguage, options);
|
|
36353
36723
|
}
|
|
36724
|
+
/**
|
|
36725
|
+
* Generate questions from text using AI.
|
|
36726
|
+
* @param {string} text - Text content to generate questions from
|
|
36727
|
+
* @param {Object} [options={}] - Generation options (count, type, etc.)
|
|
36728
|
+
* @returns {Promise<string[]>} Array of generated questions
|
|
36729
|
+
*/
|
|
36354
36730
|
async generateQuestions(text, options = {}) {
|
|
36355
36731
|
this._requireAI();
|
|
36356
36732
|
return this._ai.llm.generateQuestions(text, options);
|
|
36357
36733
|
}
|
|
36358
36734
|
// --- Schema Extraction ---
|
|
36735
|
+
/**
|
|
36736
|
+
* Extract structured data from text according to a lens schema.
|
|
36737
|
+
* @param {string} text - Text to extract data from
|
|
36738
|
+
* @param {string} lensName - Name of lens with defined schema
|
|
36739
|
+
* @param {Object} [options={}] - Extraction options
|
|
36740
|
+
* @returns {Promise<Object>} Extracted data matching schema
|
|
36741
|
+
* @throws {Error} If schema not found for lens
|
|
36742
|
+
*/
|
|
36359
36743
|
async extractToSchema(text, lensName, options = {}) {
|
|
36360
36744
|
this._requireAI();
|
|
36361
36745
|
const schemaObj = await this.getSchema(lensName);
|
|
@@ -36365,189 +36749,482 @@ function withAIMethods(Base) {
|
|
|
36365
36749
|
return this._ai.schemaExtractor.extractToSchema(text, schemaObj, options);
|
|
36366
36750
|
}
|
|
36367
36751
|
// --- Fuzzy JSON Operations ---
|
|
36752
|
+
/**
|
|
36753
|
+
* AI-powered fuzzy addition of JSON objects.
|
|
36754
|
+
* @param {Object} obj1 - First object
|
|
36755
|
+
* @param {Object} obj2 - Second object
|
|
36756
|
+
* @param {Object} [options={}] - Operation options
|
|
36757
|
+
* @returns {Promise<Object>} Result of fuzzy addition
|
|
36758
|
+
*/
|
|
36368
36759
|
async jsonAdd(obj1, obj2, options = {}) {
|
|
36369
36760
|
this._requireAI();
|
|
36370
36761
|
return this._ai.jsonOps.add(obj1, obj2, options);
|
|
36371
36762
|
}
|
|
36763
|
+
/**
|
|
36764
|
+
* AI-powered fuzzy subtraction of JSON objects.
|
|
36765
|
+
* @param {Object} obj1 - Object to subtract from
|
|
36766
|
+
* @param {Object} obj2 - Object to subtract
|
|
36767
|
+
* @param {Object} [options={}] - Operation options
|
|
36768
|
+
* @returns {Promise<Object>} Result of fuzzy subtraction
|
|
36769
|
+
*/
|
|
36372
36770
|
async jsonSubtract(obj1, obj2, options = {}) {
|
|
36373
36771
|
this._requireAI();
|
|
36374
36772
|
return this._ai.jsonOps.subtract(obj1, obj2, options);
|
|
36375
36773
|
}
|
|
36774
|
+
/**
|
|
36775
|
+
* AI-powered fuzzy union of JSON objects.
|
|
36776
|
+
* @param {Object} obj1 - First object
|
|
36777
|
+
* @param {Object} obj2 - Second object
|
|
36778
|
+
* @param {Object} [options={}] - Operation options
|
|
36779
|
+
* @returns {Promise<Object>} Result of fuzzy union
|
|
36780
|
+
*/
|
|
36376
36781
|
async jsonUnion(obj1, obj2, options = {}) {
|
|
36377
36782
|
this._requireAI();
|
|
36378
36783
|
return this._ai.jsonOps.union(obj1, obj2, options);
|
|
36379
36784
|
}
|
|
36785
|
+
/**
|
|
36786
|
+
* AI-powered fuzzy difference of JSON objects.
|
|
36787
|
+
* @param {Object} obj1 - First object
|
|
36788
|
+
* @param {Object} obj2 - Second object
|
|
36789
|
+
* @param {Object} [options={}] - Operation options
|
|
36790
|
+
* @returns {Promise<Object>} Result of fuzzy difference
|
|
36791
|
+
*/
|
|
36380
36792
|
async jsonDifference(obj1, obj2, options = {}) {
|
|
36381
36793
|
this._requireAI();
|
|
36382
36794
|
return this._ai.jsonOps.difference(obj1, obj2, options);
|
|
36383
36795
|
}
|
|
36796
|
+
/**
|
|
36797
|
+
* AI-powered fuzzy concatenation of JSON objects.
|
|
36798
|
+
* @param {Object} obj1 - First object
|
|
36799
|
+
* @param {Object} obj2 - Second object
|
|
36800
|
+
* @param {Object} [options={}] - Operation options
|
|
36801
|
+
* @returns {Promise<Object>} Result of fuzzy concatenation
|
|
36802
|
+
*/
|
|
36384
36803
|
async jsonConcatenate(obj1, obj2, options = {}) {
|
|
36385
36804
|
this._requireAI();
|
|
36386
36805
|
return this._ai.jsonOps.concatenate(obj1, obj2, options);
|
|
36387
36806
|
}
|
|
36388
36807
|
// --- Embeddings & Semantic Search ---
|
|
36808
|
+
/**
|
|
36809
|
+
* Generate embedding vector for text.
|
|
36810
|
+
* @param {string} text - Text to embed
|
|
36811
|
+
* @returns {Promise<number[]>} Embedding vector
|
|
36812
|
+
*/
|
|
36389
36813
|
async embed(text) {
|
|
36390
36814
|
this._requireAI();
|
|
36391
36815
|
return this._ai.embeddings.embed(text);
|
|
36392
36816
|
}
|
|
36817
|
+
/**
|
|
36818
|
+
* Perform semantic search on holon data using embeddings.
|
|
36819
|
+
* @param {string} query - Search query text
|
|
36820
|
+
* @param {string} holonId - Holon to search within
|
|
36821
|
+
* @param {string} lensName - Lens to search within
|
|
36822
|
+
* @param {Object} [options={}] - Search options (limit, threshold, etc.)
|
|
36823
|
+
* @returns {Promise<Object[]>} Ranked search results
|
|
36824
|
+
*/
|
|
36393
36825
|
async semanticSearch(query, holonId, lensName, options = {}) {
|
|
36394
36826
|
this._requireAI();
|
|
36395
36827
|
return this._ai.embeddings.semanticSearch(query, holonId, lensName, options);
|
|
36396
36828
|
}
|
|
36829
|
+
/**
|
|
36830
|
+
* Store data with automatically generated embedding.
|
|
36831
|
+
* @param {string} holonId - Holon ID to store in
|
|
36832
|
+
* @param {string} lensName - Lens name to store under
|
|
36833
|
+
* @param {Object} data - Data object to store
|
|
36834
|
+
* @param {string} [textField='description'] - Field to use for embedding generation
|
|
36835
|
+
* @returns {Promise<Object>} Stored data with embedding
|
|
36836
|
+
*/
|
|
36397
36837
|
async storeWithEmbedding(holonId, lensName, data, textField = "description") {
|
|
36398
36838
|
this._requireAI();
|
|
36399
36839
|
return this._ai.embeddings.storeWithEmbedding(holonId, lensName, data, textField);
|
|
36400
36840
|
}
|
|
36401
36841
|
// --- Multi-Perspective Council ---
|
|
36842
|
+
/**
|
|
36843
|
+
* Ask a question to the multi-perspective AI council.
|
|
36844
|
+
* @param {string} question - Question to ask
|
|
36845
|
+
* @param {Object} [options={}] - Council options (perspectives, synthesis, etc.)
|
|
36846
|
+
* @returns {Promise<Object>} Council responses and synthesis
|
|
36847
|
+
*/
|
|
36402
36848
|
async askCouncil(question, options = {}) {
|
|
36403
36849
|
this._requireAI();
|
|
36404
36850
|
return this._ai.council.ask(question, options);
|
|
36405
36851
|
}
|
|
36852
|
+
/**
|
|
36853
|
+
* Ask a question to a custom set of perspectives.
|
|
36854
|
+
* @param {string} question - Question to ask
|
|
36855
|
+
* @param {string[]} perspectives - Array of perspective descriptions
|
|
36856
|
+
* @param {Object} [options={}] - Council options
|
|
36857
|
+
* @returns {Promise<Object>} Custom council responses and synthesis
|
|
36858
|
+
*/
|
|
36406
36859
|
async askCouncilCustom(question, perspectives, options = {}) {
|
|
36407
36860
|
this._requireAI();
|
|
36408
36861
|
return this._ai.council.askCustom(question, perspectives, options);
|
|
36409
36862
|
}
|
|
36410
36863
|
// --- Text-to-Speech ---
|
|
36864
|
+
/**
|
|
36865
|
+
* Convert text to speech audio.
|
|
36866
|
+
* @param {string} text - Text to convert to speech
|
|
36867
|
+
* @param {string} [voice='nova'] - Voice to use (alloy, echo, fable, onyx, nova, shimmer)
|
|
36868
|
+
* @param {Object} [options={}] - TTS options (speed, format, etc.)
|
|
36869
|
+
* @returns {Promise<Buffer>} Audio buffer
|
|
36870
|
+
*/
|
|
36411
36871
|
async textToSpeech(text, voice = "nova", options = {}) {
|
|
36412
36872
|
this._requireAI();
|
|
36413
36873
|
return this._ai.tts.speak(text, voice, options);
|
|
36414
36874
|
}
|
|
36875
|
+
/**
|
|
36876
|
+
* Convert text to speech audio (base64 encoded).
|
|
36877
|
+
* @param {string} text - Text to convert to speech
|
|
36878
|
+
* @param {string} [voice='nova'] - Voice to use
|
|
36879
|
+
* @param {Object} [options={}] - TTS options
|
|
36880
|
+
* @returns {Promise<string>} Base64-encoded audio
|
|
36881
|
+
*/
|
|
36415
36882
|
async textToSpeechBase64(text, voice = "nova", options = {}) {
|
|
36416
36883
|
this._requireAI();
|
|
36417
36884
|
return this._ai.tts.speakBase64(text, voice, options);
|
|
36418
36885
|
}
|
|
36419
36886
|
// --- Natural Language Queries ---
|
|
36887
|
+
/**
|
|
36888
|
+
* Execute a natural language query on holon data.
|
|
36889
|
+
* @param {string} query - Natural language query
|
|
36890
|
+
* @param {string|null} [holonId=null] - Optional holon to query
|
|
36891
|
+
* @param {string|null} [lensName=null] - Optional lens to query
|
|
36892
|
+
* @param {Object} [options={}] - Query options
|
|
36893
|
+
* @returns {Promise<Object>} Query results
|
|
36894
|
+
*/
|
|
36420
36895
|
async nlQuery(query, holonId = null, lensName = null, options = {}) {
|
|
36421
36896
|
this._requireAI();
|
|
36422
36897
|
return this._ai.nlQuery.execute(query, holonId, lensName, options);
|
|
36423
36898
|
}
|
|
36899
|
+
/**
|
|
36900
|
+
* Parse a natural language query into structured components.
|
|
36901
|
+
* @param {string} query - Natural language query
|
|
36902
|
+
* @returns {Promise<Object>} Parsed query structure
|
|
36903
|
+
*/
|
|
36424
36904
|
async parseNLQuery(query) {
|
|
36425
36905
|
this._requireAI();
|
|
36426
36906
|
return this._ai.nlQuery.parse(query);
|
|
36427
36907
|
}
|
|
36428
36908
|
// --- Auto-Classification ---
|
|
36909
|
+
/**
|
|
36910
|
+
* Classify content to determine appropriate lens.
|
|
36911
|
+
* @param {string|Object} content - Content to classify
|
|
36912
|
+
* @param {Object} [options={}] - Classification options
|
|
36913
|
+
* @returns {Promise<string>} Recommended lens name
|
|
36914
|
+
*/
|
|
36429
36915
|
async classifyToLens(content, options = {}) {
|
|
36430
36916
|
this._requireAI();
|
|
36431
36917
|
return this._ai.classifier.classifyToLens(content, options);
|
|
36432
36918
|
}
|
|
36919
|
+
/**
|
|
36920
|
+
* Automatically classify and store content in appropriate lens.
|
|
36921
|
+
* @param {string} holonId - Holon to store in
|
|
36922
|
+
* @param {string|Object} content - Content to classify and store
|
|
36923
|
+
* @param {Object} [options={}] - Storage options
|
|
36924
|
+
* @returns {Promise<Object>} Stored data with classification info
|
|
36925
|
+
*/
|
|
36433
36926
|
async autoStore(holonId, content, options = {}) {
|
|
36434
36927
|
this._requireAI();
|
|
36435
36928
|
return this._ai.classifier.autoStore(holonId, content, options);
|
|
36436
36929
|
}
|
|
36930
|
+
/**
|
|
36931
|
+
* Register a lens for auto-classification.
|
|
36932
|
+
* @param {string} lensName - Lens name to register
|
|
36933
|
+
* @param {string} description - Lens description for classification
|
|
36934
|
+
* @param {string[]} [keywords=[]] - Keywords associated with lens
|
|
36935
|
+
*/
|
|
36437
36936
|
registerLensForClassification(lensName, description2, keywords2 = []) {
|
|
36438
36937
|
this._requireAI();
|
|
36439
36938
|
this._ai.classifier.registerLens(lensName, description2, keywords2);
|
|
36440
36939
|
}
|
|
36441
36940
|
// --- Spatial Analysis ---
|
|
36941
|
+
/**
|
|
36942
|
+
* Analyze a geographic region using AI.
|
|
36943
|
+
* @param {string} holonId - H3 holon ID to analyze
|
|
36944
|
+
* @param {string|null} [lensName=null] - Optional lens to focus on
|
|
36945
|
+
* @param {string|null} [aspect=null] - Optional aspect to analyze
|
|
36946
|
+
* @param {Object} [options={}] - Analysis options
|
|
36947
|
+
* @returns {Promise<Object>} Region analysis
|
|
36948
|
+
*/
|
|
36442
36949
|
async analyzeRegion(holonId, lensName = null, aspect = null, options = {}) {
|
|
36443
36950
|
this._requireAI();
|
|
36444
36951
|
return this._ai.spatial.analyzeRegion(holonId, lensName, aspect, options);
|
|
36445
36952
|
}
|
|
36953
|
+
/**
|
|
36954
|
+
* Compare two geographic regions using AI.
|
|
36955
|
+
* @param {string} holon1 - First H3 holon ID
|
|
36956
|
+
* @param {string} holon2 - Second H3 holon ID
|
|
36957
|
+
* @param {string|null} [lensName=null] - Optional lens to focus comparison
|
|
36958
|
+
* @returns {Promise<Object>} Comparison analysis
|
|
36959
|
+
*/
|
|
36446
36960
|
async compareRegions(holon1, holon2, lensName = null) {
|
|
36447
36961
|
this._requireAI();
|
|
36448
36962
|
return this._ai.spatial.compareRegions(holon1, holon2, lensName);
|
|
36449
36963
|
}
|
|
36964
|
+
/**
|
|
36965
|
+
* Analyze spatial trends over time.
|
|
36966
|
+
* @param {string} holonId - H3 holon ID
|
|
36967
|
+
* @param {string} lensName - Lens to analyze trends for
|
|
36968
|
+
* @param {Object|null} [timeRange=null] - Time range for trend analysis
|
|
36969
|
+
* @returns {Promise<Object>} Trend analysis
|
|
36970
|
+
*/
|
|
36450
36971
|
async spatialTrends(holonId, lensName, timeRange = null) {
|
|
36451
36972
|
this._requireAI();
|
|
36452
36973
|
return this._ai.spatial.spatialTrends(holonId, lensName, timeRange);
|
|
36453
36974
|
}
|
|
36454
36975
|
// --- Smart Aggregation ---
|
|
36976
|
+
/**
|
|
36977
|
+
* Intelligently upcast data with AI-powered aggregation.
|
|
36978
|
+
* @param {string} holonId - H3 holon ID to upcast from
|
|
36979
|
+
* @param {string} lensName - Lens to upcast
|
|
36980
|
+
* @param {Object} [options={}] - Upcast options
|
|
36981
|
+
* @returns {Promise<Object>} Smart upcast result
|
|
36982
|
+
*/
|
|
36455
36983
|
async smartUpcast(holonId, lensName, options = {}) {
|
|
36456
36984
|
this._requireAI();
|
|
36457
36985
|
return this._ai.aggregation.smartUpcast(holonId, lensName, options);
|
|
36458
36986
|
}
|
|
36987
|
+
/**
|
|
36988
|
+
* Generate AI-powered summary of holon data.
|
|
36989
|
+
* @param {string} holonId - Holon ID to summarize
|
|
36990
|
+
* @returns {Promise<string>} Generated holon summary
|
|
36991
|
+
*/
|
|
36459
36992
|
async generateHolonSummary(holonId) {
|
|
36460
36993
|
this._requireAI();
|
|
36461
36994
|
return this._ai.aggregation.generateHolonSummary(holonId);
|
|
36462
36995
|
}
|
|
36463
36996
|
// --- Federation Advisor ---
|
|
36997
|
+
/**
|
|
36998
|
+
* Get AI suggestions for holon federations.
|
|
36999
|
+
* @param {string} holonId - Holon to analyze for federation
|
|
37000
|
+
* @param {Object} [options={}] - Suggestion options
|
|
37001
|
+
* @returns {Promise<Object[]>} Array of federation suggestions
|
|
37002
|
+
*/
|
|
36464
37003
|
async suggestFederations(holonId, options = {}) {
|
|
36465
37004
|
this._requireAI();
|
|
36466
37005
|
return this._ai.federationAdvisor.suggestFederations(holonId, options);
|
|
36467
37006
|
}
|
|
37007
|
+
/**
|
|
37008
|
+
* Analyze health of holon's federations.
|
|
37009
|
+
* @param {string} holonId - Holon to analyze
|
|
37010
|
+
* @returns {Promise<Object>} Federation health report
|
|
37011
|
+
*/
|
|
36468
37012
|
async analyzeFederationHealth(holonId) {
|
|
36469
37013
|
this._requireAI();
|
|
36470
37014
|
return this._ai.federationAdvisor.analyzeFederationHealth(holonId);
|
|
36471
37015
|
}
|
|
37016
|
+
/**
|
|
37017
|
+
* Get AI recommendations for optimizing federations.
|
|
37018
|
+
* @param {string} holonId - Holon to optimize
|
|
37019
|
+
* @returns {Promise<Object>} Optimization recommendations
|
|
37020
|
+
*/
|
|
36472
37021
|
async optimizeFederation(holonId) {
|
|
36473
37022
|
this._requireAI();
|
|
36474
37023
|
return this._ai.federationAdvisor.optimizeFederation(holonId);
|
|
36475
37024
|
}
|
|
36476
37025
|
// --- Relationship Discovery ---
|
|
37026
|
+
/**
|
|
37027
|
+
* Discover relationships between data items using AI.
|
|
37028
|
+
* @param {string} holonId - Holon to analyze
|
|
37029
|
+
* @param {string|null} [lensName=null] - Optional lens to focus on
|
|
37030
|
+
* @returns {Promise<Object[]>} Discovered relationships
|
|
37031
|
+
*/
|
|
36477
37032
|
async discoverRelationships(holonId, lensName = null) {
|
|
36478
37033
|
this._requireAI();
|
|
36479
37034
|
return this._ai.relationships.discoverRelationships(holonId, lensName);
|
|
36480
37035
|
}
|
|
37036
|
+
/**
|
|
37037
|
+
* Find similar items using AI and embeddings.
|
|
37038
|
+
* @param {Object} item - Item to find similar items for
|
|
37039
|
+
* @param {string} holonId - Holon to search within
|
|
37040
|
+
* @param {string|null} [lensName=null] - Optional lens to search
|
|
37041
|
+
* @param {Object} [options={}] - Search options (limit, threshold, etc.)
|
|
37042
|
+
* @returns {Promise<Object[]>} Similar items
|
|
37043
|
+
*/
|
|
36481
37044
|
async findSimilar(item, holonId, lensName = null, options = {}) {
|
|
36482
37045
|
this._requireAI();
|
|
36483
37046
|
return this._ai.relationships.findSimilar(item, holonId, lensName, options);
|
|
36484
37047
|
}
|
|
37048
|
+
/**
|
|
37049
|
+
* Build relationship graph for holon data.
|
|
37050
|
+
* @param {string} holonId - Holon ID
|
|
37051
|
+
* @param {string} lensName - Lens to build graph for
|
|
37052
|
+
* @returns {Promise<Object>} Relationship graph structure
|
|
37053
|
+
*/
|
|
36485
37054
|
async buildRelationshipGraph(holonId, lensName) {
|
|
36486
37055
|
this._requireAI();
|
|
36487
37056
|
return this._ai.relationships.buildGraph(holonId, lensName);
|
|
36488
37057
|
}
|
|
37058
|
+
/**
|
|
37059
|
+
* Get AI suggestions for connecting an item to others.
|
|
37060
|
+
* @param {Object} item - Item to suggest connections for
|
|
37061
|
+
* @param {string} holonId - Holon context
|
|
37062
|
+
* @param {string} lensName - Lens context
|
|
37063
|
+
* @returns {Promise<Object[]>} Connection suggestions
|
|
37064
|
+
*/
|
|
36489
37065
|
async suggestConnections(item, holonId, lensName) {
|
|
36490
37066
|
this._requireAI();
|
|
36491
37067
|
return this._ai.relationships.suggestConnections(item, holonId, lensName);
|
|
36492
37068
|
}
|
|
36493
37069
|
// --- Task Breakdown ---
|
|
37070
|
+
/**
|
|
37071
|
+
* Break down complex item into subtasks using AI.
|
|
37072
|
+
* @param {Object} item - Item to break down
|
|
37073
|
+
* @param {string} holonId - Holon to store breakdown in
|
|
37074
|
+
* @param {string} lensName - Lens to use for subtasks
|
|
37075
|
+
* @param {Object} [options={}] - Breakdown options (depth, strategy, etc.)
|
|
37076
|
+
* @returns {Promise<Object>} Breakdown structure
|
|
37077
|
+
*/
|
|
36494
37078
|
async breakdown(item, holonId, lensName, options = {}) {
|
|
36495
37079
|
this._requireAI();
|
|
36496
37080
|
return this._ai.taskBreakdown.breakdown(item, holonId, lensName, options);
|
|
36497
37081
|
}
|
|
37082
|
+
/**
|
|
37083
|
+
* Get AI suggestion for breakdown strategy.
|
|
37084
|
+
* @param {Object} item - Item to analyze
|
|
37085
|
+
* @returns {Promise<Object>} Suggested breakdown strategy
|
|
37086
|
+
*/
|
|
36498
37087
|
async suggestBreakdownStrategy(item) {
|
|
36499
37088
|
this._requireAI();
|
|
36500
37089
|
return this._ai.taskBreakdown.suggestStrategy(item);
|
|
36501
37090
|
}
|
|
37091
|
+
/**
|
|
37092
|
+
* Flatten hierarchical breakdown into linear array.
|
|
37093
|
+
* @param {Object} breakdownResult - Breakdown structure to flatten
|
|
37094
|
+
* @returns {Object[]} Flattened breakdown items
|
|
37095
|
+
*/
|
|
36502
37096
|
flattenBreakdown(breakdownResult) {
|
|
36503
37097
|
this._requireAI();
|
|
36504
37098
|
return this._ai.taskBreakdown.flatten(breakdownResult);
|
|
36505
37099
|
}
|
|
37100
|
+
/**
|
|
37101
|
+
* Get dependency-ordered list of breakdown items.
|
|
37102
|
+
* @param {Object} breakdownResult - Breakdown structure
|
|
37103
|
+
* @returns {Object[]} Items ordered by dependencies
|
|
37104
|
+
*/
|
|
36506
37105
|
getBreakdownDependencyOrder(breakdownResult) {
|
|
36507
37106
|
this._requireAI();
|
|
36508
37107
|
return this._ai.taskBreakdown.getDependencyOrder(breakdownResult);
|
|
36509
37108
|
}
|
|
37109
|
+
/**
|
|
37110
|
+
* Get progress status of breakdown items.
|
|
37111
|
+
* @param {string} holonId - Holon ID
|
|
37112
|
+
* @param {string} lensName - Lens name
|
|
37113
|
+
* @param {string} itemId - Parent item ID
|
|
37114
|
+
* @returns {Promise<Object>} Progress report
|
|
37115
|
+
*/
|
|
36510
37116
|
async getBreakdownProgress(holonId, lensName, itemId) {
|
|
36511
37117
|
this._requireAI();
|
|
36512
37118
|
return this._ai.taskBreakdown.getProgress(holonId, lensName, itemId);
|
|
36513
37119
|
}
|
|
36514
37120
|
// --- H3 Geospatial AI ---
|
|
37121
|
+
/**
|
|
37122
|
+
* Get AI suggestion for optimal H3 resolution for item.
|
|
37123
|
+
* @param {Object} item - Item to analyze
|
|
37124
|
+
* @param {Object} [options={}] - Analysis options
|
|
37125
|
+
* @returns {Promise<number>} Suggested H3 resolution level
|
|
37126
|
+
*/
|
|
36515
37127
|
async suggestH3Resolution(item, options = {}) {
|
|
36516
37128
|
this._requireAI();
|
|
36517
37129
|
return this._ai.h3ai.suggestResolution(item, options);
|
|
36518
37130
|
}
|
|
37131
|
+
/**
|
|
37132
|
+
* Analyze H3 distribution patterns in data.
|
|
37133
|
+
* @param {string} holonId - H3 holon to analyze
|
|
37134
|
+
* @param {string} lensName - Lens to analyze
|
|
37135
|
+
* @param {Object} [options={}] - Analysis options
|
|
37136
|
+
* @returns {Promise<Object>} Distribution analysis
|
|
37137
|
+
*/
|
|
36519
37138
|
async analyzeH3Distribution(holonId, lensName, options = {}) {
|
|
36520
37139
|
this._requireAI();
|
|
36521
37140
|
return this._ai.h3ai.analyzeDistribution(holonId, lensName, options);
|
|
36522
37141
|
}
|
|
37142
|
+
/**
|
|
37143
|
+
* Find relevance of neighbor H3 cells.
|
|
37144
|
+
* @param {string} holonId - H3 holon ID
|
|
37145
|
+
* @param {string} lensName - Lens to analyze
|
|
37146
|
+
* @param {Object} [options={}] - Analysis options
|
|
37147
|
+
* @returns {Promise<Object[]>} Neighbor relevance scores
|
|
37148
|
+
*/
|
|
36523
37149
|
async findH3NeighborRelevance(holonId, lensName, options = {}) {
|
|
36524
37150
|
this._requireAI();
|
|
36525
37151
|
return this._ai.h3ai.findNeighborRelevance(holonId, lensName, options);
|
|
36526
37152
|
}
|
|
37153
|
+
/**
|
|
37154
|
+
* Get AI suggestion for geographic scope of item.
|
|
37155
|
+
* @param {Object} item - Item to analyze
|
|
37156
|
+
* @param {string} holonId - Context holon
|
|
37157
|
+
* @param {string} lensName - Context lens
|
|
37158
|
+
* @param {Object} [options={}] - Analysis options
|
|
37159
|
+
* @returns {Promise<Object>} Geographic scope suggestion
|
|
37160
|
+
*/
|
|
36527
37161
|
async suggestGeographicScope(item, holonId, lensName, options = {}) {
|
|
36528
37162
|
this._requireAI();
|
|
36529
37163
|
return this._ai.h3ai.suggestGeographicScope(item, holonId, lensName, options);
|
|
36530
37164
|
}
|
|
37165
|
+
/**
|
|
37166
|
+
* Analyze H3 coverage patterns.
|
|
37167
|
+
* @param {string} holonId - H3 holon to analyze
|
|
37168
|
+
* @param {string} lensName - Lens to analyze
|
|
37169
|
+
* @param {Object} [options={}] - Analysis options
|
|
37170
|
+
* @returns {Promise<Object>} Coverage analysis
|
|
37171
|
+
*/
|
|
36531
37172
|
async analyzeH3Coverage(holonId, lensName, options = {}) {
|
|
36532
37173
|
this._requireAI();
|
|
36533
37174
|
return this._ai.h3ai.analyzeCoverage(holonId, lensName, options);
|
|
36534
37175
|
}
|
|
37176
|
+
/**
|
|
37177
|
+
* Get insights across different H3 resolutions.
|
|
37178
|
+
* @param {string} holonId - H3 holon to analyze
|
|
37179
|
+
* @param {string} lensName - Lens to analyze
|
|
37180
|
+
* @param {Object} [options={}] - Analysis options
|
|
37181
|
+
* @returns {Promise<Object>} Cross-resolution insights
|
|
37182
|
+
*/
|
|
36535
37183
|
async crossH3ResolutionInsights(holonId, lensName, options = {}) {
|
|
36536
37184
|
this._requireAI();
|
|
36537
37185
|
return this._ai.h3ai.crossResolutionInsights(holonId, lensName, options);
|
|
36538
37186
|
}
|
|
37187
|
+
/**
|
|
37188
|
+
* Get AI suggestion for migrating item to different H3 resolution.
|
|
37189
|
+
* @param {Object} item - Item to migrate
|
|
37190
|
+
* @param {string} holonId - Current holon
|
|
37191
|
+
* @param {string} lensName - Lens context
|
|
37192
|
+
* @param {Object} [options={}] - Migration options
|
|
37193
|
+
* @returns {Promise<Object>} Migration suggestion
|
|
37194
|
+
*/
|
|
36539
37195
|
async suggestH3Migration(item, holonId, lensName, options = {}) {
|
|
36540
37196
|
this._requireAI();
|
|
36541
37197
|
return this._ai.h3ai.suggestMigration(item, holonId, lensName, options);
|
|
36542
37198
|
}
|
|
37199
|
+
/**
|
|
37200
|
+
* Generate comprehensive geographic report for holon.
|
|
37201
|
+
* @param {string} holonId - H3 holon to report on
|
|
37202
|
+
* @param {Object} [options={}] - Report options
|
|
37203
|
+
* @returns {Promise<string>} Generated geographic report
|
|
37204
|
+
*/
|
|
36543
37205
|
async generateH3Report(holonId, options = {}) {
|
|
36544
37206
|
this._requireAI();
|
|
36545
37207
|
return this._ai.h3ai.generateGeographicReport(holonId, options);
|
|
36546
37208
|
}
|
|
37209
|
+
/**
|
|
37210
|
+
* Find geographic clusters in holon data.
|
|
37211
|
+
* @param {string} holonId - H3 holon to analyze
|
|
37212
|
+
* @param {string} lensName - Lens to analyze
|
|
37213
|
+
* @param {Object} [options={}] - Clustering options
|
|
37214
|
+
* @returns {Promise<Object[]>} Identified clusters
|
|
37215
|
+
*/
|
|
36547
37216
|
async findH3Clusters(holonId, lensName, options = {}) {
|
|
36548
37217
|
this._requireAI();
|
|
36549
37218
|
return this._ai.h3ai.findGeographicClusters(holonId, lensName, options);
|
|
36550
37219
|
}
|
|
37220
|
+
/**
|
|
37221
|
+
* Analyze geographic impact of an item.
|
|
37222
|
+
* @param {Object} item - Item to analyze impact for
|
|
37223
|
+
* @param {string} holonId - Context holon
|
|
37224
|
+
* @param {string} lensName - Context lens
|
|
37225
|
+
* @param {Object} [options={}] - Analysis options
|
|
37226
|
+
* @returns {Promise<Object>} Impact analysis
|
|
37227
|
+
*/
|
|
36551
37228
|
async analyzeH3Impact(item, holonId, lensName, options = {}) {
|
|
36552
37229
|
this._requireAI();
|
|
36553
37230
|
return this._ai.h3ai.analyzeGeographicImpact(item, holonId, lensName, options);
|
|
@@ -36556,15 +37233,33 @@ function withAIMethods(Base) {
|
|
|
36556
37233
|
}
|
|
36557
37234
|
function withContractMethods(Base) {
|
|
36558
37235
|
return class extends Base {
|
|
37236
|
+
/**
|
|
37237
|
+
* Check if contracts are initialized.
|
|
37238
|
+
* @returns {boolean} True if contracts initialized
|
|
37239
|
+
*/
|
|
36559
37240
|
hasContracts() {
|
|
36560
37241
|
return this._contracts !== null;
|
|
36561
37242
|
}
|
|
37243
|
+
/**
|
|
37244
|
+
* Ensure contracts are initialized, throw if not.
|
|
37245
|
+
* @private
|
|
37246
|
+
* @returns {Object} Contracts object
|
|
37247
|
+
* @throws {Error} If contracts not initialized
|
|
37248
|
+
*/
|
|
36562
37249
|
_requireContracts() {
|
|
36563
37250
|
if (!this._contracts) {
|
|
36564
37251
|
throw new Error("Contracts not initialized. Call initContracts() first.");
|
|
36565
37252
|
}
|
|
36566
37253
|
return this._contracts;
|
|
36567
37254
|
}
|
|
37255
|
+
/**
|
|
37256
|
+
* Initialize contracts with server-side configuration (Node.js).
|
|
37257
|
+
* @param {Object} config - Contract configuration
|
|
37258
|
+
* @param {string} config.network - Network name (mainnet, sepolia, hardhat, etc.)
|
|
37259
|
+
* @param {string} config.privateKey - Private key for signing transactions
|
|
37260
|
+
* @param {string} [config.rpcUrl] - Optional custom RPC URL
|
|
37261
|
+
* @returns {Promise<Object>} Connection info with network details and address
|
|
37262
|
+
*/
|
|
36568
37263
|
async initContracts(config) {
|
|
36569
37264
|
const chainManager = new ChainManager(config);
|
|
36570
37265
|
const connectionInfo = await chainManager.connect(
|
|
@@ -36585,6 +37280,11 @@ function withContractMethods(Base) {
|
|
|
36585
37280
|
address: config.privateKey ? await chainManager.getAddress() : null
|
|
36586
37281
|
};
|
|
36587
37282
|
}
|
|
37283
|
+
/**
|
|
37284
|
+
* Initialize contracts with browser wallet (MetaMask, etc.).
|
|
37285
|
+
* @param {string} network - Network name to connect to
|
|
37286
|
+
* @returns {Promise<Object>} Connection info with network details
|
|
37287
|
+
*/
|
|
36588
37288
|
async initContractsBrowser(network) {
|
|
36589
37289
|
const chainManager = new ChainManager();
|
|
36590
37290
|
const connectionInfo = await chainManager.connectBrowser(network);
|
|
@@ -36598,76 +37298,190 @@ function withContractMethods(Base) {
|
|
|
36598
37298
|
};
|
|
36599
37299
|
return connectionInfo;
|
|
36600
37300
|
}
|
|
37301
|
+
/**
|
|
37302
|
+
* Deploy all core contracts (factory, templates, etc.).
|
|
37303
|
+
* @param {Object} [options={}] - Deployment options
|
|
37304
|
+
* @returns {Promise<Object>} Deployment result with addresses
|
|
37305
|
+
*/
|
|
36601
37306
|
async deployContracts(options = {}) {
|
|
36602
37307
|
const { deployer } = this._requireContracts();
|
|
36603
37308
|
return deployer.deployAll(options);
|
|
36604
37309
|
}
|
|
37310
|
+
/**
|
|
37311
|
+
* Load previously deployed contract addresses.
|
|
37312
|
+
* @param {Object} addresses - Map of contract names to addresses
|
|
37313
|
+
*/
|
|
36605
37314
|
loadDeployedContracts(addresses) {
|
|
36606
37315
|
const { deployer } = this._requireContracts();
|
|
36607
37316
|
deployer.loadDeployedAddresses(addresses);
|
|
36608
37317
|
}
|
|
37318
|
+
/**
|
|
37319
|
+
* Get all deployed contract addresses.
|
|
37320
|
+
* @returns {Object} Map of contract names to addresses
|
|
37321
|
+
*/
|
|
36609
37322
|
getDeployedContracts() {
|
|
36610
37323
|
const { deployer } = this._requireContracts();
|
|
36611
37324
|
return deployer.getDeployedAddresses();
|
|
36612
37325
|
}
|
|
37326
|
+
/**
|
|
37327
|
+
* Deploy a new contract for a holon.
|
|
37328
|
+
* @param {string} holonId - Holon ID to deploy contract for
|
|
37329
|
+
* @param {string} [type='Splitter'] - Contract type (Splitter, Managed, Zoned, Appreciative, Bundle)
|
|
37330
|
+
* @param {Object} [options={}] - Deployment options
|
|
37331
|
+
* @returns {Promise<Object>} Deployment result with contract address
|
|
37332
|
+
*/
|
|
36613
37333
|
async deployHolonContract(holonId, type2 = "Splitter", options = {}) {
|
|
36614
37334
|
const { holonContracts } = this._requireContracts();
|
|
36615
37335
|
return holonContracts.deploy(holonId, type2, options);
|
|
36616
37336
|
}
|
|
37337
|
+
/**
|
|
37338
|
+
* Link an existing contract to a holon.
|
|
37339
|
+
* @param {string} holonId - Holon ID to link
|
|
37340
|
+
* @param {string} contractAddress - Contract address to link
|
|
37341
|
+
* @param {string} [type='Splitter'] - Contract type
|
|
37342
|
+
* @returns {Promise<void>}
|
|
37343
|
+
*/
|
|
36617
37344
|
async linkHolonContract(holonId, contractAddress, type2 = "Splitter") {
|
|
36618
37345
|
const { holonContracts } = this._requireContracts();
|
|
36619
37346
|
return holonContracts.link(holonId, contractAddress, type2);
|
|
36620
37347
|
}
|
|
37348
|
+
/**
|
|
37349
|
+
* Unlink contract from a holon.
|
|
37350
|
+
* @param {string} holonId - Holon ID to unlink
|
|
37351
|
+
* @returns {Promise<void>}
|
|
37352
|
+
*/
|
|
36621
37353
|
async unlinkHolonContract(holonId) {
|
|
36622
37354
|
const { holonContracts } = this._requireContracts();
|
|
36623
37355
|
return holonContracts.unlink(holonId);
|
|
36624
37356
|
}
|
|
37357
|
+
/**
|
|
37358
|
+
* Get contract instance for a holon.
|
|
37359
|
+
* @param {string} holonId - Holon ID
|
|
37360
|
+
* @returns {Object|null} Contract instance or null if not found
|
|
37361
|
+
*/
|
|
36625
37362
|
getHolonContract(holonId) {
|
|
36626
37363
|
if (!this._contracts) return null;
|
|
36627
37364
|
return this._contracts.holonContracts.getContract(holonId);
|
|
36628
37365
|
}
|
|
37366
|
+
/**
|
|
37367
|
+
* Get contract address for a holon.
|
|
37368
|
+
* @param {string} holonId - Holon ID
|
|
37369
|
+
* @returns {string|null} Contract address or null if not found
|
|
37370
|
+
*/
|
|
36629
37371
|
getHolonContractAddress(holonId) {
|
|
36630
37372
|
if (!this._contracts) return null;
|
|
36631
37373
|
return this._contracts.holonContracts.getAddress(holonId);
|
|
36632
37374
|
}
|
|
37375
|
+
/**
|
|
37376
|
+
* Check if holon has a linked contract.
|
|
37377
|
+
* @param {string} holonId - Holon ID to check
|
|
37378
|
+
* @returns {boolean} True if contract exists
|
|
37379
|
+
*/
|
|
36633
37380
|
hasHolonContract(holonId) {
|
|
36634
37381
|
if (!this._contracts) return false;
|
|
36635
37382
|
return this._contracts.holonContracts.hasContract(holonId);
|
|
36636
37383
|
}
|
|
37384
|
+
/**
|
|
37385
|
+
* List all holon contracts.
|
|
37386
|
+
* @returns {Array<{holonId: string, address: string, type: string}>} Array of holon contract info
|
|
37387
|
+
*/
|
|
36637
37388
|
listHolonContracts() {
|
|
36638
37389
|
if (!this._contracts) return [];
|
|
36639
37390
|
return this._contracts.holonContracts.listAll();
|
|
36640
37391
|
}
|
|
37392
|
+
/**
|
|
37393
|
+
* Get operations interface for a holon contract.
|
|
37394
|
+
* @param {string} holonId - Holon ID
|
|
37395
|
+
* @returns {Object} Operations object with contract methods
|
|
37396
|
+
* @throws {Error} If holon has no contract
|
|
37397
|
+
*/
|
|
36641
37398
|
getHolonOperations(holonId) {
|
|
36642
37399
|
const { holonContracts } = this._requireContracts();
|
|
36643
37400
|
return holonContracts.requireOperations(holonId);
|
|
36644
37401
|
}
|
|
36645
37402
|
// ========== MEMBER MANAGEMENT ==========
|
|
37403
|
+
/**
|
|
37404
|
+
* Add a member to holon contract.
|
|
37405
|
+
* @param {string} holonId - Holon ID
|
|
37406
|
+
* @param {string} userId - User ID to add
|
|
37407
|
+
* @returns {Promise<Object>} Transaction result
|
|
37408
|
+
*/
|
|
36646
37409
|
async contractAddMember(holonId, userId) {
|
|
36647
37410
|
return this.getHolonOperations(holonId).addMember(userId);
|
|
36648
37411
|
}
|
|
37412
|
+
/**
|
|
37413
|
+
* Add multiple members to holon contract.
|
|
37414
|
+
* @param {string} holonId - Holon ID
|
|
37415
|
+
* @param {string[]} userIds - Array of user IDs to add
|
|
37416
|
+
* @returns {Promise<Object>} Transaction result
|
|
37417
|
+
*/
|
|
36649
37418
|
async contractAddMembers(holonId, userIds) {
|
|
36650
37419
|
return this.getHolonOperations(holonId).addMembers(userIds);
|
|
36651
37420
|
}
|
|
37421
|
+
/**
|
|
37422
|
+
* Check if user is a member of holon contract.
|
|
37423
|
+
* @param {string} holonId - Holon ID
|
|
37424
|
+
* @param {string} userId - User ID to check
|
|
37425
|
+
* @returns {Promise<boolean>} True if user is member
|
|
37426
|
+
*/
|
|
36652
37427
|
async contractIsMember(holonId, userId) {
|
|
36653
37428
|
return this.getHolonOperations(holonId).isMember(userId);
|
|
36654
37429
|
}
|
|
36655
37430
|
// ========== FUND DISTRIBUTION ==========
|
|
37431
|
+
/**
|
|
37432
|
+
* Distribute ERC20 token rewards to contract members.
|
|
37433
|
+
* @param {string} holonId - Holon ID
|
|
37434
|
+
* @param {string} tokenAddress - ERC20 token contract address
|
|
37435
|
+
* @param {string|number} amount - Amount to distribute
|
|
37436
|
+
* @returns {Promise<Object>} Transaction result
|
|
37437
|
+
*/
|
|
36656
37438
|
async contractReward(holonId, tokenAddress, amount) {
|
|
36657
37439
|
return this.getHolonOperations(holonId).reward(tokenAddress, amount);
|
|
36658
37440
|
}
|
|
37441
|
+
/**
|
|
37442
|
+
* Distribute ETH rewards to contract members.
|
|
37443
|
+
* @param {string} holonId - Holon ID
|
|
37444
|
+
* @param {string|number} amount - Amount of ETH to distribute (in wei)
|
|
37445
|
+
* @returns {Promise<Object>} Transaction result
|
|
37446
|
+
*/
|
|
36659
37447
|
async contractRewardEth(holonId, amount) {
|
|
36660
37448
|
return this.getHolonOperations(holonId).rewardEth(amount);
|
|
36661
37449
|
}
|
|
37450
|
+
/**
|
|
37451
|
+
* Send ETH to holon contract.
|
|
37452
|
+
* @param {string} holonId - Holon ID
|
|
37453
|
+
* @param {string|number} amount - Amount of ETH to send (in wei)
|
|
37454
|
+
* @returns {Promise<Object>} Transaction result
|
|
37455
|
+
*/
|
|
36662
37456
|
async contractSendEth(holonId, amount) {
|
|
36663
37457
|
return this.getHolonOperations(holonId).sendEth(amount);
|
|
36664
37458
|
}
|
|
37459
|
+
/**
|
|
37460
|
+
* Claim user's share of distributed funds.
|
|
37461
|
+
* @param {string} holonId - Holon ID
|
|
37462
|
+
* @param {string} userId - User ID claiming funds
|
|
37463
|
+
* @param {string} beneficiaryAddress - Address to send claimed funds to
|
|
37464
|
+
* @returns {Promise<Object>} Transaction result
|
|
37465
|
+
*/
|
|
36665
37466
|
async contractClaim(holonId, userId, beneficiaryAddress) {
|
|
36666
37467
|
return this.getHolonOperations(holonId).claim(userId, beneficiaryAddress);
|
|
36667
37468
|
}
|
|
37469
|
+
/**
|
|
37470
|
+
* Get user's claimable ETH balance.
|
|
37471
|
+
* @param {string} holonId - Holon ID
|
|
37472
|
+
* @param {string} userId - User ID to check
|
|
37473
|
+
* @returns {Promise<string>} ETH balance in wei
|
|
37474
|
+
*/
|
|
36668
37475
|
async contractGetEthBalance(holonId, userId) {
|
|
36669
37476
|
return this.getHolonOperations(holonId).getEthBalance(userId);
|
|
36670
37477
|
}
|
|
37478
|
+
/**
|
|
37479
|
+
* Get user's claimable token balance.
|
|
37480
|
+
* @param {string} holonId - Holon ID
|
|
37481
|
+
* @param {string} userId - User ID to check
|
|
37482
|
+
* @param {string} tokenAddress - Token contract address
|
|
37483
|
+
* @returns {Promise<string>} Token balance
|
|
37484
|
+
*/
|
|
36671
37485
|
async contractGetTokenBalance(holonId, userId, tokenAddress) {
|
|
36672
37486
|
return this.getHolonOperations(holonId).getTokenBalance(userId, tokenAddress);
|
|
36673
37487
|
}
|
|
@@ -36756,9 +37570,17 @@ function withContractMethods(Base) {
|
|
|
36756
37570
|
async contractGetTotalDeposited(holonId, tokenAddress) {
|
|
36757
37571
|
return this.getHolonOperations(holonId).getTotalDeposited(tokenAddress);
|
|
36758
37572
|
}
|
|
37573
|
+
/**
|
|
37574
|
+
* Get network utility functions.
|
|
37575
|
+
* @returns {Object} Network utilities module
|
|
37576
|
+
*/
|
|
36759
37577
|
getNetworkUtils() {
|
|
36760
37578
|
return networks;
|
|
36761
37579
|
}
|
|
37580
|
+
/**
|
|
37581
|
+
* Get the chain manager instance.
|
|
37582
|
+
* @returns {Object|null} ChainManager instance or null if not initialized
|
|
37583
|
+
*/
|
|
36762
37584
|
getChainManager() {
|
|
36763
37585
|
return this._contracts?.chainManager || null;
|
|
36764
37586
|
}
|
|
@@ -36997,6 +37819,12 @@ async function getPendingFederationRequests(client, options = {}) {
|
|
|
36997
37819
|
return pending;
|
|
36998
37820
|
}
|
|
36999
37821
|
class AuthorizationError extends Error {
|
|
37822
|
+
/**
|
|
37823
|
+
* Creates a new AuthorizationError.
|
|
37824
|
+
*
|
|
37825
|
+
* @param {string} message - Error message describing the authorization failure
|
|
37826
|
+
* @param {string|null} [requiredPermission=null] - The permission that was required
|
|
37827
|
+
*/
|
|
37000
37828
|
constructor(message, requiredPermission = null) {
|
|
37001
37829
|
super(message);
|
|
37002
37830
|
this.name = "AuthorizationError";
|
|
@@ -37004,6 +37832,11 @@ class AuthorizationError extends Error {
|
|
|
37004
37832
|
}
|
|
37005
37833
|
}
|
|
37006
37834
|
class ValidationError2 extends Error {
|
|
37835
|
+
/**
|
|
37836
|
+
* Creates a new ValidationError.
|
|
37837
|
+
*
|
|
37838
|
+
* @param {string} message - Error message describing the validation failure
|
|
37839
|
+
*/
|
|
37007
37840
|
constructor(message) {
|
|
37008
37841
|
super(message);
|
|
37009
37842
|
this.name = "ValidationError";
|
|
@@ -37012,6 +37845,13 @@ class ValidationError2 extends Error {
|
|
|
37012
37845
|
function withFederationMethods(Base) {
|
|
37013
37846
|
return class extends Base {
|
|
37014
37847
|
// === Cross-Holosphere Federation ===
|
|
37848
|
+
/**
|
|
37849
|
+
* Add a federated HoloSphere partner by public key.
|
|
37850
|
+
* @param {string} pubKey - Public key (hex) of the federated HoloSphere
|
|
37851
|
+
* @param {Object} [options={}] - Federation options (metadata, capabilities, etc.)
|
|
37852
|
+
* @returns {Promise<Object>} Federation registration result
|
|
37853
|
+
* @throws {ValidationError} If pubKey is invalid
|
|
37854
|
+
*/
|
|
37015
37855
|
async addFederatedHolosphere(pubKey, options = {}) {
|
|
37016
37856
|
if (!pubKey || typeof pubKey !== "string") {
|
|
37017
37857
|
throw new ValidationError2("pubKey must be a valid public key string");
|
|
@@ -37023,6 +37863,11 @@ function withFederationMethods(Base) {
|
|
|
37023
37863
|
options
|
|
37024
37864
|
);
|
|
37025
37865
|
}
|
|
37866
|
+
/**
|
|
37867
|
+
* Remove a federated HoloSphere partner.
|
|
37868
|
+
* @param {string} pubKey - Public key of the partner to remove
|
|
37869
|
+
* @returns {Promise<void>}
|
|
37870
|
+
*/
|
|
37026
37871
|
async removeFederatedHolosphere(pubKey) {
|
|
37027
37872
|
return removeFederatedPartner(
|
|
37028
37873
|
this.client,
|
|
@@ -37030,18 +37875,32 @@ function withFederationMethods(Base) {
|
|
|
37030
37875
|
pubKey
|
|
37031
37876
|
);
|
|
37032
37877
|
}
|
|
37878
|
+
/**
|
|
37879
|
+
* Get all federated HoloSphere public keys.
|
|
37880
|
+
* @returns {Promise<string[]>} Array of federated public keys
|
|
37881
|
+
*/
|
|
37033
37882
|
async getFederatedHolospheres() {
|
|
37034
37883
|
return getFederatedAuthors(
|
|
37035
37884
|
this.client,
|
|
37036
37885
|
this.config.appName
|
|
37037
37886
|
);
|
|
37038
37887
|
}
|
|
37888
|
+
/**
|
|
37889
|
+
* Get the complete federation registry.
|
|
37890
|
+
* @returns {Promise<Object>} Federation registry with all partners and capabilities
|
|
37891
|
+
*/
|
|
37039
37892
|
async getFederationRegistry() {
|
|
37040
37893
|
return getFederationRegistry(
|
|
37041
37894
|
this.client,
|
|
37042
37895
|
this.config.appName
|
|
37043
37896
|
);
|
|
37044
37897
|
}
|
|
37898
|
+
/**
|
|
37899
|
+
* Store an inbound capability token from a federated partner.
|
|
37900
|
+
* @param {string} partnerPubKey - Partner's public key
|
|
37901
|
+
* @param {Object} capabilityInfo - Capability token and metadata
|
|
37902
|
+
* @returns {Promise<void>}
|
|
37903
|
+
*/
|
|
37045
37904
|
async storeInboundCapability(partnerPubKey, capabilityInfo) {
|
|
37046
37905
|
return storeInboundCapability(
|
|
37047
37906
|
this.client,
|
|
@@ -37050,6 +37909,15 @@ function withFederationMethods(Base) {
|
|
|
37050
37909
|
capabilityInfo
|
|
37051
37910
|
);
|
|
37052
37911
|
}
|
|
37912
|
+
/**
|
|
37913
|
+
* Read data from a federated source with capability verification.
|
|
37914
|
+
* @param {string} sourcePubKey - Source HoloSphere public key
|
|
37915
|
+
* @param {string} holonId - Holon ID to read from
|
|
37916
|
+
* @param {string} lensName - Lens name to read from
|
|
37917
|
+
* @param {string|null} [dataId=null] - Optional specific data ID (null for all)
|
|
37918
|
+
* @returns {Promise<Object|Object[]>} Data from federated source
|
|
37919
|
+
* @throws {AuthorizationError} If capability verification fails
|
|
37920
|
+
*/
|
|
37053
37921
|
async readFromFederatedSource(sourcePubKey, holonId, lensName, dataId = null) {
|
|
37054
37922
|
const capabilityEntry = await getCapabilityForAuthor(
|
|
37055
37923
|
this.client,
|
|
@@ -37082,6 +37950,19 @@ function withFederationMethods(Base) {
|
|
|
37082
37950
|
});
|
|
37083
37951
|
}
|
|
37084
37952
|
}
|
|
37953
|
+
/**
|
|
37954
|
+
* Create a cross-HoloSphere hologram reference.
|
|
37955
|
+
* Links data from another HoloSphere into this one using capability-based access.
|
|
37956
|
+
* @param {string} sourcePubKey - Source HoloSphere public key
|
|
37957
|
+
* @param {string} sourceHolon - Source holon ID
|
|
37958
|
+
* @param {string} lensName - Lens name
|
|
37959
|
+
* @param {string} dataId - Data ID
|
|
37960
|
+
* @param {string} targetHolon - Target holon in this HoloSphere
|
|
37961
|
+
* @param {Object} [options={}] - Hologram options
|
|
37962
|
+
* @param {boolean} [options.embedCapability=true] - Embed capability in hologram
|
|
37963
|
+
* @returns {Promise<Object>} Created hologram
|
|
37964
|
+
* @throws {AuthorizationError} If no valid capability exists
|
|
37965
|
+
*/
|
|
37085
37966
|
async createCrossHolosphereHologram(sourcePubKey, sourceHolon, lensName, dataId, targetHolon, options = {}) {
|
|
37086
37967
|
const { embedCapability = true } = options;
|
|
37087
37968
|
const capabilityEntry = await getCapabilityForAuthor(
|
|
@@ -37108,6 +37989,17 @@ function withFederationMethods(Base) {
|
|
|
37108
37989
|
await write(this.client, targetPath, hologram$1);
|
|
37109
37990
|
return hologram$1;
|
|
37110
37991
|
}
|
|
37992
|
+
/**
|
|
37993
|
+
* Issue a capability token for federated access.
|
|
37994
|
+
* Grants another HoloSphere permission to access data with specified scope.
|
|
37995
|
+
* @param {string} targetPubKey - Target HoloSphere public key to grant access to
|
|
37996
|
+
* @param {Object} scope - Access scope (holonId, lensName, dataId patterns)
|
|
37997
|
+
* @param {string[]} permissions - Array of permissions ('read', 'write', etc.)
|
|
37998
|
+
* @param {Object} [options={}] - Capability options
|
|
37999
|
+
* @param {number} [options.expiresIn=3600000] - Expiration time in milliseconds
|
|
38000
|
+
* @param {boolean} [options.trackInRegistry=true] - Store in federation registry
|
|
38001
|
+
* @returns {Promise<string>} Capability token
|
|
38002
|
+
*/
|
|
37111
38003
|
async issueCapabilityForFederation(targetPubKey, scope, permissions, options = {}) {
|
|
37112
38004
|
const { expiresIn = 36e5, trackInRegistry = true } = options;
|
|
37113
38005
|
const token = await issueCapability(
|
|
@@ -37147,11 +38039,23 @@ function withFederationMethods(Base) {
|
|
|
37147
38039
|
}
|
|
37148
38040
|
return token;
|
|
37149
38041
|
}
|
|
38042
|
+
/**
|
|
38043
|
+
* Hash a capability token for storage.
|
|
38044
|
+
* @private
|
|
38045
|
+
* @param {string} token - Capability token to hash
|
|
38046
|
+
* @returns {Promise<string>} SHA256 hash of token
|
|
38047
|
+
*/
|
|
37150
38048
|
async _hashToken(token) {
|
|
37151
38049
|
const encoder = new TextEncoder();
|
|
37152
38050
|
return bytesToHex$1(sha256(encoder.encode(token)));
|
|
37153
38051
|
}
|
|
37154
38052
|
// === Nostr Discovery Protocol ===
|
|
38053
|
+
/**
|
|
38054
|
+
* Send a federation request to another HoloSphere via Nostr.
|
|
38055
|
+
* @param {string} targetPubKey - Target HoloSphere public key
|
|
38056
|
+
* @param {Object} [options={}] - Request options (message, metadata, etc.)
|
|
38057
|
+
* @returns {Promise<Object>} Request event
|
|
38058
|
+
*/
|
|
37155
38059
|
async sendFederationRequest(targetPubKey, options = {}) {
|
|
37156
38060
|
return sendFederationRequest(
|
|
37157
38061
|
this.client,
|
|
@@ -37160,9 +38064,20 @@ function withFederationMethods(Base) {
|
|
|
37160
38064
|
options
|
|
37161
38065
|
);
|
|
37162
38066
|
}
|
|
38067
|
+
/**
|
|
38068
|
+
* Subscribe to incoming federation requests.
|
|
38069
|
+
* @param {Function} callback - Callback function (request) => void
|
|
38070
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method
|
|
38071
|
+
*/
|
|
37163
38072
|
async subscribeFederationRequests(callback) {
|
|
37164
38073
|
return subscribeFederationRequests(this.client, callback);
|
|
37165
38074
|
}
|
|
38075
|
+
/**
|
|
38076
|
+
* Accept a federation request and establish partnership.
|
|
38077
|
+
* @param {Object} request - Federation request object
|
|
38078
|
+
* @param {Object} [options={}] - Acceptance options (capabilities to grant, etc.)
|
|
38079
|
+
* @returns {Promise<Object>} Acceptance event
|
|
38080
|
+
*/
|
|
37166
38081
|
async acceptFederationRequest(request, options = {}) {
|
|
37167
38082
|
return acceptFederationRequest(
|
|
37168
38083
|
this.client,
|
|
@@ -37171,6 +38086,12 @@ function withFederationMethods(Base) {
|
|
|
37171
38086
|
options
|
|
37172
38087
|
);
|
|
37173
38088
|
}
|
|
38089
|
+
/**
|
|
38090
|
+
* Decline a federation request.
|
|
38091
|
+
* @param {Object} request - Federation request object
|
|
38092
|
+
* @param {string} [reason=''] - Optional reason for declining
|
|
38093
|
+
* @returns {Promise<Object>} Decline event
|
|
38094
|
+
*/
|
|
37174
38095
|
async declineFederationRequest(request, reason = "") {
|
|
37175
38096
|
return declineFederationRequest(
|
|
37176
38097
|
this.client,
|
|
@@ -37179,6 +38100,11 @@ function withFederationMethods(Base) {
|
|
|
37179
38100
|
reason
|
|
37180
38101
|
);
|
|
37181
38102
|
}
|
|
38103
|
+
/**
|
|
38104
|
+
* Subscribe to federation request acceptances.
|
|
38105
|
+
* @param {Function} callback - Callback function (acceptance) => void
|
|
38106
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method
|
|
38107
|
+
*/
|
|
37182
38108
|
async subscribeFederationAcceptances(callback) {
|
|
37183
38109
|
return subscribeFederationAcceptances(
|
|
37184
38110
|
this.client,
|
|
@@ -37186,9 +38112,19 @@ function withFederationMethods(Base) {
|
|
|
37186
38112
|
callback
|
|
37187
38113
|
);
|
|
37188
38114
|
}
|
|
38115
|
+
/**
|
|
38116
|
+
* Subscribe to federation request declines.
|
|
38117
|
+
* @param {Function} callback - Callback function (decline) => void
|
|
38118
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method
|
|
38119
|
+
*/
|
|
37189
38120
|
async subscribeFederationDeclines(callback) {
|
|
37190
38121
|
return subscribeFederationDeclines(this.client, callback);
|
|
37191
38122
|
}
|
|
38123
|
+
/**
|
|
38124
|
+
* Get all pending federation requests.
|
|
38125
|
+
* @param {Object} [options={}] - Query options (limit, since, etc.)
|
|
38126
|
+
* @returns {Promise<Object[]>} Array of pending requests
|
|
38127
|
+
*/
|
|
37192
38128
|
async getPendingFederationRequests(options = {}) {
|
|
37193
38129
|
return getPendingFederationRequests(this.client, options);
|
|
37194
38130
|
}
|
|
@@ -37228,7 +38164,31 @@ function createAIServices(apiKey, holosphere = null, options = {}, openaiClient
|
|
|
37228
38164
|
h3ai
|
|
37229
38165
|
};
|
|
37230
38166
|
}
|
|
38167
|
+
/**
|
|
38168
|
+
* @fileoverview HoloSphere - Holonic Geospatial Communication Infrastructure
|
|
38169
|
+
*
|
|
38170
|
+
* This is the main entry point for the HoloSphere library, providing a comprehensive
|
|
38171
|
+
* distributed P2P geospatial communication system. It combines H3 hexagonal indexing
|
|
38172
|
+
* for spatial organization, Nostr protocol for distributed storage, smart contracts
|
|
38173
|
+
* for fund distribution, and AI services for intelligent data processing.
|
|
38174
|
+
*
|
|
38175
|
+
* @module holosphere
|
|
38176
|
+
* @author HoloSphere Team
|
|
38177
|
+
* @license MIT
|
|
38178
|
+
*/
|
|
37231
38179
|
class HoloSphereBase extends HoloSphere$1 {
|
|
38180
|
+
/**
|
|
38181
|
+
* Creates a new HoloSphereBase instance.
|
|
38182
|
+
*
|
|
38183
|
+
* @param {Object} config - Configuration options
|
|
38184
|
+
* @param {string} config.appName - Application namespace for data isolation
|
|
38185
|
+
* @param {string} [config.backend='nostr'] - Storage backend type ('nostr', 'gundb', 'activitypub')
|
|
38186
|
+
* @param {string[]} [config.relays] - Nostr relay URLs for distributed storage
|
|
38187
|
+
* @param {string} [config.openaiKey] - OpenAI API key for AI services
|
|
38188
|
+
* @param {Object} [config.aiOptions] - AI service configuration
|
|
38189
|
+
* @param {string} [config.aiOptions.model] - OpenAI model to use
|
|
38190
|
+
* @param {number} [config.aiOptions.temperature] - Temperature for AI responses
|
|
38191
|
+
*/
|
|
37232
38192
|
constructor(config) {
|
|
37233
38193
|
super(config);
|
|
37234
38194
|
this.schemas = /* @__PURE__ */ new Map();
|
|
@@ -37246,17 +38206,40 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37246
38206
|
}
|
|
37247
38207
|
this._contracts = null;
|
|
37248
38208
|
}
|
|
38209
|
+
/**
|
|
38210
|
+
* Gets an environment variable value (Node.js only).
|
|
38211
|
+
*
|
|
38212
|
+
* @private
|
|
38213
|
+
* @param {string} name - Environment variable name
|
|
38214
|
+
* @returns {string|undefined} Environment variable value or undefined
|
|
38215
|
+
*/
|
|
37249
38216
|
_getEnv(name2) {
|
|
37250
38217
|
if (typeof process !== "undefined" && process.env) {
|
|
37251
38218
|
return process.env[name2];
|
|
37252
38219
|
}
|
|
37253
38220
|
return void 0;
|
|
37254
38221
|
}
|
|
38222
|
+
/**
|
|
38223
|
+
* Parses a string value to a float.
|
|
38224
|
+
*
|
|
38225
|
+
* @private
|
|
38226
|
+
* @param {string|undefined|null} value - Value to parse
|
|
38227
|
+
* @returns {number|undefined} Parsed float or undefined if invalid
|
|
38228
|
+
*/
|
|
37255
38229
|
_parseFloat(value) {
|
|
37256
38230
|
if (value === void 0 || value === null) return void 0;
|
|
37257
38231
|
const parsed = parseFloat(value);
|
|
37258
38232
|
return isNaN(parsed) ? void 0 : parsed;
|
|
37259
38233
|
}
|
|
38234
|
+
/**
|
|
38235
|
+
* Initializes AI services with the provided API key.
|
|
38236
|
+
*
|
|
38237
|
+
* @private
|
|
38238
|
+
* @param {string} apiKey - OpenAI API key
|
|
38239
|
+
* @param {Object} [options={}] - AI configuration options
|
|
38240
|
+
* @param {string} [options.model] - OpenAI model to use
|
|
38241
|
+
* @param {number} [options.temperature] - Temperature for AI responses
|
|
38242
|
+
*/
|
|
37260
38243
|
_initializeAI(apiKey, options = {}) {
|
|
37261
38244
|
const llmOptions = {
|
|
37262
38245
|
...options.llm,
|
|
@@ -37283,26 +38266,79 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37283
38266
|
this._ai.taskBreakdown = new TaskBreakdown(this._ai.llm, this);
|
|
37284
38267
|
this._ai.h3ai = new H3AI(this._ai.llm, this);
|
|
37285
38268
|
}
|
|
38269
|
+
/**
|
|
38270
|
+
* Checks if AI services are initialized.
|
|
38271
|
+
*
|
|
38272
|
+
* @returns {boolean} True if AI services are available
|
|
38273
|
+
*/
|
|
37286
38274
|
hasAI() {
|
|
37287
38275
|
return this._ai !== null;
|
|
37288
38276
|
}
|
|
38277
|
+
/**
|
|
38278
|
+
* Gets the initialized AI services object.
|
|
38279
|
+
*
|
|
38280
|
+
* @returns {Object|null} AI services object containing llm, embeddings, etc., or null if not initialized
|
|
38281
|
+
*/
|
|
37289
38282
|
getAIServices() {
|
|
37290
38283
|
return this._ai;
|
|
37291
38284
|
}
|
|
37292
38285
|
// === Spatial Operations ===
|
|
38286
|
+
/**
|
|
38287
|
+
* Converts geographic coordinates to an H3 holon ID.
|
|
38288
|
+
*
|
|
38289
|
+
* @param {number} lat - Latitude (-90 to 90)
|
|
38290
|
+
* @param {number} lng - Longitude (-180 to 180)
|
|
38291
|
+
* @param {number} resolution - H3 resolution level (0-15)
|
|
38292
|
+
* @returns {Promise<string>} H3 cell ID representing the holon
|
|
38293
|
+
*/
|
|
37293
38294
|
async toHolon(lat, lng, resolution) {
|
|
37294
38295
|
return toHolon(lat, lng, resolution);
|
|
37295
38296
|
}
|
|
38297
|
+
/**
|
|
38298
|
+
* Gets all parent holons at higher resolutions.
|
|
38299
|
+
*
|
|
38300
|
+
* @param {string} holonId - H3 cell ID
|
|
38301
|
+
* @param {number} [maxResolution] - Maximum resolution to traverse up to
|
|
38302
|
+
* @returns {Promise<string[]>} Array of parent H3 cell IDs
|
|
38303
|
+
*/
|
|
37296
38304
|
async getParents(holonId, maxResolution) {
|
|
37297
38305
|
return getParents(holonId, maxResolution);
|
|
37298
38306
|
}
|
|
38307
|
+
/**
|
|
38308
|
+
* Gets all child holons at the next resolution level.
|
|
38309
|
+
*
|
|
38310
|
+
* @param {string} holonId - H3 cell ID
|
|
38311
|
+
* @returns {Promise<string[]>} Array of child H3 cell IDs
|
|
38312
|
+
*/
|
|
37299
38313
|
async getChildren(holonId) {
|
|
37300
38314
|
return getChildren(holonId);
|
|
37301
38315
|
}
|
|
38316
|
+
/**
|
|
38317
|
+
* Validates if a string is a valid H3 cell ID.
|
|
38318
|
+
*
|
|
38319
|
+
* @param {string} holonId - String to validate
|
|
38320
|
+
* @returns {boolean} True if valid H3 cell ID
|
|
38321
|
+
*/
|
|
37302
38322
|
isValidH3(holonId) {
|
|
37303
38323
|
return isValidH3(holonId);
|
|
37304
38324
|
}
|
|
37305
38325
|
// === Data Operations ===
|
|
38326
|
+
/**
|
|
38327
|
+
* Writes data to a specific holon and lens.
|
|
38328
|
+
*
|
|
38329
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38330
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
38331
|
+
* @param {Object} data - Data object to write (must have or will be assigned an id)
|
|
38332
|
+
* @param {Object} [options={}] - Write options
|
|
38333
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
38334
|
+
* @param {boolean} [options.validate=true] - Whether to validate against schema
|
|
38335
|
+
* @param {boolean} [options.strict] - Override schema strict mode
|
|
38336
|
+
* @param {boolean} [options.autoPropagate=true] - Whether to propagate to federated holons
|
|
38337
|
+
* @param {Object} [options.propagationOptions] - Options for propagation
|
|
38338
|
+
* @returns {Promise<boolean>} True if write succeeded
|
|
38339
|
+
* @throws {ValidationError} If holonId, lensName, or data is invalid
|
|
38340
|
+
* @throws {AuthorizationError} If capability token is invalid
|
|
38341
|
+
*/
|
|
37306
38342
|
async write(holonId, lensName, data, options = {}) {
|
|
37307
38343
|
if (!holonId || typeof holonId !== "string") {
|
|
37308
38344
|
throw new ValidationError$1("ValidationError: holonId must be a non-empty string");
|
|
@@ -37400,6 +38436,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37400
38436
|
}
|
|
37401
38437
|
return true;
|
|
37402
38438
|
}
|
|
38439
|
+
/**
|
|
38440
|
+
* Recursively resolves holograms (references) to their source data.
|
|
38441
|
+
* Handles circular reference detection and local overrides.
|
|
38442
|
+
*
|
|
38443
|
+
* @private
|
|
38444
|
+
* @param {Object|Array|null} data - Data that may contain holograms
|
|
38445
|
+
* @param {Set<string>} [visited=new Set()] - Set of visited paths for circular detection
|
|
38446
|
+
* @returns {Promise<Object|Array|null>} Resolved data with holograms replaced by source data
|
|
38447
|
+
*/
|
|
37403
38448
|
async _resolveHolograms(data, visited = /* @__PURE__ */ new Set()) {
|
|
37404
38449
|
if (!data) return data;
|
|
37405
38450
|
if (Array.isArray(data)) {
|
|
@@ -37478,6 +38523,19 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37478
38523
|
}
|
|
37479
38524
|
return data;
|
|
37480
38525
|
}
|
|
38526
|
+
/**
|
|
38527
|
+
* Reads data from a specific holon and lens.
|
|
38528
|
+
*
|
|
38529
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38530
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
38531
|
+
* @param {string|null} [dataId=null] - Specific data ID, or null to read all
|
|
38532
|
+
* @param {Object} [options={}] - Read options
|
|
38533
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
38534
|
+
* @param {boolean} [options.resolveHolograms=true] - Whether to resolve hologram references
|
|
38535
|
+
* @returns {Promise<Object|Array|null>} Data object, array of objects, or null if not found
|
|
38536
|
+
* @throws {ValidationError} If holonId or lensName is invalid
|
|
38537
|
+
* @throws {AuthorizationError} If capability token is invalid
|
|
38538
|
+
*/
|
|
37481
38539
|
async read(holonId, lensName, dataId = null, options = {}) {
|
|
37482
38540
|
if (!holonId || typeof holonId !== "string") {
|
|
37483
38541
|
throw new ValidationError$1("ValidationError: holonId must be a non-empty string");
|
|
@@ -37516,6 +38574,21 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37516
38574
|
this._metrics.totalReadTime += endTime - startTime;
|
|
37517
38575
|
return result;
|
|
37518
38576
|
}
|
|
38577
|
+
/**
|
|
38578
|
+
* Updates existing data in a specific holon and lens.
|
|
38579
|
+
*
|
|
38580
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38581
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
38582
|
+
* @param {string} dataId - ID of the data to update
|
|
38583
|
+
* @param {Object} updates - Object containing fields to update
|
|
38584
|
+
* @param {Object} [options={}] - Update options
|
|
38585
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
38586
|
+
* @param {boolean} [options.validate=true] - Whether to validate against schema
|
|
38587
|
+
* @param {boolean} [options.strict] - Override schema strict mode
|
|
38588
|
+
* @returns {Promise<boolean>} True if update succeeded, false if data not found
|
|
38589
|
+
* @throws {ValidationError} If holonId, lensName, dataId, or updates is invalid
|
|
38590
|
+
* @throws {AuthorizationError} If capability token is invalid
|
|
38591
|
+
*/
|
|
37519
38592
|
async update(holonId, lensName, dataId, updates, options = {}) {
|
|
37520
38593
|
if (!holonId || typeof holonId !== "string") {
|
|
37521
38594
|
throw new ValidationError$1("ValidationError: holonId must be a non-empty string");
|
|
@@ -37565,6 +38638,18 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37565
38638
|
}
|
|
37566
38639
|
return true;
|
|
37567
38640
|
}
|
|
38641
|
+
/**
|
|
38642
|
+
* Deletes data from a specific holon and lens.
|
|
38643
|
+
*
|
|
38644
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38645
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
38646
|
+
* @param {string} dataId - ID of the data to delete
|
|
38647
|
+
* @param {Object} [options={}] - Delete options
|
|
38648
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
38649
|
+
* @returns {Promise<boolean>} True if deletion succeeded, false if data not found
|
|
38650
|
+
* @throws {ValidationError} If holonId, lensName, or dataId is invalid
|
|
38651
|
+
* @throws {AuthorizationError} If not owner and no valid capability token
|
|
38652
|
+
*/
|
|
37568
38653
|
async delete(holonId, lensName, dataId, options = {}) {
|
|
37569
38654
|
if (!holonId || typeof holonId !== "string") {
|
|
37570
38655
|
throw new ValidationError$1("ValidationError: holonId must be a non-empty string");
|
|
@@ -37605,33 +38690,97 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37605
38690
|
return true;
|
|
37606
38691
|
}
|
|
37607
38692
|
// === Global Tables ===
|
|
38693
|
+
/**
|
|
38694
|
+
* Writes data to a global table (not holon-specific).
|
|
38695
|
+
*
|
|
38696
|
+
* @param {string} table - Name of the global table
|
|
38697
|
+
* @param {Object} data - Data object to write (must have an id field)
|
|
38698
|
+
* @returns {Promise<boolean>} True if write succeeded
|
|
38699
|
+
*/
|
|
37608
38700
|
async writeGlobal(table, data) {
|
|
37609
38701
|
return writeGlobal(this.client, this.config.appName, table, data);
|
|
37610
38702
|
}
|
|
38703
|
+
/**
|
|
38704
|
+
* Reads data from a global table.
|
|
38705
|
+
*
|
|
38706
|
+
* @param {string} table - Name of the global table
|
|
38707
|
+
* @param {string|null} [key=null] - Specific key to read, or null to read all
|
|
38708
|
+
* @returns {Promise<Object|Array|null>} Data object, array of objects, or null
|
|
38709
|
+
*/
|
|
37611
38710
|
async readGlobal(table, key = null) {
|
|
37612
38711
|
return readGlobal(this.client, this.config.appName, table, key);
|
|
37613
38712
|
}
|
|
38713
|
+
/**
|
|
38714
|
+
* Updates data in a global table.
|
|
38715
|
+
*
|
|
38716
|
+
* @param {string} table - Name of the global table
|
|
38717
|
+
* @param {string} key - Key of the data to update
|
|
38718
|
+
* @param {Object} updates - Object containing fields to update
|
|
38719
|
+
* @returns {Promise<boolean>} True if update succeeded
|
|
38720
|
+
*/
|
|
37614
38721
|
async updateGlobal(table, key, updates) {
|
|
37615
38722
|
return updateGlobal(this.client, this.config.appName, table, key, updates);
|
|
37616
38723
|
}
|
|
38724
|
+
/**
|
|
38725
|
+
* Deletes data from a global table.
|
|
38726
|
+
*
|
|
38727
|
+
* @param {string} table - Name of the global table
|
|
38728
|
+
* @param {string} key - Key of the data to delete
|
|
38729
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
38730
|
+
*/
|
|
37617
38731
|
async deleteGlobal(table, key) {
|
|
37618
38732
|
return deleteGlobal(this.client, this.config.appName, table, key);
|
|
37619
38733
|
}
|
|
38734
|
+
/**
|
|
38735
|
+
* Gets all data from a global table.
|
|
38736
|
+
*
|
|
38737
|
+
* @param {string} table - Name of the global table
|
|
38738
|
+
* @returns {Promise<Array>} Array of all data objects in the table
|
|
38739
|
+
*/
|
|
37620
38740
|
async getAllGlobal(table) {
|
|
37621
38741
|
return getAllGlobal(this.client, this.config.appName, table);
|
|
37622
38742
|
}
|
|
38743
|
+
/**
|
|
38744
|
+
* Deletes all data from a global table.
|
|
38745
|
+
*
|
|
38746
|
+
* @param {string} table - Name of the global table
|
|
38747
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
38748
|
+
*/
|
|
37623
38749
|
async deleteAllGlobal(table) {
|
|
37624
38750
|
return deleteAllGlobal(this.client, this.config.appName, table);
|
|
37625
38751
|
}
|
|
37626
38752
|
// === Batch Operations ===
|
|
38753
|
+
/**
|
|
38754
|
+
* Gets all data from a specific holon and lens.
|
|
38755
|
+
*
|
|
38756
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38757
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
38758
|
+
* @returns {Promise<Array|null>} Array of data objects or null
|
|
38759
|
+
*/
|
|
37627
38760
|
async getAll(holonId, lensName) {
|
|
37628
38761
|
return this.read(holonId, lensName, null);
|
|
37629
38762
|
}
|
|
38763
|
+
/**
|
|
38764
|
+
* Deletes all data from a specific holon and lens.
|
|
38765
|
+
*
|
|
38766
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38767
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
38768
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
38769
|
+
*/
|
|
37630
38770
|
async deleteAll(holonId, lensName) {
|
|
37631
38771
|
const path = buildPath(this.config.appName, holonId, lensName);
|
|
37632
38772
|
return deleteAll(this.client, path);
|
|
37633
38773
|
}
|
|
37634
38774
|
// === Schema Operations ===
|
|
38775
|
+
/**
|
|
38776
|
+
* Sets a JSON Schema for validating data in a specific lens.
|
|
38777
|
+
*
|
|
38778
|
+
* @param {string} lensName - Name of the lens to associate the schema with
|
|
38779
|
+
* @param {Object|string} schemaInput - JSON Schema object or URI reference
|
|
38780
|
+
* @param {boolean} [strict=false] - If true, validation will reject additional properties
|
|
38781
|
+
* @returns {Promise<void>}
|
|
38782
|
+
* @throws {ValidationError} If lensName is invalid or schema format is invalid
|
|
38783
|
+
*/
|
|
37635
38784
|
async setSchema(lensName, schemaInput, strict = false) {
|
|
37636
38785
|
if (!lensName || typeof lensName !== "string") {
|
|
37637
38786
|
throw new ValidationError$1("ValidationError: lensName must be a non-empty string");
|
|
@@ -37653,14 +38802,40 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37653
38802
|
}
|
|
37654
38803
|
this.schemas.set(lensName, { schema: schemaObj, strict, timestamp: Date.now() });
|
|
37655
38804
|
}
|
|
38805
|
+
/**
|
|
38806
|
+
* Gets the JSON Schema for a specific lens.
|
|
38807
|
+
*
|
|
38808
|
+
* @param {string} lensName - Name of the lens
|
|
38809
|
+
* @returns {Promise<Object|null>} The schema object or null if not set
|
|
38810
|
+
*/
|
|
37656
38811
|
async getSchema(lensName) {
|
|
37657
38812
|
const schemaObj = this.schemas.get(lensName);
|
|
37658
38813
|
return schemaObj ? schemaObj.schema : null;
|
|
37659
38814
|
}
|
|
38815
|
+
/**
|
|
38816
|
+
* Clears the JSON Schema for a specific lens.
|
|
38817
|
+
*
|
|
38818
|
+
* @param {string} lensName - Name of the lens
|
|
38819
|
+
* @returns {Promise<void>}
|
|
38820
|
+
*/
|
|
37660
38821
|
async clearSchema(lensName) {
|
|
37661
38822
|
this.schemas.delete(lensName);
|
|
37662
38823
|
}
|
|
37663
38824
|
// === Federation Operations ===
|
|
38825
|
+
/**
|
|
38826
|
+
* Sets up federation between two holons for a specific lens.
|
|
38827
|
+
* Federation enables data sharing and synchronization between holons.
|
|
38828
|
+
*
|
|
38829
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
38830
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
38831
|
+
* @param {string} lensName - Name of the lens to federate
|
|
38832
|
+
* @param {Object} [options={}] - Federation options
|
|
38833
|
+
* @param {string} [options.direction='outbound'] - Direction: 'inbound', 'outbound', or 'bidirectional'
|
|
38834
|
+
* @param {string} [options.mode='reference'] - Mode: 'reference' (hologram) or 'copy'
|
|
38835
|
+
* @param {Function} [options.filter] - Filter function to select which data to federate
|
|
38836
|
+
* @returns {Promise<boolean>} True if federation was set up successfully
|
|
38837
|
+
* @throws {Error} If trying to federate a holon with itself or invalid direction
|
|
38838
|
+
*/
|
|
37664
38839
|
async federate(sourceHolon, targetHolon, lensName, options = {}) {
|
|
37665
38840
|
const { direction = "outbound", mode = "reference", filter = null } = options;
|
|
37666
38841
|
if (sourceHolon === targetHolon) {
|
|
@@ -37686,6 +38861,18 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37686
38861
|
this._metrics.federations = (this._metrics.federations || 0) + 1;
|
|
37687
38862
|
return true;
|
|
37688
38863
|
}
|
|
38864
|
+
/**
|
|
38865
|
+
* Propagates existing data from one holon to another.
|
|
38866
|
+
*
|
|
38867
|
+
* @private
|
|
38868
|
+
* @param {string} fromHolon - Source holon H3 cell ID
|
|
38869
|
+
* @param {string} toHolon - Target holon H3 cell ID
|
|
38870
|
+
* @param {string} lensName - Name of the lens
|
|
38871
|
+
* @param {Object} [options={}] - Propagation options
|
|
38872
|
+
* @param {string} [options.mode='reference'] - Mode: 'reference' or 'copy'
|
|
38873
|
+
* @param {Function} [options.filter] - Filter function to select data
|
|
38874
|
+
* @returns {Promise<void>}
|
|
38875
|
+
*/
|
|
37689
38876
|
async _propagateExistingData(fromHolon, toHolon2, lensName, options = {}) {
|
|
37690
38877
|
const { mode = "reference", filter = null } = options;
|
|
37691
38878
|
const existingData = await this.read(fromHolon, lensName, null, { resolveHolograms: false });
|
|
@@ -37705,6 +38892,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37705
38892
|
);
|
|
37706
38893
|
}
|
|
37707
38894
|
}
|
|
38895
|
+
/**
|
|
38896
|
+
* Gets federated data from a holon, optionally resolving holograms.
|
|
38897
|
+
*
|
|
38898
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
38899
|
+
* @param {string} lensName - Name of the lens
|
|
38900
|
+
* @param {Object} [options={}] - Options
|
|
38901
|
+
* @param {boolean} [options.resolveHolograms=true] - Whether to resolve hologram references
|
|
38902
|
+
* @returns {Promise<Array|null>} Array of data objects or null
|
|
38903
|
+
*/
|
|
37708
38904
|
async getFederatedData(holonId, lensName, options = {}) {
|
|
37709
38905
|
const { resolveHolograms = true } = options;
|
|
37710
38906
|
const path = buildPath(this.config.appName, holonId, lensName);
|
|
@@ -37712,6 +38908,14 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37712
38908
|
if (!data || !resolveHolograms) return data;
|
|
37713
38909
|
return this._resolveHolograms(data);
|
|
37714
38910
|
}
|
|
38911
|
+
/**
|
|
38912
|
+
* Removes federation between two holons for a specific lens.
|
|
38913
|
+
*
|
|
38914
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
38915
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
38916
|
+
* @param {string} lensName - Name of the lens
|
|
38917
|
+
* @returns {Promise<boolean>} Always returns true (idempotent operation)
|
|
38918
|
+
*/
|
|
37715
38919
|
async unfederate(sourceHolon, targetHolon, lensName) {
|
|
37716
38920
|
const configPath = buildPath(this.config.appName, sourceHolon, lensName, "_federation");
|
|
37717
38921
|
try {
|
|
@@ -37720,6 +38924,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37720
38924
|
}
|
|
37721
38925
|
return true;
|
|
37722
38926
|
}
|
|
38927
|
+
/**
|
|
38928
|
+
* Updates local override values on a hologram.
|
|
38929
|
+
*
|
|
38930
|
+
* @param {string} holonId - H3 cell ID where the hologram exists
|
|
38931
|
+
* @param {string} lensName - Name of the lens
|
|
38932
|
+
* @param {string} dataId - ID of the hologram
|
|
38933
|
+
* @param {Object} overrides - Object containing local override values
|
|
38934
|
+
* @returns {Promise<boolean>} True if update succeeded
|
|
38935
|
+
*/
|
|
37723
38936
|
async updateHologramOverrides(holonId, lensName, dataId, overrides) {
|
|
37724
38937
|
return updateHologramOverrides(
|
|
37725
38938
|
this.client,
|
|
@@ -37730,6 +38943,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37730
38943
|
overrides
|
|
37731
38944
|
);
|
|
37732
38945
|
}
|
|
38946
|
+
/**
|
|
38947
|
+
* Creates a hologram (reference) object structure.
|
|
38948
|
+
*
|
|
38949
|
+
* @param {string} sourceHolon - Source holon H3 cell ID where the original data lives
|
|
38950
|
+
* @param {string} lensName - Name of the lens
|
|
38951
|
+
* @param {Object} data - Data object containing the id to reference
|
|
38952
|
+
* @param {string} [targetHolon=null] - Target holon for the hologram, defaults to sourceHolon
|
|
38953
|
+
* @returns {Object} Hologram object structure
|
|
38954
|
+
*/
|
|
37733
38955
|
createHologram(sourceHolon, lensName, data, targetHolon = null) {
|
|
37734
38956
|
return createHologram(
|
|
37735
38957
|
sourceHolon,
|
|
@@ -37739,6 +38961,14 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37739
38961
|
this.config.appName
|
|
37740
38962
|
);
|
|
37741
38963
|
}
|
|
38964
|
+
/**
|
|
38965
|
+
* Gets all active holograms (references) pointing to a specific data item.
|
|
38966
|
+
*
|
|
38967
|
+
* @param {string} holonId - H3 cell ID of the source holon
|
|
38968
|
+
* @param {string} lensName - Name of the lens
|
|
38969
|
+
* @param {string} dataId - ID of the source data
|
|
38970
|
+
* @returns {Promise<Array>} Array of active hologram references
|
|
38971
|
+
*/
|
|
37742
38972
|
async getActiveHolograms(holonId, lensName, dataId) {
|
|
37743
38973
|
const path = buildPath(this.config.appName, holonId, lensName, dataId);
|
|
37744
38974
|
const sourceData = await read(this.client, path);
|
|
@@ -37747,6 +38977,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37747
38977
|
}
|
|
37748
38978
|
return sourceData._meta.activeHolograms;
|
|
37749
38979
|
}
|
|
38980
|
+
/**
|
|
38981
|
+
* Removes an active hologram reference from a source data item.
|
|
38982
|
+
*
|
|
38983
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
38984
|
+
* @param {string} lensName - Name of the lens
|
|
38985
|
+
* @param {string} dataId - ID of the source data
|
|
38986
|
+
* @param {string} targetHolon - Target holon where the hologram exists
|
|
38987
|
+
* @returns {Promise<boolean>} True if removal succeeded
|
|
38988
|
+
*/
|
|
37750
38989
|
async removeActiveHologram(sourceHolon, lensName, dataId, targetHolon) {
|
|
37751
38990
|
return removeActiveHologram(
|
|
37752
38991
|
this.client,
|
|
@@ -37757,6 +38996,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37757
38996
|
targetHolon
|
|
37758
38997
|
);
|
|
37759
38998
|
}
|
|
38999
|
+
/**
|
|
39000
|
+
* Deletes a hologram and cleans up its references.
|
|
39001
|
+
*
|
|
39002
|
+
* @param {string} holonId - H3 cell ID where the hologram exists
|
|
39003
|
+
* @param {string} lensName - Name of the lens
|
|
39004
|
+
* @param {string} dataId - ID of the hologram to delete
|
|
39005
|
+
* @param {Object} [options={}] - Delete options
|
|
39006
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
39007
|
+
*/
|
|
37760
39008
|
async deleteHologram(holonId, lensName, dataId, options = {}) {
|
|
37761
39009
|
return deleteHologram(
|
|
37762
39010
|
this.client,
|
|
@@ -37767,6 +39015,17 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37767
39015
|
options
|
|
37768
39016
|
);
|
|
37769
39017
|
}
|
|
39018
|
+
/**
|
|
39019
|
+
* Propagates data from source holon to target holon.
|
|
39020
|
+
*
|
|
39021
|
+
* @param {Object} data - Data to propagate
|
|
39022
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
39023
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
39024
|
+
* @param {string} lensName - Name of the lens
|
|
39025
|
+
* @param {Object} [options={}] - Propagation options
|
|
39026
|
+
* @param {string} [options.mode='reference'] - Mode: 'reference' creates hologram, 'copy' duplicates data
|
|
39027
|
+
* @returns {Promise<Object>} Result of propagation
|
|
39028
|
+
*/
|
|
37770
39029
|
async propagateData(data, sourceHolon, targetHolon, lensName, options = {}) {
|
|
37771
39030
|
const mode = options.mode || "reference";
|
|
37772
39031
|
return propagateData(
|
|
@@ -37779,18 +39038,51 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37779
39038
|
mode
|
|
37780
39039
|
);
|
|
37781
39040
|
}
|
|
39041
|
+
/**
|
|
39042
|
+
* Resolves a hologram to its source data.
|
|
39043
|
+
*
|
|
39044
|
+
* @param {Object} hologram - Hologram object to resolve
|
|
39045
|
+
* @param {Object} [options={}] - Resolution options
|
|
39046
|
+
* @returns {Promise<Object|null>} Resolved data or null if source not found
|
|
39047
|
+
*/
|
|
37782
39048
|
async resolveHologram(hologram$1, options = {}) {
|
|
37783
39049
|
return resolveHologram(this.client, hologram$1, /* @__PURE__ */ new Set(), [], { ...options, appname: this.config.appName });
|
|
37784
39050
|
}
|
|
39051
|
+
/**
|
|
39052
|
+
* Checks if an object is a hologram (unresolved reference).
|
|
39053
|
+
*
|
|
39054
|
+
* @param {Object} data - Data object to check
|
|
39055
|
+
* @returns {boolean} True if the object is a hologram
|
|
39056
|
+
*/
|
|
37785
39057
|
isHologram(data) {
|
|
37786
39058
|
return isHologram(data);
|
|
37787
39059
|
}
|
|
39060
|
+
/**
|
|
39061
|
+
* Checks if an object is a resolved hologram (has _hologram metadata).
|
|
39062
|
+
*
|
|
39063
|
+
* @param {Object} data - Data object to check
|
|
39064
|
+
* @returns {boolean} True if the object is a resolved hologram
|
|
39065
|
+
*/
|
|
37788
39066
|
isResolvedHologram(data) {
|
|
37789
39067
|
return isResolvedHologram(data);
|
|
37790
39068
|
}
|
|
39069
|
+
/**
|
|
39070
|
+
* Gets the source information from a hologram or resolved hologram.
|
|
39071
|
+
*
|
|
39072
|
+
* @param {Object} data - Hologram or resolved hologram object
|
|
39073
|
+
* @returns {Object|null} Source information or null
|
|
39074
|
+
*/
|
|
37791
39075
|
getHologramSource(data) {
|
|
37792
39076
|
return getHologramSource(data);
|
|
37793
39077
|
}
|
|
39078
|
+
/**
|
|
39079
|
+
* Cleans up circular hologram references in a holon.
|
|
39080
|
+
*
|
|
39081
|
+
* @param {string} holonId - H3 cell ID of the holon
|
|
39082
|
+
* @param {string} lensName - Name of the lens
|
|
39083
|
+
* @param {Object} [options={}] - Cleanup options
|
|
39084
|
+
* @returns {Promise<Object>} Cleanup results
|
|
39085
|
+
*/
|
|
37794
39086
|
async cleanupCircularHolograms(holonId, lensName, options = {}) {
|
|
37795
39087
|
return cleanupCircularHolograms(
|
|
37796
39088
|
this.client,
|
|
@@ -37800,6 +39092,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37800
39092
|
options
|
|
37801
39093
|
);
|
|
37802
39094
|
}
|
|
39095
|
+
/**
|
|
39096
|
+
* Cleans up circular hologram references for specific data IDs.
|
|
39097
|
+
*
|
|
39098
|
+
* @param {string} holonId - H3 cell ID of the holon
|
|
39099
|
+
* @param {string} lensName - Name of the lens
|
|
39100
|
+
* @param {string[]} dataIds - Array of data IDs to check
|
|
39101
|
+
* @param {Object} [options={}] - Cleanup options
|
|
39102
|
+
* @returns {Promise<Object>} Cleanup results
|
|
39103
|
+
*/
|
|
37803
39104
|
async cleanupCircularHologramsByIds(holonId, lensName, dataIds, options = {}) {
|
|
37804
39105
|
return cleanupCircularHologramsByIds(
|
|
37805
39106
|
this.client,
|
|
@@ -37810,6 +39111,17 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37810
39111
|
options
|
|
37811
39112
|
);
|
|
37812
39113
|
}
|
|
39114
|
+
/**
|
|
39115
|
+
* Propagates data to all federated holons.
|
|
39116
|
+
*
|
|
39117
|
+
* @param {string} holonId - Source holon H3 cell ID
|
|
39118
|
+
* @param {string} lensName - Name of the lens
|
|
39119
|
+
* @param {Object} data - Data to propagate
|
|
39120
|
+
* @param {Object} [options={}] - Propagation options
|
|
39121
|
+
* @param {boolean} [options.useHolograms=true] - Whether to create holograms
|
|
39122
|
+
* @param {boolean} [options.resolveExisting=true] - Whether to resolve existing data
|
|
39123
|
+
* @returns {Promise<Array|undefined>} Array of propagation results or undefined if no targets
|
|
39124
|
+
*/
|
|
37813
39125
|
async propagate(holonId, lensName, data, options = {}) {
|
|
37814
39126
|
const federationData = await this.getFederation(holonId);
|
|
37815
39127
|
const targets = federationData?.federated || federationData?.outbound || [];
|
|
@@ -37828,6 +39140,13 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37828
39140
|
}
|
|
37829
39141
|
return results;
|
|
37830
39142
|
}
|
|
39143
|
+
/**
|
|
39144
|
+
* Gets the federation configuration for a holon.
|
|
39145
|
+
*
|
|
39146
|
+
* @param {string} holonId - H3 cell ID of the holon
|
|
39147
|
+
* @returns {Promise<Object|null>} Federation configuration object or null
|
|
39148
|
+
* @throws {Error} If holonId is not provided
|
|
39149
|
+
*/
|
|
37831
39150
|
async getFederation(holonId) {
|
|
37832
39151
|
if (!holonId) {
|
|
37833
39152
|
throw new Error("getFederation: Missing holon ID");
|
|
@@ -37844,8 +39163,22 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37844
39163
|
}
|
|
37845
39164
|
return data;
|
|
37846
39165
|
}
|
|
39166
|
+
/**
|
|
39167
|
+
* Establishes a holon-level federation relationship.
|
|
39168
|
+
*
|
|
39169
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
39170
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
39171
|
+
* @param {Object} [options={}] - Federation options
|
|
39172
|
+
* @param {Object} [options.lensConfig] - Lens configuration for federation
|
|
39173
|
+
* @param {string[]} [options.lensConfig.inbound] - Lenses for inbound federation
|
|
39174
|
+
* @param {string[]} [options.lensConfig.outbound] - Lenses for outbound federation
|
|
39175
|
+
* @param {string} [options.partnerName] - Human-readable name for the partner holon
|
|
39176
|
+
* @param {boolean} [options.skipPropagation=false] - Skip propagating existing data
|
|
39177
|
+
* @returns {Promise<boolean>} True if federation was established
|
|
39178
|
+
* @throws {Error} If trying to federate a holon with itself
|
|
39179
|
+
*/
|
|
37847
39180
|
async federateHolon(sourceHolon, targetHolon, options = {}) {
|
|
37848
|
-
const { lensConfig = { inbound: [], outbound: [] }, partnerName = null } = options;
|
|
39181
|
+
const { lensConfig = { inbound: [], outbound: [] }, partnerName = null, skipPropagation = false } = options;
|
|
37849
39182
|
if (sourceHolon === targetHolon) {
|
|
37850
39183
|
throw new Error("Cannot federate a holon with itself");
|
|
37851
39184
|
}
|
|
@@ -37891,7 +39224,7 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37891
39224
|
};
|
|
37892
39225
|
const success = await this.writeGlobal("federation", federationData);
|
|
37893
39226
|
this.clearCache("federation");
|
|
37894
|
-
if (success) {
|
|
39227
|
+
if (success && !skipPropagation) {
|
|
37895
39228
|
for (const lens of lensConfig.inbound || []) {
|
|
37896
39229
|
await this.federate(targetHolon, sourceHolon, lens, { direction: "outbound", mode: "reference" });
|
|
37897
39230
|
}
|
|
@@ -37901,6 +39234,13 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37901
39234
|
}
|
|
37902
39235
|
return success;
|
|
37903
39236
|
}
|
|
39237
|
+
/**
|
|
39238
|
+
* Removes a holon-level federation relationship.
|
|
39239
|
+
*
|
|
39240
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
39241
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
39242
|
+
* @returns {Promise<boolean>} True if unfederation succeeded, false if no federation existed
|
|
39243
|
+
*/
|
|
37904
39244
|
async unfederateHolon(sourceHolon, targetHolon) {
|
|
37905
39245
|
const federationData = await this.readGlobal("federation", sourceHolon);
|
|
37906
39246
|
if (!federationData) return false;
|
|
@@ -37923,16 +39263,43 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37923
39263
|
}
|
|
37924
39264
|
return success;
|
|
37925
39265
|
}
|
|
39266
|
+
/**
|
|
39267
|
+
* Gets the federation configuration between two holons.
|
|
39268
|
+
*
|
|
39269
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
39270
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
39271
|
+
* @returns {Promise<Object|null>} Lens configuration or null
|
|
39272
|
+
*/
|
|
37926
39273
|
async getFederatedConfig(sourceHolon, targetHolon) {
|
|
37927
39274
|
const federationData = await this.readGlobal("federation", sourceHolon);
|
|
37928
39275
|
if (!federationData || !federationData.lensConfig) return null;
|
|
37929
39276
|
return federationData.lensConfig[targetHolon] || null;
|
|
37930
39277
|
}
|
|
37931
39278
|
// === Hierarchical Operations ===
|
|
39279
|
+
/**
|
|
39280
|
+
* Performs hierarchical upcast aggregation.
|
|
39281
|
+
* Aggregates data from child holons up to parent holons in the H3 hierarchy.
|
|
39282
|
+
*
|
|
39283
|
+
* @param {string} holonId - Starting holon H3 cell ID
|
|
39284
|
+
* @param {string} lensName - Name of the lens
|
|
39285
|
+
* @param {string} dataId - ID of the data to upcast
|
|
39286
|
+
* @param {Object} [options={}] - Upcast options
|
|
39287
|
+
* @returns {Promise<Object>} Aggregation result
|
|
39288
|
+
*/
|
|
37932
39289
|
async upcast(holonId, lensName, dataId, options = {}) {
|
|
37933
39290
|
return upcast(this, holonId, lensName, dataId, options);
|
|
37934
39291
|
}
|
|
37935
39292
|
// === Subscriptions ===
|
|
39293
|
+
/**
|
|
39294
|
+
* Subscribes to real-time updates for a holon and lens.
|
|
39295
|
+
*
|
|
39296
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39297
|
+
* @param {string} lensName - Name of the lens
|
|
39298
|
+
* @param {Function} callback - Callback function called with updated data
|
|
39299
|
+
* @param {Object} [options={}] - Subscription options
|
|
39300
|
+
* @returns {{unsubscribe: Function}} Subscription object with unsubscribe method
|
|
39301
|
+
* @throws {TypeError} If callback is not a function
|
|
39302
|
+
*/
|
|
37936
39303
|
subscribe(holonId, lensName, callback, options = {}) {
|
|
37937
39304
|
if (typeof callback !== "function") {
|
|
37938
39305
|
throw new TypeError("callback must be a function");
|
|
@@ -37962,6 +39329,15 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37962
39329
|
}
|
|
37963
39330
|
};
|
|
37964
39331
|
}
|
|
39332
|
+
/**
|
|
39333
|
+
* Subscribes to real-time updates for a global table.
|
|
39334
|
+
*
|
|
39335
|
+
* @param {string} table - Name of the global table
|
|
39336
|
+
* @param {string} key - Key to subscribe to
|
|
39337
|
+
* @param {Function} callback - Callback function called with updated data
|
|
39338
|
+
* @param {Object} [options={}] - Subscription options
|
|
39339
|
+
* @returns {Promise<{unsubscribe: Function}>} Subscription object
|
|
39340
|
+
*/
|
|
37965
39341
|
async subscribeGlobal(table, key, callback, options = {}) {
|
|
37966
39342
|
return subscribeGlobal(
|
|
37967
39343
|
this.client,
|
|
@@ -37973,22 +39349,71 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
37973
39349
|
);
|
|
37974
39350
|
}
|
|
37975
39351
|
// === Crypto Operations ===
|
|
39352
|
+
/**
|
|
39353
|
+
* Derives a public key from a private key.
|
|
39354
|
+
*
|
|
39355
|
+
* @param {string} privateKey - Hex-encoded private key
|
|
39356
|
+
* @returns {Promise<string>} Hex-encoded public key
|
|
39357
|
+
*/
|
|
37976
39358
|
async getPublicKey(privateKey) {
|
|
37977
39359
|
return getPublicKey$1(privateKey);
|
|
37978
39360
|
}
|
|
39361
|
+
/**
|
|
39362
|
+
* Signs content with a private key.
|
|
39363
|
+
*
|
|
39364
|
+
* @param {string|Object} content - Content to sign
|
|
39365
|
+
* @param {string} privateKey - Hex-encoded private key
|
|
39366
|
+
* @returns {Promise<string>} Hex-encoded signature
|
|
39367
|
+
*/
|
|
37979
39368
|
async sign(content, privateKey) {
|
|
37980
39369
|
return sign(content, privateKey);
|
|
37981
39370
|
}
|
|
39371
|
+
/**
|
|
39372
|
+
* Verifies a signature against content and public key.
|
|
39373
|
+
*
|
|
39374
|
+
* @param {string|Object} content - Original content
|
|
39375
|
+
* @param {string} signature - Hex-encoded signature
|
|
39376
|
+
* @param {string} publicKey - Hex-encoded public key
|
|
39377
|
+
* @returns {Promise<boolean>} True if signature is valid
|
|
39378
|
+
*/
|
|
37982
39379
|
async verify(content, signature, publicKey) {
|
|
37983
39380
|
return verify(content, signature, publicKey);
|
|
37984
39381
|
}
|
|
39382
|
+
/**
|
|
39383
|
+
* Issues a capability token for authorization.
|
|
39384
|
+
*
|
|
39385
|
+
* @param {string[]} permissions - Array of permissions ('read', 'write', 'delete')
|
|
39386
|
+
* @param {Object} scope - Scope of the capability (holonId, lensName, etc.)
|
|
39387
|
+
* @param {string} recipient - Public key of the recipient
|
|
39388
|
+
* @param {Object} [options] - Additional options
|
|
39389
|
+
* @returns {Promise<string>} Signed capability token
|
|
39390
|
+
*/
|
|
37985
39391
|
async issueCapability(permissions, scope, recipient, options) {
|
|
37986
39392
|
return issueCapability(permissions, scope, recipient, options);
|
|
37987
39393
|
}
|
|
39394
|
+
/**
|
|
39395
|
+
* Verifies a capability token.
|
|
39396
|
+
*
|
|
39397
|
+
* @param {string} token - Capability token to verify
|
|
39398
|
+
* @param {string} requiredPermission - Required permission to check
|
|
39399
|
+
* @param {Object} scope - Scope to verify against
|
|
39400
|
+
* @returns {Promise<boolean>} True if token is valid and has required permission
|
|
39401
|
+
*/
|
|
37988
39402
|
async verifyCapability(token, requiredPermission, scope) {
|
|
37989
39403
|
return verifyCapability(token, requiredPermission, scope);
|
|
37990
39404
|
}
|
|
37991
39405
|
// === Social Protocol Operations ===
|
|
39406
|
+
/**
|
|
39407
|
+
* Publishes a Nostr event to a holon.
|
|
39408
|
+
*
|
|
39409
|
+
* @param {Object} event - Nostr event object
|
|
39410
|
+
* @param {number} event.kind - Event kind
|
|
39411
|
+
* @param {string} event.content - Event content
|
|
39412
|
+
* @param {Array} [event.tags] - Event tags
|
|
39413
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39414
|
+
* @param {string} [lensName='social'] - Name of the lens
|
|
39415
|
+
* @returns {Promise<boolean>} True if publish succeeded
|
|
39416
|
+
*/
|
|
37992
39417
|
async publishNostr(event, holonId, lensName = "social") {
|
|
37993
39418
|
validateNostrEvent(event, true, true);
|
|
37994
39419
|
const enrichedEvent = {
|
|
@@ -38004,6 +39429,16 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
38004
39429
|
await write(this.client, path, eventWithProtocol);
|
|
38005
39430
|
return true;
|
|
38006
39431
|
}
|
|
39432
|
+
/**
|
|
39433
|
+
* Publishes an ActivityPub object to a holon.
|
|
39434
|
+
*
|
|
39435
|
+
* @param {Object} object - ActivityPub object
|
|
39436
|
+
* @param {string} object.type - ActivityPub type (Note, Article, etc.)
|
|
39437
|
+
* @param {string} [object.actor] - Actor ID (defaults to client public key)
|
|
39438
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39439
|
+
* @param {string} [lensName='social'] - Name of the lens
|
|
39440
|
+
* @returns {Promise<boolean>} True if publish succeeded
|
|
39441
|
+
*/
|
|
38007
39442
|
async publishActivityPub(object, holonId, lensName = "social") {
|
|
38008
39443
|
validateActivityPubObject(object, true);
|
|
38009
39444
|
const activity = transformActivityPubObject({
|
|
@@ -38012,6 +39447,18 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
38012
39447
|
});
|
|
38013
39448
|
return this.write(holonId, lensName, activity);
|
|
38014
39449
|
}
|
|
39450
|
+
/**
|
|
39451
|
+
* Queries social protocol data from a holon.
|
|
39452
|
+
*
|
|
39453
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39454
|
+
* @param {Object} [options={}] - Query options
|
|
39455
|
+
* @param {string} [options.lens='social'] - Name of the lens
|
|
39456
|
+
* @param {string} [options.protocol] - Filter by protocol ('nostr', 'activitypub', 'all')
|
|
39457
|
+
* @param {string} [options.type] - Filter by content type
|
|
39458
|
+
* @param {number} [options.since] - Filter events after this timestamp
|
|
39459
|
+
* @param {number} [options.until] - Filter events before this timestamp
|
|
39460
|
+
* @returns {Promise<Array>} Array of matching social items
|
|
39461
|
+
*/
|
|
38015
39462
|
async querySocial(holonId, options = {}) {
|
|
38016
39463
|
const lensName = options.lens || "social";
|
|
38017
39464
|
const data = await this.read(holonId, lensName);
|
|
@@ -38025,12 +39472,37 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
38025
39472
|
return true;
|
|
38026
39473
|
});
|
|
38027
39474
|
}
|
|
39475
|
+
/**
|
|
39476
|
+
* Verifies a Nostr event signature.
|
|
39477
|
+
*
|
|
39478
|
+
* @param {Object} event - Nostr event to verify
|
|
39479
|
+
* @param {string} event.id - Event ID
|
|
39480
|
+
* @param {string} event.pubkey - Author public key
|
|
39481
|
+
* @param {number} event.created_at - Creation timestamp
|
|
39482
|
+
* @param {number} event.kind - Event kind
|
|
39483
|
+
* @param {Array} event.tags - Event tags
|
|
39484
|
+
* @param {string} event.content - Event content
|
|
39485
|
+
* @param {string} event.sig - Event signature
|
|
39486
|
+
* @returns {Promise<boolean>} True if event signature is valid
|
|
39487
|
+
*/
|
|
38028
39488
|
async verifyNostrEvent(event) {
|
|
38029
39489
|
const { id: id2, pubkey, created_at, kind: kind2, tags, content, sig } = event;
|
|
38030
39490
|
const standardEvent = { id: id2, pubkey, created_at, kind: kind2, tags, content, sig };
|
|
38031
39491
|
return verifyEvent(standardEvent);
|
|
38032
39492
|
}
|
|
38033
39493
|
// === Metrics ===
|
|
39494
|
+
/**
|
|
39495
|
+
* Gets performance metrics for this HoloSphere instance.
|
|
39496
|
+
*
|
|
39497
|
+
* @returns {Object} Metrics object
|
|
39498
|
+
* @returns {number} return.reads - Number of read operations
|
|
39499
|
+
* @returns {number} return.writes - Number of write operations
|
|
39500
|
+
* @returns {number} return.deletes - Number of delete operations
|
|
39501
|
+
* @returns {number} return.federations - Number of federation operations
|
|
39502
|
+
* @returns {number} return.subscriptions - Number of active subscriptions
|
|
39503
|
+
* @returns {number} return.avgReadTime - Average read time in milliseconds
|
|
39504
|
+
* @returns {number} return.avgWriteTime - Average write time in milliseconds
|
|
39505
|
+
*/
|
|
38034
39506
|
metrics() {
|
|
38035
39507
|
const reads = this._metrics.reads || 0;
|
|
38036
39508
|
const writes = this._metrics.writes || 0;
|
|
@@ -38047,46 +39519,142 @@ class HoloSphereBase extends HoloSphere$1 {
|
|
|
38047
39519
|
};
|
|
38048
39520
|
}
|
|
38049
39521
|
// === Aliases ===
|
|
39522
|
+
/**
|
|
39523
|
+
* Alias for {@link HoloSphereBase#write}.
|
|
39524
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39525
|
+
* @param {string} lensName - Name of the lens
|
|
39526
|
+
* @param {Object} data - Data to write
|
|
39527
|
+
* @param {Object} [options] - Write options
|
|
39528
|
+
* @returns {Promise<boolean>}
|
|
39529
|
+
*/
|
|
38050
39530
|
async put(holonId, lensName, data, options = {}) {
|
|
38051
39531
|
return this.write(holonId, lensName, data, options);
|
|
38052
39532
|
}
|
|
39533
|
+
/**
|
|
39534
|
+
* Alias for {@link HoloSphereBase#read}.
|
|
39535
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39536
|
+
* @param {string} lensName - Name of the lens
|
|
39537
|
+
* @param {string|null} [dataId] - Specific data ID or null
|
|
39538
|
+
* @param {Object} [options] - Read options
|
|
39539
|
+
* @returns {Promise<Object|Array|null>}
|
|
39540
|
+
*/
|
|
38053
39541
|
async get(holonId, lensName, dataId = null, options = {}) {
|
|
38054
39542
|
return this.read(holonId, lensName, dataId, options);
|
|
38055
39543
|
}
|
|
39544
|
+
/**
|
|
39545
|
+
* Alias for {@link HoloSphereBase#delete}.
|
|
39546
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39547
|
+
* @param {string} lensName - Name of the lens
|
|
39548
|
+
* @param {string} dataId - Data ID to delete
|
|
39549
|
+
* @param {Object} [options] - Delete options
|
|
39550
|
+
* @returns {Promise<boolean>}
|
|
39551
|
+
*/
|
|
38056
39552
|
async remove(holonId, lensName, dataId, options = {}) {
|
|
38057
39553
|
return this.delete(holonId, lensName, dataId, options);
|
|
38058
39554
|
}
|
|
39555
|
+
/**
|
|
39556
|
+
* Alias for {@link HoloSphereBase#writeGlobal}.
|
|
39557
|
+
* @param {string} table - Global table name
|
|
39558
|
+
* @param {Object} data - Data to write
|
|
39559
|
+
* @returns {Promise<boolean>}
|
|
39560
|
+
*/
|
|
38059
39561
|
async putGlobal(table, data) {
|
|
38060
39562
|
return this.writeGlobal(table, data);
|
|
38061
39563
|
}
|
|
39564
|
+
/**
|
|
39565
|
+
* Alias for {@link HoloSphereBase#readGlobal}.
|
|
39566
|
+
* @param {string} table - Global table name
|
|
39567
|
+
* @param {string|null} [key] - Key to read
|
|
39568
|
+
* @returns {Promise<Object|Array|null>}
|
|
39569
|
+
*/
|
|
38062
39570
|
async getGlobal(table, key = null) {
|
|
38063
39571
|
return this.readGlobal(table, key);
|
|
38064
39572
|
}
|
|
39573
|
+
/**
|
|
39574
|
+
* Alias for {@link HoloSphereBase#deleteGlobal}.
|
|
39575
|
+
* @param {string} table - Global table name
|
|
39576
|
+
* @param {string} key - Key to delete
|
|
39577
|
+
* @returns {Promise<boolean>}
|
|
39578
|
+
*/
|
|
38065
39579
|
async removeGlobal(table, key) {
|
|
38066
39580
|
return this.deleteGlobal(table, key);
|
|
38067
39581
|
}
|
|
39582
|
+
/**
|
|
39583
|
+
* Alias for {@link HoloSphereBase#setSchema}.
|
|
39584
|
+
* @param {string} lensName - Lens name
|
|
39585
|
+
* @param {Object|string} schemaObj - Schema object or URI
|
|
39586
|
+
* @param {boolean} [strict] - Strict mode
|
|
39587
|
+
* @returns {Promise<void>}
|
|
39588
|
+
*/
|
|
38068
39589
|
async defineSchema(lensName, schemaObj, strict = false) {
|
|
38069
39590
|
return this.setSchema(lensName, schemaObj, strict);
|
|
38070
39591
|
}
|
|
39592
|
+
/**
|
|
39593
|
+
* Alias for {@link HoloSphereBase#getSchema}.
|
|
39594
|
+
* @param {string} lensName - Lens name
|
|
39595
|
+
* @returns {Promise<Object|null>}
|
|
39596
|
+
*/
|
|
38071
39597
|
async fetchSchema(lensName) {
|
|
38072
39598
|
return this.getSchema(lensName);
|
|
38073
39599
|
}
|
|
39600
|
+
/**
|
|
39601
|
+
* Alias for {@link HoloSphereBase#clearSchema}.
|
|
39602
|
+
* @param {string} lensName - Lens name
|
|
39603
|
+
* @returns {Promise<void>}
|
|
39604
|
+
*/
|
|
38074
39605
|
async removeSchema(lensName) {
|
|
38075
39606
|
return this.clearSchema(lensName);
|
|
38076
39607
|
}
|
|
39608
|
+
/**
|
|
39609
|
+
* Alias for {@link HoloSphereBase#write}.
|
|
39610
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39611
|
+
* @param {string} lensName - Name of the lens
|
|
39612
|
+
* @param {Object} data - Data to write
|
|
39613
|
+
* @param {Object} [options] - Write options
|
|
39614
|
+
* @returns {Promise<boolean>}
|
|
39615
|
+
*/
|
|
38077
39616
|
async store(holonId, lensName, data, options = {}) {
|
|
38078
39617
|
return this.write(holonId, lensName, data, options);
|
|
38079
39618
|
}
|
|
39619
|
+
/**
|
|
39620
|
+
* Alias for {@link HoloSphereBase#read}.
|
|
39621
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39622
|
+
* @param {string} lensName - Name of the lens
|
|
39623
|
+
* @param {string|null} [dataId] - Specific data ID or null
|
|
39624
|
+
* @param {Object} [options] - Read options
|
|
39625
|
+
* @returns {Promise<Object|Array|null>}
|
|
39626
|
+
*/
|
|
38080
39627
|
async fetch(holonId, lensName, dataId = null, options = {}) {
|
|
38081
39628
|
return this.read(holonId, lensName, dataId, options);
|
|
38082
39629
|
}
|
|
39630
|
+
/**
|
|
39631
|
+
* Alias for {@link HoloSphereBase#write}.
|
|
39632
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39633
|
+
* @param {string} lensName - Name of the lens
|
|
39634
|
+
* @param {Object} data - Data to write
|
|
39635
|
+
* @param {Object} [options] - Write options
|
|
39636
|
+
* @returns {Promise<boolean>}
|
|
39637
|
+
*/
|
|
38083
39638
|
async save(holonId, lensName, data, options = {}) {
|
|
38084
39639
|
return this.write(holonId, lensName, data, options);
|
|
38085
39640
|
}
|
|
39641
|
+
/**
|
|
39642
|
+
* Alias for {@link HoloSphereBase#read}.
|
|
39643
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
39644
|
+
* @param {string} lensName - Name of the lens
|
|
39645
|
+
* @param {string|null} [dataId] - Specific data ID or null
|
|
39646
|
+
* @param {Object} [options] - Read options
|
|
39647
|
+
* @returns {Promise<Object|Array|null>}
|
|
39648
|
+
*/
|
|
38086
39649
|
async load(holonId, lensName, dataId = null, options = {}) {
|
|
38087
39650
|
return this.read(holonId, lensName, dataId, options);
|
|
38088
39651
|
}
|
|
38089
39652
|
// === Cache ===
|
|
39653
|
+
/**
|
|
39654
|
+
* Clears the internal cache.
|
|
39655
|
+
*
|
|
39656
|
+
* @param {string|null} [pattern=null] - If provided, only clear cache entries matching this pattern
|
|
39657
|
+
*/
|
|
38090
39658
|
clearCache(pattern = null) {
|
|
38091
39659
|
if (pattern) {
|
|
38092
39660
|
for (const key of this._cache.keys()) {
|
|
@@ -38270,4 +39838,4 @@ export {
|
|
|
38270
39838
|
exists as y,
|
|
38271
39839
|
bytes as z
|
|
38272
39840
|
};
|
|
38273
|
-
//# sourceMappingURL=index-
|
|
39841
|
+
//# sourceMappingURL=index-DJXftyvB.js.map
|