holosphere 2.0.0-alpha0 → 2.0.0-alpha10

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.
Files changed (418) hide show
  1. package/CHANGELOG.md +473 -0
  2. package/FEATURES.md +431 -0
  3. package/LICENSE +29 -42
  4. package/LICENSE-AGPL.md +180 -0
  5. package/README.md +97 -16
  6. package/dist/2019-D2OG2idw.js +6680 -0
  7. package/dist/2019-D2OG2idw.js.map +1 -0
  8. package/dist/2019-EION3wKo.cjs +8 -0
  9. package/dist/2019-EION3wKo.cjs.map +1 -0
  10. package/dist/_commonjsHelpers-C37NGDzP.cjs +2 -0
  11. package/dist/_commonjsHelpers-C37NGDzP.cjs.map +1 -0
  12. package/dist/_commonjsHelpers-CUmg6egw.js +7 -0
  13. package/dist/_commonjsHelpers-CUmg6egw.js.map +1 -0
  14. package/dist/browser-BSniCNqO.js +3058 -0
  15. package/dist/browser-BSniCNqO.js.map +1 -0
  16. package/dist/browser-Cq59Ij19.cjs +2 -0
  17. package/dist/browser-Cq59Ij19.cjs.map +1 -0
  18. package/dist/cdn/holosphere.min.js +55 -0
  19. package/dist/cdn/holosphere.min.js.map +1 -0
  20. package/dist/cjs/holosphere.cjs +2 -0
  21. package/dist/cjs/holosphere.cjs.map +1 -0
  22. package/dist/esm/holosphere.js +53 -0
  23. package/dist/esm/holosphere.js.map +1 -0
  24. package/dist/index-DDGt_V9o.cjs +12 -0
  25. package/dist/index-DDGt_V9o.cjs.map +1 -0
  26. package/dist/index-DJXftyvB.js +39841 -0
  27. package/dist/index-DJXftyvB.js.map +1 -0
  28. package/dist/index-DMbdcMtK.cjs +18 -0
  29. package/dist/index-DMbdcMtK.cjs.map +1 -0
  30. package/dist/index-DeZ1xz_s.js +15104 -0
  31. package/dist/index-DeZ1xz_s.js.map +1 -0
  32. package/dist/indexeddb-storage-BFt6hMeF.js +176 -0
  33. package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
  34. package/dist/indexeddb-storage-BK5tv4Sh.cjs +2 -0
  35. package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
  36. package/dist/memory-storage-C9HuoL2E.js +91 -0
  37. package/dist/memory-storage-C9HuoL2E.js.map +1 -0
  38. package/dist/memory-storage-Dao7jfYG.cjs +2 -0
  39. package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
  40. package/dist/secp256k1-BbKzbLtD.cjs +12 -0
  41. package/dist/secp256k1-BbKzbLtD.cjs.map +1 -0
  42. package/dist/secp256k1-CreY7Pcl.js +1890 -0
  43. package/dist/secp256k1-CreY7Pcl.js.map +1 -0
  44. package/docs/CONTRACTS.md +797 -0
  45. package/docs/FOSDEM_PROPOSAL.md +388 -0
  46. package/docs/LOCALFIRST.md +266 -0
  47. package/docs/api/ai_aggregation.js.html +333 -0
  48. package/docs/api/ai_breakdown.js.html +524 -0
  49. package/docs/api/ai_classifier.js.html +231 -0
  50. package/docs/api/ai_council.js.html +246 -0
  51. package/docs/api/ai_embeddings.js.html +304 -0
  52. package/docs/api/ai_federation-ai.js.html +338 -0
  53. package/docs/api/ai_h3-ai.js.html +970 -0
  54. package/docs/api/ai_index.js.html +124 -0
  55. package/docs/api/ai_json-ops.js.html +241 -0
  56. package/docs/api/ai_llm-service.js.html +239 -0
  57. package/docs/api/ai_nl-query.js.html +236 -0
  58. package/docs/api/ai_relationships.js.html +367 -0
  59. package/docs/api/ai_schema-extractor.js.html +235 -0
  60. package/docs/api/ai_spatial.js.html +307 -0
  61. package/docs/api/ai_tts.js.html +214 -0
  62. package/docs/api/content_social-protocols.js.html +180 -0
  63. package/docs/api/core_holosphere.js.html +757 -0
  64. package/docs/api/crypto_nostr-utils.js.html +306 -0
  65. package/docs/api/crypto_secp256k1.js.html +267 -0
  66. package/docs/api/data/search.json +1 -0
  67. package/docs/api/federation_discovery.js.html +337 -0
  68. package/docs/api/federation_handshake.js.html +478 -0
  69. package/docs/api/federation_hologram.js.html +1053 -0
  70. package/docs/api/federation_registry.js.html +389 -0
  71. package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
  72. package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
  73. package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
  74. package/docs/api/global.html +3 -0
  75. package/docs/api/hierarchical_upcast.js.html +128 -0
  76. package/docs/api/index.html +265 -0
  77. package/docs/api/index.js.html +1868 -0
  78. package/docs/api/lib_ai-methods.js.html +660 -0
  79. package/docs/api/lib_contract-methods.js.html +445 -0
  80. package/docs/api/lib_errors.js.html +56 -0
  81. package/docs/api/lib_federation-methods.js.html +348 -0
  82. package/docs/api/lib_index.js.html +33 -0
  83. package/docs/api/module-ai.html +5 -0
  84. package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
  85. package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
  86. package/docs/api/module-ai_aggregation.html +3 -0
  87. package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
  88. package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
  89. package/docs/api/module-ai_breakdown.html +3 -0
  90. package/docs/api/module-ai_classifier-Classifier.html +6 -0
  91. package/docs/api/module-ai_classifier.Classifier.html +3 -0
  92. package/docs/api/module-ai_classifier.html +3 -0
  93. package/docs/api/module-ai_council-Council.html +6 -0
  94. package/docs/api/module-ai_council.Council.html +3 -0
  95. package/docs/api/module-ai_council.html +3 -0
  96. package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
  97. package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
  98. package/docs/api/module-ai_embeddings.html +3 -0
  99. package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
  100. package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
  101. package/docs/api/module-ai_federation-ai.html +3 -0
  102. package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
  103. package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
  104. package/docs/api/module-ai_h3-ai.html +3 -0
  105. package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
  106. package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
  107. package/docs/api/module-ai_json-ops.html +3 -0
  108. package/docs/api/module-ai_llm-service-LLMService.html +5 -0
  109. package/docs/api/module-ai_llm-service.LLMService.html +3 -0
  110. package/docs/api/module-ai_llm-service.html +3 -0
  111. package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
  112. package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
  113. package/docs/api/module-ai_nl-query.html +3 -0
  114. package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
  115. package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
  116. package/docs/api/module-ai_relationships.html +3 -0
  117. package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
  118. package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
  119. package/docs/api/module-ai_schema-extractor.html +3 -0
  120. package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
  121. package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
  122. package/docs/api/module-ai_spatial.html +3 -0
  123. package/docs/api/module-ai_tts-TTS.html +5 -0
  124. package/docs/api/module-ai_tts.TTS.html +3 -0
  125. package/docs/api/module-ai_tts.html +3 -0
  126. package/docs/api/module-content_social-protocols.html +3 -0
  127. package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
  128. package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
  129. package/docs/api/module-core_holosphere.html +3 -0
  130. package/docs/api/module-crypto_nostr-utils.html +3 -0
  131. package/docs/api/module-crypto_secp256k1.html +3 -0
  132. package/docs/api/module-federation_hologram.html +3 -0
  133. package/docs/api/module-hierarchical_upcast.html +3 -0
  134. package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
  135. package/docs/api/module-holosphere.html +3 -0
  136. package/docs/api/module-lib_ai-methods.html +3 -0
  137. package/docs/api/module-lib_contract-methods.html +3 -0
  138. package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
  139. package/docs/api/module-lib_errors-ValidationError.html +3 -0
  140. package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
  141. package/docs/api/module-lib_errors.ValidationError.html +3 -0
  142. package/docs/api/module-lib_errors.html +3 -0
  143. package/docs/api/module-lib_federation-methods.html +3 -0
  144. package/docs/api/module-lib_index.html +3 -0
  145. package/docs/api/module-schema_validator-ValidationError.html +3 -0
  146. package/docs/api/module-schema_validator.ValidationError.html +3 -0
  147. package/docs/api/module-schema_validator.html +3 -0
  148. package/docs/api/module-spatial_h3-operations.html +4 -0
  149. package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
  150. package/docs/api/module-storage_backend-factory.html +3 -0
  151. package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
  152. package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
  153. package/docs/api/module-storage_backend-interface.html +3 -0
  154. package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
  155. package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
  156. package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
  157. package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
  158. package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
  159. package/docs/api/module-storage_backends_activitypub_server.html +3 -0
  160. package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
  161. package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
  162. package/docs/api/module-storage_backends_gundb-backend.html +3 -0
  163. package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
  164. package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
  165. package/docs/api/module-storage_backends_nostr-backend.html +3 -0
  166. package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
  167. package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
  168. package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
  169. package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
  170. package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
  171. package/docs/api/module-storage_filesystem-storage.html +3 -0
  172. package/docs/api/module-storage_global-tables.html +3 -0
  173. package/docs/api/module-storage_gun-async.html +3 -0
  174. package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
  175. package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
  176. package/docs/api/module-storage_gun-auth.html +3 -0
  177. package/docs/api/module-storage_gun-federation.html +3 -0
  178. package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
  179. package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
  180. package/docs/api/module-storage_gun-references.html +3 -0
  181. package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
  182. package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
  183. package/docs/api/module-storage_gun-schema.html +3 -0
  184. package/docs/api/module-storage_gun-wrapper.html +11 -0
  185. package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
  186. package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
  187. package/docs/api/module-storage_indexeddb-storage.html +3 -0
  188. package/docs/api/module-storage_key-storage-simple.html +3 -0
  189. package/docs/api/module-storage_key-storage.html +4 -0
  190. package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
  191. package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
  192. package/docs/api/module-storage_memory-storage.html +3 -0
  193. package/docs/api/module-storage_migration-MigrationTool.html +6 -0
  194. package/docs/api/module-storage_migration.MigrationTool.html +3 -0
  195. package/docs/api/module-storage_migration.html +3 -0
  196. package/docs/api/module-storage_nostr-async.html +18 -0
  197. package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
  198. package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
  199. package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
  200. package/docs/api/module-storage_nostr-client.html +6 -0
  201. package/docs/api/module-storage_nostr-wrapper.html +3 -0
  202. package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
  203. package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
  204. package/docs/api/module-storage_outbox-queue.html +3 -0
  205. package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
  206. package/docs/api/module-storage_persistent-storage.html +4 -0
  207. package/docs/api/module-storage_sync-service-SyncService.html +5 -0
  208. package/docs/api/module-storage_sync-service.SyncService.html +3 -0
  209. package/docs/api/module-storage_sync-service.html +3 -0
  210. package/docs/api/module-storage_unified-storage.html +3 -0
  211. package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
  212. package/docs/api/module-subscriptions_manager.html +3 -0
  213. package/docs/api/schema_validator.js.html +113 -0
  214. package/docs/api/scripts/core.js +726 -0
  215. package/docs/api/scripts/core.min.js +23 -0
  216. package/docs/api/scripts/resize.js +90 -0
  217. package/docs/api/scripts/search.js +265 -0
  218. package/docs/api/scripts/search.min.js +6 -0
  219. package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
  220. package/docs/api/scripts/third-party/fuse.js +9 -0
  221. package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
  222. package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
  223. package/docs/api/scripts/third-party/hljs-original.js +5171 -0
  224. package/docs/api/scripts/third-party/hljs.js +1 -0
  225. package/docs/api/scripts/third-party/popper.js +5 -0
  226. package/docs/api/scripts/third-party/tippy.js +1 -0
  227. package/docs/api/scripts/third-party/tocbot.js +672 -0
  228. package/docs/api/scripts/third-party/tocbot.min.js +1 -0
  229. package/docs/api/spatial_h3-operations.js.html +129 -0
  230. package/docs/api/storage_backend-factory.js.html +133 -0
  231. package/docs/api/storage_backend-interface.js.html +164 -0
  232. package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
  233. package/docs/api/storage_backends_activitypub_server.js.html +678 -0
  234. package/docs/api/storage_backends_gundb-backend.js.html +878 -0
  235. package/docs/api/storage_backends_nostr-backend.js.html +254 -0
  236. package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
  237. package/docs/api/storage_filesystem-storage.js.html +207 -0
  238. package/docs/api/storage_global-tables.js.html +116 -0
  239. package/docs/api/storage_gun-async.js.html +344 -0
  240. package/docs/api/storage_gun-auth.js.html +376 -0
  241. package/docs/api/storage_gun-federation.js.html +788 -0
  242. package/docs/api/storage_gun-references.js.html +212 -0
  243. package/docs/api/storage_gun-schema.js.html +309 -0
  244. package/docs/api/storage_gun-wrapper.js.html +645 -0
  245. package/docs/api/storage_indexeddb-storage.js.html +224 -0
  246. package/docs/api/storage_key-storage-simple.js.html +102 -0
  247. package/docs/api/storage_key-storage.js.html +171 -0
  248. package/docs/api/storage_memory-storage.js.html +128 -0
  249. package/docs/api/storage_migration.js.html +354 -0
  250. package/docs/api/storage_nostr-async.js.html +1076 -0
  251. package/docs/api/storage_nostr-client.js.html +1598 -0
  252. package/docs/api/storage_nostr-wrapper.js.html +218 -0
  253. package/docs/api/storage_outbox-queue.js.html +248 -0
  254. package/docs/api/storage_persistent-storage.js.html +160 -0
  255. package/docs/api/storage_sync-service.js.html +201 -0
  256. package/docs/api/storage_unified-storage.js.html +157 -0
  257. package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
  258. package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
  259. package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
  260. package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  261. package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  262. package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
  263. package/docs/api/subscriptions_manager.js.html +162 -0
  264. package/docs/contracts/api-interface.md +793 -0
  265. package/docs/data-model.md +476 -0
  266. package/docs/gun-async-usage.md +338 -0
  267. package/docs/plan.md +349 -0
  268. package/docs/quickstart.md +674 -0
  269. package/docs/research.md +362 -0
  270. package/docs/spec.md +244 -0
  271. package/docs/storage-backends.md +326 -0
  272. package/docs/tasks.md +947 -0
  273. package/examples/demo.html +47 -0
  274. package/examples/holosphere-widget.js +1242 -0
  275. package/examples/widget-demo.html +274 -0
  276. package/examples/widget.html +703 -0
  277. package/jsdoc.json +26 -0
  278. package/package.json +25 -7
  279. package/src/ai/aggregation.js +13 -2
  280. package/src/ai/breakdown.js +12 -2
  281. package/src/ai/classifier.js +14 -3
  282. package/src/ai/council.js +22 -7
  283. package/src/ai/embeddings.js +37 -15
  284. package/src/ai/federation-ai.js +13 -2
  285. package/src/ai/h3-ai.js +14 -2
  286. package/src/ai/index.js +16 -7
  287. package/src/ai/json-ops.js +18 -5
  288. package/src/ai/llm-service.js +62 -31
  289. package/src/ai/nl-query.js +12 -2
  290. package/src/ai/relationships.js +13 -2
  291. package/src/ai/schema-extractor.js +24 -10
  292. package/src/ai/spatial.js +13 -2
  293. package/src/ai/tts.js +25 -8
  294. package/src/cdn-entry.js +22 -0
  295. package/src/content/social-protocols.js +34 -25
  296. package/src/contracts/abis/Appreciative.json +1280 -0
  297. package/src/contracts/abis/AppreciativeFactory.json +101 -0
  298. package/src/contracts/abis/Bundle.json +1438 -0
  299. package/src/contracts/abis/BundleFactory.json +106 -0
  300. package/src/contracts/abis/Holon.json +881 -0
  301. package/src/contracts/abis/Holons.json +330 -0
  302. package/src/contracts/abis/Managed.json +1262 -0
  303. package/src/contracts/abis/ManagedFactory.json +149 -0
  304. package/src/contracts/abis/Membrane.json +261 -0
  305. package/src/contracts/abis/Splitter.json +1624 -0
  306. package/src/contracts/abis/SplitterFactory.json +220 -0
  307. package/src/contracts/abis/TestToken.json +321 -0
  308. package/src/contracts/abis/Zoned.json +1461 -0
  309. package/src/contracts/abis/ZonedFactory.json +154 -0
  310. package/src/contracts/chain-manager.js +403 -0
  311. package/src/contracts/deployer.js +500 -0
  312. package/src/contracts/event-listener.js +539 -0
  313. package/src/contracts/holon-contracts.js +359 -0
  314. package/src/contracts/index.js +82 -0
  315. package/src/contracts/networks.js +229 -0
  316. package/src/contracts/operations.js +687 -0
  317. package/src/contracts/queries.js +638 -0
  318. package/src/core/holosphere.js +487 -6
  319. package/src/crypto/nostr-utils.js +303 -0
  320. package/src/crypto/secp256k1.js +7 -2
  321. package/src/federation/handshake.js +475 -0
  322. package/src/federation/hologram.js +117 -3
  323. package/src/hierarchical/upcast.js +40 -25
  324. package/src/index.js +1501 -1909
  325. package/src/lib/ai-methods.js +657 -0
  326. package/src/lib/contract-methods.js +442 -0
  327. package/src/lib/errors.js +53 -0
  328. package/src/lib/federation-methods.js +345 -0
  329. package/src/lib/index.js +30 -0
  330. package/src/schema/validator.js +22 -3
  331. package/src/spatial/h3-operations.js +19 -3
  332. package/src/storage/backend-factory.js +7 -2
  333. package/src/storage/backend-interface.js +21 -2
  334. package/src/storage/backends/activitypub/server.js +25 -3
  335. package/src/storage/backends/activitypub-backend.js +25 -2
  336. package/src/storage/backends/gundb-backend.js +692 -50
  337. package/src/storage/backends/nostr-backend.js +116 -1
  338. package/src/storage/filesystem-storage-browser.js +42 -2
  339. package/src/storage/filesystem-storage.js +72 -5
  340. package/src/storage/global-tables.js +35 -3
  341. package/src/storage/gun-async.js +75 -15
  342. package/src/storage/gun-auth.js +373 -0
  343. package/src/storage/gun-federation.js +785 -0
  344. package/src/storage/gun-references.js +209 -0
  345. package/src/storage/gun-schema.js +306 -0
  346. package/src/storage/gun-wrapper.js +475 -54
  347. package/src/storage/indexeddb-storage.js +112 -13
  348. package/src/storage/key-storage-simple.js +32 -9
  349. package/src/storage/key-storage.js +45 -13
  350. package/src/storage/memory-storage.js +68 -2
  351. package/src/storage/migration.js +20 -7
  352. package/src/storage/nostr-async.js +412 -122
  353. package/src/storage/nostr-client.js +749 -76
  354. package/src/storage/nostr-wrapper.js +6 -2
  355. package/src/storage/outbox-queue.js +55 -18
  356. package/src/storage/persistent-storage.js +62 -14
  357. package/src/storage/sync-service.js +51 -17
  358. package/src/storage/unified-storage.js +154 -0
  359. package/src/subscriptions/manager.js +34 -17
  360. package/types/index.d.ts +133 -0
  361. package/vite.config.cdn.js +60 -0
  362. package/tests/unit/ai/aggregation.test.js +0 -295
  363. package/tests/unit/ai/breakdown.test.js +0 -446
  364. package/tests/unit/ai/classifier.test.js +0 -294
  365. package/tests/unit/ai/council.test.js +0 -262
  366. package/tests/unit/ai/embeddings.test.js +0 -384
  367. package/tests/unit/ai/federation-ai.test.js +0 -344
  368. package/tests/unit/ai/h3-ai.test.js +0 -458
  369. package/tests/unit/ai/index.test.js +0 -304
  370. package/tests/unit/ai/json-ops.test.js +0 -307
  371. package/tests/unit/ai/llm-service.test.js +0 -390
  372. package/tests/unit/ai/nl-query.test.js +0 -383
  373. package/tests/unit/ai/relationships.test.js +0 -311
  374. package/tests/unit/ai/schema-extractor.test.js +0 -384
  375. package/tests/unit/ai/spatial.test.js +0 -279
  376. package/tests/unit/ai/tts.test.js +0 -279
  377. package/tests/unit/content.test.js +0 -332
  378. package/tests/unit/contract/core.test.js +0 -88
  379. package/tests/unit/contract/crypto.test.js +0 -198
  380. package/tests/unit/contract/data.test.js +0 -223
  381. package/tests/unit/contract/federation.test.js +0 -181
  382. package/tests/unit/contract/hierarchical.test.js +0 -113
  383. package/tests/unit/contract/schema.test.js +0 -114
  384. package/tests/unit/contract/social.test.js +0 -217
  385. package/tests/unit/contract/spatial.test.js +0 -110
  386. package/tests/unit/contract/subscriptions.test.js +0 -128
  387. package/tests/unit/contract/utils.test.js +0 -159
  388. package/tests/unit/core.test.js +0 -152
  389. package/tests/unit/crypto.test.js +0 -328
  390. package/tests/unit/federation.test.js +0 -234
  391. package/tests/unit/gun-async.test.js +0 -252
  392. package/tests/unit/hierarchical.test.js +0 -399
  393. package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
  394. package/tests/unit/integration/scenario-02-federation.test.js +0 -76
  395. package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
  396. package/tests/unit/integration/scenario-04-validation.test.js +0 -129
  397. package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
  398. package/tests/unit/integration/scenario-06-social.test.js +0 -135
  399. package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
  400. package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
  401. package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
  402. package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
  403. package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
  404. package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
  405. package/tests/unit/performance/benchmark.test.js +0 -85
  406. package/tests/unit/schema.test.js +0 -213
  407. package/tests/unit/spatial.test.js +0 -158
  408. package/tests/unit/storage.test.js +0 -195
  409. package/tests/unit/subscriptions.test.js +0 -328
  410. package/tests/unit/test-data-permanence-debug.js +0 -197
  411. package/tests/unit/test-data-permanence.js +0 -340
  412. package/tests/unit/test-key-persistence-fixed.js +0 -148
  413. package/tests/unit/test-key-persistence.js +0 -172
  414. package/tests/unit/test-relay-permanence.js +0 -376
  415. package/tests/unit/test-second-node.js +0 -95
  416. package/tests/unit/test-simple-write.js +0 -89
  417. /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
  418. /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
