@cilow/sdk 0.2.1 → 0.3.0

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.
Files changed (84) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +109 -492
  3. package/dist/abstain.d.ts +43 -0
  4. package/dist/abstain.d.ts.map +1 -0
  5. package/dist/abstain.js +42 -0
  6. package/dist/abstain.js.map +1 -0
  7. package/dist/adapters/anthropic.d.ts +57 -0
  8. package/dist/adapters/anthropic.d.ts.map +1 -0
  9. package/dist/adapters/anthropic.js +57 -0
  10. package/dist/adapters/anthropic.js.map +1 -0
  11. package/dist/adapters/index.d.ts +16 -0
  12. package/dist/adapters/index.d.ts.map +1 -0
  13. package/dist/adapters/index.js +16 -0
  14. package/dist/adapters/index.js.map +1 -0
  15. package/dist/adapters/langchain.d.ts +62 -0
  16. package/dist/adapters/langchain.d.ts.map +1 -0
  17. package/dist/adapters/langchain.js +68 -0
  18. package/dist/adapters/langchain.js.map +1 -0
  19. package/dist/adapters/memory.d.ts +105 -0
  20. package/dist/adapters/memory.d.ts.map +1 -0
  21. package/dist/adapters/memory.js +105 -0
  22. package/dist/adapters/memory.js.map +1 -0
  23. package/dist/adapters/openai.d.ts +56 -0
  24. package/dist/adapters/openai.d.ts.map +1 -0
  25. package/dist/adapters/openai.js +64 -0
  26. package/dist/adapters/openai.js.map +1 -0
  27. package/dist/adapters/remaining.d.ts +52 -0
  28. package/dist/adapters/remaining.d.ts.map +1 -0
  29. package/dist/adapters/remaining.js +67 -0
  30. package/dist/adapters/remaining.js.map +1 -0
  31. package/dist/client.d.ts +512 -173
  32. package/dist/client.d.ts.map +1 -0
  33. package/dist/client.js +648 -504
  34. package/dist/client.js.map +1 -1
  35. package/dist/errors.d.ts +25 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/errors.js +28 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/hash.d.ts +13 -0
  40. package/dist/hash.d.ts.map +1 -0
  41. package/dist/hash.js +92 -0
  42. package/dist/hash.js.map +1 -0
  43. package/dist/index.d.ts +18 -109
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +16 -876
  46. package/dist/index.js.map +1 -1
  47. package/dist/types.d.ts +809 -486
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +18 -17
  50. package/dist/types.js.map +1 -1
  51. package/package.json +30 -103
  52. package/dist/client.d.mts +0 -224
  53. package/dist/client.mjs +0 -505
  54. package/dist/client.mjs.map +0 -1
  55. package/dist/index.d.mts +0 -111
  56. package/dist/index.mjs +0 -863
  57. package/dist/index.mjs.map +0 -1
  58. package/dist/providers/langchain.js +0 -821
  59. package/dist/providers/langchain.js.map +0 -1
  60. package/dist/providers/langchain.mjs +0 -816
  61. package/dist/providers/langchain.mjs.map +0 -1
  62. package/dist/providers/openai.js +0 -737
  63. package/dist/providers/openai.js.map +0 -1
  64. package/dist/providers/openai.mjs +0 -732
  65. package/dist/providers/openai.mjs.map +0 -1
  66. package/dist/providers/vercel.js +0 -866
  67. package/dist/providers/vercel.js.map +0 -1
  68. package/dist/providers/vercel.mjs +0 -860
  69. package/dist/providers/vercel.mjs.map +0 -1
  70. package/dist/react/hooks.d.mts +0 -327
  71. package/dist/react/hooks.d.ts +0 -327
  72. package/dist/react/hooks.js +0 -1183
  73. package/dist/react/hooks.js.map +0 -1
  74. package/dist/react/hooks.mjs +0 -1172
  75. package/dist/react/hooks.mjs.map +0 -1
  76. package/dist/types.d.mts +0 -494
  77. package/dist/types.mjs +0 -14
  78. package/dist/types.mjs.map +0 -1
  79. package/dist/websocket.d.mts +0 -160
  80. package/dist/websocket.d.ts +0 -160
  81. package/dist/websocket.js +0 -342
  82. package/dist/websocket.js.map +0 -1
  83. package/dist/websocket.mjs +0 -339
  84. package/dist/websocket.mjs.map +0 -1
