@cilow/sdk 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Cilow AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,322 @@
1
+ # @cilow/sdk
2
+
3
+ TypeScript/JavaScript SDK for the Cilow AI Agent Platform - Production-ready memory system for AI agents with unlimited context.
4
+
5
+ ## Features
6
+
7
+ - **Semantic Memory Storage** - Store and retrieve memories using vector embeddings
8
+ - **Multi-tier Storage** - Hot/Warm/Cold tiers with automatic optimization
9
+ - **Tag-based Organization** - Organize memories with flexible tagging
10
+ - **Full-text + Semantic Search** - Hybrid search combining BM25 and embeddings
11
+ - **Knowledge Graph** - Entity extraction and relationship mapping
12
+ - **Multi-tenant Support** - User isolation for secure multi-user apps
13
+ - **TypeScript First** - Full type safety with comprehensive types
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @cilow/sdk
19
+ # or
20
+ yarn add @cilow/sdk
21
+ # or
22
+ pnpm add @cilow/sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import { CilowClient } from '@cilow/sdk';
29
+
30
+ // Initialize with API key
31
+ const client = new CilowClient({
32
+ apiKey: 'cilow_your_api_key',
33
+ baseUrl: 'https://api.cilow.ai', // or your self-hosted URL
34
+ });
35
+
36
+ // Add a memory
37
+ const { memoryId } = await client.addMemory({
38
+ content: 'User prefers TypeScript over JavaScript for backend development',
39
+ tags: ['preference', 'programming', 'backend'],
40
+ });
41
+
42
+ // Search memories semantically
43
+ const results = await client.searchMemories({
44
+ query: 'What programming languages does the user prefer?',
45
+ limit: 5,
46
+ });
47
+
48
+ console.log(results);
49
+ // [
50
+ // {
51
+ // memoryId: 'mem_xxx',
52
+ // content: 'User prefers TypeScript over JavaScript...',
53
+ // similarity: 0.92,
54
+ // score: 0.18,
55
+ // tags: ['preference', 'programming', 'backend']
56
+ // }
57
+ // ]
58
+ ```
59
+
60
+ ## Authentication
61
+
62
+ ### API Key Authentication (Recommended for backends)
63
+
64
+ ```typescript
65
+ const client = new CilowClient({
66
+ apiKey: 'cilow_your_api_key',
67
+ });
68
+ ```
69
+
70
+ ### JWT Authentication (For frontend apps)
71
+
72
+ ```typescript
73
+ const client = new CilowClient({
74
+ baseUrl: 'https://api.cilow.ai',
75
+ });
76
+
77
+ // Login to get access token
78
+ const auth = await client.login('user@example.com', 'password');
79
+ console.log(`Logged in as: ${auth.user.email}`);
80
+
81
+ // Token is automatically set for subsequent requests
82
+ ```
83
+
84
+ ## Memory Operations
85
+
86
+ ### Add Memory
87
+
88
+ ```typescript
89
+ const { memoryId } = await client.addMemory({
90
+ content: 'Meeting notes: Q4 planning discussed roadmap priorities',
91
+ tags: ['meeting', 'planning', 'q4'],
92
+ metadata: {
93
+ source: 'meeting-notes',
94
+ date: '2024-01-15',
95
+ },
96
+ });
97
+ ```
98
+
99
+ ### Search Memories
100
+
101
+ ```typescript
102
+ // Semantic search
103
+ const results = await client.searchMemories({
104
+ query: 'What were the Q4 priorities?',
105
+ limit: 10,
106
+ minScore: 0.5,
107
+ });
108
+
109
+ // Search with tag filtering
110
+ const taggedResults = await client.searchMemories({
111
+ query: 'planning discussions',
112
+ tags: ['meeting', 'planning'],
113
+ tagMode: 'all', // 'all' = AND, 'any' = OR
114
+ });
115
+ ```
116
+
117
+ ### Update Memory
118
+
119
+ ```typescript
120
+ await client.updateMemory(memoryId, {
121
+ content: 'Updated content with new information',
122
+ tags: ['updated', 'important'],
123
+ });
124
+ ```
125
+
126
+ ### Delete Memory
127
+
128
+ ```typescript
129
+ await client.deleteMemory(memoryId);
130
+ ```
131
+
132
+ ### List Memories
133
+
134
+ ```typescript
135
+ // List all memories
136
+ const memories = await client.listMemories();
137
+
138
+ // Filter by tier
139
+ const hotMemories = await client.listMemories({
140
+ tier: 'hot',
141
+ limit: 50,
142
+ offset: 0,
143
+ });
144
+ ```
145
+
146
+ ### Get Statistics
147
+
148
+ ```typescript
149
+ const stats = await client.getMemoryStats();
150
+ console.log(stats);
151
+ // {
152
+ // totalMemories: 1500,
153
+ // hotTier: 200,
154
+ // warmTier: 800,
155
+ // coldTier: 500,
156
+ // totalTokens: 45000,
157
+ // avgSalience: 0.65
158
+ // }
159
+ ```
160
+
161
+ ## Tag Management
162
+
163
+ ```typescript
164
+ // Add tags to a memory
165
+ await client.addTags(memoryId, ['important', 'follow-up']);
166
+
167
+ // Remove tags
168
+ await client.removeTags(memoryId, ['follow-up']);
169
+
170
+ // Replace all tags
171
+ await client.setTags(memoryId, ['new-tag-set']);
172
+
173
+ // Filter memories by tags
174
+ const tagged = await client.filterByTags(['important'], 'any');
175
+
176
+ // List all tags with counts
177
+ const allTags = await client.listAllTags();
178
+
179
+ // Get tag statistics
180
+ const tagStats = await client.getTagStats();
181
+ ```
182
+
183
+ ## Agent Operations
184
+
185
+ ```typescript
186
+ // Create an agent
187
+ const agentId = await client.createAgent({
188
+ name: 'research-assistant',
189
+ model: 'gpt-4',
190
+ systemPrompt: 'You are a helpful research assistant.',
191
+ });
192
+
193
+ // Execute a task
194
+ const result = await client.executeTask(agentId, {
195
+ task: 'Summarize the key points from recent meetings',
196
+ context: 'User is preparing for Q1 planning',
197
+ });
198
+
199
+ // Get agent status
200
+ const agent = await client.getAgent(agentId);
201
+
202
+ // List all agents
203
+ const agents = await client.listAgents();
204
+
205
+ // Delete agent
206
+ await client.deleteAgent(agentId);
207
+ ```
208
+
209
+ ## API Key Management
210
+
211
+ ```typescript
212
+ // Create a new API key
213
+ const apiKey = await client.createApiKey({
214
+ name: 'Production API Key',
215
+ expiresAt: new Date('2025-01-01'),
216
+ });
217
+
218
+ // List API keys
219
+ const keys = await client.listApiKeys();
220
+
221
+ // Revoke an API key
222
+ await client.revokeApiKey(keyId);
223
+
224
+ // Delete an API key
225
+ await client.deleteApiKey(keyId);
226
+ ```
227
+
228
+ ## Session Management
229
+
230
+ ```typescript
231
+ // List active sessions
232
+ const sessions = await client.listSessions();
233
+
234
+ // Revoke a specific session
235
+ await client.revokeSession(sessionId);
236
+
237
+ // Revoke all other sessions
238
+ await client.revokeOtherSessions();
239
+
240
+ // Revoke all sessions (logout everywhere)
241
+ await client.revokeAllSessions();
242
+ ```
243
+
244
+ ## Error Handling
245
+
246
+ ```typescript
247
+ import {
248
+ CilowError,
249
+ AuthenticationError,
250
+ NotFoundError,
251
+ RateLimitError
252
+ } from '@cilow/sdk';
253
+
254
+ try {
255
+ await client.searchMemories({ query: 'test' });
256
+ } catch (error) {
257
+ if (error instanceof AuthenticationError) {
258
+ console.error('Invalid API key');
259
+ } else if (error instanceof NotFoundError) {
260
+ console.error('Resource not found');
261
+ } else if (error instanceof RateLimitError) {
262
+ console.error('Rate limited, retry later');
263
+ } else if (error instanceof CilowError) {
264
+ console.error(`API error: ${error.message}`);
265
+ }
266
+ }
267
+ ```
268
+
269
+ ## Configuration Options
270
+
271
+ ```typescript
272
+ const client = new CilowClient({
273
+ // API base URL (default: http://localhost:8080)
274
+ baseUrl: 'https://api.cilow.ai',
275
+
276
+ // API key for authentication
277
+ apiKey: 'cilow_your_api_key',
278
+
279
+ // JWT access token (alternative to API key)
280
+ accessToken: 'eyJhbGc...',
281
+
282
+ // Request timeout in milliseconds (default: 30000)
283
+ timeout: 60000,
284
+ });
285
+ ```
286
+
287
+ ## Types
288
+
289
+ All types are fully exported for TypeScript users:
290
+
291
+ ```typescript
292
+ import type {
293
+ Memory,
294
+ MemoryStats,
295
+ SearchResult,
296
+ Agent,
297
+ User,
298
+ ApiKey,
299
+ AddMemoryOptions,
300
+ SearchMemoriesOptions,
301
+ } from '@cilow/sdk';
302
+ ```
303
+
304
+ ## Self-Hosting
305
+
306
+ Cilow can be self-hosted. Point the SDK to your instance:
307
+
308
+ ```typescript
309
+ const client = new CilowClient({
310
+ baseUrl: 'http://localhost:8080',
311
+ apiKey: 'your-local-api-key',
312
+ });
313
+ ```
314
+
315
+ ## Requirements
316
+
317
+ - Node.js >= 18.0.0
318
+ - ES2020+ or modern browser with fetch support
319
+
320
+ ## License
321
+
322
+ MIT