holosphere 1.1.19 → 2.0.0-alpha0

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 (146) hide show
  1. package/.env.example +36 -0
  2. package/.eslintrc.json +16 -0
  3. package/.prettierrc.json +7 -0
  4. package/README.md +476 -531
  5. package/bin/holosphere-activitypub.js +158 -0
  6. package/cleanup-test-data.js +204 -0
  7. package/examples/demo.html +1333 -0
  8. package/examples/example-bot.js +197 -0
  9. package/package.json +47 -87
  10. package/scripts/check-bundle-size.js +54 -0
  11. package/scripts/check-quest-ids.js +77 -0
  12. package/scripts/import-holons.js +578 -0
  13. package/scripts/publish-to-relay.js +101 -0
  14. package/scripts/read-example.js +186 -0
  15. package/scripts/relay-diagnostic.js +59 -0
  16. package/scripts/relay-example.js +179 -0
  17. package/scripts/resync-to-relay.js +245 -0
  18. package/scripts/revert-import.js +196 -0
  19. package/scripts/test-hybrid-mode.js +108 -0
  20. package/scripts/test-local-storage.js +63 -0
  21. package/scripts/test-nostr-direct.js +55 -0
  22. package/scripts/test-read-data.js +45 -0
  23. package/scripts/test-write-read.js +63 -0
  24. package/scripts/verify-import.js +95 -0
  25. package/scripts/verify-relay-data.js +139 -0
  26. package/src/ai/aggregation.js +319 -0
  27. package/src/ai/breakdown.js +511 -0
  28. package/src/ai/classifier.js +217 -0
  29. package/src/ai/council.js +228 -0
  30. package/src/ai/embeddings.js +279 -0
  31. package/src/ai/federation-ai.js +324 -0
  32. package/src/ai/h3-ai.js +955 -0
  33. package/src/ai/index.js +112 -0
  34. package/src/ai/json-ops.js +225 -0
  35. package/src/ai/llm-service.js +205 -0
  36. package/src/ai/nl-query.js +223 -0
  37. package/src/ai/relationships.js +353 -0
  38. package/src/ai/schema-extractor.js +218 -0
  39. package/src/ai/spatial.js +293 -0
  40. package/src/ai/tts.js +194 -0
  41. package/src/content/social-protocols.js +168 -0
  42. package/src/core/holosphere.js +273 -0
  43. package/src/crypto/secp256k1.js +259 -0
  44. package/src/federation/discovery.js +334 -0
  45. package/src/federation/hologram.js +1042 -0
  46. package/src/federation/registry.js +386 -0
  47. package/src/hierarchical/upcast.js +110 -0
  48. package/src/index.js +2669 -0
  49. package/src/schema/validator.js +91 -0
  50. package/src/spatial/h3-operations.js +110 -0
  51. package/src/storage/backend-factory.js +125 -0
  52. package/src/storage/backend-interface.js +142 -0
  53. package/src/storage/backends/activitypub/server.js +653 -0
  54. package/src/storage/backends/activitypub-backend.js +272 -0
  55. package/src/storage/backends/gundb-backend.js +233 -0
  56. package/src/storage/backends/nostr-backend.js +136 -0
  57. package/src/storage/filesystem-storage-browser.js +41 -0
  58. package/src/storage/filesystem-storage.js +138 -0
  59. package/src/storage/global-tables.js +81 -0
  60. package/src/storage/gun-async.js +281 -0
  61. package/src/storage/gun-wrapper.js +221 -0
  62. package/src/storage/indexeddb-storage.js +122 -0
  63. package/src/storage/key-storage-simple.js +76 -0
  64. package/src/storage/key-storage.js +136 -0
  65. package/src/storage/memory-storage.js +59 -0
  66. package/src/storage/migration.js +338 -0
  67. package/src/storage/nostr-async.js +811 -0
  68. package/src/storage/nostr-client.js +939 -0
  69. package/src/storage/nostr-wrapper.js +211 -0
  70. package/src/storage/outbox-queue.js +208 -0
  71. package/src/storage/persistent-storage.js +109 -0
  72. package/src/storage/sync-service.js +164 -0
  73. package/src/subscriptions/manager.js +142 -0
  74. package/test-ai-real-api.js +202 -0
  75. package/tests/unit/ai/aggregation.test.js +295 -0
  76. package/tests/unit/ai/breakdown.test.js +446 -0
  77. package/tests/unit/ai/classifier.test.js +294 -0
  78. package/tests/unit/ai/council.test.js +262 -0
  79. package/tests/unit/ai/embeddings.test.js +384 -0
  80. package/tests/unit/ai/federation-ai.test.js +344 -0
  81. package/tests/unit/ai/h3-ai.test.js +458 -0
  82. package/tests/unit/ai/index.test.js +304 -0
  83. package/tests/unit/ai/json-ops.test.js +307 -0
  84. package/tests/unit/ai/llm-service.test.js +390 -0
  85. package/tests/unit/ai/nl-query.test.js +383 -0
  86. package/tests/unit/ai/relationships.test.js +311 -0
  87. package/tests/unit/ai/schema-extractor.test.js +384 -0
  88. package/tests/unit/ai/spatial.test.js +279 -0
  89. package/tests/unit/ai/tts.test.js +279 -0
  90. package/tests/unit/content.test.js +332 -0
  91. package/tests/unit/contract/core.test.js +88 -0
  92. package/tests/unit/contract/crypto.test.js +198 -0
  93. package/tests/unit/contract/data.test.js +223 -0
  94. package/tests/unit/contract/federation.test.js +181 -0
  95. package/tests/unit/contract/hierarchical.test.js +113 -0
  96. package/tests/unit/contract/schema.test.js +114 -0
  97. package/tests/unit/contract/social.test.js +217 -0
  98. package/tests/unit/contract/spatial.test.js +110 -0
  99. package/tests/unit/contract/subscriptions.test.js +128 -0
  100. package/tests/unit/contract/utils.test.js +159 -0
  101. package/tests/unit/core.test.js +152 -0
  102. package/tests/unit/crypto.test.js +328 -0
  103. package/tests/unit/federation.test.js +234 -0
  104. package/tests/unit/gun-async.test.js +252 -0
  105. package/tests/unit/hierarchical.test.js +399 -0
  106. package/tests/unit/integration/scenario-01-geographic-storage.test.js +74 -0
  107. package/tests/unit/integration/scenario-02-federation.test.js +76 -0
  108. package/tests/unit/integration/scenario-03-subscriptions.test.js +102 -0
  109. package/tests/unit/integration/scenario-04-validation.test.js +129 -0
  110. package/tests/unit/integration/scenario-05-hierarchy.test.js +125 -0
  111. package/tests/unit/integration/scenario-06-social.test.js +135 -0
  112. package/tests/unit/integration/scenario-07-persistence.test.js +130 -0
  113. package/tests/unit/integration/scenario-08-authorization.test.js +161 -0
  114. package/tests/unit/integration/scenario-09-cross-dimensional.test.js +139 -0
  115. package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +357 -0
  116. package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +410 -0
  117. package/tests/unit/integration/scenario-12-capability-federated-read.test.js +719 -0
  118. package/tests/unit/performance/benchmark.test.js +85 -0
  119. package/tests/unit/schema.test.js +213 -0
  120. package/tests/unit/spatial.test.js +158 -0
  121. package/tests/unit/storage.test.js +195 -0
  122. package/tests/unit/subscriptions.test.js +328 -0
  123. package/tests/unit/test-data-permanence-debug.js +197 -0
  124. package/tests/unit/test-data-permanence.js +340 -0
  125. package/tests/unit/test-key-persistence-fixed.js +148 -0
  126. package/tests/unit/test-key-persistence.js +172 -0
  127. package/tests/unit/test-relay-permanence.js +376 -0
  128. package/tests/unit/test-second-node.js +95 -0
  129. package/tests/unit/test-simple-write.js +89 -0
  130. package/vite.config.js +49 -0
  131. package/vitest.config.js +20 -0
  132. package/FEDERATION.md +0 -213
  133. package/compute.js +0 -298
  134. package/content.js +0 -1022
  135. package/federation.js +0 -1234
  136. package/global.js +0 -736
  137. package/hexlib.js +0 -335
  138. package/hologram.js +0 -183
  139. package/holosphere-bundle.esm.js +0 -34549
  140. package/holosphere-bundle.js +0 -34580
  141. package/holosphere-bundle.min.js +0 -49
  142. package/holosphere.d.ts +0 -604
  143. package/holosphere.js +0 -739
  144. package/node.js +0 -246
  145. package/schema.js +0 -139
  146. package/utils.js +0 -302
