@nebula-ai/sdk 1.2.0 → 1.2.2
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/README.md +0 -2
- package/dist/index.d.mts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +66 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -339,7 +339,7 @@ var _Nebula = class _Nebula {
|
|
|
339
339
|
*/
|
|
340
340
|
async storeMemory(memory, name) {
|
|
341
341
|
let mem;
|
|
342
|
-
if ("collection_id" in memory) {
|
|
342
|
+
if ("collection_id" in memory || "snapshot" in memory) {
|
|
343
343
|
mem = memory;
|
|
344
344
|
} else {
|
|
345
345
|
const memRecord2 = memory;
|
|
@@ -348,9 +348,23 @@ var _Nebula = class _Nebula {
|
|
|
348
348
|
content: memRecord2.content || "",
|
|
349
349
|
role: memRecord2.role,
|
|
350
350
|
memory_id: memRecord2.memory_id || memRecord2.memoryId || void 0,
|
|
351
|
-
metadata: memRecord2.metadata || {}
|
|
351
|
+
metadata: memRecord2.metadata || {},
|
|
352
|
+
snapshot: memRecord2.snapshot
|
|
352
353
|
};
|
|
353
354
|
}
|
|
355
|
+
if (mem.snapshot) {
|
|
356
|
+
const contentText = await this._serializeContentAsText(mem.content);
|
|
357
|
+
const payload2 = {
|
|
358
|
+
snapshot: mem.snapshot,
|
|
359
|
+
raw_text: contentText
|
|
360
|
+
};
|
|
361
|
+
const response2 = await this._makeRequest("POST", "/v1/memories", payload2);
|
|
362
|
+
const snapshot = response2?.results?.snapshot;
|
|
363
|
+
if (snapshot) {
|
|
364
|
+
return snapshot;
|
|
365
|
+
}
|
|
366
|
+
return response2?.results ?? {};
|
|
367
|
+
}
|
|
354
368
|
if (mem.memory_id) {
|
|
355
369
|
return await this._appendToMemory(mem.memory_id, mem);
|
|
356
370
|
}
|
|
@@ -819,6 +833,27 @@ var _Nebula = class _Nebula {
|
|
|
819
833
|
* https://docs.trynebula.ai/guides/metadata-filtering
|
|
820
834
|
*/
|
|
821
835
|
async search(options) {
|
|
836
|
+
if (options.snapshot) {
|
|
837
|
+
const snapshotData = {
|
|
838
|
+
snapshot: options.snapshot,
|
|
839
|
+
query: options.query
|
|
840
|
+
};
|
|
841
|
+
if (options.effort) {
|
|
842
|
+
snapshotData.effort = options.effort;
|
|
843
|
+
}
|
|
844
|
+
const response2 = await this._makeRequest("POST", "/v1/memories/search", snapshotData);
|
|
845
|
+
const memoryResponseData2 = response2.results;
|
|
846
|
+
return {
|
|
847
|
+
query: memoryResponseData2.query || options.query,
|
|
848
|
+
semantics: memoryResponseData2.semantics || memoryResponseData2.knowledge || [],
|
|
849
|
+
procedures: memoryResponseData2.procedures || [],
|
|
850
|
+
episodes: memoryResponseData2.episodes || [],
|
|
851
|
+
sources: memoryResponseData2.sources || [],
|
|
852
|
+
total_traversal_time_ms: memoryResponseData2.total_traversal_time_ms,
|
|
853
|
+
token_count: memoryResponseData2.token_count,
|
|
854
|
+
entities: memoryResponseData2.entities || []
|
|
855
|
+
};
|
|
856
|
+
}
|
|
822
857
|
const data = {
|
|
823
858
|
query: options.query
|
|
824
859
|
};
|
|
@@ -839,7 +874,12 @@ var _Nebula = class _Nebula {
|
|
|
839
874
|
data.search_settings = options.searchSettings;
|
|
840
875
|
}
|
|
841
876
|
const collectionIds = data.collection_ids;
|
|
842
|
-
|
|
877
|
+
let extraHeaders;
|
|
878
|
+
if (collectionIds && collectionIds.length === 1) {
|
|
879
|
+
extraHeaders = { "X-Nebula-Collection-Id": collectionIds[0] };
|
|
880
|
+
} else if (collectionIds && collectionIds.length > 1) {
|
|
881
|
+
extraHeaders = { "X-Nebula-Collection-Id": [...collectionIds].sort().join(",") };
|
|
882
|
+
}
|
|
843
883
|
const response = await this._makeRequest("POST", "/v1/memories/search", data, void 0, extraHeaders);
|
|
844
884
|
const memoryResponseData = response.results;
|
|
845
885
|
const memoryResponse = {
|
|
@@ -1174,6 +1214,29 @@ var _Nebula = class _Nebula {
|
|
|
1174
1214
|
}
|
|
1175
1215
|
return response;
|
|
1176
1216
|
}
|
|
1217
|
+
// ------------------------------------------------------------------
|
|
1218
|
+
// Device Memory
|
|
1219
|
+
// ------------------------------------------------------------------
|
|
1220
|
+
/**
|
|
1221
|
+
* Export a collection's full graph state as a portable snapshot.
|
|
1222
|
+
*/
|
|
1223
|
+
async exportSnapshot(collectionId) {
|
|
1224
|
+
const response = await this._makeRequest("POST", "/v1/device-memory/snapshot/export", {
|
|
1225
|
+
collection_id: collectionId
|
|
1226
|
+
});
|
|
1227
|
+
return response.results ?? response;
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Import a snapshot into an ephemeral server-side collection.
|
|
1231
|
+
* @returns The ephemeral collection ID.
|
|
1232
|
+
*/
|
|
1233
|
+
async importSnapshot(snapshot) {
|
|
1234
|
+
const response = await this._makeRequest("POST", "/v1/device-memory/snapshot/import", {
|
|
1235
|
+
snapshot
|
|
1236
|
+
});
|
|
1237
|
+
const result = response.results ?? response;
|
|
1238
|
+
return result.ephemeral_collection_id ?? "";
|
|
1239
|
+
}
|
|
1177
1240
|
};
|
|
1178
1241
|
// Files larger than 5MB are automatically uploaded to S3
|
|
1179
1242
|
_Nebula.MAX_INLINE_SIZE = 5 * 1024 * 1024;
|