package/dist/types.d.mts DELETED
@@ -1,494 +0,0 @@
1
- /**
2
- * Cilow SDK TypeScript Type Definitions
3
- *
4
- * Comprehensive type definitions for the Cilow memory system.
5
- */
6
- /**
7
- * Memory tier classification based on access frequency and recency
8
- */
9
- type MemoryTier = 'hot' | 'warm' | 'cold';
10
- /**
11
- * Memory status for lifecycle management
12
- */
13
- type MemoryStatus = 'active' | 'archived' | 'deleted';
14
- /**
15
- * Core memory entity representing a stored piece of information
16
- */
17
- interface Memory {
18
- /** Unique identifier for the memory */
19
- id: string;
20
- /** The content of the memory */
21
- content: string;
22
- /** Tags for categorization and filtering */
23
- tags: string[];
24
- /** User ID associated with this memory */
25
- userId?: string;
26
- /** Session ID for grouping related memories */
27
- sessionId?: string;
28
- /** Current tier classification */
29
- tier: MemoryTier;
30
- /** Memory status */
31
- status: MemoryStatus;
32
- /** Access count for prioritization */
33
- accessCount: number;
34
- /** Token count for the content */
35
- tokenCount: number;
36
- /** Embedding vector (if available) */
37
- embedding?: number[];
38
- /** Additional metadata */
39
- metadata: Record<string, unknown>;
40
- /** ISO timestamp of creation */
41
- createdAt: string;
42
- /** ISO timestamp of last update */
43
- updatedAt: string;
44
- /** ISO timestamp of last access */
45
- lastAccessedAt: string;
46
- }
47
- /**
48
- * Minimal memory representation for list operations
49
- */
50
- interface MemorySummary {
51
- id: string;
52
- content: string;
53
- tags: string[];
54
- tier: MemoryTier;
55
- createdAt: string;
56
- }
57
- /**
58
- * Options for creating a new memory
59
- */
60
- interface CreateMemoryOptions {
61
- /** Tags to apply to the memory */
62
- tags?: string[];
63
- /** User ID to associate */
64
- userId?: string;
65
- /** Session ID for grouping */
66
- sessionId?: string;
67
- /** Additional metadata */
68
- metadata?: Record<string, unknown>;
69
- /** Force a specific tier */
70
- tier?: MemoryTier;
71
- }
72
- /**
73
- * Options for updating a memory
74
- */
75
- interface UpdateMemoryOptions {
76
- /** New content */
77
- content?: string;
78
- /** New tags (replaces existing) */
79
- tags?: string[];
80
- /** Updated metadata (merged with existing) */
81
- metadata?: Record<string, unknown>;
82
- /** Force tier change */
83
- tier?: MemoryTier;
84
- }
85
- /**
86
- * Search result containing a memory and its relevance score
87
- */
88
- interface SearchResult {
89
- /** The matching memory */
90
- memory: Memory;
91
- /** Relevance score (0.0 - 1.0) */
92
- score: number;
93
- /** Matched terms or phrases */
94
- matchedTerms?: string[];
95
- /** Highlighted content snippets */
96
- highlights?: string[];
97
- }
98
- /**
99
- * Search query parameters
100
- */
101
- interface SearchQuery {
102
- /** The search text */
103
- text: string;
104
- /** Maximum number of results */
105
- limit?: number;
106
- /** Minimum relevance score threshold (0.0 - 1.0) */
107
- minRelevance?: number;
108
- /** Filter by tags (AND logic) */
109
- tags?: string[];
110
- /** Filter by user ID */
111
- userId?: string;
112
- /** Filter by session ID */
113
- sessionId?: string;
114
- /** Filter by tier */
115
- tier?: MemoryTier;
116
- /** Filter by date range - start */
117
- createdAfter?: string;
118
- /** Filter by date range - end */
119
- createdBefore?: string;
120
- /** Include archived memories */
121
- includeArchived?: boolean;
122
- /** Search mode */
123
- mode?: 'semantic' | 'keyword' | 'hybrid';
124
- }
125
- /**
126
- * Advanced search options for complex queries
127
- */
128
- interface AdvancedSearchOptions extends SearchQuery {
129
- /** Boost recent memories */
130
- recencyBoost?: number;
131
- /** Boost frequently accessed memories */
132
- frequencyBoost?: number;
133
- /** Required tags (must have all) */
134
- requiredTags?: string[];
135
- /** Excluded tags (must not have any) */
136
- excludedTags?: string[];
137
- /** Metadata filters */
138
- metadataFilters?: Record<string, unknown>;
139
- /** Custom reranking function name */
140
- reranker?: string;
141
- }
142
- /**
143
- * Node in the memory knowledge graph
144
- */
145
- interface GraphNode {
146
- /** Unique node identifier */
147
- id: string;
148
- /** Node type/label */
149
- type: string;
150
- /** Display name */
151
- name: string;
152
- /** Node properties */
153
- properties: Record<string, unknown>;
154
- /** Associated memory IDs */
155
- memoryIds: string[];
156
- /** Creation timestamp */
157
- createdAt: string;
158
- /** Last update timestamp */
159
- updatedAt: string;
160
- }
161
- /**
162
- * Edge connecting two nodes in the graph
163
- */
164
- interface GraphEdge {
165
- /** Unique edge identifier */
166
- id: string;
167
- /** Source node ID */
168
- sourceId: string;
169
- /** Target node ID */
170
- targetId: string;
171
- /** Relationship type */
172
- type: string;
173
- /** Edge weight/strength */
174
- weight: number;
175
- /** Edge properties */
176
- properties: Record<string, unknown>;
177
- /** Creation timestamp */
178
- createdAt: string;
179
- }
180
- /**
181
- * Subgraph result for graph traversal queries
182
- */
183
- interface GraphSubgraph {
184
- /** Nodes in the subgraph */
185
- nodes: GraphNode[];
186
- /** Edges in the subgraph */
187
- edges: GraphEdge[];
188
- /** Central node ID (if applicable) */
189
- centerId?: string;
190
- }
191
- /**
192
- * Options for graph traversal
193
- */
194
- interface GraphTraversalOptions {
195
- /** Starting node ID */
196
- startNodeId: string;
197
- /** Maximum traversal depth */
198
- maxDepth?: number;
199
- /** Filter by relationship types */
200
- relationshipTypes?: string[];
201
- /** Maximum nodes to return */
202
- limit?: number;
203
- /** Traversal direction */
204
- direction?: 'outbound' | 'inbound' | 'both';
205
- }
206
- /**
207
- * Memory system statistics
208
- */
209
- interface MemoryStats {
210
- /** Total number of memories */
211
- totalMemories: number;
212
- /** Number of hot tier memories */
213
- hotMemories: number;
214
- /** Number of warm tier memories */
215
- warmMemories: number;
216
- /** Number of cold tier memories */
217
- coldMemories: number;
218
- /** Total token count across all memories */
219
- totalTokens: number;
220
- /** Average tokens per memory */
221
- averageTokensPerMemory: number;
222
- /** Number of unique users */
223
- uniqueUsers: number;
224
- /** Number of unique sessions */
225
- uniqueSessions: number;
226
- /** Total number of tags */
227
- totalTags: number;
228
- /** Storage size in bytes */
229
- storageSizeBytes: number;
230
- /** Stats generation timestamp */
231
- generatedAt: string;
232
- }
233
- /**
234
- * Tag with usage count
235
- */
236
- interface TagCount {
237
- /** Tag name */
238
- tag: string;
239
- /** Usage count */
240
- count: number;
241
- }
242
- /**
243
- * User activity statistics
244
- */
245
- interface UserStats {
246
- /** User ID */
247
- userId: string;
248
- /** Number of memories */
249
- memoryCount: number;
250
- /** Total tokens used */
251
- totalTokens: number;
252
- /** Number of sessions */
253
- sessionCount: number;
254
- /** First activity timestamp */
255
- firstActivityAt: string;
256
- /** Last activity timestamp */
257
- lastActivityAt: string;
258
- }
259
- /**
260
- * Base event type
261
- */
262
- interface BaseEvent {
263
- /** Event type identifier */
264
- type: string;
265
- /** Event timestamp */
266
- timestamp: string;
267
- /** Correlation ID for tracking */
268
- correlationId?: string;
269
- }
270
- /**
271
- * Memory created event
272
- */
273
- interface MemoryCreatedEvent extends BaseEvent {
274
- type: 'memory.created';
275
- /** The created memory */
276
- memory: Memory;
277
- }
278
- /**
279
- * Memory updated event
280
- */
281
- interface MemoryUpdatedEvent extends BaseEvent {
282
- type: 'memory.updated';
283
- /** The updated memory */
284
- memory: Memory;
285
- /** Changed fields */
286
- changedFields: string[];
287
- }
288
- /**
289
- * Memory deleted event
290
- */
291
- interface MemoryDeletedEvent extends BaseEvent {
292
- type: 'memory.deleted';
293
- /** Deleted memory ID */
294
- memoryId: string;
295
- }
296
- /**
297
- * Memory tier changed event
298
- */
299
- interface MemoryTierChangedEvent extends BaseEvent {
300
- type: 'memory.tier_changed';
301
- /** Memory ID */
302
- memoryId: string;
303
- /** Previous tier */
304
- previousTier: MemoryTier;
305
- /** New tier */
306
- newTier: MemoryTier;
307
- }
308
- /**
309
- * Graph node created event
310
- */
311
- interface GraphNodeCreatedEvent extends BaseEvent {
312
- type: 'graph.node_created';
313
- /** The created node */
314
- node: GraphNode;
315
- }
316
- /**
317
- * Graph edge created event
318
- */
319
- interface GraphEdgeCreatedEvent extends BaseEvent {
320
- type: 'graph.edge_created';
321
- /** The created edge */
322
- edge: GraphEdge;
323
- }
324
- /**
325
- * Connection status event
326
- */
327
- interface ConnectionStatusEvent extends BaseEvent {
328
- type: 'connection.status';
329
- /** Connection status */
330
- status: 'connected' | 'disconnected' | 'reconnecting';
331
- /** Reason for status change */
332
- reason?: string;
333
- }
334
- /**
335
- * Union type of all events
336
- */
337
- type CilowEvent = MemoryCreatedEvent | MemoryUpdatedEvent | MemoryDeletedEvent | MemoryTierChangedEvent | GraphNodeCreatedEvent | GraphEdgeCreatedEvent | ConnectionStatusEvent;
338
- /**
339
- * Pagination parameters
340
- */
341
- interface PaginationParams {
342
- /** Number of items per page */
343
- limit?: number;
344
- /** Offset for pagination */
345
- offset?: number;
346
- /** Cursor for cursor-based pagination */
347
- cursor?: string;
348
- }
349
- /**
350
- * Paginated response wrapper
351
- */
352
- interface PaginatedResponse<T> {
353
- /** Items in this page */
354
- items: T[];
355
- /** Total count of items */
356
- total: number;
357
- /** Current offset */
358
- offset: number;
359
- /** Items per page */
360
- limit: number;
361
- /** Cursor for next page */
362
- nextCursor?: string;
363
- /** Whether there are more items */
364
- hasMore: boolean;
365
- }
366
- /**
367
- * API error response
368
- */
369
- interface ApiError {
370
- /** Error code */
371
- code: string;
372
- /** Human-readable error message */
373
- message: string;
374
- /** Additional error details */
375
- details?: Record<string, unknown>;
376
- /** Request ID for debugging */
377
- requestId?: string;
378
- }
379
- /**
380
- * Health check response
381
- */
382
- interface HealthCheck {
383
- /** Service status */
384
- status: 'healthy' | 'degraded' | 'unhealthy';
385
- /** Service version */
386
- version: string;
387
- /** Uptime in seconds */
388
- uptimeSeconds: number;
389
- /** Component statuses */
390
- components: {
391
- name: string;
392
- status: 'healthy' | 'degraded' | 'unhealthy';
393
- latencyMs?: number;
394
- }[];
395
- }
396
- /**
397
- * Client configuration options
398
- */
399
- interface CilowConfig {
400
- /** Base URL of the Cilow API */
401
- apiUrl: string;
402
- /** API key for authentication */
403
- apiKey: string;
404
- /** Request timeout in milliseconds */
405
- timeout?: number;
406
- /** Number of retry attempts for failed requests */
407
- retries?: number;
408
- /** Custom headers to include in requests */
409
- headers?: Record<string, string>;
410
- /** Enable debug logging */
411
- debug?: boolean;
412
- }
413
- /**
414
- * WebSocket configuration options
415
- */
416
- interface WebSocketConfig {
417
- /** WebSocket URL (defaults to apiUrl with ws:// protocol) */
418
- wsUrl?: string;
419
- /** Reconnection attempts */
420
- reconnectAttempts?: number;
421
- /** Reconnection delay in milliseconds */
422
- reconnectDelay?: number;
423
- /** Heartbeat interval in milliseconds */
424
- heartbeatInterval?: number;
425
- /** Message queue size for offline buffering */
426
- messageQueueSize?: number;
427
- }
428
- /**
429
- * Combined configuration for full client
430
- */
431
- interface FullCilowConfig extends CilowConfig, WebSocketConfig {
432
- /** Default user ID for all operations */
433
- defaultUserId?: string;
434
- /** Default session ID */
435
- defaultSessionId?: string;
436
- /** Default tags to apply */
437
- defaultTags?: string[];
438
- }
439
- /**
440
- * Context result for AI integrations
441
- */
442
- interface ContextResult {
443
- /** Formatted context string */
444
- context: string;
445
- /** Number of memories used */
446
- memoriesUsed: number;
447
- /** Estimated token count */
448
- estimatedTokens: number;
449
- /** Memory IDs included */
450
- memoryIds: string[];
451
- /** Search scores */
452
- scores: number[];
453
- }
454
- /**
455
- * Conversation turn for storing dialogues
456
- */
457
- interface ConversationTurn {
458
- /** User's message */
459
- userMessage: string;
460
- /** Assistant's response */
461
- assistantResponse: string;
462
- /** Session ID */
463
- sessionId?: string;
464
- /** Additional metadata */
465
- metadata?: Record<string, unknown>;
466
- }
467
- /**
468
- * Batch operation result
469
- */
470
- interface BatchResult<T> {
471
- /** Successful operations */
472
- succeeded: T[];
473
- /** Failed operations with errors */
474
- failed: {
475
- item: T;
476
- error: string;
477
- }[];
478
- /** Total operations attempted */
479
- total: number;
480
- }
481
- /**
482
- * Check if an event is a memory event
483
- */
484
- declare function isMemoryEvent(event: CilowEvent): event is MemoryCreatedEvent | MemoryUpdatedEvent | MemoryDeletedEvent;
485
- /**
486
- * Check if an event is a graph event
487
- */
488
- declare function isGraphEvent(event: CilowEvent): event is GraphNodeCreatedEvent | GraphEdgeCreatedEvent;
489
- /**
490
- * Check if an object is an API error
491
- */
492
- declare function isApiError(obj: unknown): obj is ApiError;
493
-
494
- export { type AdvancedSearchOptions, type ApiError, type BaseEvent, type BatchResult, type CilowConfig, type CilowEvent, type ConnectionStatusEvent, type ContextResult, type ConversationTurn, type CreateMemoryOptions, type FullCilowConfig, type GraphEdge, type GraphEdgeCreatedEvent, type GraphNode, type GraphNodeCreatedEvent, type GraphSubgraph, type GraphTraversalOptions, type HealthCheck, type Memory, type MemoryCreatedEvent, type MemoryDeletedEvent, type MemoryStats, type MemoryStatus, type MemorySummary, type MemoryTier, type MemoryTierChangedEvent, type MemoryUpdatedEvent, type PaginatedResponse, type PaginationParams, type SearchQuery, type SearchResult, type TagCount, type UpdateMemoryOptions, type UserStats, type WebSocketConfig, isApiError, isGraphEvent, isMemoryEvent };
package/dist/types.mjs DELETED
@@ -1,14 +0,0 @@
1
- // src/types.ts
2
- function isMemoryEvent(event) {
3
- return event.type.startsWith("memory.");
4
- }
5
- function isGraphEvent(event) {
6
- return event.type.startsWith("graph.");
7
- }
8
- function isApiError(obj) {
9
- return typeof obj === "object" && obj !== null && "code" in obj && "message" in obj;
10
- }
11
-
12
- export { isApiError, isGraphEvent, isMemoryEvent };
13
- //# sourceMappingURL=types.mjs.map
14
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";AAkjBO,SAAS,cAAc,KAAA,EAA0F;AACtH,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,UAAA,CAAW,SAAS,CAAA;AACxC;AAKO,SAAS,aAAa,KAAA,EAA2E;AACtG,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,UAAA,CAAW,QAAQ,CAAA;AACvC;AAKO,SAAS,WAAW,GAAA,EAA+B;AACxD,EAAA,OACE,OAAO,GAAA,KAAQ,QAAA,IACf,QAAQ,IAAA,IACR,MAAA,IAAU,OACV,SAAA,IAAa,GAAA;AAEjB","file":"types.mjs","sourcesContent":["/**\n * Cilow SDK TypeScript Type Definitions\n *\n * Comprehensive type definitions for the Cilow memory system.\n */\n\n// =============================================================================\n// Core Memory Types\n// =============================================================================\n\n/**\n * Memory tier classification based on access frequency and recency\n */\nexport type MemoryTier = 'hot' | 'warm' | 'cold';\n\n/**\n * Memory status for lifecycle management\n */\nexport type MemoryStatus = 'active' | 'archived' | 'deleted';\n\n/**\n * Core memory entity representing a stored piece of information\n */\nexport interface Memory {\n /** Unique identifier for the memory */\n id: string;\n /** The content of the memory */\n content: string;\n /** Tags for categorization and filtering */\n tags: string[];\n /** User ID associated with this memory */\n userId?: string;\n /** Session ID for grouping related memories */\n sessionId?: string;\n /** Current tier classification */\n tier: MemoryTier;\n /** Memory status */\n status: MemoryStatus;\n /** Access count for prioritization */\n accessCount: number;\n /** Token count for the content */\n tokenCount: number;\n /** Embedding vector (if available) */\n embedding?: number[];\n /** Additional metadata */\n metadata: Record<string, unknown>;\n /** ISO timestamp of creation */\n createdAt: string;\n /** ISO timestamp of last update */\n updatedAt: string;\n /** ISO timestamp of last access */\n lastAccessedAt: string;\n}\n\n/**\n * Minimal memory representation for list operations\n */\nexport interface MemorySummary {\n id: string;\n content: string;\n tags: string[];\n tier: MemoryTier;\n createdAt: string;\n}\n\n/**\n * Options for creating a new memory\n */\nexport interface CreateMemoryOptions {\n /** Tags to apply to the memory */\n tags?: string[];\n /** User ID to associate */\n userId?: string;\n /** Session ID for grouping */\n sessionId?: string;\n /** Additional metadata */\n metadata?: Record<string, unknown>;\n /** Force a specific tier */\n tier?: MemoryTier;\n}\n\n/**\n * Options for updating a memory\n */\nexport interface UpdateMemoryOptions {\n /** New content */\n content?: string;\n /** New tags (replaces existing) */\n tags?: string[];\n /** Updated metadata (merged with existing) */\n metadata?: Record<string, unknown>;\n /** Force tier change */\n tier?: MemoryTier;\n}\n\n// =============================================================================\n// Search Types\n// =============================================================================\n\n/**\n * Search result containing a memory and its relevance score\n */\nexport interface SearchResult {\n /** The matching memory */\n memory: Memory;\n /** Relevance score (0.0 - 1.0) */\n score: number;\n /** Matched terms or phrases */\n matchedTerms?: string[];\n /** Highlighted content snippets */\n highlights?: string[];\n}\n\n/**\n * Search query parameters\n */\nexport interface SearchQuery {\n /** The search text */\n text: string;\n /** Maximum number of results */\n limit?: number;\n /** Minimum relevance score threshold (0.0 - 1.0) */\n minRelevance?: number;\n /** Filter by tags (AND logic) */\n tags?: string[];\n /** Filter by user ID */\n userId?: string;\n /** Filter by session ID */\n sessionId?: string;\n /** Filter by tier */\n tier?: MemoryTier;\n /** Filter by date range - start */\n createdAfter?: string;\n /** Filter by date range - end */\n createdBefore?: string;\n /** Include archived memories */\n includeArchived?: boolean;\n /** Search mode */\n mode?: 'semantic' | 'keyword' | 'hybrid';\n}\n\n/**\n * Advanced search options for complex queries\n */\nexport interface AdvancedSearchOptions extends SearchQuery {\n /** Boost recent memories */\n recencyBoost?: number;\n /** Boost frequently accessed memories */\n frequencyBoost?: number;\n /** Required tags (must have all) */\n requiredTags?: string[];\n /** Excluded tags (must not have any) */\n excludedTags?: string[];\n /** Metadata filters */\n metadataFilters?: Record<string, unknown>;\n /** Custom reranking function name */\n reranker?: string;\n}\n\n// =============================================================================\n// Graph Types\n// =============================================================================\n\n/**\n * Node in the memory knowledge graph\n */\nexport interface GraphNode {\n /** Unique node identifier */\n id: string;\n /** Node type/label */\n type: string;\n /** Display name */\n name: string;\n /** Node properties */\n properties: Record<string, unknown>;\n /** Associated memory IDs */\n memoryIds: string[];\n /** Creation timestamp */\n createdAt: string;\n /** Last update timestamp */\n updatedAt: string;\n}\n\n/**\n * Edge connecting two nodes in the graph\n */\nexport interface GraphEdge {\n /** Unique edge identifier */\n id: string;\n /** Source node ID */\n sourceId: string;\n /** Target node ID */\n targetId: string;\n /** Relationship type */\n type: string;\n /** Edge weight/strength */\n weight: number;\n /** Edge properties */\n properties: Record<string, unknown>;\n /** Creation timestamp */\n createdAt: string;\n}\n\n/**\n * Subgraph result for graph traversal queries\n */\nexport interface GraphSubgraph {\n /** Nodes in the subgraph */\n nodes: GraphNode[];\n /** Edges in the subgraph */\n edges: GraphEdge[];\n /** Central node ID (if applicable) */\n centerId?: string;\n}\n\n/**\n * Options for graph traversal\n */\nexport interface GraphTraversalOptions {\n /** Starting node ID */\n startNodeId: string;\n /** Maximum traversal depth */\n maxDepth?: number;\n /** Filter by relationship types */\n relationshipTypes?: string[];\n /** Maximum nodes to return */\n limit?: number;\n /** Traversal direction */\n direction?: 'outbound' | 'inbound' | 'both';\n}\n\n// =============================================================================\n// Statistics Types\n// =============================================================================\n\n/**\n * Memory system statistics\n */\nexport interface MemoryStats {\n /** Total number of memories */\n totalMemories: number;\n /** Number of hot tier memories */\n hotMemories: number;\n /** Number of warm tier memories */\n warmMemories: number;\n /** Number of cold tier memories */\n coldMemories: number;\n /** Total token count across all memories */\n totalTokens: number;\n /** Average tokens per memory */\n averageTokensPerMemory: number;\n /** Number of unique users */\n uniqueUsers: number;\n /** Number of unique sessions */\n uniqueSessions: number;\n /** Total number of tags */\n totalTags: number;\n /** Storage size in bytes */\n storageSizeBytes: number;\n /** Stats generation timestamp */\n generatedAt: string;\n}\n\n/**\n * Tag with usage count\n */\nexport interface TagCount {\n /** Tag name */\n tag: string;\n /** Usage count */\n count: number;\n}\n\n/**\n * User activity statistics\n */\nexport interface UserStats {\n /** User ID */\n userId: string;\n /** Number of memories */\n memoryCount: number;\n /** Total tokens used */\n totalTokens: number;\n /** Number of sessions */\n sessionCount: number;\n /** First activity timestamp */\n firstActivityAt: string;\n /** Last activity timestamp */\n lastActivityAt: string;\n}\n\n// =============================================================================\n// Event Types (WebSocket)\n// =============================================================================\n\n/**\n * Base event type\n */\nexport interface BaseEvent {\n /** Event type identifier */\n type: string;\n /** Event timestamp */\n timestamp: string;\n /** Correlation ID for tracking */\n correlationId?: string;\n}\n\n/**\n * Memory created event\n */\nexport interface MemoryCreatedEvent extends BaseEvent {\n type: 'memory.created';\n /** The created memory */\n memory: Memory;\n}\n\n/**\n * Memory updated event\n */\nexport interface MemoryUpdatedEvent extends BaseEvent {\n type: 'memory.updated';\n /** The updated memory */\n memory: Memory;\n /** Changed fields */\n changedFields: string[];\n}\n\n/**\n * Memory deleted event\n */\nexport interface MemoryDeletedEvent extends BaseEvent {\n type: 'memory.deleted';\n /** Deleted memory ID */\n memoryId: string;\n}\n\n/**\n * Memory tier changed event\n */\nexport interface MemoryTierChangedEvent extends BaseEvent {\n type: 'memory.tier_changed';\n /** Memory ID */\n memoryId: string;\n /** Previous tier */\n previousTier: MemoryTier;\n /** New tier */\n newTier: MemoryTier;\n}\n\n/**\n * Graph node created event\n */\nexport interface GraphNodeCreatedEvent extends BaseEvent {\n type: 'graph.node_created';\n /** The created node */\n node: GraphNode;\n}\n\n/**\n * Graph edge created event\n */\nexport interface GraphEdgeCreatedEvent extends BaseEvent {\n type: 'graph.edge_created';\n /** The created edge */\n edge: GraphEdge;\n}\n\n/**\n * Connection status event\n */\nexport interface ConnectionStatusEvent extends BaseEvent {\n type: 'connection.status';\n /** Connection status */\n status: 'connected' | 'disconnected' | 'reconnecting';\n /** Reason for status change */\n reason?: string;\n}\n\n/**\n * Union type of all events\n */\nexport type CilowEvent =\n | MemoryCreatedEvent\n | MemoryUpdatedEvent\n | MemoryDeletedEvent\n | MemoryTierChangedEvent\n | GraphNodeCreatedEvent\n | GraphEdgeCreatedEvent\n | ConnectionStatusEvent;\n\n// =============================================================================\n// API Request/Response Types\n// =============================================================================\n\n/**\n * Pagination parameters\n */\nexport interface PaginationParams {\n /** Number of items per page */\n limit?: number;\n /** Offset for pagination */\n offset?: number;\n /** Cursor for cursor-based pagination */\n cursor?: string;\n}\n\n/**\n * Paginated response wrapper\n */\nexport interface PaginatedResponse<T> {\n /** Items in this page */\n items: T[];\n /** Total count of items */\n total: number;\n /** Current offset */\n offset: number;\n /** Items per page */\n limit: number;\n /** Cursor for next page */\n nextCursor?: string;\n /** Whether there are more items */\n hasMore: boolean;\n}\n\n/**\n * API error response\n */\nexport interface ApiError {\n /** Error code */\n code: string;\n /** Human-readable error message */\n message: string;\n /** Additional error details */\n details?: Record<string, unknown>;\n /** Request ID for debugging */\n requestId?: string;\n}\n\n/**\n * Health check response\n */\nexport interface HealthCheck {\n /** Service status */\n status: 'healthy' | 'degraded' | 'unhealthy';\n /** Service version */\n version: string;\n /** Uptime in seconds */\n uptimeSeconds: number;\n /** Component statuses */\n components: {\n name: string;\n status: 'healthy' | 'degraded' | 'unhealthy';\n latencyMs?: number;\n }[];\n}\n\n// =============================================================================\n// Client Configuration Types\n// =============================================================================\n\n/**\n * Client configuration options\n */\nexport interface CilowConfig {\n /** Base URL of the Cilow API */\n apiUrl: string;\n /** API key for authentication */\n apiKey: string;\n /** Request timeout in milliseconds */\n timeout?: number;\n /** Number of retry attempts for failed requests */\n retries?: number;\n /** Custom headers to include in requests */\n headers?: Record<string, string>;\n /** Enable debug logging */\n debug?: boolean;\n}\n\n/**\n * WebSocket configuration options\n */\nexport interface WebSocketConfig {\n /** WebSocket URL (defaults to apiUrl with ws:// protocol) */\n wsUrl?: string;\n /** Reconnection attempts */\n reconnectAttempts?: number;\n /** Reconnection delay in milliseconds */\n reconnectDelay?: number;\n /** Heartbeat interval in milliseconds */\n heartbeatInterval?: number;\n /** Message queue size for offline buffering */\n messageQueueSize?: number;\n}\n\n/**\n * Combined configuration for full client\n */\nexport interface FullCilowConfig extends CilowConfig, WebSocketConfig {\n /** Default user ID for all operations */\n defaultUserId?: string;\n /** Default session ID */\n defaultSessionId?: string;\n /** Default tags to apply */\n defaultTags?: string[];\n}\n\n// =============================================================================\n// Framework Integration Types\n// =============================================================================\n\n/**\n * Context result for AI integrations\n */\nexport interface ContextResult {\n /** Formatted context string */\n context: string;\n /** Number of memories used */\n memoriesUsed: number;\n /** Estimated token count */\n estimatedTokens: number;\n /** Memory IDs included */\n memoryIds: string[];\n /** Search scores */\n scores: number[];\n}\n\n/**\n * Conversation turn for storing dialogues\n */\nexport interface ConversationTurn {\n /** User's message */\n userMessage: string;\n /** Assistant's response */\n assistantResponse: string;\n /** Session ID */\n sessionId?: string;\n /** Additional metadata */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Batch operation result\n */\nexport interface BatchResult<T> {\n /** Successful operations */\n succeeded: T[];\n /** Failed operations with errors */\n failed: {\n item: T;\n error: string;\n }[];\n /** Total operations attempted */\n total: number;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if an event is a memory event\n */\nexport function isMemoryEvent(event: CilowEvent): event is MemoryCreatedEvent | MemoryUpdatedEvent | MemoryDeletedEvent {\n return event.type.startsWith('memory.');\n}\n\n/**\n * Check if an event is a graph event\n */\nexport function isGraphEvent(event: CilowEvent): event is GraphNodeCreatedEvent | GraphEdgeCreatedEvent {\n return event.type.startsWith('graph.');\n}\n\n/**\n * Check if an object is an API error\n */\nexport function isApiError(obj: unknown): obj is ApiError {\n return (\n typeof obj === 'object' &&\n obj !== null &&\n 'code' in obj &&\n 'message' in obj\n );\n}\n"]}
@@ -1,160 +0,0 @@
1
- import { CilowConfig, WebSocketConfig, CilowEvent, MemoryCreatedEvent, MemoryUpdatedEvent, MemoryDeletedEvent, MemoryTierChangedEvent, GraphNodeCreatedEvent, GraphEdgeCreatedEvent, ConnectionStatusEvent } from './types.mjs';
2
-
3
- /**
4
- * Cilow WebSocket Client
5
- *
6
- * Real-time connection for memory updates, graph changes, and event streaming.
7
- */
8
-
9
- /**
10
- * WebSocket connection states
11
- */
12
- type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
13
- /**
14
- * Event listener type
15
- */
16
- type EventListener<T extends CilowEvent = CilowEvent> = (event: T) => void;
17
- /**
18
- * Subscription filter options
19
- */
20
- interface SubscriptionFilter {
21
- /** Filter by user ID */
22
- userId?: string;
23
- /** Filter by session ID */
24
- sessionId?: string;
25
- /** Filter by tags */
26
- tags?: string[];
27
- /** Filter by event types */
28
- eventTypes?: string[];
29
- }
30
- /**
31
- * CilowWebSocket - Real-time WebSocket client for Cilow
32
- *
33
- * @example
34
- * ```typescript
35
- * const ws = new CilowWebSocket({
36
- * apiUrl: 'https://api.cilow.ai',
37
- * apiKey: 'your-key'
38
- * });
39
- *
40
- * // Subscribe to memory events
41
- * ws.on('memory.created', (event) => {
42
- * console.log('New memory:', event.memory);
43
- * });
44
- *
45
- * // Connect
46
- * await ws.connect();
47
- *
48
- * // Subscribe to specific user's events
49
- * ws.subscribe({ userId: 'user-123' });
50
- * ```
51
- */
52
- declare class CilowWebSocket {
53
- private ws;
54
- private readonly wsUrl;
55
- private readonly apiKey;
56
- private readonly reconnectAttempts;
57
- private readonly reconnectDelay;
58
- private readonly heartbeatInterval;
59
- private readonly messageQueueSize;
60
- private state;
61
- private reconnectCount;
62
- private heartbeatTimer;
63
- private reconnectTimer;
64
- private messageQueue;
65
- private subscriptions;
66
- private listeners;
67
- private allListeners;
68
- constructor(config: CilowConfig & WebSocketConfig);
69
- /**
70
- * Get current connection state
71
- */
72
- get connectionState(): ConnectionState;
73
- /**
74
- * Check if connected
75
- */
76
- get isConnected(): boolean;
77
- /**
78
- * Connect to the WebSocket server
79
- */
80
- connect(): Promise<void>;
81
- /**
82
- * Disconnect from the WebSocket server
83
- */
84
- disconnect(): void;
85
- /**
86
- * Subscribe to events with optional filter
87
- */
88
- subscribe(filter?: SubscriptionFilter): void;
89
- /**
90
- * Unsubscribe from events
91
- */
92
- unsubscribe(filter?: SubscriptionFilter): void;
93
- /**
94
- * Add event listener for specific event type
95
- */
96
- on<T extends CilowEvent>(eventType: T['type'], listener: EventListener<T>): () => void;
97
- /**
98
- * Add listener for all events
99
- */
100
- onAny(listener: EventListener): () => void;
101
- /**
102
- * Remove event listener
103
- */
104
- off<T extends CilowEvent>(eventType: T['type'], listener: EventListener<T>): void;
105
- /**
106
- * Remove all listeners for an event type
107
- */
108
- offAll(eventType?: string): void;
109
- /**
110
- * Listen for memory created events
111
- */
112
- onMemoryCreated(listener: EventListener<MemoryCreatedEvent>): () => void;
113
- /**
114
- * Listen for memory updated events
115
- */
116
- onMemoryUpdated(listener: EventListener<MemoryUpdatedEvent>): () => void;
117
- /**
118
- * Listen for memory deleted events
119
- */
120
- onMemoryDeleted(listener: EventListener<MemoryDeletedEvent>): () => void;
121
- /**
122
- * Listen for memory tier changed events
123
- */
124
- onMemoryTierChanged(listener: EventListener<MemoryTierChangedEvent>): () => void;
125
- /**
126
- * Listen for graph node created events
127
- */
128
- onGraphNodeCreated(listener: EventListener<GraphNodeCreatedEvent>): () => void;
129
- /**
130
- * Listen for graph edge created events
131
- */
132
- onGraphEdgeCreated(listener: EventListener<GraphEdgeCreatedEvent>): () => void;
133
- /**
134
- * Listen for connection status changes
135
- */
136
- onConnectionStatus(listener: EventListener<ConnectionStatusEvent>): () => void;
137
- /**
138
- * Wait for specific event (one-time)
139
- */
140
- once<T extends CilowEvent>(eventType: T['type'], timeout?: number): Promise<T>;
141
- private send;
142
- private sendSubscription;
143
- private resubscribe;
144
- private flushMessageQueue;
145
- private handleMessage;
146
- private handleClose;
147
- private handleError;
148
- private scheduleReconnect;
149
- private clearReconnectTimer;
150
- private startHeartbeat;
151
- private stopHeartbeat;
152
- private emit;
153
- private emitStatusEvent;
154
- }
155
- /**
156
- * Create a WebSocket client instance (convenience function)
157
- */
158
- declare function createWebSocket(config: CilowConfig & WebSocketConfig): CilowWebSocket;
159
-
160
- export { CilowWebSocket, type ConnectionState, type EventListener, type SubscriptionFilter, createWebSocket };