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