@nebula-ai/sdk 0.0.24 → 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.mts CHANGED
@@ -1,30 +1,37 @@
1
- declare enum RetrievalType {
2
- BASIC = "basic",
3
- ADVANCED = "advanced",
4
- CUSTOM = "custom"
5
- }
6
1
  declare enum GraphSearchResultType {
7
2
  ENTITY = "entity",
8
3
  RELATIONSHIP = "relationship",
9
4
  COMMUNITY = "community"
10
5
  }
6
+ interface Chunk {
7
+ id: string;
8
+ content: string;
9
+ metadata: Record<string, any>;
10
+ role?: string;
11
+ }
11
12
  interface MemoryResponse {
12
13
  id: string;
13
14
  content?: string;
14
- chunks?: string[];
15
+ chunks?: Chunk[];
15
16
  metadata: Record<string, any>;
16
- cluster_ids: string[];
17
+ collection_ids: string[];
17
18
  created_at?: string;
18
19
  updated_at?: string;
19
20
  }
20
21
  interface Memory {
21
- cluster_id: string;
22
- 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
+ }>;
23
29
  role?: string;
24
- parent_id?: string;
30
+ memory_id?: string;
25
31
  metadata: Record<string, any>;
32
+ authority?: number;
26
33
  }
27
- interface Cluster {
34
+ interface Collection {
28
35
  id: string;
29
36
  name: string;
30
37
  description?: string;
@@ -39,6 +46,11 @@ interface SearchResult {
39
46
  score: number;
40
47
  metadata: Record<string, any>;
41
48
  source?: string;
49
+ timestamp?: string;
50
+ display_name?: string;
51
+ source_role?: string;
52
+ memory_id?: string;
53
+ owner_id?: string;
42
54
  content?: string;
43
55
  graph_result_type?: GraphSearchResultType;
44
56
  graph_entity?: GraphEntityResult;
@@ -78,7 +90,7 @@ interface AgentResponse {
78
90
  interface SearchOptions {
79
91
  limit: number;
80
92
  filters?: Record<string, any>;
81
- retrieval_type: RetrievalType;
93
+ search_mode?: 'fast' | 'super';
82
94
  }
83
95
  interface NebulaClientConfig {
84
96
  apiKey: string;
@@ -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,55 +143,296 @@ 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(name: string, description?: string, metadata?: Record<string, any>): Promise<Cluster>;
133
- /** Get a specific cluster by ID */
134
- getCluster(clusterId: string): Promise<Cluster>;
135
- /** Get a specific cluster by name */
136
- getClusterByName(name: string): Promise<Cluster>;
137
- /** Get all clusters */
138
- listClusters(limit?: number, offset?: number): Promise<Cluster[]>;
139
- /** List conversations for the authenticated user */
140
- listConversations(limit?: number, offset?: number, cluster_ids?: string[]): Promise<any[]>;
146
+ /** Create a new collection */
147
+ createCollection(options: {
148
+ name: string;
149
+ description?: string;
150
+ metadata?: Record<string, any>;
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?: {
158
+ limit?: number;
159
+ offset?: number;
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
+ */
190
+ listConversations(options?: {
191
+ limit?: number;
192
+ offset?: number;
193
+ collection_ids?: string[];
194
+ metadata_filters?: Record<string, any>;
195
+ }): Promise<any[]>;
141
196
  /** Get conversation messages directly from the conversations API */
142
197
  getConversationMessages(conversationId: string): Promise<MemoryResponse[]>;
143
198
  getConversationMessages(conversationIds: string[]): Promise<Record<string, MemoryResponse[]>>;
144
199
  /** Helper method to transform conversation messages to MemoryResponse format */
145
200
  private _transformConversationMessages;
146
- /** Update a cluster */
147
- updateCluster(clusterId: string, name?: string, description?: string, metadata?: Record<string, any>): Promise<Cluster>;
148
- /** Delete a cluster */
149
- deleteCluster(clusterId: string): Promise<boolean>;
201
+ /** Update a collection */
202
+ updateCollection(options: {
203
+ collectionId: string;
204
+ name?: string;
205
+ description?: string;
206
+ metadata?: Record<string, any>;
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>;
150
214
  /**
151
- * 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
152
220
  */
153
- store(content: string, clusterId: string, metadata?: Record<string, any>): Promise<MemoryResponse>;
154
- /** Store a single memory */
155
- storeMemory(memory: Memory | Record<string, any>): Promise<string>;
156
- /** 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 */
157
229
  storeMemories(memories: Memory[]): Promise<string[]>;
158
- /** Delete a specific memory */
159
- delete(memoryId: string): Promise<boolean>;
230
+ /** Delete one or more memories */
231
+ delete(memoryIds: string | string[]): Promise<boolean | {
232
+ message: string;
233
+ results: {
234
+ successful: string[];
235
+ failed: Array<{
236
+ id: string;
237
+ error: string;
238
+ }>;
239
+ summary: {
240
+ total: number;
241
+ succeeded: number;
242
+ failed: number;
243
+ };
244
+ };
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>;
160
279
  /** Delete a conversation and all its messages */
161
280
  deleteConversation(conversationId: string): Promise<boolean>;
162
- /** Get all memories from specific clusters */
163
- listMemories(clusterIds: string | string[], limit?: number, offset?: number): Promise<MemoryResponse[]>;
164
- /** Get a specific memory by ID */
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
+ */
314
+ listMemories(options: {
315
+ collection_ids: string | string[];
316
+ limit?: number;
317
+ offset?: number;
318
+ metadata_filters?: Record<string, any>;
319
+ }): Promise<MemoryResponse[]>;
320
+ /** Get a specific memory by engram ID */
165
321
  getMemory(memoryId: string): Promise<MemoryResponse>;
166
- /** Search within specific clusters */
167
- search(query: string, clusters: string | string[], limitOrOptions?: number | {
322
+ /**
323
+ * Search within specific collections with optional metadata filtering.
324
+ *
325
+ * @param options - Search configuration
326
+ * @param options.query - Search query string
327
+ * @param options.collection_ids - One or more collection IDs to search within
328
+ * @param options.limit - Maximum number of results to return (default: 10)
329
+ * @param options.retrieval_type - Retrieval strategy (default: ADVANCED)
330
+ * @param options.filters - Optional filters to apply to the search. Supports comprehensive metadata filtering
331
+ * with MongoDB-like operators for both vector/chunk search and graph search.
332
+ * @param options.searchSettings - Optional search configuration
333
+ *
334
+ * @returns Promise resolving to array of SearchResult objects containing both vector/chunk and graph search results
335
+ *
336
+ * @example
337
+ * // Basic equality filter
338
+ * await client.search({
339
+ * query: "machine learning",
340
+ * collection_ids: ["research-collection"],
341
+ * filters: {
342
+ * "metadata.category": { $eq: "research" },
343
+ * "metadata.verified": true // Shorthand for $eq
344
+ * }
345
+ * });
346
+ *
347
+ * @example
348
+ * // Numeric comparisons
349
+ * await client.search({
350
+ * query: "high priority",
351
+ * collection_ids: ["tasks"],
352
+ * filters: {
353
+ * "metadata.priority": { $gte: 8 },
354
+ * "metadata.score": { $lt: 100 }
355
+ * }
356
+ * });
357
+ *
358
+ * @example
359
+ * // String matching
360
+ * await client.search({
361
+ * query: "employees",
362
+ * collection_ids: ["team"],
363
+ * filters: {
364
+ * "metadata.email": { $ilike: "%@company.com" } // Case-insensitive
365
+ * }
366
+ * });
367
+ *
368
+ * @example
369
+ * // Array operations
370
+ * await client.search({
371
+ * query: "developers",
372
+ * collection_ids: ["team"],
373
+ * filters: {
374
+ * "metadata.skills": { $overlap: ["python", "typescript"] } // Has any
375
+ * }
376
+ * });
377
+ *
378
+ * @example
379
+ * // Nested paths
380
+ * await client.search({
381
+ * query: "users",
382
+ * collection_ids: ["profiles"],
383
+ * filters: {
384
+ * "metadata.user.preferences.theme": { $eq: "dark" }
385
+ * }
386
+ * });
387
+ *
388
+ * @example
389
+ * // Complex logical combinations
390
+ * await client.search({
391
+ * query: "candidates",
392
+ * collection_ids: ["hiring"],
393
+ * filters: {
394
+ * $and: [
395
+ * { "metadata.verified": true },
396
+ * { "metadata.level": { $gte: 5 } },
397
+ * {
398
+ * $or: [
399
+ * { "metadata.skills": { $overlap: ["python", "go"] } },
400
+ * { "metadata.years_experience": { $gte: 8 } }
401
+ * ]
402
+ * }
403
+ * ]
404
+ * }
405
+ * });
406
+ *
407
+ * @remarks
408
+ * Supported Operators:
409
+ * - Comparison: $eq, $ne, $lt, $lte, $gt, $gte
410
+ * - String: $like (case-sensitive), $ilike (case-insensitive)
411
+ * - Array: $in, $nin, $overlap, $contains
412
+ * - JSONB: $json_contains
413
+ * - Logical: $and, $or
414
+ *
415
+ * For comprehensive filtering documentation, see the Metadata Filtering Guide:
416
+ * https://docs.nebulacloud.app/guides/metadata-filtering
417
+ */
418
+ search(options: {
419
+ query: string;
420
+ collection_ids: string | string[];
168
421
  limit?: number;
169
- }, retrievalType?: RetrievalType | string, filters?: Record<string, any>, searchSettings?: Record<string, any>): Promise<SearchResult[]>;
422
+ filters?: Record<string, any>;
423
+ search_mode?: 'fast' | 'super';
424
+ searchSettings?: Record<string, any>;
425
+ }): Promise<SearchResult[]>;
170
426
  /**
171
427
  * Legacy wrapper: store a two-message conversation turn as a document
172
428
  */
173
- storeConversation(userMessage: string, assistantMessage: string, clusterId: string, sessionId: string): Promise<MemoryResponse>;
429
+ storeConversation(userMessage: string, assistantMessage: string, collectionId: string, sessionId: string): Promise<MemoryResponse>;
174
430
  /**
175
431
  * Legacy wrapper: search conversations optionally scoped by session
176
432
  */
177
- searchConversations(query: string, clusterId: string, sessionId?: string, includeAllSessions?: boolean): Promise<SearchResult[]>;
433
+ searchConversations(query: string, collectionId: string, sessionId?: string, includeAllSessions?: boolean): Promise<SearchResult[]>;
178
434
  healthCheck(): Promise<Record<string, any>>;
179
- private _clusterFromDict;
435
+ private _collectionFromDict;
180
436
  private _memoryResponseFromDict;
181
437
  private _searchResultFromDict;
182
438
  private _searchResultFromGraphDict;
@@ -184,4 +440,4 @@ declare class NebulaClient {
184
440
  private _formDataFromObject;
185
441
  }
186
442
 
187
- 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, RetrievalType, 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 };