@nebula-ai/sdk 0.0.27 → 0.0.29

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/dist/index.d.ts CHANGED
@@ -3,23 +3,35 @@ declare enum GraphSearchResultType {
3
3
  RELATIONSHIP = "relationship",
4
4
  COMMUNITY = "community"
5
5
  }
6
+ interface Chunk {
7
+ id: string;
8
+ content: string;
9
+ metadata: Record<string, any>;
10
+ role?: string;
11
+ }
6
12
  interface MemoryResponse {
7
13
  id: string;
8
14
  content?: string;
9
- chunks?: string[];
15
+ chunks?: Chunk[];
10
16
  metadata: Record<string, any>;
11
- cluster_ids: string[];
17
+ collection_ids: string[];
12
18
  created_at?: string;
13
19
  updated_at?: string;
14
20
  }
15
21
  interface Memory {
16
- cluster_id: string;
17
- content: string;
22
+ collection_id: string;
23
+ content: string | string[] | Array<{
24
+ content: string;
25
+ role: string;
26
+ metadata?: Record<string, any>;
27
+ authority?: number;
28
+ }>;
18
29
  role?: string;
19
- parent_id?: string;
30
+ memory_id?: string;
20
31
  metadata: Record<string, any>;
32
+ authority?: number;
21
33
  }
