@nexusm/sdk 1.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.
- package/LICENSE +21 -0
- package/README.md +276 -0
- package/dist/index.d.mts +2572 -0
- package/dist/index.d.ts +2572 -0
- package/dist/index.js +1513 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1444 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 10CG Team
|
|
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,276 @@
|
|
|
1
|
+
# @nexusm/sdk
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for the Nexus AI Cognitive Services Platform.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **6 Services** -- Context, Memory, Conversation, Knowledge, Activity, Tenant
|
|
8
|
+
- **TypeScript-first** -- Full type definitions for all requests and responses
|
|
9
|
+
- **LRU Caching** -- Configurable in-memory cache with TTL for read endpoints
|
|
10
|
+
- **Auto Retry** -- Exponential back-off with configurable limits
|
|
11
|
+
- **Offline Queue** -- Queues requests when the network is unavailable
|
|
12
|
+
- **Error Hierarchy** -- Typed error classes mapped to HTTP status codes
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @nexusm/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { NexusClient } from '@nexusm/sdk';
|
|
24
|
+
|
|
25
|
+
const nexus = new NexusClient({
|
|
26
|
+
apiKey: process.env.NEXUS_API_KEY!,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Aggregated context retrieval (Chat main flow)
|
|
30
|
+
const context = await nexus.context.retrieve({
|
|
31
|
+
user_id: 'user_42',
|
|
32
|
+
query: 'What are the user preferences?',
|
|
33
|
+
layers: ['recent', 'semantic', 'graph'],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Semantic memory search
|
|
37
|
+
const results = await nexus.memories.search({
|
|
38
|
+
user_id: 'user_42',
|
|
39
|
+
query: 'UI preferences',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Log an activity
|
|
43
|
+
await nexus.activities.log({
|
|
44
|
+
action: 'edit_file',
|
|
45
|
+
activity_data: { path: 'src/index.ts', lines_changed: 12 },
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const nexus = new NexusClient({
|
|
53
|
+
// Required
|
|
54
|
+
apiKey: 'nx_live_...',
|
|
55
|
+
|
|
56
|
+
// Optional (defaults shown)
|
|
57
|
+
baseUrl: 'http://localhost:8001/v1',
|
|
58
|
+
tenantId: 'my-tenant', // Multi-tenant isolation header
|
|
59
|
+
timeout: 30_000, // Request timeout in ms
|
|
60
|
+
|
|
61
|
+
// Cache -- pass false to disable
|
|
62
|
+
cache: {
|
|
63
|
+
max: 1000, // Max LRU entries
|
|
64
|
+
ttl: 300, // TTL in seconds (5 min)
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
// Retry -- pass false to disable
|
|
68
|
+
retry: {
|
|
69
|
+
maxRetries: 3, // Retry attempts (excluding initial)
|
|
70
|
+
initialDelay: 1000, // First retry delay in ms
|
|
71
|
+
maxDelay: 10_000, // Upper bound for delay in ms
|
|
72
|
+
backoffFactor: 2, // Multiplier per attempt
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
### Context Service
|
|
80
|
+
|
|
81
|
+
The primary entry point for Chat main flows. Fetches user profile, conversation history, and knowledge graph data in a single call.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const ctx = await nexus.context.retrieve({
|
|
85
|
+
user_id: 'user_42',
|
|
86
|
+
query: 'project status',
|
|
87
|
+
layers: ['recent', 'semantic', 'graph'],
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Method | Description |
|
|
92
|
+
|--------|-------------|
|
|
93
|
+
| `retrieve(request)` | Aggregated context retrieval across memory, conversation, and knowledge layers |
|
|
94
|
+
|
|
95
|
+
### Memory Service
|
|
96
|
+
|
|
97
|
+
Long-term memory management powered by Mem0. Supports CRUD, semantic search, and the Memory Journal view.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const memory = await nexus.memories.create({
|
|
101
|
+
user_id: 'user_42',
|
|
102
|
+
content: 'User prefers dark mode',
|
|
103
|
+
memory_type: 'semantic',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const results = await nexus.memories.search({
|
|
107
|
+
user_id: 'user_42',
|
|
108
|
+
query: 'UI preferences',
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
| Method | Description |
|
|
113
|
+
|--------|-------------|
|
|
114
|
+
| `create(data)` | Create a new memory record |
|
|
115
|
+
| `list(params?)` | List memories with optional filtering and pagination |
|
|
116
|
+
| `get(memoryId)` | Retrieve a single memory by ID |
|
|
117
|
+
| `update(memoryId, data)` | Partial update of a memory record |
|
|
118
|
+
| `delete(memoryId)` | Delete a memory record |
|
|
119
|
+
| `search(request)` | Semantic similarity search across memories |
|
|
120
|
+
| `journal(params?)` | Chronological Memory Journal view (markdown or JSON) |
|
|
121
|
+
|
|
122
|
+
### Conversation Service
|
|
123
|
+
|
|
124
|
+
Conversation history and auto-summary management powered by Zep OSS.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const conv = await nexus.conversations.create({
|
|
128
|
+
user_id: 'user_42',
|
|
129
|
+
metadata: { topic: 'project planning' },
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await nexus.conversations.addMessage(conv.id, {
|
|
133
|
+
role: 'user',
|
|
134
|
+
content: 'Let us discuss the roadmap.',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const summary = await nexus.conversations.getSummary(conv.id);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
| Method | Description |
|
|
141
|
+
|--------|-------------|
|
|
142
|
+
| `create(data)` | Create a new conversation session |
|
|
143
|
+
| `list(params?)` | List conversations with optional filtering |
|
|
144
|
+
| `get(conversationId)` | Retrieve a conversation with messages |
|
|
145
|
+
| `addMessage(conversationId, message)` | Add a message to a conversation |
|
|
146
|
+
| `getMessages(conversationId, params?)` | List messages within a conversation |
|
|
147
|
+
| `getSummary(conversationId)` | Get auto-generated conversation summary |
|
|
148
|
+
| `delete(conversationId)` | Delete a conversation and all its messages |
|
|
149
|
+
|
|
150
|
+
### Knowledge Service
|
|
151
|
+
|
|
152
|
+
Knowledge graph construction and query powered by Fast GraphRAG.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const extraction = await nexus.knowledge.extract({
|
|
156
|
+
text: 'Alice works at Acme Corp on the Phoenix project.',
|
|
157
|
+
owner_user_id: 'user_42',
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const graph = await nexus.knowledge.query({
|
|
161
|
+
entity_name: 'Alice',
|
|
162
|
+
depth: 2,
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| Method | Description |
|
|
167
|
+
|--------|-------------|
|
|
168
|
+
| `createEntity(data)` | Create a new entity in the knowledge graph |
|
|
169
|
+
| `listEntities(params?)` | List entities with optional filtering |
|
|
170
|
+
| `query(request)` | BFS graph traversal from a named entity |
|
|
171
|
+
| `extract(request)` | Extract entities and relationships from text |
|
|
172
|
+
|
|
173
|
+
### Activity Service
|
|
174
|
+
|
|
175
|
+
Activity stream ingestion for passive memory collection.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
await nexus.activities.log({
|
|
179
|
+
action: 'edit_file',
|
|
180
|
+
activity_data: { path: 'src/app.ts', lines_changed: 42 },
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
await nexus.activities.stream({
|
|
184
|
+
agent_id: 'cursor-agent',
|
|
185
|
+
activities: [
|
|
186
|
+
{ action: 'read_file', activity_data: { path: 'README.md' } },
|
|
187
|
+
{ action: 'run_test', activity_data: { suite: 'unit', passed: true } },
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Method | Description |
|
|
193
|
+
|--------|-------------|
|
|
194
|
+
| `stream(request)` | Batch-ingest up to 1000 activities |
|
|
195
|
+
| `log(activity, agentId?)` | Convenience method to log a single activity |
|
|
196
|
+
|
|
197
|
+
### Tenant Service
|
|
198
|
+
|
|
199
|
+
Tenant profile and usage management. Identity is derived from the API key.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
const tenant = await nexus.tenants.me();
|
|
203
|
+
console.log(tenant.name, tenant.tier);
|
|
204
|
+
|
|
205
|
+
const usage = await nexus.tenants.usage();
|
|
206
|
+
console.log('Memories:', usage.memories_count);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
| Method | Description |
|
|
210
|
+
|--------|-------------|
|
|
211
|
+
| `me()` | Retrieve the current tenant profile |
|
|
212
|
+
| `usage()` | Retrieve resource usage statistics |
|
|
213
|
+
|
|
214
|
+
## Error Handling
|
|
215
|
+
|
|
216
|
+
All SDK errors extend `NexusError` and carry a machine-readable `code` field.
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
NexusError (base)
|
|
220
|
+
+-- ConfigurationError -- Invalid SDK options
|
|
221
|
+
+-- NetworkError -- Connection failures
|
|
222
|
+
+-- TimeoutError -- Request timeout exceeded
|
|
223
|
+
+-- ApiError -- HTTP API errors (has statusCode)
|
|
224
|
+
+-- AuthenticationError -- 401
|
|
225
|
+
+-- ValidationError -- 400 (has details)
|
|
226
|
+
+-- NotFoundError -- 404
|
|
227
|
+
+-- RateLimitError -- 429 (has retryAfter)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { ApiError, RateLimitError, NotFoundError } from '@nexusm/sdk';
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
await nexus.memories.get('non-existent-id');
|
|
235
|
+
} catch (err) {
|
|
236
|
+
if (err instanceof NotFoundError) {
|
|
237
|
+
console.log('Memory not found');
|
|
238
|
+
} else if (err instanceof RateLimitError) {
|
|
239
|
+
console.log(`Rate limited. Retry after ${err.retryAfter}s`);
|
|
240
|
+
} else if (err instanceof ApiError) {
|
|
241
|
+
console.log(`API error ${err.statusCode}: ${err.message}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Caching
|
|
247
|
+
|
|
248
|
+
The SDK includes an LRU cache that automatically caches responses from read endpoints:
|
|
249
|
+
|
|
250
|
+
- All `GET` requests (list, get operations)
|
|
251
|
+
- Read-oriented `POST` endpoints: `/context/retrieve`, `/memories/search`, `/knowledge/query`
|
|
252
|
+
|
|
253
|
+
Write operations (`POST`, `PATCH`, `DELETE`) automatically invalidate related cache entries by path prefix, ensuring read-after-write consistency.
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// Disable caching entirely
|
|
257
|
+
const nexus = new NexusClient({
|
|
258
|
+
apiKey: 'nx_live_...',
|
|
259
|
+
cache: false,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// Custom cache settings
|
|
263
|
+
const nexus2 = new NexusClient({
|
|
264
|
+
apiKey: 'nx_live_...',
|
|
265
|
+
cache: { max: 500, ttl: 120 },
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Requirements
|
|
270
|
+
|
|
271
|
+
- Node.js >= 18.0.0
|
|
272
|
+
- TypeScript >= 5.0 (recommended)
|
|
273
|
+
|
|
274
|
+
## License
|
|
275
|
+
|
|
276
|
+
MIT
|