package/jsdoc.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "source": {
3
+ "include": ["src"],
4
+ "includePattern": ".+\\.js$",
5
+ "excludePattern": "(node_modules|tests|contracts)"
6
+ },
7
+ "opts": {
8
+ "template": "node_modules/clean-jsdoc-theme",
9
+ "destination": "./docs/api",
10
+ "recurse": true,
11
+ "readme": "./README.md"
12
+ },
13
+ "plugins": ["plugins/markdown"],
14
+ "templates": {
15
+ "cleverLinks": true,
16
+ "monospaceLinks": true,
17
+ "default": {
18
+ "outputSourceFiles": true,
19
+ "includeDate": false
20
+ }
21
+ },
22
+ "tags": {
23
+ "allowUnknownTags": true,
24
+ "dictionaries": ["jsdoc", "closure"]
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "holosphere",
3
- "version": "2.0.0-alpha0",
4
- "description": "Holonic geospatial communication infrastructure combining H3 hexagonal indexing with GunDB distributed P2P storage",
3
+ "version": "2.0.0-alpha10",
4
+ "description": "Holonic geospatial communication infrastructure combining H3 hexagonal indexing with distributed P2P storage",
5
5
  "type": "module",
6
6
  "bin": {
7
- "holosphere-activitypub": "./bin/holosphere-activitypub.js"
7
+ "holosphere-activitypub": "bin/holosphere-activitypub.js"
8
8
  },
9
9
  "main": "./dist/cjs/holosphere.cjs",
10
10
  "module": "./dist/esm/holosphere.js",
11
11
  "browser": "./dist/cdn/holosphere.min.js",
12
- "types": "./dist/types/index.d.ts",
12
+ "types": "./types/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
15
  "import": "./dist/esm/holosphere.js",
@@ -19,6 +19,9 @@
19
19
  "scripts": {
20
20
  "dev": "vite",
21
21
  "build": "vite build",
22
+ "build:cdn": "vite build --config vite.config.cdn.js",
23
+ "build:all": "npm run build && npm run build:cdn",
24
+ "docs": "jsdoc -c jsdoc.json",
22
25
  "test": "vitest run",
23
26
  "test:watch": "vitest",
24
27
  "test:coverage": "vitest run --coverage",
@@ -33,14 +36,27 @@
33
36
  "distributed",
34
37
  "holonic",
35
38
  "federation",
36
- "noosphere"
39
+ "noosphere",
40
+ "smart-contracts",
41
+ "ethereum",
42
+ "erc20",
43
+ "fractal"
37
44
  ],
38
- "author": "",
39
- "license": "MIT",
45
+ "author": "Roberto Valenti",
46
+ "license": "AGPL-3.0-or-later",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/liminalvillage/holosphere2.git"
50
+ },
51
+ "homepage": "https://github.com/liminalvillage/holosphere2#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/liminalvillage/holosphere2/issues"
54
+ },
40
55
  "dependencies": {
41
56
  "@noble/curves": "^1.3.0",
42
57
  "ajv": "^8.12.0",
43
58
  "dotenv": "^17.2.3",
59
+ "ethers": "^6.13.4",
44
60
  "express": "^4.21.0",
45
61
  "h3-js": "^4.1.0",
46
62
  "nostr-tools": "^2.17.0",
@@ -52,7 +68,9 @@
52
68
  },