package/holosphere.js DELETED
@@ -1,739 +0,0 @@
1
- /**
2
- * @module holosphere
3
- * @version 1.1.18
4
- * @description Holonic Geospatial Communication Infrastructure
5
- * @author Roberto Valenti
6
- * @license GPL-3.0-or-later
7
- */
8
-
9
- import OpenAI from 'openai';
10
- import Gun from 'gun';
11
- import 'gun/lib/radisk.js';
12
- import Ajv2019 from 'ajv/dist/2019.js'
13
- import * as Federation from './federation.js';
14
- import * as SchemaOps from './schema.js';
15
- import * as ContentOps from './content.js';
16
- import * as NodeOps from './node.js';
17
- import * as GlobalOps from './global.js';
18
- import * as HologramOps from './hologram.js';
19
- import * as ComputeOps from './compute.js';
20
- import * as Utils from './utils.js';
21
-
22
- // Define the version constant
23
- const HOLOSPHERE_VERSION = '1.1.19';
24
-
25
- class HoloSphere {
26
- /**
27
- * Initializes a new instance of the HoloSphere class.
28
- * @param {string} appname - The name of the application.
29
- * @param {boolean} [strict=false] - Whether to enforce strict schema validation.
30
- * @param {string|null} [openaikey=null] - The OpenAI API key.
31
- * @param {object} [gunOptions={}] - Optional Gun constructor options (e.g., peers, localStorage, radisk).
32
- */
33
- constructor(appname, strict = false, openaikey = null, gunOptions = {}) {
34
- console.log('HoloSphere v' + HOLOSPHERE_VERSION);
35
- this.appname = appname
36
- this.strict = strict;
37
- this.validator = new Ajv2019({
38
- allErrors: true,
39
- strict: false, // Keep this false to avoid Ajv strict mode issues
40
- validateSchema: true // Always validate schemas
41
- });
42
-
43
-
44
- // Define default Gun options
45
- const defaultGunOptions = {
46
- peers: ['https://gun.holons.io/gun'],
47
- axe: false,
48
- localStorage: false,
49
- radisk: true,
50
- file: './holosphere.db' // Default directory for radisk storage
51
- // Add other potential defaults here if needed
52
- };
53
-
54
- // Merge provided options with defaults
55
- const finalGunOptions = { ...defaultGunOptions, ...gunOptions };
56
- console.log("Initializing Gun with options:", finalGunOptions);
57
-
58
- // Use provided Gun instance or create new one with final options
59
- this.gun = Gun(finalGunOptions); // Pass the merged options
60
-
61
-
62
- if (openaikey != null) {
63
- this.openai = new OpenAI({
64
- apiKey: openaikey,
65
- });
66
- }
67
-
68
- // Initialize subscriptions
69
- this.subscriptions = {};
70
-
71
- // Initialize schema cache
72
- this.schemaCache = new Map();
73
- }
74
-
75
- getGun() {
76
- return this.gun;
77
- }
78
-
79
- // ================================ SCHEMA FUNCTIONS ================================
80
-
81
- /**
82
- * Sets the JSON schema for a specific lens.
83
- * @param {string} lens - The lens identifier.
84
- * @param {object} schema - The JSON schema to set.
85
- * @returns {Promise} - Resolves when the schema is set.
86
- */
87
- async setSchema(lens, schema) {
88
- // Delegate to the external function
89
- return SchemaOps.setSchema(this, lens, schema);
90
- }
91
-
92
- /**
93
- * Retrieves the JSON schema for a specific lens.
94
- * @param {string} lens - The lens identifier.
95
- * @param {object} [options] - Additional options
96
- * @param {boolean} [options.useCache=true] - Whether to use the schema cache
97
- * @param {number} [options.maxCacheAge=3600000] - Maximum cache age in milliseconds (default: 1 hour)
98
- * @returns {Promise<object|null>} - The retrieved schema or null if not found.
99
- */
100
- async getSchema(lens, options = {}) {
101
- // Delegate to the external function
102
- return SchemaOps.getSchema(this, lens, options);
103
- }
104
-
105
- /**
106
- * Clears the schema cache or a specific schema from the cache.
107
- * @param {string} [lens] - Optional lens to clear from cache. If not provided, clears entire cache.
108
- * @returns {boolean} - Returns true if successful
109
- */
110
- clearSchemaCache(lens = null) {
111
- // Delegate to the external function
112
- return SchemaOps.clearSchemaCache(this, lens);
113
- }
114
-
115
- // ================================ CONTENT FUNCTIONS ================================
116
-
117
- /**
118
- * Stores content in the specified holon and lens.
119
- * @param {string} holon - The holon identifier.
120
- * @param {string} lens - The lens under which to store the content.
121
- * @param {object} data - The data to store.
122
- * @param {string} [password] - Optional password for private holon.
123
- * @param {object} [options] - Additional options
124
- * @param {boolean} [options.autoPropagate=true] - Whether to automatically propagate to federated holons (default: true)
125
- * @param {object} [options.propagationOptions] - Options to pass to propagate
126
- * @param {boolean} [options.propagationOptions.useReferences=true] - Whether to use references instead of duplicating data
127
- * @returns {Promise<boolean>} - Returns true if successful, false if there was an error
128
- */
129
- async put(holon, lens, data, password = null, options = {}) {
130
- // Delegate to the external function
131
- return ContentOps.put(this, holon, lens, data, password, options);
132
- }
133
-
134
- /**
135
- * Retrieves content from the specified holon and lens.
136
- * @param {string} holon - The holon identifier.
137
- * @param {string} lens - The lens from which to retrieve content.
138
- * @param {string} key - The specific key to retrieve.
139
- * @param {string} [password] - Optional password for private holon.
140
- * @param {object} [options] - Additional options
141
- * @param {boolean} [options.resolveReferences=true] - Whether to automatically resolve federation references
142
- * @returns {Promise<object|null>} - The retrieved content or null if not found.
143
- */
144
- async get(holon, lens, key, password = null, options = {}) {
145
- // Delegate to the external function
146
- return ContentOps.get(this, holon, lens, key, password, options);
147
- }
148
-
149
- /**
150
- * Retrieves all content from the specified holon and lens.
151
- * @param {string} holon - The holon identifier.
152
- * @param {string} lens - The lens from which to retrieve content.
153
- * @param {string} [password] - Optional password for private holon.
154
- * @returns {Promise<Array<object>>} - The retrieved content.
155
- */
156
- async getAll(holon, lens, password = null) {
157
- // Delegate to the external function
158
- return ContentOps.getAll(this, holon, lens, password);
159
- }
160
-
161
- /**
162
- * Parses data from GunDB, handling various data formats and references.
163
- * @param {*} data - The data to parse, could be a string, object, or GunDB reference.
164
- * @returns {Promise<object>} - The parsed data.
165
- */
166
- async parse(rawData) {
167
- // Delegate to the external function
168
- return ContentOps.parse(this, rawData);
169
- }
170
-
171
- /**
172
- * Filters an array of data, removing raw GunDB nodes and invalid entries.
173
- * @param {Array} dataArray - Array of data that might contain raw GunDB nodes
174
- * @returns {Promise<Array>} - Filtered array with only valid data
175
- */
176
- async filterValidData(dataArray) {
177
- if (!Array.isArray(dataArray)) {
178
- return [];
179
- }
180
-
181
- const validData = [];
182
- for (const item of dataArray) {
183
- const parsed = await this.parse(item);
184
- if (parsed !== null) {
185
- validData.push(parsed);
186
- }
187
- }
188
-
189
- return validData;
190
- }
191
-
192
- /**
193
- * Deletes a specific key from a given holon and lens.
194
- * @param {string} holon - The holon identifier.
195
- * @param {string} lens - The lens from which to delete the key.
196
- * @param {string} key - The specific key to delete.
197
- * @param {string} [password] - Optional password for private holon.
198
- * @returns {Promise<boolean>} - Returns true if successful
199
- */
200
- async delete(holon, lens, key, password = null) {
201
- // Delegate to the external function (renamed to deleteFunc in module)
202
- return ContentOps.deleteFunc(this, holon, lens, key, password);
203
- }
204
-
205
- /**
206
- * Deletes all keys from a given holon and lens.
207
- * @param {string} holon - The holon identifier.
208
- * @param {string} lens - The lens from which to delete all keys.
209
- * @param {string} [password] - Optional password for private holon.
210
- * @returns {Promise<boolean>} - Returns true if successful
211
- */
212
- async deleteAll(holon, lens, password = null) {
213
- // Delegate to the external function
214
- return ContentOps.deleteAll(this, holon, lens, password);
215
- }
216
-
217
- // ================================ NODE FUNCTIONS ================================
218
-
219
-
220
- /**
221
- * Stores a specific gun node in a given holon and lens.
222
- * @param {string} holon - The holon identifier.
223
- * @param {string} lens - The lens under which to store the node.
224
- * @param {object} data - The node to store.
225
- */
226
- async putNode(holon, lens, data) {
227
- // Delegate to the external function
228
- return NodeOps.putNode(this, holon, lens, data);
229
- }
230
-
231
- /**
232
- * Retrieves a specific gun node from the specified holon and lens.
233
- * @param {string} holon - The holon identifier.
234
- * @param {string} lens - The lens identifier.
235
- * @param {string} key - The specific key to retrieve.
236
- * @returns {Promise<any>} - The retrieved node or null if not found.
237
- */
238
- async getNode(holon, lens, key) {
239
- // Delegate to the external function
240
- return NodeOps.getNode(this, holon, lens, key);
241
- }
242
-
243
- /**
244
- * Retrieves a Gun node reference using its soul path
245
- * @param {string} soul - The soul path of the node
246
- * @returns {Gun.ChainReference} - The Gun node reference
247
- */
248
- getNodeRef(soul) {
249
- // Delegate to the external function
250
- return NodeOps.getNodeRef(this, soul);
251
- }
252
-
253
- /**
254
- * Retrieves a node directly using its soul path
255
- * @param {string} soul - The soul path of the node
256
- * @returns {Promise<any>} - The retrieved node or null if not found.
257
- */
258
- async getNodeBySoul(soul) {
259
- // Delegate to the external function
260
- return NodeOps.getNodeBySoul(this, soul);
261
- }
262
-
263
- /**
264
- * Deletes a specific gun node from a given holon and lens.
265
- * @param {string} holon - The holon identifier.
266
- * @param {string} lens - The lens identifier.
267
- * @param {string} key - The key of the node to delete.
268
- * @returns {Promise<boolean>} - Returns true if successful
269
- */
270
- async deleteNode(holon, lens, key) {
271
- // Delegate to the external function
272
- return NodeOps.deleteNode(this, holon, lens, key);
273
- }
274
-
275
- // ================================ GLOBAL FUNCTIONS ================================
276
- /**
277
- * Stores data in a global (non-holon-specific) table.
278
- * @param {string} tableName - The table name to store data in.
279
- * @param {object} data - The data to store. If it has an 'id' field, it will be used as the key.
280
- * @param {string} [password] - Optional password for private holon.
281
- * @returns {Promise<void>}
282
- */
283
- async putGlobal(tableName, data, password = null) {
284
- // Delegate to the external function
285
- return GlobalOps.putGlobal(this, tableName, data, password);
286
- }
287
-
288
- /**
289
- * Retrieves a specific key from a global table.
290
- * @param {string} tableName - The table name to retrieve from.
291
- * @param {string} key - The key to retrieve.
292
- * @param {string} [password] - Optional password for private holon.
293
- * @returns {Promise<object|null>} - The parsed data for the key or null if not found.
294
- */
295
- async getGlobal(tableName, key, password = null) {
296
- // Delegate to the external function
297
- return GlobalOps.getGlobal(this, tableName, key, password);
298
- }
299
-
300
- /**
301
- * Retrieves all data from a global table.
302
- * @param {string} tableName - The table name to retrieve data from.
303
- * @param {string} [password] - Optional password for private holon.
304
- * @returns {Promise<Array<object>>} - The parsed data from the table as an array.
305
- */
306
- async getAllGlobal(tableName, password = null) {
307
- // Delegate to the external function
308
- return GlobalOps.getAllGlobal(this, tableName, password);
309
- }
310
-
311
- /**
312
- * Deletes a specific key from a global table.
313
- * @param {string} tableName - The table name to delete from.
314
- * @param {string} key - The key to delete.
315
- * @param {string} [password] - Optional password for private holon.
316
- * @returns {Promise<boolean>}
317
- */
318
- async deleteGlobal(tableName, key, password = null) {
319
- // Delegate to the external function
320
- return GlobalOps.deleteGlobal(this, tableName, key, password);
321
- }
322
-
323
- /**
324
- * Deletes an entire global table.
325
- * @param {string} tableName - The table name to delete.
326
- * @param {string} [password] - Optional password for private holon.
327
- * @returns {Promise<boolean>}
328
- */
329
- async deleteAllGlobal(tableName, password = null) {
330
- // Delegate to the external function
331
- return GlobalOps.deleteAllGlobal(this, tableName, password);
332
- }
333
-
334
- // ================================ REFERENCE FUNCTIONS ================================
335
-
336
- /**
337
- * Creates a soul hologram object for a data item
338
- * @param {string} holon - The holon where the original data is stored
339
- * @param {string} lens - The lens where the original data is stored
340
- * @param {object} data - The data to create a hologram for
341
- * @returns {object} - A hologram object with id and soul
342
- */
343
- createHologram(holon, lens, data) {
344
- // Delegate to the external function
345
- return HologramOps.createHologram(this, holon, lens, data);
346
- }
347
-
348
- /**
349
- * Parses a soul path into its components
350
- * @param {string} soul - The soul path to parse
351
- * @returns {object|null} - The parsed components or null if invalid format
352
- */
353
- parseSoulPath(soul) {
354
- // Delegate to the external function (doesn't need instance)
355
- return HologramOps.parseSoulPath(soul);
356
- }
357
-
358
- /**
359
- * Checks if an object is a hologram
360
- * @param {object} data - The data to check
361
- * @returns {boolean} - True if the object is a hologram
362
- */
363
- isHologram(data) {
364
- // Delegate to the external function (doesn't need instance)
365
- return HologramOps.isHologram(data);
366
- }
367
-
368
- /**
369
- * Resolves a hologram to its actual data
370
- * @param {object} hologram - The hologram to resolve
371
- * @param {object} [options] - Optional parameters
372
- * @param {boolean} [options.followHolograms=true] - Whether to follow nested holograms
373
- * @param {Set<string>} [options.visited] - Internal use: Tracks visited souls to prevent loops
374
- * @returns {Promise<object|null>} - The resolved data, null if resolution failed due to target not found, or the original hologram for circular/invalid cases.
375
- */
376
- async resolveHologram(hologram, options = {}) {
377
- // Delegate to the external function
378
- return HologramOps.resolveHologram(this, hologram, options);
379
- }
380
-
381
- // ================================ COMPUTE FUNCTIONS ================================
382
- /**
383
- * Computes operations across multiple layers up the hierarchy
384
- * @param {string} holon - Starting holon identifier
385
- * @param {string} lens - The lens to compute
386
- * @param {object} options - Computation options
387
- * @param {number} [maxLevels=15] - Maximum levels to compute up
388
- * @param {string} [password] - Optional password for private holons
389
- */
390
- async computeHierarchy(holon, lens, options, maxLevels = 15, password = null) {
391
- // Delegate to the external function
392
- return ComputeOps.computeHierarchy(this, holon, lens, options, maxLevels, password);
393
- }
394
-
395
- /**
396
- * Computes operations on content within a holon and lens for one layer up.
397
- * @param {string} holon - The holon identifier.
398
- * @param {string} lens - The lens to compute.
399
- * @param {object} options - Computation options
400
- * @param {string} options.operation - The operation to perform ('summarize', 'aggregate', 'concatenate')
401
- * @param {string[]} [options.fields] - Fields to perform operation on
402
- * @param {string} [options.targetField] - Field to store the result in
403
- * @param {string} [password] - Optional password for private holons
404
- * @throws {Error} If parameters are invalid or missing
405
- */
406
- async compute(holon, lens, options, password = null) {
407
- // Delegate to the external function
408
- return ComputeOps.compute(this, holon, lens, options, password);
409
- }
410
-
411
- /**
412
- * Summarizes provided history text using OpenAI.
413
- * @param {string} history - The history text to summarize.
414
- * @returns {Promise<string>} - The summarized text.
415
- */
416
- async summarize(history) {
417
- // Delegate to the external function
418
- return ComputeOps.summarize(this, history);
419
- }
420
-
421
- /**
422
- * Upcasts content to parent holonagons recursively using references.
423
- * @param {string} holon - The current holon identifier.
424
- * @param {string} lens - The lens under which to upcast.
425
- * @param {object} content - The content to upcast.
426
- * @param {number} [maxLevels=15] - Maximum levels to upcast.
427
- * @returns {Promise<object>} - The original content.
428
- */
429
- async upcast(holon, lens, content, maxLevels = 15) {
430
- // Delegate to the external function
431
- return ComputeOps.upcast(this, holon, lens, content, maxLevels);
432
- }
433
-
434
- /**
435
- * Updates the parent holon with a new report.
436
- * @param {string} id - The child holon identifier.
437
- * @param {string} report - The report to update.
438
- * @returns {Promise<object>} - The updated parent information.
439
- */
440
- async updateParent(id, report) {
441
- // Delegate to the external function
442
- return ComputeOps.updateParent(this, id, report);
443
- }
444
-
445
- /**
446
- * Propagates data to federated holons
447
- * @param {string} holon - The holon identifier
448
- * @param {string} lens - The lens identifier
449
- * @param {object} data - The data to propagate
450
- * @param {object} [options] - Propagation options
451
- * @returns {Promise<object>} - Result with success count and errors
452
- */
453
- async propagate(holon, lens, data, options = {}) {
454
- return Federation.propagate(this, holon, lens, data, options);
455
- }
456
-
457
- /**
458
- * Converts latitude and longitude to a holon identifier.
459
- * @param {number} lat - The latitude.
460
- * @param {number} lng - The longitude.
461
- * @param {number} resolution - The resolution level.
462
- * @returns {Promise<string>} - The resulting holon identifier.
463
- */
464
- async getHolon(lat, lng, resolution) {
465
- // Delegate to the external function
466
- return Utils.getHolon(lat, lng, resolution);
467
- }
468
-
469
- /**
470
- * Retrieves all containing holonagons at all scales for given coordinates.
471
- * @param {number} lat - The latitude.
472
- * @param {number} lng - The longitude.
473
- * @returns {Array<string>} - List of holon identifiers.
474
- */
475
- getScalespace(lat, lng) {
476
- // Delegate to the external function
477
- return Utils.getScalespace(lat, lng);
478
- }
479
-
480
- /**
481
- * Retrieves all containing holonagons at all scales for a given holon.
482
- * @param {string} holon - The holon identifier.
483
- * @returns {Array<string>} - List of holon identifiers.
484
- */
485
- getHolonScalespace(holon) {
486
- // Delegate to the external function
487
- return Utils.getHolonScalespace(holon);
488
- }
489
-
490
- /**
491
- * Subscribes to changes in a specific holon and lens.
492
- * @param {string} holon - The holon identifier.
493
- * @param {string} lens - The lens to subscribe to.
494
- * @param {function} callback - The callback to execute on changes.
495
- * @returns {Promise<object>} - Subscription object with unsubscribe method
496
- */
497
- async subscribe(holon, lens, callback) {
498
- // Delegate to the external function
499
- return Utils.subscribe(this, holon, lens, callback);
500
- }
501
-
502
- /**
503
- * Notifies subscribers about data changes
504
- * @param {object} data - The data to notify about
505
- * @private
506
- */
507
- notifySubscribers(data) {
508
- // Delegate to the external function
509
- return Utils.notifySubscribers(this, data);
510
- }
511
-
512
- // Add ID generation method
513
- generateId() {
514
- // Delegate to the external function
515
- return Utils.generateId();
516
- }
517
-
518
- // ================================ FEDERATION FUNCTIONS ================================
519
-
520
- /**
521
- * Creates a federation relationship between two holons
522
- * @param {string} holonId1 - The first holon ID
523
- * @param {string} holonId2 - The second holon ID
524
- * @param {string} [password1] - Optional password for the first holon
525
- * @param {string} [password2] - Optional password for the second holon
526
- * @param {boolean} [bidirectional=true] - Whether to set up bidirectional notifications automatically
527
- * @param {object} [lensConfig] - Optional lens-specific configuration
528
- * @param {string[]} [lensConfig.federate] - List of lenses to federate (default: all)
529
- * @param {string[]} [lensConfig.notify] - List of lenses to notify (default: all)
530
- * @returns {Promise<boolean>} - True if federation was created successfully
531
- */
532
- async federate(holonId1, holonId2, password1 = null, password2 = null, bidirectional = true, lensConfig = {}) {
533
- return Federation.federate(this, holonId1, holonId2, password1, password2, bidirectional, lensConfig);
534
- }
535
-
536
- /**
537
- * Subscribes to federation notifications for a holon
538
- * @param {string} holonId - The holon ID to subscribe to
539
- * @param {string} password - Password for the holon
540
- * @param {function} callback - The callback to execute on notifications
541
- * @param {object} [options] - Subscription options
542
- * @param {string[]} [options.lenses] - Specific lenses to subscribe to (default: all)
543
- * @param {number} [options.throttle] - Throttle notifications in ms (default: 0)
544
- * @returns {Promise<object>} - Subscription object with unsubscribe() method
545
- */
546
- async subscribeFederation(holonId, password, callback, options = {}) {
547
- return Federation.subscribeFederation(this, holonId, password, callback, options);
548
- }
549
-
550
- /**
551
- * Gets federation info for a holon
552
- * @param {string} holonId - The holon ID
553
- * @param {string} [password] - Optional password for the holon
554
- * @returns {Promise<object|null>} - Federation info or null if not found
555
- */
556
- async getFederation(holonId, password = null) {
557
- return Federation.getFederation(this, holonId, password);
558
- }
559
-
560
- /**
561
- * Retrieves the lens-specific configuration for a federation link between two holons.
562
- * @param {string} holonId - The ID of the source holon.
563
- * @param {string} targetHolonId - The ID of the target holon in the federation link.
564
- * @param {string} [password] - Optional password for the source holon.
565
- * @returns {Promise<object|null>} - An object with 'federate' and 'notify' arrays, or null if not found.
566
- */
567
- async getFederatedConfig(holonId, targetHolonId, password = null) {
568
- return Federation.getFederatedConfig(this, holonId, targetHolonId, password);
569
- }
570
-
571
- /**
572
- * Removes a federation relationship between holons
573
- * @param {string} holonId1 - The first holon ID
574
- * @param {string} holonId2 - The second holon ID
575
- * @param {string} password1 - Password for the first holon
576
- * @param {string} [password2] - Optional password for the second holon
577
- * @returns {Promise<boolean>} - True if federation was removed successfully
578
- */
579
- async unfederate(holonId1, holonId2, password1, password2 = null) {
580
- return await Federation.unfederate(this, holonId1, holonId2, password1, password2);
581
- }
582
-
583
- /**
584
- * Removes a notification relationship between two spaces
585
- * This removes spaceId2 from the notify list of spaceId1
586
- *
587
- * @param {string} holonId1 - The space to modify (remove from its notify list)
588
- * @param {string} holonId2 - The space to be removed from notifications
589
- * @param {string} [password1] - Optional password for the first space
590
- * @returns {Promise<boolean>} - True if notification was removed successfully
591
- */
592
- async removeNotify(holonId1, holonId2, password1 = null) {
593
- console.log(`HoloSphere.removeNotify called: ${holonId1}, ${holonId2}`);
594
- try {
595
- const result = await Federation.removeNotify(this, holonId1, holonId2, password1);
596
- console.log(`HoloSphere.removeNotify completed successfully: ${result}`);
597
- return result;
598
- } catch (error) {
599
- console.error(`HoloSphere.removeNotify failed:`, error);
600
- throw error;
601
- }
602
- }
603
-
604
- /**
605
- * Get and aggregate data from federated holons
606
- * @param {string} holon The holon name
607
- * @param {string} lens The lens name
608
- * @param {Object} options Options for retrieval and aggregation
609
- * @returns {Promise<Array>} Combined array of local and federated data
610
- */
611
- async getFederated(holon, lens, options = {}) {
612
- return Federation.getFederated(this, holon, lens, options);
613
- }
614
-
615
- /**
616
- * Tracks a federated message across different chats
617
- * @param {string} originalChatId - The ID of the original chat
618
- * @param {string} messageId - The ID of the original message
619
- * @param {string} federatedChatId - The ID of the federated chat
620
- * @param {string} federatedMessageId - The ID of the message in the federated chat
621
- * @param {string} type - The type of message (e.g., 'quest', 'announcement')
622
- * @returns {Promise<void>}
623
- */
624
- async federateMessage(originalChatId, messageId, federatedChatId, federatedMessageId, type = 'generic') {
625
- return Federation.federateMessage(this, originalChatId, messageId, federatedChatId, federatedMessageId, type);
626
- }
627
-
628
- /**
629
- * Gets all federated messages for a given original message
630
- * @param {string} originalChatId - The ID of the original chat
631
- * @param {string} messageId - The ID of the original message
632
- * @returns {Promise<Object|null>} The tracking information for the message
633
- */
634
- async getFederatedMessages(originalChatId, messageId) {
635
- return Federation.getFederatedMessages(this, originalChatId, messageId);
636
- }
637
-
638
- /**
639
- * Updates a federated message across all federated chats
640
- * @param {string} originalChatId - The ID of the original chat
641
- * @param {string} messageId - The ID of the original message
642
- * @param {Function} updateCallback - Function to update the message in each chat
643
- * @returns {Promise<void>}
644
- */
645
- async updateFederatedMessages(originalChatId, messageId, updateCallback) {
646
- return Federation.updateFederatedMessages(this, originalChatId, messageId, updateCallback);
647
- }
648
-
649
- /**
650
- * Resets the federation settings for a holon
651
- * @param {string} holonId - The holon ID
652
- * @param {string} [password] - Optional password for the holon
653
- * @returns {Promise<boolean>} - True if federation was reset successfully
654
- */
655
- async resetFederation(holonId, password = null) {
656
- return Federation.resetFederation(this, holonId, password);
657
- }
658
-
659
- // ================================ END FEDERATION FUNCTIONS ================================
660
- /**
661
- * Closes the HoloSphere instance and cleans up resources.
662
- * @returns {Promise<void>}
663
- */
664
- async close() {
665
- // Delegate to the external function
666
- return Utils.close(this);
667
- }
668
-
669
- /**
670
- * Creates a namespaced username for Gun authentication
671
- * @private
672
- * @param {string} holonId - The holon ID
673
- * @returns {string} - Namespaced username
674
- */
675
- userName(holonId) {
676
- // Delegate to the external function
677
- return Utils.userName(this, holonId);
678
- }
679
-
680
- /**
681
- * Returns the current version of the HoloSphere library.
682
- * @returns {string} The library version.
683
- */
684
- getVersion() {
685
- return HOLOSPHERE_VERSION;
686
- }
687
-
688
- /**
689
- * Configures radisk storage options for GunDB.
690
- * @param {object} options - Radisk configuration options
691
- * @param {string} [options.file='./radata'] - Directory for radisk storage
692
- * @param {boolean} [options.radisk=true] - Whether to enable radisk storage
693
- * @param {number} [options.until] - Timestamp until which to keep data
694
- * @param {number} [options.retry] - Number of retries for failed operations
695
- * @param {number} [options.timeout] - Timeout for operations in milliseconds
696
- */
697
- configureRadisk(options = {}) {
698
- const defaultOptions = {
699
- file: './radata',
700
- radisk: true,
701
- until: null,
702
- retry: 3,
703
- timeout: 5000
704
- };
705
-
706
- const radiskOptions = { ...defaultOptions, ...options };
707
-
708
- // Update Gun instance with new radisk options
709
- if (this.gun && this.gun._.opt) {
710
- Object.assign(this.gun._.opt, radiskOptions);
711
- console.log('Radisk configuration updated:', radiskOptions);
712
- } else {
713
- console.warn('Gun instance not available for radisk configuration');
714
- }
715
- }
716
-
717
- /**
718
- * Gets radisk storage statistics and information.
719
- * @returns {object} Radisk statistics including file path, enabled status, and storage info
720
- */
721
- getRadiskStats() {
722
- if (!this.gun || !this.gun._.opt) {
723
- return { error: 'Gun instance not available' };
724
- }
725
-
726
- const options = this.gun._.opt;
727
- return {
728
- enabled: options.radisk || false,
729
- filePath: options.file || './radata',
730
- retry: options.retry || 3,
731
- timeout: options.timeout || 5000,
732
- until: options.until || null,
733
- peers: options.peers || [],
734
- localStorage: options.localStorage || false
735
- };
736
- }
737
- }
738
-
739
- export default HoloSphere;