22
- interface Cluster {
34
+ interface Collection {
23
35
  id: string;
24
36
  name: string;
25
37
  description?: string;
@@ -37,7 +49,7 @@ interface SearchResult {
37
49
  timestamp?: string;
38
50
  display_name?: string;
39
51
  source_role?: string;
40
- document_id?: string;
52
+ memory_id?: string;
41
53
  owner_id?: string;
42
54
  content?: string;
43
55
  graph_result_type?: GraphSearchResultType;
@@ -104,9 +116,12 @@ declare class NebulaValidationException extends NebulaException {
104
116
  details?: any | undefined;
105
117
  constructor(message?: string, details?: any | undefined);
106
118
  }
107
- declare class NebulaClusterNotFoundException extends NebulaException {
119
+ declare class NebulaCollectionNotFoundException extends NebulaException {
108
120
  constructor(message?: string);
109
121
  }
122
+ declare class NebulaNotFoundException extends NebulaException {
123
+ constructor(resourceId: string, resourceType?: string);
124
+ }
110
125
 
111
126
  /**
112
127
  * Official Nebula JavaScript/TypeScript SDK
@@ -128,48 +143,89 @@ declare class NebulaClient {
128
143
  private _buildAuthHeaders;
129
144
  /** Make an HTTP request to the Nebula API */
130
145
  private _makeRequest;
131
- /** Create a new cluster */
132
- createCluster(options: {
146
+ /** Create a new collection */
147
+ createCollection(options: {
133
148
  name: string;
134
149
  description?: string;
135
150
  metadata?: Record<string, any>;
136
- }): Promise<Cluster>;
137
- /** Get a specific cluster by ID */
138
- getCluster(clusterId: string): Promise<Cluster>;
139
- /** Get a specific cluster by name */
140
- getClusterByName(name: string): Promise<Cluster>;
141
- /** Get all clusters */
142
- listClusters(options?: {
151
+ }): Promise<Collection>;
152
+ /** Get a specific collection by ID */
153
+ getCollection(collectionId: string): Promise<Collection>;
154
+ /** Get a specific collection by name */
155
+ getCollectionByName(name: string): Promise<Collection>;
156
+ /** Get all collections */
157
+ listCollections(options?: {
143
158
  limit?: number;
144
159
  offset?: number;
145
- }): Promise<Cluster[]>;
146
- /** List conversations for the authenticated user */
160
+ }): Promise<Collection[]>;
161
+ /**
162
+ * List conversations for the authenticated user with optional metadata filtering
163
+ *
164
+ * @param options - Configuration for listing conversations
165
+ * @param options.limit - Maximum number of conversations to return (default: 100)
166
+ * @param options.offset - Number of conversations to skip for pagination (default: 0)
167
+ * @param options.collection_ids - Optional list of collection IDs to filter conversations by
168
+ * @param options.metadata_filters - Optional metadata filters using MongoDB-like operators.
169
+ * Supported operators: $eq, $ne, $in, $nin, $exists, $and, $or
170
+ *
171
+ * @returns Promise resolving to array of conversation objects with fields: id, created_at, user_id, name, collection_ids
172
+ *
173
+ * @example
174
+ * // Get all playground conversations
175
+ * const conversations = await client.listConversations({
176
+ * collection_ids: ['collection-id'],
177
+ * metadata_filters: {
178
+ * 'metadata.playground': { $eq: true }
179
+ * }
180
+ * });
181
+ *
182
+ * @example
183
+ * // Filter by session ID
184
+ * const conversations = await client.listConversations({
185
+ * metadata_filters: {
186
+ * 'metadata.session_id': { $eq: 'session-123' }
187
+ * }
188
+ * });
189
+ */
147
190
  listConversations(options?: {
148
191
  limit?: number;
149
192
  offset?: number;
150
- cluster_ids?: string[];
193
+ collection_ids?: string[];
194
+ metadata_filters?: Record<string, any>;
151
195
  }): Promise<any[]>;
152
196
  /** Get conversation messages directly from the conversations API */
153
197
  getConversationMessages(conversationId: string): Promise<MemoryResponse[]>;
154
198
  getConversationMessages(conversationIds: string[]): Promise<Record<string, MemoryResponse[]>>;
155
199
  /** Helper method to transform conversation messages to MemoryResponse format */
156
200
  private _transformConversationMessages;
157
- /** Update a cluster */
158
- updateCluster(options: {
159
- clusterId: string;
201
+ /** Update a collection */
202
+ updateCollection(options: {
203
+ collectionId: string;
160
204
  name?: string;
161
205
  description?: string;
162
206
  metadata?: Record<string, any>;
163
- }): Promise<Cluster>;
164
- /** Delete a cluster */
165
- deleteCluster(clusterId: string): Promise<boolean>;
207
+ }): Promise<Collection>;
208
+ /** Delete a collection */
209
+ deleteCollection(collectionId: string): Promise<boolean>;
210
+ /**
211
+ * Legacy convenience: store raw text content into a collection as a document
212
+ */
213
+ store(content: string, collectionId: string, metadata?: Record<string, any>): Promise<MemoryResponse>;
166
214
  /**
167
- * Legacy convenience: store raw text content into a cluster as a document
215
+ * Store a single memory using the unified engrams API.
216
+ *
217
+ * Automatically infers memory type:
218
+ * - If role is present, creates a conversation
219
+ * - Otherwise, creates a document
168
220
  */
169
- store(content: string, clusterId: string, metadata?: Record<string, any>): Promise<MemoryResponse>;
170
- /** Store a single memory */
171
- storeMemory(memory: Memory | Record<string, any>): Promise<string>;
172
- /** Store multiple memories */
221
+ storeMemory(memory: Memory | Record<string, any>, name?: string): Promise<string>;
222
+ /**
223
+ * Internal method to append content to an existing engram
224
+ *
225
+ * @throws NebulaNotFoundException if engram_id doesn't exist
226
+ */
227
+ private _appendToMemory;
228
+ /** Store multiple memories using the unified engrams API */
173
229
  storeMemories(memories: Memory[]): Promise<string[]>;
174
230
  /** Delete one or more memories */
175
231
  delete(memoryIds: string | string[]): Promise<boolean | {
@@ -187,22 +243,88 @@ declare class NebulaClient {
187
243
  };
188
244
  };
189
245
  }>;
246
+ /** Delete a specific chunk or message within a memory */
247
+ deleteChunk(chunkId: string): Promise<boolean>;
248
+ /** Update a specific chunk or message within a memory */
249
+ updateChunk(chunkId: string, content: string, metadata?: Record<string, any>): Promise<boolean>;
250
+ /**
251
+ * Update memory-level properties including name, metadata, and collection associations.
252
+ *
253
+ * This method allows updating properties of an entire memory (document or conversation)
254
+ * without modifying its content. For updating individual chunks or messages within a memory,
255
+ * use updateChunk(). For updating content, use storeMemory() to append.
256
+ *
257
+ * @param options - Update configuration
258
+ * @param options.memoryId - The ID of the memory to update
259
+ * @param options.name - New name for the memory (useful for conversations and documents)
260
+ * @param options.metadata - Metadata to set. By default, replaces existing metadata.
261
+ * Set mergeMetadata=true to merge with existing metadata instead.
262
+ * @param options.collectionIds - New collection associations. Must specify at least one valid collection.
263
+ * @param options.mergeMetadata - If true, merges provided metadata with existing metadata.
264
+ * If false (default), replaces existing metadata entirely.
265
+ *
266
+ * @returns Promise resolving to true if successful
267
+ *
268
+ * @throws NebulaNotFoundException if memory_id doesn't exist
269
+ * @throws NebulaValidationException if validation fails (e.g., no fields provided)
270
+ * @throws NebulaAuthenticationException if user doesn't have permission to update this memory
271
+ */
272
+ updateMemory(options: {
273
+ memoryId: string;
274
+ name?: string;
275
+ metadata?: Record<string, any>;
276
+ collectionIds?: string[];
277
+ mergeMetadata?: boolean;
278
+ }): Promise<boolean>;
190
279
  /** Delete a conversation and all its messages */
191
280
  deleteConversation(conversationId: string): Promise<boolean>;
192
- /** Get all memories from specific clusters */
281
+ /**
282
+ * Get all memories from specific collections with optional metadata filtering
283
+ *
284
+ * @param options - Configuration for listing memories
285
+ * @param options.collection_ids - One or more collection IDs to retrieve memories from
286
+ * @param options.limit - Maximum number of memories to return (default: 100)
287
+ * @param options.offset - Number of memories to skip for pagination (default: 0)
288
+ * @param options.metadata_filters - Optional metadata filters using MongoDB-like operators.
289
+ * Supported operators: $eq, $ne, $in, $nin, $exists, $and, $or
290
+ *
291
+ * @returns Promise resolving to array of MemoryResponse objects
292
+ *
293
+ * @example
294
+ * // Get all playground memories excluding conversations
295
+ * const memories = await client.listMemories({
296
+ * collection_ids: ['collection-id'],
297
+ * metadata_filters: {
298
+ * 'metadata.content_type': { $ne: 'conversation' }
299
+ * }
300
+ * });
301
+ *
302
+ * @example
303
+ * // Complex filter with multiple conditions
304
+ * const memories = await client.listMemories({
305
+ * collection_ids: ['collection-id'],
306
+ * metadata_filters: {
307
+ * $and: [
308
+ * { 'metadata.playground': { $eq: true } },
309
+ * { 'metadata.session_id': { $exists: true } }
310
+ * ]
311
+ * }
312
+ * });
313
+ */
193
314
  listMemories(options: {
194
- cluster_ids: string | string[];
315
+ collection_ids: string | string[];
195
316
  limit?: number;
196
317
  offset?: number;
318
+ metadata_filters?: Record<string, any>;
197
319
  }): Promise<MemoryResponse[]>;
198
- /** Get a specific memory by ID */
320
+ /** Get a specific memory by engram ID */
199
321
  getMemory(memoryId: string): Promise<MemoryResponse>;
200
322
  /**
201
- * Search within specific clusters with optional metadata filtering.
323
+ * Search within specific collections with optional metadata filtering.
202
324
  *
203
325
  * @param options - Search configuration
204
326
  * @param options.query - Search query string
205
- * @param options.cluster_ids - One or more cluster IDs to search within
327
+ * @param options.collection_ids - One or more collection IDs to search within
206
328
  * @param options.limit - Maximum number of results to return (default: 10)
207
329
  * @param options.retrieval_type - Retrieval strategy (default: ADVANCED)
208
330
  * @param options.filters - Optional filters to apply to the search. Supports comprehensive metadata filtering
@@ -215,7 +337,7 @@ declare class NebulaClient {
215
337
  * // Basic equality filter
216
338
  * await client.search({
217
339
  * query: "machine learning",
218
- * cluster_ids: ["research-cluster"],
340
+ * collection_ids: ["research-collection"],
219
341
  * filters: {
220
342
  * "metadata.category": { $eq: "research" },
221
343
  * "metadata.verified": true // Shorthand for $eq
@@ -226,7 +348,7 @@ declare class NebulaClient {
226
348
  * // Numeric comparisons
227
349
  * await client.search({
228
350
  * query: "high priority",
229
- * cluster_ids: ["tasks"],
351
+ * collection_ids: ["tasks"],
230
352
  * filters: {
231
353
  * "metadata.priority": { $gte: 8 },
232
354
  * "metadata.score": { $lt: 100 }
@@ -237,7 +359,7 @@ declare class NebulaClient {
237
359
  * // String matching
238
360
  * await client.search({
239
361
  * query: "employees",
240
- * cluster_ids: ["team"],
362
+ * collection_ids: ["team"],
241
363
  * filters: {
242
364
  * "metadata.email": { $ilike: "%@company.com" } // Case-insensitive
243
365
  * }
@@ -247,7 +369,7 @@ declare class NebulaClient {
247
369
  * // Array operations
248
370
  * await client.search({
249
371
  * query: "developers",
250
- * cluster_ids: ["team"],
372
+ * collection_ids: ["team"],
251
373
  * filters: {
252
374
  * "metadata.skills": { $overlap: ["python", "typescript"] } // Has any
253
375
  * }
@@ -257,7 +379,7 @@ declare class NebulaClient {
257
379
  * // Nested paths
258
380
  * await client.search({
259
381
  * query: "users",
260
- * cluster_ids: ["profiles"],
382
+ * collection_ids: ["profiles"],
261
383
  * filters: {
262
384
  * "metadata.user.preferences.theme": { $eq: "dark" }
263
385
  * }
@@ -267,7 +389,7 @@ declare class NebulaClient {
267
389
  * // Complex logical combinations
268
390
  * await client.search({
269
391
  * query: "candidates",
270
- * cluster_ids: ["hiring"],
392
+ * collection_ids: ["hiring"],
271
393
  * filters: {
272
394
  * $and: [
273
395
  * { "metadata.verified": true },
@@ -295,7 +417,7 @@ declare class NebulaClient {
295
417
  */
296
418
  search(options: {
297
419
  query: string;
298
- cluster_ids: string | string[];
420
+ collection_ids: string | string[];
299
421
  limit?: number;
300
422
  filters?: Record<string, any>;
301
423
  search_mode?: 'fast' | 'super';
@@ -304,13 +426,13 @@ declare class NebulaClient {
304
426
  /**
305
427
  * Legacy wrapper: store a two-message conversation turn as a document
306
428
  */
307
- storeConversation(userMessage: string, assistantMessage: string, clusterId: string, sessionId: string): Promise<MemoryResponse>;
429
+ storeConversation(userMessage: string, assistantMessage: string, collectionId: string, sessionId: string): Promise<MemoryResponse>;
308
430
  /**
309
431
  * Legacy wrapper: search conversations optionally scoped by session
310
432
  */
311
- searchConversations(query: string, clusterId: string, sessionId?: string, includeAllSessions?: boolean): Promise<SearchResult[]>;
433
+ searchConversations(query: string, collectionId: string, sessionId?: string, includeAllSessions?: boolean): Promise<SearchResult[]>;
312
434
  healthCheck(): Promise<Record<string, any>>;
313
- private _clusterFromDict;
435
+ private _collectionFromDict;
314
436
  private _memoryResponseFromDict;
315
437
  private _searchResultFromDict;
316
438
  private _searchResultFromGraphDict;
@@ -318,4 +440,4 @@ declare class NebulaClient {
318
440
  private _formDataFromObject;
319
441
  }
320
442
 
321
- export { type AgentResponse, type Cluster, type GraphCommunityResult, type GraphEntityResult, type GraphRelationshipResult, GraphSearchResultType, type Memory, type MemoryResponse, NebulaAuthenticationException, NebulaClient, type NebulaClientConfig, NebulaClientException, NebulaClusterNotFoundException, NebulaException, NebulaRateLimitException, NebulaValidationException, type SearchOptions, type SearchResult };
443
+ export { type AgentResponse, type Chunk, type Collection, type GraphCommunityResult, type GraphEntityResult, type GraphRelationshipResult, GraphSearchResultType, type Memory, type MemoryResponse, NebulaAuthenticationException, NebulaClient, type NebulaClientConfig, NebulaClientException, NebulaCollectionNotFoundException, NebulaException, NebulaNotFoundException, NebulaRateLimitException, NebulaValidationException, type SearchOptions, type SearchResult };