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
package/src/ai/h3-ai.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview Geospatial intelligence for H3 hexagonal hierarchies.
|
|
3
|
+
* Provides AI-powered analysis of geographic data distribution, resolution suggestions,
|
|
4
|
+
* coverage analysis, and cross-resolution insights using the H3 geospatial indexing system.
|
|
5
|
+
* @module ai/h3-ai
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import * as h3 from 'h3-js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
|
-
*
|
|
11
|
+
* Service class for geospatial intelligence using H3 hexagonal hierarchies.
|
|
12
|
+
* Analyzes geographic data patterns, suggests optimal resolutions, identifies coverage gaps,
|
|
13
|
+
* and provides multi-scale geographic insights across H3's hierarchical grid system.
|
|
14
|
+
*
|
|
15
|
+
* @class H3AI
|
|
16
|
+
* @example
|
|
17
|
+
* const h3ai = new H3AI(llmService, holosphere);
|
|
18
|
+
* const resolution = await h3ai.suggestResolution(project);
|
|
19
|
+
* const coverage = await h3ai.analyzeCoverage(holonId, 'projects');
|
|
20
|
+
* const distribution = await h3ai.analyzeDistribution(holonId, 'events');
|
|
9
21
|
*/
|
|
10
22
|
export class H3AI {
|
|
11
23
|
/**
|
package/src/ai/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HoloSphere AI Module
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview HoloSphere AI Module - Comprehensive AI functionality using OpenAI.
|
|
3
|
+
* Provides unified access to all AI services including LLM, embeddings, semantic operations,
|
|
4
|
+
* spatial analysis, task breakdown, and relationship discovery.
|
|
5
|
+
* @module ai
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
// Import all modules for local use and re-export
|
|
@@ -41,12 +43,19 @@ export {
|
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
|
-
*
|
|
46
|
+
* Factory function to create all AI services with shared LLM instance.
|
|
47
|
+
* Provides a convenient way to initialize the complete AI stack with a single call.
|
|
48
|
+
*
|
|
45
49
|
* @param {string} apiKey - OpenAI API key
|
|
46
|
-
* @param {Object} holosphere - HoloSphere instance
|
|
47
|
-
* @param {Object} options - Configuration options
|
|
48
|
-
* @param {Object}
|
|
49
|
-
* @
|
|
50
|
+
* @param {Object} [holosphere=null] - HoloSphere instance for data operations
|
|
51
|
+
* @param {Object} [options={}] - Configuration options
|
|
52
|
+
* @param {Object} [options.llm] - LLM service configuration (model, maxTokens, temperature)
|
|
53
|
+
* @param {Object} [openaiClient=null] - Pre-created OpenAI client for embeddings/TTS
|
|
54
|
+
* @returns {Object} Object containing all initialized AI service instances
|
|
55
|
+
* @example
|
|
56
|
+
* const ai = createAIServices(apiKey, holosphere, { llm: { model: 'gpt-4o-mini' } });
|
|
57
|
+
* const summary = await ai.llm.summarize(text);
|
|
58
|
+
* const results = await ai.nlQuery.execute("find projects near Rome");
|
|
50
59
|
*/
|
|
51
60
|
export function createAIServices(apiKey, holosphere = null, options = {}, openaiClient = null) {
|
|
52
61
|
// Create shared LLM service
|
package/src/ai/json-ops.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview AI-assisted semantic operations on JSON structures.
|
|
3
|
+
* Provides fuzzy operations like merge, subtract, union, and transform that understand semantic meaning.
|
|
4
|
+
* @module ai/json-ops
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Service class for semantic JSON manipulation using AI.
|
|
9
|
+
* Performs intelligent operations on JSON objects that go beyond simple structural merging,
|
|
10
|
+
* understanding semantic similarity and conceptual relationships between data.
|
|
11
|
+
*
|
|
12
|
+
* @class JSONOps
|
|
13
|
+
* @example
|
|
14
|
+
* const jsonOps = new JSONOps(llmService);
|
|
15
|
+
* const merged = await jsonOps.add(obj1, obj2);
|
|
16
|
+
* const diff = await jsonOps.difference(oldData, newData);
|
|
7
17
|
*/
|
|
8
18
|
export class JSONOps {
|
|
9
19
|
/**
|
|
@@ -14,11 +24,14 @@ export class JSONOps {
|
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
/**
|
|
17
|
-
* Semantically merge two JSON objects
|
|
27
|
+
* Semantically merge two JSON objects with intelligent deduplication.
|
|
28
|
+
* Combines information from both objects, resolving conflicts semantically.
|
|
29
|
+
*
|
|
18
30
|
* @param {Object} obj1 - First object
|
|
19
31
|
* @param {Object} obj2 - Second object
|
|
20
|
-
* @param {Object} options - Merge options
|
|
21
|
-
* @
|
|
32
|
+
* @param {Object} [options={}] - Merge options
|
|
33
|
+
* @param {boolean} [options.preferSecond=false] - Prefer second object's values in conflicts
|
|
34
|
+
* @returns {Promise<Object>} Merged object with combined information
|
|
22
35
|
*/
|
|
23
36
|
async add(obj1, obj2, options = {}) {
|
|
24
37
|
const systemPrompt = `You are a JSON merge expert. Semantically merge these two JSON objects.
|
package/src/ai/llm-service.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview Core OpenAI wrapper providing simple chat completions without Assistants API.
|
|
3
|
+
* @module ai/llm-service
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import OpenAI from 'openai';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Service class for interacting with OpenAI's chat completion API.
|
|
10
|
+
* Provides high-level methods for common LLM operations including summarization,
|
|
11
|
+
* analysis, categorization, translation, and structured JSON responses.
|
|
12
|
+
*
|
|
13
|
+
* @class LLMService
|
|
14
|
+
* @example
|
|
15
|
+
* const llm = new LLMService(apiKey, { model: 'gpt-4o-mini' });
|
|
16
|
+
* const summary = await llm.summarize(longText);
|
|
17
|
+
* const keywords = await llm.extractKeywords(text);
|
|
10
18
|
*/
|
|
11
19
|
export class LLMService {
|
|
12
20
|
/**
|
|
@@ -28,11 +36,16 @@ export class LLMService {
|
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
/**
|
|
31
|
-
* Send a message to the LLM
|
|
32
|
-
*
|
|
33
|
-
* @param {string}
|
|
34
|
-
* @param {
|
|
39
|
+
* Send a single-turn message to the LLM with system and user prompts.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} systemPrompt - System prompt defining role and behavior
|
|
42
|
+
* @param {string} userMessage - User message content
|
|
43
|
+
* @param {Object} [options={}] - Override options
|
|
44
|
+
* @param {string} [options.model] - Override model
|
|
45
|
+
* @param {number} [options.maxTokens] - Override max tokens
|
|
46
|
+
* @param {number} [options.temperature] - Override temperature
|
|
35
47
|
* @returns {Promise<string>} Response content
|
|
48
|
+
* @throws {Error} If LLM request fails
|
|
36
49
|
*/
|
|
37
50
|
async sendMessage(systemPrompt, userMessage, options = {}) {
|
|
38
51
|
try {
|
|
@@ -53,10 +66,15 @@ export class LLMService {
|
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
/**
|
|
56
|
-
* Send multiple messages
|
|
57
|
-
*
|
|
58
|
-
* @param {
|
|
69
|
+
* Send multiple messages in a conversation format.
|
|
70
|
+
*
|
|
71
|
+
* @param {Array<{role: string, content: string}>} messages - Array of message objects with role and content
|
|
72
|
+
* @param {Object} [options={}] - Override options
|
|
73
|
+
* @param {string} [options.model] - Override model
|
|
74
|
+
* @param {number} [options.maxTokens] - Override max tokens
|
|
75
|
+
* @param {number} [options.temperature] - Override temperature
|
|
59
76
|
* @returns {Promise<string>} Response content
|
|
77
|
+
* @throws {Error} If LLM chat fails
|
|
60
78
|
*/
|
|
61
79
|
async chat(messages, options = {}) {
|
|
62
80
|
try {
|
|
@@ -74,10 +92,13 @@ export class LLMService {
|
|
|
74
92
|
}
|
|
75
93
|
|
|
76
94
|
/**
|
|
77
|
-
*
|
|
95
|
+
* Generate a concise summary of text while preserving key information.
|
|
96
|
+
*
|
|
78
97
|
* @param {string} text - Text to summarize
|
|
79
|
-
* @param {Object} options -
|
|
80
|
-
* @
|
|
98
|
+
* @param {Object} [options={}] - Summarization options
|
|
99
|
+
* @param {number} [options.maxLength] - Maximum word count for summary
|
|
100
|
+
* @param {string} [options.style] - Summary style (e.g., 'bullet points', 'executive summary')
|
|
101
|
+
* @returns {Promise<string>} Summary text
|
|
81
102
|
*/
|
|
82
103
|
async summarize(text, options = {}) {
|
|
83
104
|
const systemPrompt = `You are a helpful assistant that summarizes text concisely while preserving key information. Keep summaries clear and focused.${
|
|
@@ -88,10 +109,11 @@ export class LLMService {
|
|
|
88
109
|
}
|
|
89
110
|
|
|
90
111
|
/**
|
|
91
|
-
* Analyze text from a specific perspective
|
|
112
|
+
* Analyze text from a specific perspective or aspect.
|
|
113
|
+
*
|
|
92
114
|
* @param {string} text - Text to analyze
|
|
93
|
-
* @param {string} aspect -
|
|
94
|
-
* @returns {Promise<string>}
|
|
115
|
+
* @param {string} aspect - Analysis aspect (e.g., 'sentiment', 'themes', 'tone', 'bias')
|
|
116
|
+
* @returns {Promise<string>} Structured analysis
|
|
95
117
|
*/
|
|
96
118
|
async analyze(text, aspect) {
|
|
97
119
|
const systemPrompt = `You are an expert analyst. Analyze the following text from the perspective of "${aspect}". Provide a clear, structured analysis.`;
|
|
@@ -99,10 +121,12 @@ export class LLMService {
|
|
|
99
121
|
}
|
|
100
122
|
|
|
101
123
|
/**
|
|
102
|
-
* Extract
|
|
124
|
+
* Extract key words and phrases from text.
|
|
125
|
+
*
|
|
103
126
|
* @param {string} text - Text to extract keywords from
|
|
104
|
-
* @param {number} maxKeywords - Maximum keywords
|
|
105
|
-
* @returns {Promise<string[]>} Array of
|
|
127
|
+
* @param {number} [maxKeywords=10] - Maximum number of keywords to extract
|
|
128
|
+
* @returns {Promise<string[]>} Array of keyword strings
|
|
129
|
+
* @throws {Error} If JSON parsing fails after retry attempts
|
|
106
130
|
*/
|
|
107
131
|
async extractKeywords(text, maxKeywords = 10) {
|
|
108
132
|
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"]`;
|
|
@@ -121,10 +145,11 @@ export class LLMService {
|
|
|
121
145
|
}
|
|
122
146
|
|
|
123
147
|
/**
|
|
124
|
-
* Categorize text into
|
|
148
|
+
* Categorize text into one of the provided categories with confidence score.
|
|
149
|
+
*
|
|
125
150
|
* @param {string} text - Text to categorize
|
|
126
|
-
* @param {string[]} categories - Available
|
|
127
|
-
* @returns {Promise<{category: string, confidence: number, reasoning: string}>}
|
|
151
|
+
* @param {string[]} categories - Available category options
|
|
152
|
+
* @returns {Promise<{category: string, confidence: number, reasoning: string}>} Categorization result
|
|
128
153
|
*/
|
|
129
154
|
async categorize(text, categories) {
|
|
130
155
|
const systemPrompt = `Categorize the following text into one of these categories: ${categories.join(', ')}.
|
|
@@ -144,9 +169,10 @@ Return ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.
|
|
|
144
169
|
}
|
|
145
170
|
|
|
146
171
|
/**
|
|
147
|
-
* Translate text to target language
|
|
172
|
+
* Translate text to a target language.
|
|
173
|
+
*
|
|
148
174
|
* @param {string} text - Text to translate
|
|
149
|
-
* @param {string} targetLanguage - Target language
|
|
175
|
+
* @param {string} targetLanguage - Target language name (e.g., 'Spanish', 'French')
|
|
150
176
|
* @returns {Promise<string>} Translated text
|
|
151
177
|
*/
|
|
152
178
|
async translate(text, targetLanguage) {
|
|
@@ -155,10 +181,11 @@ Return ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.
|
|
|
155
181
|
}
|
|
156
182
|
|
|
157
183
|
/**
|
|
158
|
-
* Generate questions about content
|
|
184
|
+
* Generate insightful questions about the content.
|
|
185
|
+
*
|
|
159
186
|
* @param {string} text - Text to generate questions about
|
|
160
|
-
* @param {number} count - Number of questions
|
|
161
|
-
* @returns {Promise<string[]>} Array of
|
|
187
|
+
* @param {number} [count=5] - Number of questions to generate
|
|
188
|
+
* @returns {Promise<string[]>} Array of question strings
|
|
162
189
|
*/
|
|
163
190
|
async generateQuestions(text, count = 5) {
|
|
164
191
|
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?"]`;
|
|
@@ -176,11 +203,15 @@ Return ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.
|
|
|
176
203
|
}
|
|
177
204
|
|
|
178
205
|
/**
|
|
179
|
-
* Get JSON response from LLM
|
|
180
|
-
*
|
|
206
|
+
* Get a structured JSON response from the LLM with automatic parsing.
|
|
207
|
+
* Attempts to extract JSON from response even if surrounded by additional text.
|
|
208
|
+
*
|
|
209
|
+
* @param {string} systemPrompt - System prompt (JSON instruction will be appended)
|
|
181
210
|
* @param {string} userMessage - User message
|
|
182
|
-
* @param {Object} options -
|
|
183
|
-
* @
|
|
211
|
+
* @param {Object} [options={}] - Request options
|
|
212
|
+
* @param {number} [options.temperature=0.2] - Temperature (defaults to 0.2 for structured output)
|
|
213
|
+
* @returns {Promise<Object>} Parsed JSON object
|
|
214
|
+
* @throws {Error} If JSON parsing fails completely
|
|
184
215
|
*/
|
|
185
216
|
async getJSON(systemPrompt, userMessage, options = {}) {
|
|
186
217
|
const response = await this.sendMessage(
|
package/src/ai/nl-query.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Natural
|
|
2
|
+
* @fileoverview Natural language query interface for HoloSphere data.
|
|
3
|
+
* Converts natural language queries to structured filters and executes searches.
|
|
4
|
+
* @module ai/nl-query
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Service class for querying HoloSphere data using natural language.
|
|
9
|
+
* Translates natural language queries into structured filters with support for
|
|
10
|
+
* spatial, temporal, and field-based filtering.
|
|
11
|
+
*
|
|
12
|
+
* @class NLQuery
|
|
13
|
+
* @example
|
|
14
|
+
* const nlQuery = new NLQuery(llmService, holosphere);
|
|
15
|
+
* const results = await nlQuery.execute("find projects near Rome with more than 10 participants");
|
|
16
|
+
* const suggestions = await nlQuery.suggest({ holons: ['rome', 'milan'] });
|
|
7
17
|
*/
|
|
8
18
|
export class NLQuery {
|
|
9
19
|
/**
|
package/src/ai/relationships.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview Discover hidden connections and relationships across data.
|
|
3
|
+
* Provides relationship discovery, graph building, pattern detection, and connection suggestions.
|
|
4
|
+
* @module ai/relationships
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Service class for discovering hidden connections and relationships in data.
|
|
9
|
+
* Identifies thematic, entity, temporal, causal, and geographic relationships,
|
|
10
|
+
* builds relationship graphs, and suggests collaboration opportunities.
|
|
11
|
+
*
|
|
12
|
+
* @class RelationshipDiscovery
|
|
13
|
+
* @example
|
|
14
|
+
* const discovery = new RelationshipDiscovery(llmService, holosphere, embeddings);
|
|
15
|
+
* const relationships = await discovery.discoverRelationships(holonId, 'projects');
|
|
16
|
+
* const similar = await discovery.findSimilar(item, holonId, 'quests');
|
|
17
|
+
* const graph = await discovery.buildGraph(holonId, 'events');
|
|
7
18
|
*/
|
|
8
19
|
export class RelationshipDiscovery {
|
|
9
20
|
/**
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview Extract structured data from unstructured text using JSON schemas.
|
|
3
|
+
* Provides schema-based data extraction, validation, and field completion.
|
|
4
|
+
* @module ai/schema-extractor
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Service class for extracting structured data from text using JSON schemas.
|
|
9
|
+
* Leverages LLM to parse unstructured content and map it to defined schemas.
|
|
10
|
+
*
|
|
11
|
+
* @class SchemaExtractor
|
|
12
|
+
* @example
|
|
13
|
+
* const extractor = new SchemaExtractor(llmService);
|
|
14
|
+
* const schema = { properties: { name: { type: "string" }, age: { type: "number" } } };
|
|
15
|
+
* const data = await extractor.extractToSchema(text, schema);
|
|
7
16
|
*/
|
|
8
17
|
export class SchemaExtractor {
|
|
9
18
|
/**
|
|
@@ -14,10 +23,13 @@ export class SchemaExtractor {
|
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
|
-
* Extract data from text
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param {
|
|
26
|
+
* Extract structured data from text according to a JSON schema.
|
|
27
|
+
* Uses LLM to intelligently parse unstructured text and map to schema fields.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} text - Unstructured text to extract from
|
|
30
|
+
* @param {Object} schema - JSON schema defining target structure
|
|
31
|
+
* @param {Object} [options={}] - Extraction options
|
|
32
|
+
* @param {number} [options.maxTokens=2000] - Maximum tokens for response
|
|
21
33
|
* @returns {Promise<Object>} Extracted data conforming to schema
|
|
22
34
|
*/
|
|
23
35
|
async extractToSchema(text, schema, options = {}) {
|
|
@@ -157,10 +169,12 @@ Return JSON with ONLY the missing fields that you can extract. Do not modify exi
|
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
/**
|
|
160
|
-
* Validate extracted data against schema
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @
|
|
172
|
+
* Validate extracted data against a JSON schema.
|
|
173
|
+
* Performs basic type checking and required field validation.
|
|
174
|
+
*
|
|
175
|
+
* @param {Object} data - Extracted data to validate
|
|
176
|
+
* @param {Object} schema - JSON schema to validate against
|
|
177
|
+
* @returns {{valid: boolean, errors: string[]}} Validation result with error list
|
|
164
178
|
*/
|
|
165
179
|
validateExtraction(data, schema) {
|
|
166
180
|
const errors = [];
|
package/src/ai/spatial.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview AI-powered spatial analysis of data patterns across geographic regions.
|
|
3
|
+
* Provides region analysis, comparison, trend detection, hotspot identification, and reporting.
|
|
4
|
+
* @module ai/spatial
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Service class for analyzing spatial data patterns across geographic regions.
|
|
9
|
+
* Identifies trends, compares regions, finds hotspots, and generates comprehensive
|
|
10
|
+
* spatial reports using AI-driven analysis.
|
|
11
|
+
*
|
|
12
|
+
* @class SpatialAnalysis
|
|
13
|
+
* @example
|
|
14
|
+
* const spatial = new SpatialAnalysis(llmService, holosphere);
|
|
15
|
+
* const analysis = await spatial.analyzeRegion(holonId, 'projects', 'activity');
|
|
16
|
+
* const comparison = await spatial.compareRegions(holon1, holon2, 'quests');
|
|
17
|
+
* const trends = await spatial.spatialTrends(holonId, 'events', { start: '2024-01-01' });
|
|
7
18
|
*/
|
|
8
19
|
export class SpatialAnalysis {
|
|
9
20
|
/**
|
package/src/ai/tts.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview OpenAI text-to-speech integration for audio generation.
|
|
3
|
+
* Provides methods for converting text to speech with various voices and formats.
|
|
4
|
+
* @module ai/tts
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* Available
|
|
8
|
+
* Available voice options for text-to-speech.
|
|
9
|
+
* @enum {string}
|
|
7
10
|
*/
|
|
8
11
|
export const VOICES = {
|
|
9
12
|
ALLOY: 'alloy',
|
|
@@ -15,7 +18,8 @@ export const VOICES = {
|
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
|
-
* Available TTS
|
|
21
|
+
* Available TTS model options.
|
|
22
|
+
* @enum {string}
|
|
19
23
|
*/
|
|
20
24
|
export const MODELS = {
|
|
21
25
|
TTS_1: 'tts-1',
|
|
@@ -23,7 +27,14 @@ export const MODELS = {
|
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
|
-
*
|
|
30
|
+
* Service class for converting text to speech using OpenAI's TTS API.
|
|
31
|
+
* Supports multiple voices, output formats, and handles long text with automatic chunking.
|
|
32
|
+
*
|
|
33
|
+
* @class TTS
|
|
34
|
+
* @example
|
|
35
|
+
* const tts = new TTS(openaiClient);
|
|
36
|
+
* const audioBuffer = await tts.speak("Hello world", { voice: VOICES.NOVA });
|
|
37
|
+
* const dataUrl = await tts.speakDataUrl("Hello", { voice: VOICES.ECHO });
|
|
27
38
|
*/
|
|
28
39
|
export class TTS {
|
|
29
40
|
/**
|
|
@@ -36,10 +47,16 @@ export class TTS {
|
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
/**
|
|
39
|
-
* Convert text to speech
|
|
40
|
-
*
|
|
41
|
-
* @param {
|
|
42
|
-
* @
|
|
50
|
+
* Convert text to speech audio.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} text - Text to convert to speech
|
|
53
|
+
* @param {Object} [options={}] - TTS generation options
|
|
54
|
+
* @param {string} [options.voice] - Voice to use (from VOICES enum)
|
|
55
|
+
* @param {string} [options.model] - Model to use (from MODELS enum)
|
|
56
|
+
* @param {number} [options.speed=1.0] - Speech speed (0.25 to 4.0)
|
|
57
|
+
* @param {string} [options.responseFormat='mp3'] - Audio format (mp3, opus, aac, flac)
|
|
58
|
+
* @returns {Promise<Buffer>} Audio buffer
|
|
59
|
+
* @throws {Error} If TTS generation fails
|
|
43
60
|
*/
|
|
44
61
|
async speak(text, options = {}) {
|
|
45
62
|
const {
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Social
|
|
2
|
+
* @fileoverview Social protocol adapters for Nostr (NIP-01) and ActivityPub formats.
|
|
3
|
+
* Provides validation, transformation, and filtering utilities for social content integration.
|
|
4
|
+
* @module content/social-protocols
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
// Import ValidationError from the validator module
|
|
6
8
|
import { ValidationError } from '../schema/validator.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
* Validate Nostr NIP-01 event format
|
|
10
|
-
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
11
|
+
* Validate Nostr NIP-01 event format.
|
|
12
|
+
* Checks required fields (kind, tags, content, created_at) and optionally id, pubkey, sig.
|
|
13
|
+
* @param {Object} event - Nostr event object to validate
|
|
14
|
+
* @param {boolean} [partial=true] - Allow partial events (missing id, pubkey, sig for signing)
|
|
15
|
+
* @param {boolean} [throwOnError=false] - Throw ValidationError on failure instead of returning false
|
|
16
|
+
* @returns {boolean} True if valid, false otherwise (unless throwOnError is true)
|
|
17
|
+
* @throws {ValidationError} If validation fails and throwOnError is true
|
|
14
18
|
*/
|
|
15
19
|
export function validateNostrEvent(event, partial = true, throwOnError = false) {
|
|
16
20
|
if (!event || typeof event !== 'object') {
|
|
@@ -56,12 +60,13 @@ export function validateNostrEvent(event, partial = true, throwOnError = false)
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
|
-
* Validate ActivityPub object format
|
|
60
|
-
* @
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {boolean}
|
|
63
|
-
* @
|
|
64
|
-
* @
|
|
63
|
+
* Validate ActivityPub object format.
|
|
64
|
+
* Checks for required @context and type fields, optionally validates id field.
|
|
65
|
+
* @param {Object} object - ActivityPub object to validate
|
|
66
|
+
* @param {boolean} [throwOnError=false] - Throw ValidationError on failure instead of returning false
|
|
67
|
+
* @param {boolean} [requireId=false] - Require id field (default: false, will be auto-generated)
|
|
68
|
+
* @returns {boolean} True if valid, false otherwise (unless throwOnError is true)
|
|
69
|
+
* @throws {ValidationError} If validation fails and throwOnError is true
|
|
65
70
|
*/
|
|
66
71
|
export function validateActivityPubObject(object, throwOnError = false, requireId = false) {
|
|
67
72
|
if (!object || typeof object !== 'object') {
|
|
@@ -85,9 +90,10 @@ export function validateActivityPubObject(object, throwOnError = false, requireI
|
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
/**
|
|
88
|
-
* Transform Nostr event to HoloSphere format
|
|
89
|
-
*
|
|
90
|
-
* @
|
|
93
|
+
* Transform Nostr event to HoloSphere storage format.
|
|
94
|
+
* Normalizes Nostr events and adds metadata for HoloSphere compatibility.
|
|
95
|
+
* @param {Object} event - Nostr NIP-01 event object
|
|
96
|
+
* @returns {Object} HoloSphere data object with protocol metadata
|
|
91
97
|
*/
|
|
92
98
|
export function transformNostrEvent(event) {
|
|
93
99
|
// Generate missing fields if needed
|
|
@@ -115,9 +121,10 @@ export function transformNostrEvent(event) {
|
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
/**
|
|
118
|
-
* Transform ActivityPub object to HoloSphere format
|
|
124
|
+
* Transform ActivityPub object to HoloSphere storage format.
|
|
125
|
+
* Normalizes ActivityPub objects and adds metadata for HoloSphere compatibility.
|
|
119
126
|
* @param {Object} object - ActivityPub object
|
|
120
|
-
* @returns {Object} HoloSphere data object
|
|
127
|
+
* @returns {Object} HoloSphere data object with protocol metadata
|
|
121
128
|
*/
|
|
122
129
|
export function transformActivityPubObject(object) {
|
|
123
130
|
// Generate ID if not provided
|
|
@@ -139,10 +146,11 @@ export function transformActivityPubObject(object) {
|
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
/**
|
|
142
|
-
* Filter social content by access level
|
|
143
|
-
*
|
|
144
|
-
* @param {
|
|
145
|
-
* @
|
|
149
|
+
* Filter social content by access level.
|
|
150
|
+
* Returns items matching the specified access level or all items if no level specified.
|
|
151
|
+
* @param {Object[]} content - Array of social content items
|
|
152
|
+
* @param {string} accessLevel - Access level to filter by (e.g., 'public', 'private')
|
|
153
|
+
* @returns {Object[]} Filtered content array
|
|
146
154
|
*/
|
|
147
155
|
export function filterByAccessLevel(content, accessLevel) {
|
|
148
156
|
if (!accessLevel) return content;
|
|
@@ -153,10 +161,11 @@ export function filterByAccessLevel(content, accessLevel) {
|
|
|
153
161
|
}
|
|
154
162
|
|
|
155
163
|
/**
|
|
156
|
-
* Filter social content by protocol
|
|
157
|
-
*
|
|
158
|
-
* @param {
|
|
159
|
-
* @
|
|
164
|
+
* Filter social content by protocol type.
|
|
165
|
+
* Returns items matching the specified protocol or all items if 'all' is specified.
|
|
166
|
+
* @param {Object[]} content - Array of social content items
|
|
167
|
+
* @param {string} protocol - Protocol to filter by ('nostr', 'activitypub', or 'all')
|
|
168
|
+
* @returns {Object[]} Filtered content array
|
|
160
169
|
*/
|
|
161
170
|
export function filterByProtocol(content, protocol) {
|
|
162
171
|
if (!protocol || protocol === 'all') return content;
|