53
69
  "devDependencies": {
54
70
  "@vitest/coverage-v8": "^1.3.0",
71
+ "clean-jsdoc-theme": "^4.3.0",
55
72
  "eslint": "^8.57.0",
73
+ "jsdoc": "^4.0.4",
56
74
  "prettier": "^3.2.5",
57
75
  "terser": "^5.44.0",
58
76
  "vite": "^5.1.0",
@@ -1,11 +1,22 @@
1
1
  /**
2
- * Smart Aggregation - AI-assisted hierarchical data aggregation up the holon tree
2
+ * @fileoverview AI-assisted hierarchical data aggregation up the H3 holon tree.
3
+ * Provides smart upcast, summary generation, and temporal comparison across hierarchical levels.
4
+ * @module ai/aggregation
3
5
  */
4
6
 
5
7
  import * as h3 from 'h3-js';
6
8
 
7
9
  /**
8
- * Smart Aggregation class
10
+ * Service class for intelligent hierarchical data aggregation.
11
+ * Automatically summarizes data at each level and propagates insights up the H3 hierarchy,
12
+ * enabling multi-scale understanding of geographic data.
13
+ *
14
+ * @class SmartAggregation
15
+ * @example
16
+ * const aggregation = new SmartAggregation(llmService, holosphere);
17
+ * const upcast = await aggregation.smartUpcast(holonId, 'projects', { maxLevels: 3 });
18
+ * const summary = await aggregation.generateHolonSummary(holonId);
19
+ * const comparison = await aggregation.comparePeriods(holonId, 'events', period1, period2);
9
20
  */
10
21
  export class SmartAggregation {
11
22
  /**
@@ -1,9 +1,19 @@
1
1
  /**
2
- * Task Breakdown - Recursively decompose tasks/quests into subtasks
2
+ * @fileoverview Recursive task decomposition system for breaking down complex tasks into manageable subtasks.
3
+ * Provides AI-powered hierarchical task breakdown with dependency tracking and progress monitoring.
4
+ * @module ai/breakdown
3
5
  */
4
6
 
5
7
  /**
6
- * Task Breakdown class
8
+ * Service class for recursively decomposing tasks/quests into hierarchical subtasks.
9
+ * Uses AI to intelligently break down complex tasks while maintaining dependency relationships
10
+ * and enabling progress tracking across the task tree.
11
+ *
12
+ * @class TaskBreakdown
13
+ * @example
14
+ * const taskBreakdown = new TaskBreakdown(llmService, holosphere);
15
+ * const result = await taskBreakdown.breakdown(task, holonId, 'quests', { depth: 3 });
16
+ * const progress = await taskBreakdown.getProgress(holonId, 'quests', taskId);
7
17
  */
8
18
  export class TaskBreakdown {
9
19
  /**
@@ -1,9 +1,20 @@
1
1
  /**
2
- * Classifier - Auto-classification of content to appropriate lenses
2
+ * @fileoverview AI-powered content classification to appropriate data lenses.
3
+ * Provides automatic categorization, multi-label classification, and schema suggestion.
4
+ * @module ai/classifier
3
5
  */
4
6
 
5
7
  /**
6
- * Classifier class for content categorization
8
+ * Service class for automatically classifying content into appropriate lenses.
9
+ * Uses AI to determine the best lens(es) for content storage and provides
10
+ * schema validation and suggestion capabilities.
11
+ *
12
+ * @class Classifier
13
+ * @example
14
+ * const classifier = new Classifier(llmService, holosphere);
15
+ * classifier.registerLens('projects', 'Community projects and initiatives');
16
+ * const result = await classifier.classifyToLens(content);
17
+ * await classifier.autoStore(holonId, content);
7
18
  */
8
19
  export class Classifier {
9
20
  /**
@@ -36,7 +47,7 @@ export class Classifier {
36
47
 
37
48
  /**
38
49
  * Register multiple lenses
39
- * @param {Object<string, {description: string, schema?: Object}>} lenses
50
+ * @param {Object.<string, Object>} lenses - Map of lens names to config objects with description and optional schema
40
51
  */
41
52
  registerLenses(lenses) {
42
53
  for (const [name, config] of Object.entries(lenses)) {
package/src/ai/council.js CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Council - Multi-perspective wisdom from different viewpoints
2
+ * @fileoverview Multi-perspective wisdom gathering from different viewpoints.
3
+ * Implements a council of perspectives to analyze questions from diverse angles.
4
+ * @module ai/council
3
5
  */
4
6
 
5
- // Default 12 perspectives based on HolonsBot
7
+ // Default 12 perspectives based on HolonsBot holistic framework
6
8
  const DEFAULT_PERSPECTIVES = [
7
9
  { name: 'Values & Worldview', prompt: 'Answer from the embodied perspective of Values and Worldview - considering ethics, beliefs, culture, and meaning.' },
8
10
  { name: 'Health & Wellbeing', prompt: 'Answer from the embodied perspective of Health & Wellbeing - considering physical, mental, and social health.' },
@@ -19,7 +21,16 @@ const DEFAULT_PERSPECTIVES = [
19
21
  ];
20
22
 
21
23
  /**
22
- * Council class for multi-perspective answers
24
+ * Service class for gathering multi-perspective wisdom on questions and topics.
25
+ * Simulates a council of experts answering from diverse viewpoints,
26
+ * then synthesizes their responses into balanced insights.
27
+ *
28
+ * @class Council
29
+ * @example
30
+ * const council = new Council(llmService);
31
+ * const result = await council.ask("How should we approach climate change?");
32
+ * console.log(result.perspectives); // Array of perspective responses
33
+ * console.log(result.summary); // Synthesized wisdom
23
34
  */
24
35
  export class Council {
25
36
  /**
@@ -48,10 +59,14 @@ export class Council {
48
59
  }
49
60
 
50
61
  /**
51
- * Ask a question to the council
52
- * @param {string} question - Question to ask
53
- * @param {Object} options - Options
54
- * @returns {Promise<{perspectives: Array, summary: string}>}
62
+ * Ask a question to the council and receive diverse perspective responses.
63
+ *
64
+ * @param {string} question - Question to ask the council
65
+ * @param {Object} [options={}] - Options
66
+ * @param {boolean} [options.parallel=true] - Query perspectives in parallel or sequentially
67
+ * @param {boolean} [options.includeSummary=true] - Generate a synthesis summary
68
+ * @param {Array} [options.perspectives] - Override default perspectives
69
+ * @returns {Promise<{question: string, perspectives: Array, summary: string, timestamp: number}>} Council responses
55
70
  */
56
71
  async ask(question, options = {}) {
57
72
  const { parallel = true, includeSummary = true } = options;
@@ -1,9 +1,19 @@
1
1
  /**
2
- * Embeddings - Vector embedding generation and semantic search
2
+ * @fileoverview Vector embedding generation and semantic search functionality using OpenAI's text-embedding models.
3
+ * Provides methods for generating embeddings, calculating similarity, semantic search, and k-means clustering.
4
+ * @module ai/embeddings
3
5
  */
4
6
 
5
7
  /**
6
- * Embeddings class for vector operations
8
+ * Service class for vector embeddings and semantic operations.
9
+ * Supports single and batch embedding generation, cosine similarity calculations,
10
+ * semantic search across HoloSphere data, and k-means clustering.
11
+ *
12
+ * @class Embeddings
13
+ * @example
14
+ * const embeddings = new Embeddings(openaiClient, holosphere);
15
+ * const vector = await embeddings.embed("sample text");
16
+ * const results = await embeddings.semanticSearch("query", holon, lens);
7
17
  */
8
18
  export class Embeddings {
9
19
  /**
@@ -26,9 +36,11 @@ export class Embeddings {
26
36
  }
27
37
 
28
38
  /**
29
- * Generate embedding for text
39
+ * Generate a vector embedding for the given text.
40
+ *
30
41
  * @param {string} text - Text to embed
31
- * @returns {Promise<number[]>} Embedding vector
42
+ * @returns {Promise<number[]>} Embedding vector (1536 dimensions by default)
43
+ * @throws {Error} If embedding generation fails
32
44
  */
33
45
  async embed(text) {
34
46
  try {
@@ -62,10 +74,13 @@ export class Embeddings {
62
74
  }
63
75
 
64
76
  /**
65
- * Calculate cosine similarity between two vectors
66
- * @param {number[]} vec1 - First vector
67
- * @param {number[]} vec2 - Second vector
68
- * @returns {number} Similarity score (0-1)
77
+ * Calculate cosine similarity between two embedding vectors.
78
+ * Returns a score between -1 and 1, where 1 indicates identical vectors.
79
+ *
80
+ * @param {number[]} vec1 - First embedding vector
81
+ * @param {number[]} vec2 - Second embedding vector
82
+ * @returns {number} Similarity score (0-1 for normalized vectors)
83
+ * @throws {Error} If vectors have different lengths
69
84
  */
70
85
  cosineSimilarity(vec1, vec2) {
71
86
  if (vec1.length !== vec2.length) {
@@ -124,12 +139,17 @@ export class Embeddings {
124
139
  }
125
140
 
126
141
  /**
127
- * Semantic search within a holon/lens
128
- * @param {string} query - Search query
142
+ * Perform semantic search within a holon/lens using vector similarity.
143
+ * Returns items ranked by semantic similarity to the query.
144
+ *
145
+ * @param {string} query - Natural language search query
129
146
  * @param {string} holon - Holon identifier
130
147
  * @param {string} lens - Lens name
131
- * @param {Object} options - Search options
132
- * @returns {Promise<Array<{item: Object, similarity: number}>>} Ranked results
148
+ * @param {Object} [options={}] - Search options
149
+ * @param {number} [options.limit=10] - Maximum results to return
150
+ * @param {number} [options.threshold=0.5] - Minimum similarity score (0-1)
151
+ * @returns {Promise<Array<{item: Object, similarity: number}>>} Results ranked by similarity descending
152
+ * @throws {Error} If HoloSphere instance not configured
133
153
  */
134
154
  async semanticSearch(query, holon, lens, options = {}) {
135
155
  if (!this.holosphere) {
@@ -180,10 +200,12 @@ export class Embeddings {
180
200
  }
181
201
 
182
202
  /**
183
- * Cluster items by semantic similarity
203
+ * Cluster items by semantic similarity using k-means algorithm.
204
+ * Automatically generates embeddings for items that don't have them.
205
+ *
184
206
  * @param {Object[]} items - Items to cluster
185
- * @param {number} numClusters - Approximate number of clusters
186
- * @returns {Promise<Object[][]>} Clustered items
207
+ * @param {number} [numClusters=5] - Target number of clusters
208
+ * @returns {Promise<Object[][]>} Array of clusters, each containing related items
187
209
  */
188
210
  async cluster(items, numClusters = 5) {
189
211
  // Get embeddings for items that don't have them
@@ -1,9 +1,20 @@
1
1
  /**
2
- * Federation Advisor - AI-powered federation suggestions and analysis
2
+ * @fileoverview AI-powered federation recommendations and network health analysis.
3
+ * Provides suggestions for federation partnerships, health monitoring, and network optimization.
4
+ * @module ai/federation-ai
3
5
  */
4
6
 
5
7
  /**
6
- * Federation Advisor class
8
+ * Service class for analyzing and optimizing holon federation networks.
9
+ * Suggests federation partnerships based on content similarity, analyzes network health,
10
+ * identifies bridges between clusters, and recommends optimizations.
11
+ *
12
+ * @class FederationAdvisor
13
+ * @example
14
+ * const advisor = new FederationAdvisor(llmService, holosphere, embeddings);
15
+ * const suggestions = await advisor.suggestFederations(holonId, { candidateHolons });
16
+ * const health = await advisor.analyzeFederationHealth(holonId);
17
+ * const bridges = await advisor.findBridges(holonIds);
7
18
  */
8
19
  export class FederationAdvisor {
9
20
  /**
package/src/ai/h3-ai.js CHANGED
@@ -1,11 +1,23 @@
1
1
  /**
2
- * H3 AI - Geospatial intelligence for H3 hexagonal hierarchies
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
- * H3 AI class for geospatial intelligence
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
- * Comprehensive AI functionality using OpenAI chat completions
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
- * Create all AI services with shared LLM instance
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 (optional)
47
- * @param {Object} options - Configuration options
48
- * @param {Object} openaiClient - Optional pre-created OpenAI client
49
- * @returns {Object} AI services
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
@@ -1,9 +1,19 @@
1
1
  /**
2
- * Fuzzy JSON Operations - AI-assisted semantic operations on JSON structures
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
- * JSON Operations class for semantic JSON manipulation
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
- * @returns {Promise<Object>} Merged object
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.
@@ -1,12 +1,20 @@
1
1
  /**
2
- * LLM Service - Core OpenAI wrapper for HoloSphere
3
- * Provides simple chat completions without Assistants API
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
- * LLM Service class for interacting with OpenAI
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
- * @param {string} systemPrompt - System prompt
33
- * @param {string} userMessage - User message
34
- * @param {Object} options - Override options
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 (conversation)
57
- * @param {Array<{role: string, content: string}>} messages - Messages array
58
- * @param {Object} options - Override options
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
- * Summarize text
95
+ * Generate a concise summary of text while preserving key information.
96
+ *
78
97
  * @param {string} text - Text to summarize
79
- * @param {Object} options - Options (maxLength, style)
80
- * @returns {Promise<string>} Summary
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 - Aspect to analyze (sentiment, themes, tone, etc.)
94
- * @returns {Promise<string>} Analysis
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 keywords from text
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 (default: 10)
105
- * @returns {Promise<string[]>} Array of keywords
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 given categories
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 categories
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 (default: 5)
161
- * @returns {Promise<string[]>} Array of questions
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
- * @param {string} systemPrompt - System prompt
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 - Options
183
- * @returns {Promise<Object>} Parsed JSON response
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(
@@ -1,9 +1,19 @@
1
1
  /**
2
- * Natural Language Query - Query HoloSphere data using natural language
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
- * NL Query class for natural language to structured query conversion
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
  /**