@nebula-ai/sdk 1.1.6 → 1.1.7
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 +11 -7
- package/dist/index.d.mts +1 -62
- package/dist/index.d.ts +1 -62
- package/dist/index.js +14 -160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -160
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -137,23 +137,27 @@ const result = await client.delete(['id1', 'id2', 'id3']); // Returns detailed r
|
|
|
137
137
|
const conversationId = await client.storeMemory({
|
|
138
138
|
collection_id: collection.id,
|
|
139
139
|
content: 'What is machine learning?',
|
|
140
|
-
role: 'user'
|
|
140
|
+
role: 'user',
|
|
141
|
+
metadata: { content_type: 'conversation' }
|
|
141
142
|
});
|
|
142
143
|
|
|
143
144
|
await client.storeMemory({
|
|
144
145
|
collection_id: collection.id,
|
|
145
146
|
content: 'Machine learning is a subset of AI...',
|
|
146
147
|
role: 'assistant',
|
|
147
|
-
parent_id: conversationId
|
|
148
|
+
parent_id: conversationId,
|
|
149
|
+
metadata: { content_type: 'conversation' }
|
|
148
150
|
});
|
|
149
151
|
|
|
150
|
-
// List
|
|
151
|
-
const conversations = await client.
|
|
152
|
-
collection_ids: [collection.id]
|
|
152
|
+
// List conversation memories
|
|
153
|
+
const conversations = await client.listMemories({
|
|
154
|
+
collection_ids: [collection.id],
|
|
155
|
+
metadata_filters: { 'metadata.content_type': { $eq: 'conversation' } }
|
|
153
156
|
});
|
|
154
157
|
|
|
155
|
-
// Get messages
|
|
156
|
-
const
|
|
158
|
+
// Get messages from a conversation memory
|
|
159
|
+
const conversation = await client.getMemory(conversationId);
|
|
160
|
+
const messages = conversation.chunks ?? [];
|
|
157
161
|
```
|
|
158
162
|
|
|
159
163
|
## Error Handling
|
package/dist/index.d.mts
CHANGED
|
@@ -216,55 +216,6 @@ declare class Nebula {
|
|
|
216
216
|
limit?: number;
|
|
217
217
|
offset?: number;
|
|
218
218
|
}): Promise<Collection[]>;
|
|
219
|
-
/**
|
|
220
|
-
* List conversations for the authenticated user with optional metadata filtering
|
|
221
|
-
*
|
|
222
|
-
* @param options - Configuration for listing conversations
|
|
223
|
-
* @param options.limit - Maximum number of conversations to return (default: 100)
|
|
224
|
-
* @param options.offset - Number of conversations to skip for pagination (default: 0)
|
|
225
|
-
* @param options.collection_ids - Optional list of collection IDs to filter conversations by
|
|
226
|
-
* @param options.metadata_filters - Optional metadata filters using MongoDB-like operators.
|
|
227
|
-
* Supported operators: $eq, $ne, $in, $nin, $exists, $and, $or
|
|
228
|
-
*
|
|
229
|
-
* @returns Promise resolving to array of conversation objects with fields: id, created_at, user_id, name, collection_ids
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* // Get all playground conversations
|
|
233
|
-
* const conversations = await client.listConversations({
|
|
234
|
-
* collection_ids: ['collection-id'],
|
|
235
|
-
* metadata_filters: {
|
|
236
|
-
* 'metadata.playground': { $eq: true }
|
|
237
|
-
* }
|
|
238
|
-
* });
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* // Filter by session ID
|
|
242
|
-
* const conversations = await client.listConversations({
|
|
243
|
-
* metadata_filters: {
|
|
244
|
-
* 'metadata.session_id': { $eq: 'session-123' }
|
|
245
|
-
* }
|
|
246
|
-
* });
|
|
247
|
-
*/
|
|
248
|
-
listConversations(options?: {
|
|
249
|
-
limit?: number;
|
|
250
|
-
offset?: number;
|
|
251
|
-
collection_ids?: string[];
|
|
252
|
-
metadata_filters?: Record<string, any>;
|
|
253
|
-
}): Promise<any[]>;
|
|
254
|
-
/**
|
|
255
|
-
* Get conversation messages from the engrams API.
|
|
256
|
-
*
|
|
257
|
-
* This method retrieves conversation engrams and parses their chunks into structured messages.
|
|
258
|
-
* Expects conversation engrams to contain structured chunks with role metadata:
|
|
259
|
-
* `{text: string, role: 'user'|'assistant'|'system'}`.
|
|
260
|
-
* Converts chunks to `MemoryResponse` objects with proper role metadata.
|
|
261
|
-
*
|
|
262
|
-
* @param conversationId - Single conversation ID (returns array of messages)
|
|
263
|
-
* @param conversationIds - Multiple conversation IDs (returns map of conversation_id -> messages)
|
|
264
|
-
* @returns Messages for the requested conversation(s)
|
|
265
|
-
*/
|
|
266
|
-
getConversationMessages(conversationId: string): Promise<MemoryResponse[]>;
|
|
267
|
-
getConversationMessages(conversationIds: string[]): Promise<Record<string, MemoryResponse[]>>;
|
|
268
219
|
/** Update a collection */
|
|
269
220
|
updateCollection(options: {
|
|
270
221
|
collectionId: string;
|
|
@@ -343,8 +294,6 @@ declare class Nebula {
|
|
|
343
294
|
collectionIds?: string[];
|
|
344
295
|
mergeMetadata?: boolean;
|
|
345
296
|
}): Promise<boolean>;
|
|
346
|
-
/** Delete a conversation and all its messages */
|
|
347
|
-
deleteConversation(conversationId: string): Promise<boolean>;
|
|
348
297
|
/**
|
|
349
298
|
* Get all memories from specific collections with optional metadata filtering
|
|
350
299
|
*
|
|
@@ -484,21 +433,11 @@ declare class Nebula {
|
|
|
484
433
|
*/
|
|
485
434
|
search(options: {
|
|
486
435
|
query: string;
|
|
487
|
-
collection_ids
|
|
436
|
+
collection_ids?: string | string[];
|
|
488
437
|
limit?: number;
|
|
489
438
|
filters?: Record<string, any>;
|
|
490
|
-
search_mode?: 'fast' | 'super';
|
|
491
439
|
searchSettings?: Record<string, any>;
|
|
492
440
|
}): Promise<MemoryRecall>;
|
|
493
|
-
/**
|
|
494
|
-
* Legacy wrapper: store a two-message conversation turn as a document
|
|
495
|
-
*/
|
|
496
|
-
storeConversation(userMessage: string, assistantMessage: string, collectionId: string, sessionId: string): Promise<MemoryResponse>;
|
|
497
|
-
/**
|
|
498
|
-
* Legacy wrapper: search conversations optionally scoped by session
|
|
499
|
-
* Now returns MemoryRecall with hierarchical memory structure
|
|
500
|
-
*/
|
|
501
|
-
searchConversations(query: string, collectionId: string, sessionId?: string, includeAllSessions?: boolean): Promise<MemoryRecall>;
|
|
502
441
|
healthCheck(): Promise<Record<string, any>>;
|
|
503
442
|
private _collectionFromDict;
|
|
504
443
|
private _memoryResponseFromDict;
|
package/dist/index.d.ts
CHANGED
|
@@ -216,55 +216,6 @@ declare class Nebula {
|
|
|
216
216
|
limit?: number;
|
|
217
217
|
offset?: number;
|
|
218
218
|
}): Promise<Collection[]>;
|
|
219
|
-
/**
|
|
220
|
-
* List conversations for the authenticated user with optional metadata filtering
|
|
221
|
-
*
|
|
222
|
-
* @param options - Configuration for listing conversations
|
|
223
|
-
* @param options.limit - Maximum number of conversations to return (default: 100)
|
|
224
|
-
* @param options.offset - Number of conversations to skip for pagination (default: 0)
|
|
225
|
-
* @param options.collection_ids - Optional list of collection IDs to filter conversations by
|
|
226
|
-
* @param options.metadata_filters - Optional metadata filters using MongoDB-like operators.
|
|
227
|
-
* Supported operators: $eq, $ne, $in, $nin, $exists, $and, $or
|
|
228
|
-
*
|
|
229
|
-
* @returns Promise resolving to array of conversation objects with fields: id, created_at, user_id, name, collection_ids
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* // Get all playground conversations
|
|
233
|
-
* const conversations = await client.listConversations({
|
|
234
|
-
* collection_ids: ['collection-id'],
|
|
235
|
-
* metadata_filters: {
|
|
236
|
-
* 'metadata.playground': { $eq: true }
|
|
237
|
-
* }
|
|
238
|
-
* });
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* // Filter by session ID
|
|
242
|
-
* const conversations = await client.listConversations({
|
|
243
|
-
* metadata_filters: {
|
|
244
|
-
* 'metadata.session_id': { $eq: 'session-123' }
|
|
245
|
-
* }
|
|
246
|
-
* });
|
|
247
|
-
*/
|
|
248
|
-
listConversations(options?: {
|
|
249
|
-
limit?: number;
|
|
250
|
-
offset?: number;
|
|
251
|
-
collection_ids?: string[];
|
|
252
|
-
metadata_filters?: Record<string, any>;
|
|
253
|
-
}): Promise<any[]>;
|
|
254
|
-
/**
|
|
255
|
-
* Get conversation messages from the engrams API.
|
|
256
|
-
*
|
|
257
|
-
* This method retrieves conversation engrams and parses their chunks into structured messages.
|
|
258
|
-
* Expects conversation engrams to contain structured chunks with role metadata:
|
|
259
|
-
* `{text: string, role: 'user'|'assistant'|'system'}`.
|
|
260
|
-
* Converts chunks to `MemoryResponse` objects with proper role metadata.
|
|
261
|
-
*
|
|
262
|
-
* @param conversationId - Single conversation ID (returns array of messages)
|
|
263
|
-
* @param conversationIds - Multiple conversation IDs (returns map of conversation_id -> messages)
|
|
264
|
-
* @returns Messages for the requested conversation(s)
|
|
265
|
-
*/
|
|
266
|
-
getConversationMessages(conversationId: string): Promise<MemoryResponse[]>;
|
|
267
|
-
getConversationMessages(conversationIds: string[]): Promise<Record<string, MemoryResponse[]>>;
|
|
268
219
|
/** Update a collection */
|
|
269
220
|
updateCollection(options: {
|
|
270
221
|
collectionId: string;
|
|
@@ -343,8 +294,6 @@ declare class Nebula {
|
|
|
343
294
|
collectionIds?: string[];
|
|
344
295
|
mergeMetadata?: boolean;
|
|
345
296
|
}): Promise<boolean>;
|
|
346
|
-
/** Delete a conversation and all its messages */
|
|
347
|
-
deleteConversation(conversationId: string): Promise<boolean>;
|
|
348
297
|
/**
|
|
349
298
|
* Get all memories from specific collections with optional metadata filtering
|
|
350
299
|
*
|
|
@@ -484,21 +433,11 @@ declare class Nebula {
|
|
|
484
433
|
*/
|
|
485
434
|
search(options: {
|
|
486
435
|
query: string;
|
|
487
|
-
collection_ids
|
|
436
|
+
collection_ids?: string | string[];
|
|
488
437
|
limit?: number;
|
|
489
438
|
filters?: Record<string, any>;
|
|
490
|
-
search_mode?: 'fast' | 'super';
|
|
491
439
|
searchSettings?: Record<string, any>;
|
|
492
440
|
}): Promise<MemoryRecall>;
|
|
493
|
-
/**
|
|
494
|
-
* Legacy wrapper: store a two-message conversation turn as a document
|
|
495
|
-
*/
|
|
496
|
-
storeConversation(userMessage: string, assistantMessage: string, collectionId: string, sessionId: string): Promise<MemoryResponse>;
|
|
497
|
-
/**
|
|
498
|
-
* Legacy wrapper: search conversations optionally scoped by session
|
|
499
|
-
* Now returns MemoryRecall with hierarchical memory structure
|
|
500
|
-
*/
|
|
501
|
-
searchConversations(query: string, collectionId: string, sessionId?: string, includeAllSessions?: boolean): Promise<MemoryRecall>;
|
|
502
441
|
healthCheck(): Promise<Record<string, any>>;
|
|
503
442
|
private _collectionFromDict;
|
|
504
443
|
private _memoryResponseFromDict;
|
package/dist/index.js
CHANGED
|
@@ -208,110 +208,6 @@ var Nebula = class {
|
|
|
208
208
|
}
|
|
209
209
|
return collections.map((collection) => this._collectionFromDict(collection));
|
|
210
210
|
}
|
|
211
|
-
// Conversations Methods
|
|
212
|
-
/**
|
|
213
|
-
* List conversations for the authenticated user with optional metadata filtering
|
|
214
|
-
*
|
|
215
|
-
* @param options - Configuration for listing conversations
|
|
216
|
-
* @param options.limit - Maximum number of conversations to return (default: 100)
|
|
217
|
-
* @param options.offset - Number of conversations to skip for pagination (default: 0)
|
|
218
|
-
* @param options.collection_ids - Optional list of collection IDs to filter conversations by
|
|
219
|
-
* @param options.metadata_filters - Optional metadata filters using MongoDB-like operators.
|
|
220
|
-
* Supported operators: $eq, $ne, $in, $nin, $exists, $and, $or
|
|
221
|
-
*
|
|
222
|
-
* @returns Promise resolving to array of conversation objects with fields: id, created_at, user_id, name, collection_ids
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* // Get all playground conversations
|
|
226
|
-
* const conversations = await client.listConversations({
|
|
227
|
-
* collection_ids: ['collection-id'],
|
|
228
|
-
* metadata_filters: {
|
|
229
|
-
* 'metadata.playground': { $eq: true }
|
|
230
|
-
* }
|
|
231
|
-
* });
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* // Filter by session ID
|
|
235
|
-
* const conversations = await client.listConversations({
|
|
236
|
-
* metadata_filters: {
|
|
237
|
-
* 'metadata.session_id': { $eq: 'session-123' }
|
|
238
|
-
* }
|
|
239
|
-
* });
|
|
240
|
-
*/
|
|
241
|
-
async listConversations(options) {
|
|
242
|
-
const params = {
|
|
243
|
-
limit: options?.limit ?? 100,
|
|
244
|
-
offset: options?.offset ?? 0
|
|
245
|
-
};
|
|
246
|
-
if (options?.collection_ids && options.collection_ids.length > 0) {
|
|
247
|
-
params.collection_ids = options.collection_ids;
|
|
248
|
-
}
|
|
249
|
-
if (options?.metadata_filters) {
|
|
250
|
-
params.metadata_filters = JSON.stringify(options.metadata_filters);
|
|
251
|
-
}
|
|
252
|
-
const response = await this._makeRequest("GET", "/v1/memories", void 0, params);
|
|
253
|
-
let conversations;
|
|
254
|
-
if (response && response.results) {
|
|
255
|
-
conversations = response.results;
|
|
256
|
-
} else if (Array.isArray(response)) {
|
|
257
|
-
conversations = response;
|
|
258
|
-
} else {
|
|
259
|
-
conversations = response ? [response] : [];
|
|
260
|
-
}
|
|
261
|
-
return conversations;
|
|
262
|
-
}
|
|
263
|
-
async getConversationMessages(conversationIdOrIds) {
|
|
264
|
-
if (typeof conversationIdOrIds === "string") {
|
|
265
|
-
const batchResults = await this.getConversationMessages([conversationIdOrIds]);
|
|
266
|
-
return batchResults[conversationIdOrIds] || [];
|
|
267
|
-
}
|
|
268
|
-
if (!Array.isArray(conversationIdOrIds) || conversationIdOrIds.length === 0) {
|
|
269
|
-
return {};
|
|
270
|
-
}
|
|
271
|
-
const params = { ids: conversationIdOrIds };
|
|
272
|
-
const response = await this._makeRequest("GET", "/v1/memories", void 0, params);
|
|
273
|
-
const results = {};
|
|
274
|
-
if (response && response.results && Array.isArray(response.results)) {
|
|
275
|
-
for (const doc of response.results) {
|
|
276
|
-
const conversationId = doc.id;
|
|
277
|
-
if (!conversationId) {
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
if (Array.isArray(doc.chunks) && doc.chunks.length > 0) {
|
|
281
|
-
const messages = [];
|
|
282
|
-
for (let i = 0; i < doc.chunks.length; i++) {
|
|
283
|
-
const structuredChunk = doc.chunks[i];
|
|
284
|
-
if (!structuredChunk || typeof structuredChunk.text !== "string" || structuredChunk.text.length === 0) {
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
const text = structuredChunk.text;
|
|
288
|
-
const role = structuredChunk.role ?? "user";
|
|
289
|
-
messages.push({
|
|
290
|
-
id: `${doc.id}-${i}`,
|
|
291
|
-
content: text,
|
|
292
|
-
metadata: {
|
|
293
|
-
...doc.metadata,
|
|
294
|
-
// Copy engram metadata (playground, session_id, etc.)
|
|
295
|
-
role
|
|
296
|
-
// Add/override role for this specific message
|
|
297
|
-
},
|
|
298
|
-
created_at: doc.created_at,
|
|
299
|
-
collection_ids: doc.collection_ids || []
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
results[conversationId] = messages;
|
|
303
|
-
} else {
|
|
304
|
-
results[conversationId] = [];
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
for (const conversationId of conversationIdOrIds) {
|
|
309
|
-
if (!(conversationId in results)) {
|
|
310
|
-
results[conversationId] = [];
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return results;
|
|
314
|
-
}
|
|
315
211
|
/** Update a collection */
|
|
316
212
|
async updateCollection(options) {
|
|
317
213
|
const data = {};
|
|
@@ -674,18 +570,6 @@ var Nebula = class {
|
|
|
674
570
|
throw error;
|
|
675
571
|
}
|
|
676
572
|
}
|
|
677
|
-
/** Delete a conversation and all its messages */
|
|
678
|
-
async deleteConversation(conversationId) {
|
|
679
|
-
try {
|
|
680
|
-
await this._makeRequest("DELETE", `/v1/memories/${conversationId}`);
|
|
681
|
-
return true;
|
|
682
|
-
} catch (error) {
|
|
683
|
-
if (error instanceof Error) {
|
|
684
|
-
throw error;
|
|
685
|
-
}
|
|
686
|
-
throw new NebulaClientException(`Unknown error: ${String(error)}`);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
573
|
/**
|
|
690
574
|
* Get all memories from specific collections with optional metadata filtering
|
|
691
575
|
*
|
|
@@ -855,28 +739,23 @@ var Nebula = class {
|
|
|
855
739
|
* https://docs.nebulacloud.app/guides/metadata-filtering
|
|
856
740
|
*/
|
|
857
741
|
async search(options) {
|
|
858
|
-
const collectionIds = Array.isArray(options.collection_ids) ? options.collection_ids : [options.collection_ids];
|
|
859
|
-
const validCollectionIds = collectionIds.filter((id) => id && id.trim() !== "");
|
|
860
|
-
if (!validCollectionIds.length) {
|
|
861
|
-
throw new NebulaClientException("collection_ids must be provided to search().");
|
|
862
|
-
}
|
|
863
|
-
const limit = options.limit ?? 10;
|
|
864
|
-
const searchMode = options.search_mode ?? "super";
|
|
865
|
-
const effectiveSettings = {
|
|
866
|
-
...options.searchSettings
|
|
867
|
-
};
|
|
868
|
-
effectiveSettings.limit = limit;
|
|
869
|
-
const userFilters = { ...effectiveSettings.filters };
|
|
870
|
-
if (options.filters) {
|
|
871
|
-
Object.assign(userFilters, options.filters);
|
|
872
|
-
}
|
|
873
|
-
userFilters.collection_ids = { $overlap: validCollectionIds };
|
|
874
|
-
effectiveSettings.filters = userFilters;
|
|
875
742
|
const data = {
|
|
876
743
|
query: options.query,
|
|
877
|
-
|
|
878
|
-
search_settings: effectiveSettings
|
|
744
|
+
limit: options.limit ?? 10
|
|
879
745
|
};
|
|
746
|
+
if (options.collection_ids) {
|
|
747
|
+
const collectionIds = Array.isArray(options.collection_ids) ? options.collection_ids : [options.collection_ids];
|
|
748
|
+
const validCollectionIds = collectionIds.filter((id) => id && id.trim() !== "");
|
|
749
|
+
if (validCollectionIds.length) {
|
|
750
|
+
data.collection_ids = validCollectionIds;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (options.filters) {
|
|
754
|
+
data.filters = options.filters;
|
|
755
|
+
}
|
|
756
|
+
if (options.searchSettings) {
|
|
757
|
+
data.search_settings = options.searchSettings;
|
|
758
|
+
}
|
|
880
759
|
const response = await this._makeRequest("POST", "/v1/retrieval/search", data);
|
|
881
760
|
const memoryRecall = response.results || {
|
|
882
761
|
query: options.query,
|
|
@@ -889,31 +768,6 @@ var Nebula = class {
|
|
|
889
768
|
};
|
|
890
769
|
return memoryRecall;
|
|
891
770
|
}
|
|
892
|
-
/**
|
|
893
|
-
* Legacy wrapper: store a two-message conversation turn as a document
|
|
894
|
-
*/
|
|
895
|
-
async storeConversation(userMessage, assistantMessage, collectionId, sessionId) {
|
|
896
|
-
const content = `User: ${String(userMessage || "")}
|
|
897
|
-
Assistant: ${String(assistantMessage || "")}`;
|
|
898
|
-
const metadata = { session_id: sessionId, content_type: "conversation" };
|
|
899
|
-
return this.store(content, collectionId, metadata);
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Legacy wrapper: search conversations optionally scoped by session
|
|
903
|
-
* Now returns MemoryRecall with hierarchical memory structure
|
|
904
|
-
*/
|
|
905
|
-
async searchConversations(query, collectionId, sessionId, includeAllSessions = true) {
|
|
906
|
-
const filters = { "metadata.content_type": "conversation" };
|
|
907
|
-
if (sessionId && !includeAllSessions) {
|
|
908
|
-
filters["metadata.session_id"] = sessionId;
|
|
909
|
-
}
|
|
910
|
-
return this.search({
|
|
911
|
-
query,
|
|
912
|
-
collection_ids: [collectionId],
|
|
913
|
-
limit: 10,
|
|
914
|
-
filters
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
771
|
// Health Check
|
|
918
772
|
async healthCheck() {
|
|
919
773
|
return this._makeRequest("GET", "/v1/health");
|