@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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2572 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { ZodError, z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @nexusm/sdk - Common Types
|
|
6
|
+
*
|
|
7
|
+
* Shared type definitions used across all Nexus SDK modules.
|
|
8
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for offline request queuing.
|
|
12
|
+
* When enabled, requests made while offline are queued and replayed on reconnect.
|
|
13
|
+
*/
|
|
14
|
+
interface OfflineConfig {
|
|
15
|
+
/** Whether offline queuing is enabled. */
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum number of requests to buffer while offline.
|
|
19
|
+
* @default 100
|
|
20
|
+
*/
|
|
21
|
+
maxQueueSize?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compound ID used for multi-tenant isolation.
|
|
25
|
+
* Format: `tenant_id::user_id`
|
|
26
|
+
*/
|
|
27
|
+
type CompoundId = `${string}::${string}`;
|
|
28
|
+
/** Sort order for list queries */
|
|
29
|
+
type SortOrder = 'asc' | 'desc';
|
|
30
|
+
/**
|
|
31
|
+
* Pagination metadata returned with list responses.
|
|
32
|
+
* Follows the Nexus API pagination contract.
|
|
33
|
+
*/
|
|
34
|
+
interface Pagination {
|
|
35
|
+
/** Total number of items across all pages */
|
|
36
|
+
total: number;
|
|
37
|
+
/** Number of items per page */
|
|
38
|
+
limit: number;
|
|
39
|
+
/** Current offset from the beginning */
|
|
40
|
+
offset: number;
|
|
41
|
+
/** Whether more items exist beyond the current page */
|
|
42
|
+
has_more: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generic paginated response wrapper.
|
|
46
|
+
* Used for all list endpoints that support pagination.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam T - The type of items in the data array
|
|
49
|
+
*/
|
|
50
|
+
interface PaginatedResponse<T> {
|
|
51
|
+
/** Array of items for the current page */
|
|
52
|
+
data: T[];
|
|
53
|
+
/** Pagination metadata */
|
|
54
|
+
pagination: Pagination;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generic API response wrapper.
|
|
58
|
+
* Used for endpoints that return a single resource or operation result.
|
|
59
|
+
*
|
|
60
|
+
* @typeParam T - The type of the response data
|
|
61
|
+
*/
|
|
62
|
+
interface ApiResponse<T> {
|
|
63
|
+
/** Response payload */
|
|
64
|
+
data: T;
|
|
65
|
+
/** Optional metadata about the response */
|
|
66
|
+
meta?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Structured error detail returned by the Nexus API.
|
|
70
|
+
*/
|
|
71
|
+
interface ApiErrorDetail {
|
|
72
|
+
/** Machine-readable error code (e.g., "VALIDATION_ERROR", "UNAUTHORIZED") */
|
|
73
|
+
code: string;
|
|
74
|
+
/** Human-readable error message */
|
|
75
|
+
message: string;
|
|
76
|
+
/** Additional error context */
|
|
77
|
+
details?: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
/** Service health status */
|
|
80
|
+
type HealthStatus = 'healthy' | 'degraded' | 'unhealthy';
|
|
81
|
+
/** Individual service availability */
|
|
82
|
+
type ServiceStatus = 'up' | 'down';
|
|
83
|
+
/**
|
|
84
|
+
* Health check response from the `/health` endpoint.
|
|
85
|
+
*/
|
|
86
|
+
interface HealthResponse {
|
|
87
|
+
/** Overall platform health status */
|
|
88
|
+
status: HealthStatus;
|
|
89
|
+
/** Platform version string */
|
|
90
|
+
version: string;
|
|
91
|
+
/** Timestamp of the health check */
|
|
92
|
+
timestamp: string;
|
|
93
|
+
/** Status of individual backing services */
|
|
94
|
+
services: {
|
|
95
|
+
database: ServiceStatus;
|
|
96
|
+
ollama: ServiceStatus;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @module config
|
|
102
|
+
* @description Configuration management for the Nexus SDK.
|
|
103
|
+
*
|
|
104
|
+
* Provides sensible defaults, deep-merges user overrides, and exposes a
|
|
105
|
+
* fully-resolved configuration object where every field is guaranteed to
|
|
106
|
+
* be present.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/** Cache layer configuration. */
|
|
110
|
+
interface CacheConfig {
|
|
111
|
+
/** Maximum number of entries in the LRU cache. */
|
|
112
|
+
max?: number;
|
|
113
|
+
/** Time-to-live for cached entries, in **seconds**. */
|
|
114
|
+
ttl?: number;
|
|
115
|
+
}
|
|
116
|
+
/** Automatic retry configuration with exponential back-off. */
|
|
117
|
+
interface RetryConfig {
|
|
118
|
+
/** Maximum number of retry attempts (excluding the initial request). */
|
|
119
|
+
maxRetries?: number;
|
|
120
|
+
/** Delay before the first retry, in **milliseconds**. */
|
|
121
|
+
initialDelay?: number;
|
|
122
|
+
/** Upper bound for the retry delay, in **milliseconds**. */
|
|
123
|
+
maxDelay?: number;
|
|
124
|
+
/** Multiplier applied to the delay after each attempt. */
|
|
125
|
+
backoffFactor?: number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* User-facing SDK configuration.
|
|
129
|
+
*
|
|
130
|
+
* Only `apiKey` is strictly required; every other field falls back to a
|
|
131
|
+
* sensible default (see {@link DEFAULT_CONFIG}).
|
|
132
|
+
*/
|
|
133
|
+
interface NexusConfig {
|
|
134
|
+
/** API key used for authentication. */
|
|
135
|
+
apiKey: string;
|
|
136
|
+
/**
|
|
137
|
+
* Tenant identifier for multi-tenant isolation.
|
|
138
|
+
* When provided, it is sent as the `X-Tenant-ID` header on every request.
|
|
139
|
+
*/
|
|
140
|
+
tenantId?: string;
|
|
141
|
+
/** Base URL of the Nexus API (without trailing slash). */
|
|
142
|
+
baseUrl?: string;
|
|
143
|
+
/** Request timeout in **milliseconds**. */
|
|
144
|
+
timeout?: number;
|
|
145
|
+
/** LRU cache settings. Pass `false` to disable caching entirely. */
|
|
146
|
+
cache?: CacheConfig | false;
|
|
147
|
+
/** Retry behaviour. Pass `false` to disable retries entirely. */
|
|
148
|
+
retry?: RetryConfig | false;
|
|
149
|
+
/** Offline queue configuration. */
|
|
150
|
+
offline?: OfflineConfig;
|
|
151
|
+
/**
|
|
152
|
+
* Automatically report HTTP 4xx/5xx errors to the Nexus error tracking API.
|
|
153
|
+
* Defaults to `false`. When enabled, failed API responses are submitted to
|
|
154
|
+
* `POST /v1/errors` in the background (fire-and-forget).
|
|
155
|
+
*/
|
|
156
|
+
autoErrorReport?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/** Fully-resolved cache configuration (all fields required). */
|
|
159
|
+
interface ResolvedCacheConfig {
|
|
160
|
+
/** Maximum number of entries in the LRU cache. */
|
|
161
|
+
max: number;
|
|
162
|
+
/** Time-to-live for cached entries, in **seconds**. */
|
|
163
|
+
ttl: number;
|
|
164
|
+
}
|
|
165
|
+
/** Fully-resolved retry configuration (all fields required). */
|
|
166
|
+
interface ResolvedRetryConfig {
|
|
167
|
+
/** Maximum number of retry attempts. */
|
|
168
|
+
maxRetries: number;
|
|
169
|
+
/** Delay before the first retry, in **milliseconds**. */
|
|
170
|
+
initialDelay: number;
|
|
171
|
+
/** Upper bound for the retry delay, in **milliseconds**. */
|
|
172
|
+
maxDelay: number;
|
|
173
|
+
/** Multiplier applied to the delay after each attempt. */
|
|
174
|
+
backoffFactor: number;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Fully-resolved SDK configuration.
|
|
178
|
+
*
|
|
179
|
+
* Every field is guaranteed to be present after calling
|
|
180
|
+
* {@link resolveConfig}.
|
|
181
|
+
*/
|
|
182
|
+
interface ResolvedConfig {
|
|
183
|
+
/** API key used for authentication. */
|
|
184
|
+
apiKey: string;
|
|
185
|
+
/** Tenant identifier (may be `undefined` if not provided). */
|
|
186
|
+
tenantId?: string;
|
|
187
|
+
/** Base URL of the Nexus API (without trailing slash). */
|
|
188
|
+
baseUrl: string;
|
|
189
|
+
/** Request timeout in **milliseconds**. */
|
|
190
|
+
timeout: number;
|
|
191
|
+
/** Resolved cache settings, or `false` if caching is disabled. */
|
|
192
|
+
cache: ResolvedCacheConfig | false;
|
|
193
|
+
/** Resolved retry settings, or `false` if retries are disabled. */
|
|
194
|
+
retry: ResolvedRetryConfig | false;
|
|
195
|
+
/** Offline queue configuration (undefined if not provided). */
|
|
196
|
+
offline?: OfflineConfig;
|
|
197
|
+
/** Whether to auto-report HTTP 4xx/5xx errors. */
|
|
198
|
+
autoErrorReport: boolean;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Default SDK configuration values.
|
|
202
|
+
*
|
|
203
|
+
* These are used as the base when merging user-provided overrides.
|
|
204
|
+
*/
|
|
205
|
+
declare const DEFAULT_CONFIG: {
|
|
206
|
+
readonly baseUrl: "http://localhost:8001/v1";
|
|
207
|
+
readonly timeout: 30000;
|
|
208
|
+
readonly cache: ResolvedCacheConfig;
|
|
209
|
+
readonly retry: ResolvedRetryConfig;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Deep-merge user configuration with defaults and return a fully-resolved
|
|
213
|
+
* configuration object.
|
|
214
|
+
*
|
|
215
|
+
* @param userConfig - Partial configuration provided by the SDK consumer.
|
|
216
|
+
* @returns A {@link ResolvedConfig} with every field populated.
|
|
217
|
+
*
|
|
218
|
+
* @throws {Error} If `apiKey` is missing or empty.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const resolved = resolveConfig({
|
|
223
|
+
* apiKey: 'sk-...',
|
|
224
|
+
* timeout: 5000,
|
|
225
|
+
* retry: { maxRetries: 5 },
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* resolved.timeout; // 5000
|
|
229
|
+
* resolved.retry.maxRetries; // 5
|
|
230
|
+
* resolved.retry.initialDelay; // 1000 (default)
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare function resolveConfig(userConfig: NexusConfig): ResolvedConfig;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @module http/queue
|
|
237
|
+
* @description Offline request queue for the Nexus SDK.
|
|
238
|
+
*
|
|
239
|
+
* When the network is unavailable, requests can be enqueued and later
|
|
240
|
+
* flushed (replayed) once connectivity is restored. Each enqueued request
|
|
241
|
+
* returns a `Promise` so callers can `await` the eventual result
|
|
242
|
+
* transparently.
|
|
243
|
+
*/
|
|
244
|
+
/**
|
|
245
|
+
* A request that has been queued for later execution.
|
|
246
|
+
*
|
|
247
|
+
* The `resolve` and `reject` callbacks are wired to the `Promise` returned
|
|
248
|
+
* by {@link OfflineQueue.enqueue}, allowing the original caller to `await`
|
|
249
|
+
* the result even though the actual HTTP call is deferred.
|
|
250
|
+
*/
|
|
251
|
+
interface QueuedRequest {
|
|
252
|
+
/** Unique identifier for this queued request. */
|
|
253
|
+
id: string;
|
|
254
|
+
/** HTTP method (e.g. `GET`, `POST`, `PUT`, `DELETE`). */
|
|
255
|
+
method: string;
|
|
256
|
+
/** URL path relative to the base URL. */
|
|
257
|
+
path: string;
|
|
258
|
+
/** Optional request body. */
|
|
259
|
+
data?: unknown;
|
|
260
|
+
/** Resolve the caller's deferred promise with the response. */
|
|
261
|
+
resolve: (value: unknown) => void;
|
|
262
|
+
/** Reject the caller's deferred promise with an error. */
|
|
263
|
+
reject: (error: unknown) => void;
|
|
264
|
+
/** Unix timestamp (ms) when the request was enqueued. */
|
|
265
|
+
timestamp: number;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Queues HTTP requests while the client is offline and replays them
|
|
269
|
+
* when connectivity is restored.
|
|
270
|
+
*
|
|
271
|
+
* Each call to {@link enqueue} returns a `Promise` that resolves (or
|
|
272
|
+
* rejects) only after the request has been successfully flushed via
|
|
273
|
+
* {@link flush}. This allows consuming code to `await` the result as
|
|
274
|
+
* if the request were executed immediately.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* const queue = new OfflineQueue(50);
|
|
279
|
+
*
|
|
280
|
+
* // While offline -- the promise won't settle until flush()
|
|
281
|
+
* const pending = queue.enqueue({ method: 'POST', path: '/memory/add', data: { text: 'hello' } });
|
|
282
|
+
*
|
|
283
|
+
* // Later, when online again
|
|
284
|
+
* await queue.flush(async (req) => httpClient.post(req.path, req.data));
|
|
285
|
+
*
|
|
286
|
+
* // Now `pending` has resolved with the server response
|
|
287
|
+
* const result = await pending;
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
declare class OfflineQueue {
|
|
291
|
+
/** Internal FIFO queue of deferred requests. */
|
|
292
|
+
private readonly queue;
|
|
293
|
+
/** Maximum number of requests the queue will hold. */
|
|
294
|
+
private readonly maxSize;
|
|
295
|
+
/** Guard flag to prevent concurrent flush operations. */
|
|
296
|
+
private processing;
|
|
297
|
+
/** Auto-incrementing counter used to generate unique request IDs. */
|
|
298
|
+
private idCounter;
|
|
299
|
+
/**
|
|
300
|
+
* Create a new offline queue.
|
|
301
|
+
*
|
|
302
|
+
* @param maxSize - Maximum number of requests to buffer. When the queue
|
|
303
|
+
* is full, subsequent {@link enqueue} calls will reject
|
|
304
|
+
* immediately. Defaults to `100`.
|
|
305
|
+
*/
|
|
306
|
+
constructor(maxSize?: number);
|
|
307
|
+
/**
|
|
308
|
+
* Add a request to the queue.
|
|
309
|
+
*
|
|
310
|
+
* The returned `Promise` settles only when the request is eventually
|
|
311
|
+
* executed during a {@link flush} call.
|
|
312
|
+
*
|
|
313
|
+
* @param request - The request descriptor (method, path, and optional data).
|
|
314
|
+
* @returns A `Promise` that resolves with the executor's return value
|
|
315
|
+
* once the request is flushed, or rejects if the queue is full
|
|
316
|
+
* or the executor fails.
|
|
317
|
+
*
|
|
318
|
+
* @throws {NexusError} If the queue has reached its maximum capacity.
|
|
319
|
+
*/
|
|
320
|
+
enqueue<T = unknown>(request: Omit<QueuedRequest, 'id' | 'resolve' | 'reject' | 'timestamp'>): Promise<T>;
|
|
321
|
+
/**
|
|
322
|
+
* Process all queued requests in FIFO order.
|
|
323
|
+
*
|
|
324
|
+
* Each request is passed to the provided `executor` function. On success
|
|
325
|
+
* the caller's deferred promise is resolved; on failure it is rejected.
|
|
326
|
+
*
|
|
327
|
+
* Requests are processed sequentially to preserve ordering guarantees.
|
|
328
|
+
* If a flush is already in progress, subsequent calls are silently ignored.
|
|
329
|
+
*
|
|
330
|
+
* @param executor - An async function that performs the actual HTTP call
|
|
331
|
+
* for a given queued request and returns the response.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* await queue.flush(async (req) => {
|
|
336
|
+
* return httpClient.request(req.method, req.path, req.data);
|
|
337
|
+
* });
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
flush(executor: (req: QueuedRequest) => Promise<unknown>): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* The number of requests currently waiting in the queue.
|
|
343
|
+
*/
|
|
344
|
+
get size(): number;
|
|
345
|
+
/**
|
|
346
|
+
* Remove all pending requests from the queue.
|
|
347
|
+
*
|
|
348
|
+
* Every deferred promise is rejected with a cancellation error so that
|
|
349
|
+
* callers are not left hanging indefinitely.
|
|
350
|
+
*/
|
|
351
|
+
clear(): void;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @module http/client
|
|
356
|
+
* @description Low-level HTTP client for the Nexus SDK.
|
|
357
|
+
*
|
|
358
|
+
* Wraps an Axios instance with automatic authentication headers,
|
|
359
|
+
* request/response interceptors, and error normalisation so that
|
|
360
|
+
* every failure surfaces as a typed {@link NexusError} subclass.
|
|
361
|
+
*/
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* HTTP client that communicates with the Nexus API.
|
|
365
|
+
*
|
|
366
|
+
* All service-level modules (Memory, Conversation, Knowledge, Context)
|
|
367
|
+
* delegate their network calls to a shared `HttpClient` instance, which
|
|
368
|
+
* guarantees consistent authentication, timeout handling, and error
|
|
369
|
+
* mapping across the entire SDK surface.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* import { resolveConfig } from '../config';
|
|
374
|
+
* import { HttpClient } from './client';
|
|
375
|
+
*
|
|
376
|
+
* const config = resolveConfig({ apiKey: 'nx_test_abc123' });
|
|
377
|
+
* const http = new HttpClient(config);
|
|
378
|
+
*
|
|
379
|
+
* const memories = await http.get<Memory[]>('/memory/search', { query: 'hello' });
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
declare class HttpClient {
|
|
383
|
+
/** Underlying Axios instance. */
|
|
384
|
+
private readonly axios;
|
|
385
|
+
/** Fully-resolved SDK configuration snapshot. */
|
|
386
|
+
private readonly config;
|
|
387
|
+
/** LRU cache for read requests. */
|
|
388
|
+
private readonly cache;
|
|
389
|
+
/** Retry manager for transient failures. */
|
|
390
|
+
private readonly retry;
|
|
391
|
+
/** Offline request queue (only created when offline config is provided). */
|
|
392
|
+
private readonly offlineQueue?;
|
|
393
|
+
/** Whether the client is currently considered online. */
|
|
394
|
+
private _isOnline;
|
|
395
|
+
/**
|
|
396
|
+
* Optional callback to auto-report API errors to POST /v1/errors.
|
|
397
|
+
* Set by NexusClient after ErrorService is initialized.
|
|
398
|
+
* @internal
|
|
399
|
+
*/
|
|
400
|
+
onApiError?: (statusCode: number, method: string, url: string, detail: string) => void;
|
|
401
|
+
/**
|
|
402
|
+
* Create a new HTTP client.
|
|
403
|
+
*
|
|
404
|
+
* @param config - Fully-resolved SDK configuration (see {@link resolveConfig}).
|
|
405
|
+
*/
|
|
406
|
+
constructor(config: ResolvedConfig);
|
|
407
|
+
/**
|
|
408
|
+
* Set the online/offline status of the client.
|
|
409
|
+
*
|
|
410
|
+
* When transitioning from offline to online, the queued requests are
|
|
411
|
+
* automatically flushed.
|
|
412
|
+
*
|
|
413
|
+
* @param online - `true` if the client is online, `false` if offline.
|
|
414
|
+
*/
|
|
415
|
+
setOnline(online: boolean): void;
|
|
416
|
+
/**
|
|
417
|
+
* Access the offline queue instance (if offline mode is enabled).
|
|
418
|
+
*/
|
|
419
|
+
get queue(): OfflineQueue | undefined;
|
|
420
|
+
/**
|
|
421
|
+
* Send a GET request.
|
|
422
|
+
*
|
|
423
|
+
* @typeParam T - Expected shape of the response body.
|
|
424
|
+
* @param path - URL path relative to the base URL (e.g. `/memory/search`).
|
|
425
|
+
* @param params - Optional query parameters.
|
|
426
|
+
* @param signal - Optional {@link AbortSignal} to cancel the request.
|
|
427
|
+
* @returns The parsed response body.
|
|
428
|
+
*/
|
|
429
|
+
get<T>(path: string, params?: Record<string, unknown>, signal?: AbortSignal): Promise<T>;
|
|
430
|
+
/**
|
|
431
|
+
* Send a POST request.
|
|
432
|
+
*
|
|
433
|
+
* @typeParam T - Expected shape of the response body.
|
|
434
|
+
* @param path - URL path relative to the base URL.
|
|
435
|
+
* @param data - Optional request body.
|
|
436
|
+
* @param signal - Optional {@link AbortSignal} to cancel the request.
|
|
437
|
+
* @returns The parsed response body.
|
|
438
|
+
*/
|
|
439
|
+
post<T>(path: string, data?: unknown, signal?: AbortSignal): Promise<T>;
|
|
440
|
+
/**
|
|
441
|
+
* Send a PUT request.
|
|
442
|
+
*
|
|
443
|
+
* @typeParam T - Expected shape of the response body.
|
|
444
|
+
* @param path - URL path relative to the base URL.
|
|
445
|
+
* @param data - Optional request body.
|
|
446
|
+
* @param signal - Optional {@link AbortSignal} to cancel the request.
|
|
447
|
+
* @returns The parsed response body.
|
|
448
|
+
*/
|
|
449
|
+
put<T>(path: string, data?: unknown, signal?: AbortSignal): Promise<T>;
|
|
450
|
+
/**
|
|
451
|
+
* Send a PATCH request.
|
|
452
|
+
*
|
|
453
|
+
* @typeParam T - Expected shape of the response body.
|
|
454
|
+
* @param path - URL path relative to the base URL.
|
|
455
|
+
* @param data - Optional request body.
|
|
456
|
+
* @param signal - Optional {@link AbortSignal} to cancel the request.
|
|
457
|
+
* @returns The parsed response body.
|
|
458
|
+
*/
|
|
459
|
+
patch<T>(path: string, data?: unknown, signal?: AbortSignal): Promise<T>;
|
|
460
|
+
/**
|
|
461
|
+
* Send a DELETE request.
|
|
462
|
+
*
|
|
463
|
+
* @typeParam T - Expected shape of the response body.
|
|
464
|
+
* @param path - URL path relative to the base URL.
|
|
465
|
+
* @param signal - Optional {@link AbortSignal} to cancel the request.
|
|
466
|
+
* @returns The parsed response body.
|
|
467
|
+
*/
|
|
468
|
+
delete<T>(path: string, signal?: AbortSignal): Promise<T>;
|
|
469
|
+
/**
|
|
470
|
+
* Attach the request interceptor.
|
|
471
|
+
*
|
|
472
|
+
* Responsibilities:
|
|
473
|
+
* - Set `X-API-Key` authentication header.
|
|
474
|
+
* - Set `X-Tenant-ID` header when a tenant identifier is configured.
|
|
475
|
+
* - Ensure `Content-Type` is `application/json`.
|
|
476
|
+
*/
|
|
477
|
+
private setupRequestInterceptor;
|
|
478
|
+
/**
|
|
479
|
+
* Attach the response interceptor.
|
|
480
|
+
*
|
|
481
|
+
* Successful responses pass through unchanged. Errors are normalised
|
|
482
|
+
* into the appropriate {@link NexusError} subclass:
|
|
483
|
+
*
|
|
484
|
+
* | Condition | Error class |
|
|
485
|
+
* |------------------------|--------------------|
|
|
486
|
+
* | Request cancelled | *(re-thrown as-is)*|
|
|
487
|
+
* | Timeout (`ECONNABORTED`, `ETIMEDOUT`) | {@link TimeoutError} |
|
|
488
|
+
* | No response received | {@link NetworkError} |
|
|
489
|
+
* | HTTP 4xx / 5xx | {@link ApiError} (or subclass) |
|
|
490
|
+
*/
|
|
491
|
+
private setupResponseInterceptor;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* @module services/base
|
|
496
|
+
* @description Abstract base class for all Nexus service modules.
|
|
497
|
+
*
|
|
498
|
+
* Every service (Context, Memory, Conversation, Knowledge) extends this
|
|
499
|
+
* class to gain access to the shared {@link HttpClient} instance, which
|
|
500
|
+
* handles authentication, error normalisation, and timeout management.
|
|
501
|
+
*/
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Options that can be passed to any service method.
|
|
505
|
+
*/
|
|
506
|
+
interface RequestOptions {
|
|
507
|
+
/** Optional AbortSignal to cancel the request. */
|
|
508
|
+
signal?: AbortSignal;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Abstract base class that all Nexus service classes extend.
|
|
512
|
+
*
|
|
513
|
+
* Provides a protected reference to the SDK's {@link HttpClient} so that
|
|
514
|
+
* subclasses can issue HTTP requests without managing connection details.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* class MyService extends BaseService {
|
|
519
|
+
* async ping(): Promise<string> {
|
|
520
|
+
* return this.http.get<string>('/ping');
|
|
521
|
+
* }
|
|
522
|
+
* }
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
declare abstract class BaseService {
|
|
526
|
+
/** Shared HTTP client instance configured with API key and tenant headers. */
|
|
527
|
+
protected readonly http: HttpClient;
|
|
528
|
+
/**
|
|
529
|
+
* @param http - Fully-configured {@link HttpClient} instance.
|
|
530
|
+
*/
|
|
531
|
+
constructor(http: HttpClient);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* @nexusm/sdk - Context Types
|
|
536
|
+
*
|
|
537
|
+
* Type definitions for the Context Service - the core aggregated context
|
|
538
|
+
* retrieval API used in Chat main flows.
|
|
539
|
+
*
|
|
540
|
+
* v2.0 DX Enhanced temporal-anchored multi-layer retrieval.
|
|
541
|
+
*
|
|
542
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
543
|
+
*/
|
|
544
|
+
/**
|
|
545
|
+
* Available context retrieval layers for multi-layer parallel retrieval.
|
|
546
|
+
* - "recent": Time-anchored activities from the activity stream
|
|
547
|
+
* - "semantic": Vector similarity search against memory store (Mem0)
|
|
548
|
+
* - "graph": Knowledge graph traversal (Fast GraphRAG)
|
|
549
|
+
*/
|
|
550
|
+
type ContextLayer = 'recent' | 'semantic' | 'graph';
|
|
551
|
+
/**
|
|
552
|
+
* Convenience depth levels for context retrieval.
|
|
553
|
+
*
|
|
554
|
+
* | Level | Profile | History | Graph | Layers |
|
|
555
|
+
* |-------|---------|---------|-------|-------------------|
|
|
556
|
+
* | L0 | 1 mem | off | off | [] |
|
|
557
|
+
* | L1 | 3 mems | off | off | [] |
|
|
558
|
+
* | L2 | 10 mems | off | off | ["semantic"] |
|
|
559
|
+
* | L3 | 20 mems | on | on | ["semantic","graph"] |
|
|
560
|
+
*
|
|
561
|
+
* Use with the `depth` parameter on {@link ContextRequest}.
|
|
562
|
+
* Explicit fields always override the preset values.
|
|
563
|
+
*/
|
|
564
|
+
type ContextDepth = 'L0' | 'L1' | 'L2' | 'L3';
|
|
565
|
+
/** @internal Partial ContextRequest overrides applied for each depth preset. */
|
|
566
|
+
type ContextDepthPreset = Pick<ContextRequest, 'include_profile' | 'profile_limit' | 'include_history' | 'include_graph' | 'layers'>;
|
|
567
|
+
/**
|
|
568
|
+
* Preset field overrides for each {@link ContextDepth} level.
|
|
569
|
+
* Applied before user-supplied options so explicit values always win.
|
|
570
|
+
*/
|
|
571
|
+
declare const DEPTH_PRESETS: Record<ContextDepth, ContextDepthPreset>;
|
|
572
|
+
/**
|
|
573
|
+
* Request payload for the v2.0 DX Enhanced context retrieval endpoint.
|
|
574
|
+
* Supports multi-layer parallel retrieval with temporal anchoring (US-014).
|
|
575
|
+
*
|
|
576
|
+
* POST /context/retrieve
|
|
577
|
+
*
|
|
578
|
+
* The optional `depth` field is a client-side convenience shorthand.
|
|
579
|
+
* It is resolved to concrete field values before the request is sent to the
|
|
580
|
+
* backend, so it never appears in the wire payload.
|
|
581
|
+
*/
|
|
582
|
+
interface ContextRequest {
|
|
583
|
+
/**
|
|
584
|
+
* Convenience depth preset. When set, applies a predefined combination of
|
|
585
|
+
* `include_profile`, `profile_limit`, `include_history`, `include_graph`,
|
|
586
|
+
* and `layers`. Any field you supply explicitly overrides the preset value.
|
|
587
|
+
*
|
|
588
|
+
* @see {@link DEPTH_PRESETS} for exact values per level.
|
|
589
|
+
*/
|
|
590
|
+
depth?: ContextDepth;
|
|
591
|
+
/** User ID within the tenant (Nexus auto-prefixes tenant ID) */
|
|
592
|
+
user_id: string;
|
|
593
|
+
/** Optional semantic query text (used for the semantic layer) */
|
|
594
|
+
query?: string;
|
|
595
|
+
/**
|
|
596
|
+
* Context layers to retrieve in parallel.
|
|
597
|
+
* @default ["semantic", "graph"]
|
|
598
|
+
*/
|
|
599
|
+
layers?: ContextLayer[];
|
|
600
|
+
/**
|
|
601
|
+
* Time window for the recent layer in hours.
|
|
602
|
+
* @default 4
|
|
603
|
+
*/
|
|
604
|
+
recent_hours?: number;
|
|
605
|
+
/**
|
|
606
|
+
* Maximum number of recent activities to return.
|
|
607
|
+
* @default 10
|
|
608
|
+
*/
|
|
609
|
+
recent_limit?: number;
|
|
610
|
+
/**
|
|
611
|
+
* Whether to include memory profile (semantic layer).
|
|
612
|
+
* @default true
|
|
613
|
+
*/
|
|
614
|
+
include_profile?: boolean;
|
|
615
|
+
/**
|
|
616
|
+
* Maximum number of profile memories to return.
|
|
617
|
+
* @default 5
|
|
618
|
+
*/
|
|
619
|
+
profile_limit?: number;
|
|
620
|
+
/**
|
|
621
|
+
* Whether to include conversation history.
|
|
622
|
+
* @default true
|
|
623
|
+
*/
|
|
624
|
+
include_history?: boolean;
|
|
625
|
+
/**
|
|
626
|
+
* Maximum number of conversation history messages to return.
|
|
627
|
+
* @default 10
|
|
628
|
+
*/
|
|
629
|
+
history_limit?: number;
|
|
630
|
+
/**
|
|
631
|
+
* Whether to include knowledge graph entities (graph layer).
|
|
632
|
+
* @default true
|
|
633
|
+
*/
|
|
634
|
+
include_graph?: boolean;
|
|
635
|
+
/**
|
|
636
|
+
* Maximum number of knowledge graph entities to return.
|
|
637
|
+
* @default 5
|
|
638
|
+
*/
|
|
639
|
+
graph_limit?: number;
|
|
640
|
+
/**
|
|
641
|
+
* Optional point-in-time anchor for temporal-aware retrieval.
|
|
642
|
+
* RFC 3339 datetime **with timezone offset** (e.g.
|
|
643
|
+
* `"2026-01-01T00:00:00+00:00"` or `"2026-01-01T00:00:00Z"`).
|
|
644
|
+
* When set, layers that support temporal anchoring (semantic, recent)
|
|
645
|
+
* scope their retrieval to facts known to the system at that
|
|
646
|
+
* timestamp — useful for replaying past states (debugging,
|
|
647
|
+
* compliance) or running deterministic evaluations against
|
|
648
|
+
* a historical snapshot.
|
|
649
|
+
*
|
|
650
|
+
* Naive datetimes (no timezone) are rejected client-side by the
|
|
651
|
+
* zod schema to prevent silent UTC vs local-time mismatches at
|
|
652
|
+
* the ingest boundary.
|
|
653
|
+
*
|
|
654
|
+
* @since 1.3.0 (US-037 Wave 1 TASK-005)
|
|
655
|
+
*/
|
|
656
|
+
as_of?: string;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* A single memory item within the context profile.
|
|
660
|
+
* Sourced from Mem0 memory store.
|
|
661
|
+
*/
|
|
662
|
+
interface ContextMemory {
|
|
663
|
+
/** Unique memory identifier (UUID) */
|
|
664
|
+
id: string;
|
|
665
|
+
/** Memory content text */
|
|
666
|
+
content: string;
|
|
667
|
+
/** Type of memory */
|
|
668
|
+
memory_type: 'episodic' | 'semantic' | 'procedural';
|
|
669
|
+
/** Relevance score from similarity search */
|
|
670
|
+
score?: number;
|
|
671
|
+
/** Timestamp when the memory was created (ISO 8601) */
|
|
672
|
+
created_at: string;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* User profile memories section of the context response.
|
|
676
|
+
* Contains memories retrieved from Mem0.
|
|
677
|
+
*/
|
|
678
|
+
interface ContextProfile {
|
|
679
|
+
/** List of relevant memories */
|
|
680
|
+
memories: ContextMemory[];
|
|
681
|
+
/** Total number of memories the user has */
|
|
682
|
+
total_count: number;
|
|
683
|
+
}
|
|
684
|
+
/** A single message within conversation history. */
|
|
685
|
+
interface ContextMessage {
|
|
686
|
+
/** Message role */
|
|
687
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
688
|
+
/** Message content text */
|
|
689
|
+
content: string;
|
|
690
|
+
/** Timestamp when the message was created (ISO 8601) */
|
|
691
|
+
created_at: string;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Conversation history section of the context response.
|
|
695
|
+
* Sourced from Zep conversation store.
|
|
696
|
+
*/
|
|
697
|
+
interface ContextHistory {
|
|
698
|
+
/** List of recent messages */
|
|
699
|
+
messages: ContextMessage[];
|
|
700
|
+
/** Auto-generated conversation summary (if available) */
|
|
701
|
+
summary?: string;
|
|
702
|
+
/** Session identifier */
|
|
703
|
+
session_id?: string;
|
|
704
|
+
}
|
|
705
|
+
/** Entity ownership type in the knowledge graph */
|
|
706
|
+
type OwnerType = 'agent' | 'user';
|
|
707
|
+
/**
|
|
708
|
+
* A knowledge entity within the graph context.
|
|
709
|
+
* Sourced from Fast GraphRAG.
|
|
710
|
+
*/
|
|
711
|
+
interface ContextEntity {
|
|
712
|
+
/** Unique entity identifier (UUID) */
|
|
713
|
+
id: string;
|
|
714
|
+
/** Entity display name */
|
|
715
|
+
name: string;
|
|
716
|
+
/** Entity type classification (e.g., Person, Organization) */
|
|
717
|
+
entity_type: string;
|
|
718
|
+
/** Entity description */
|
|
719
|
+
description?: string;
|
|
720
|
+
/** Additional entity properties */
|
|
721
|
+
properties?: Record<string, unknown>;
|
|
722
|
+
/** Ownership type: agent=public knowledge, user=private social graph */
|
|
723
|
+
owner_type?: OwnerType;
|
|
724
|
+
}
|
|
725
|
+
/** A relationship between two entities in the knowledge graph. */
|
|
726
|
+
interface ContextRelation {
|
|
727
|
+
/** Source entity name */
|
|
728
|
+
source: string;
|
|
729
|
+
/** Relationship type label */
|
|
730
|
+
relation: string;
|
|
731
|
+
/** Target entity name */
|
|
732
|
+
target: string;
|
|
733
|
+
/** Relationship weight/strength */
|
|
734
|
+
weight?: number;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Knowledge graph section of the context response.
|
|
738
|
+
* Sourced from Fast GraphRAG.
|
|
739
|
+
*/
|
|
740
|
+
interface ContextGraph {
|
|
741
|
+
/** List of relevant entities */
|
|
742
|
+
entities: ContextEntity[];
|
|
743
|
+
/** List of relationships between entities */
|
|
744
|
+
relations: ContextRelation[];
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Retrieval performance metadata.
|
|
748
|
+
* Provides timing information for each retrieval layer.
|
|
749
|
+
*/
|
|
750
|
+
interface ContextMeta {
|
|
751
|
+
/** Total retrieval time in milliseconds */
|
|
752
|
+
took_ms: number;
|
|
753
|
+
/** Memory retrieval time in milliseconds */
|
|
754
|
+
memory_took_ms?: number;
|
|
755
|
+
/** History retrieval time in milliseconds */
|
|
756
|
+
history_took_ms?: number;
|
|
757
|
+
/** Graph retrieval time in milliseconds */
|
|
758
|
+
graph_took_ms?: number;
|
|
759
|
+
/** Original query text */
|
|
760
|
+
query?: string;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Aggregated context response from the retrieve endpoint.
|
|
764
|
+
* Contains parallel-fetched results from all requested layers.
|
|
765
|
+
*/
|
|
766
|
+
interface ContextRetrieveResponse {
|
|
767
|
+
/** User profile memories from Mem0 */
|
|
768
|
+
profile?: ContextProfile;
|
|
769
|
+
/** Conversation history from Zep */
|
|
770
|
+
history?: ContextHistory;
|
|
771
|
+
/** Knowledge graph data from GraphRAG */
|
|
772
|
+
graph?: ContextGraph;
|
|
773
|
+
/** Retrieval performance metadata */
|
|
774
|
+
meta?: ContextMeta;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* @module services/context
|
|
779
|
+
* @description Context Service - Aggregated context retrieval for Chat main flows.
|
|
780
|
+
*
|
|
781
|
+
* The Context Service is the primary entry point for AI agents to fetch
|
|
782
|
+
* all relevant user context in a single call. It orchestrates parallel
|
|
783
|
+
* retrieval across Memory (Mem0), Conversation (Zep), and Knowledge
|
|
784
|
+
* (GraphRAG) layers.
|
|
785
|
+
*
|
|
786
|
+
* Based on Nexus API v2.0 - POST /context/retrieve
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Service for aggregated context retrieval.
|
|
791
|
+
*
|
|
792
|
+
* This is the core API surface for Chat main flows. A single call to
|
|
793
|
+
* {@link ContextService.retrieve} fetches user profile memories,
|
|
794
|
+
* conversation history, and knowledge graph data in parallel.
|
|
795
|
+
*
|
|
796
|
+
* @example
|
|
797
|
+
* ```typescript
|
|
798
|
+
* const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
|
|
799
|
+
*
|
|
800
|
+
* const context = await nexus.context.retrieve({
|
|
801
|
+
* user_id: 'user_42',
|
|
802
|
+
* query: 'What did we discuss about the project?',
|
|
803
|
+
* layers: ['recent', 'semantic', 'graph'],
|
|
804
|
+
* });
|
|
805
|
+
*
|
|
806
|
+
* console.log(context.profile?.memories);
|
|
807
|
+
* console.log(context.history?.messages);
|
|
808
|
+
* console.log(context.graph?.entities);
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
declare class ContextService extends BaseService {
|
|
812
|
+
/**
|
|
813
|
+
* Retrieve aggregated context for a user across multiple layers.
|
|
814
|
+
*
|
|
815
|
+
* Performs v2.0 three-layer parallel retrieval:
|
|
816
|
+
* - **recent**: Time-anchored activities from the activity stream
|
|
817
|
+
* - **semantic**: Vector similarity search against Mem0 memory store
|
|
818
|
+
* - **graph**: Knowledge graph traversal via Fast GraphRAG
|
|
819
|
+
*
|
|
820
|
+
* @param request - Context retrieval parameters including user_id, query, and layer configuration.
|
|
821
|
+
* @returns Aggregated context containing profile, history, graph, and performance metadata.
|
|
822
|
+
*/
|
|
823
|
+
retrieve(request: ContextRequest, options?: RequestOptions): Promise<ContextRetrieveResponse>;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @nexusm/sdk - Memory Types
|
|
828
|
+
*
|
|
829
|
+
* Type definitions for the Memory Service powered by Mem0.
|
|
830
|
+
* Supports episodic, semantic, and procedural memory types
|
|
831
|
+
* with vector similarity search.
|
|
832
|
+
*
|
|
833
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
834
|
+
*/
|
|
835
|
+
/** Classification of memory types stored in Mem0 */
|
|
836
|
+
type MemoryType = 'episodic' | 'semantic' | 'procedural';
|
|
837
|
+
/**
|
|
838
|
+
* A memory record stored in the Nexus platform.
|
|
839
|
+
* Represents a single piece of user knowledge managed by Mem0.
|
|
840
|
+
*/
|
|
841
|
+
interface Memory {
|
|
842
|
+
/** Unique memory identifier (UUID) */
|
|
843
|
+
id: string;
|
|
844
|
+
/** User ID that owns this memory */
|
|
845
|
+
user_id: string;
|
|
846
|
+
/** Memory content text */
|
|
847
|
+
content: string;
|
|
848
|
+
/** Classification of the memory */
|
|
849
|
+
memory_type: MemoryType;
|
|
850
|
+
/** Additional metadata key-value pairs */
|
|
851
|
+
metadata?: Record<string, unknown>;
|
|
852
|
+
/** Relevance score (present in search results) */
|
|
853
|
+
score?: number;
|
|
854
|
+
/** Timestamp when the memory was created (ISO 8601) */
|
|
855
|
+
created_at: string;
|
|
856
|
+
/** Timestamp when the memory was last updated (ISO 8601) */
|
|
857
|
+
updated_at: string;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Request payload for creating a new memory.
|
|
861
|
+
*
|
|
862
|
+
* POST /memories
|
|
863
|
+
*/
|
|
864
|
+
interface MemoryCreate {
|
|
865
|
+
/** User ID to associate the memory with */
|
|
866
|
+
user_id: string;
|
|
867
|
+
/** Memory content text (1-10000 characters) */
|
|
868
|
+
content: string;
|
|
869
|
+
/**
|
|
870
|
+
* Classification of the memory.
|
|
871
|
+
* @default "episodic"
|
|
872
|
+
*/
|
|
873
|
+
memory_type?: MemoryType;
|
|
874
|
+
/** Additional metadata key-value pairs */
|
|
875
|
+
metadata?: Record<string, unknown>;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Request payload for updating an existing memory.
|
|
879
|
+
*
|
|
880
|
+
* PATCH /memories/:memory_id
|
|
881
|
+
*/
|
|
882
|
+
interface MemoryUpdate {
|
|
883
|
+
/** Updated memory content text */
|
|
884
|
+
content?: string;
|
|
885
|
+
/** Updated memory type classification */
|
|
886
|
+
memory_type?: MemoryType;
|
|
887
|
+
/** Updated metadata (replaces existing metadata) */
|
|
888
|
+
metadata?: Record<string, unknown>;
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Request payload for semantic memory search.
|
|
892
|
+
*
|
|
893
|
+
* POST /memories/search
|
|
894
|
+
*/
|
|
895
|
+
interface MemorySearch {
|
|
896
|
+
/** User ID to search within */
|
|
897
|
+
user_id: string;
|
|
898
|
+
/** Semantic search query text */
|
|
899
|
+
query: string;
|
|
900
|
+
/** Filter by memory type */
|
|
901
|
+
memory_type?: MemoryType;
|
|
902
|
+
/**
|
|
903
|
+
* Maximum number of results to return.
|
|
904
|
+
* @default 10
|
|
905
|
+
* @minimum 1
|
|
906
|
+
* @maximum 50
|
|
907
|
+
*/
|
|
908
|
+
limit?: number;
|
|
909
|
+
/**
|
|
910
|
+
* Minimum similarity score threshold.
|
|
911
|
+
* @default 0.7
|
|
912
|
+
* @minimum 0
|
|
913
|
+
* @maximum 1
|
|
914
|
+
*/
|
|
915
|
+
threshold?: number;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Response from a semantic memory search operation.
|
|
919
|
+
*/
|
|
920
|
+
interface MemorySearchResult {
|
|
921
|
+
/** Array of matching memories (with score populated) */
|
|
922
|
+
results: Memory[];
|
|
923
|
+
/** Original search query */
|
|
924
|
+
query: string;
|
|
925
|
+
/** Search execution time in milliseconds */
|
|
926
|
+
took_ms: number;
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Paginated list of memories.
|
|
930
|
+
*
|
|
931
|
+
* GET /memories?user_id=...
|
|
932
|
+
*/
|
|
933
|
+
interface MemoryList {
|
|
934
|
+
/** Array of memory records */
|
|
935
|
+
data: Memory[];
|
|
936
|
+
/** Pagination metadata */
|
|
937
|
+
pagination: {
|
|
938
|
+
/** Total number of memories */
|
|
939
|
+
total: number;
|
|
940
|
+
/** Current page size limit */
|
|
941
|
+
limit: number;
|
|
942
|
+
/** Current offset */
|
|
943
|
+
offset: number;
|
|
944
|
+
/** Whether more results exist */
|
|
945
|
+
has_more: boolean;
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* A single journal entry representing a memory on a specific date.
|
|
950
|
+
* Used in the Memory Journal view (US-015).
|
|
951
|
+
*/
|
|
952
|
+
interface JournalEntry {
|
|
953
|
+
/** Date key in YYYY-MM-DD format */
|
|
954
|
+
date: string;
|
|
955
|
+
/** Memories created on this date */
|
|
956
|
+
memories: Memory[];
|
|
957
|
+
/** Number of memories on this date */
|
|
958
|
+
count: number;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Response from the memory journal endpoint.
|
|
962
|
+
* Groups memories by date for chronological review.
|
|
963
|
+
*
|
|
964
|
+
* GET /memories/journal
|
|
965
|
+
*/
|
|
966
|
+
interface JournalResponse {
|
|
967
|
+
/** User ID for the journal */
|
|
968
|
+
user_id: string;
|
|
969
|
+
/** Start date of the journal range (ISO 8601 date) */
|
|
970
|
+
start_date: string;
|
|
971
|
+
/** End date of the journal range (ISO 8601 date) */
|
|
972
|
+
end_date: string;
|
|
973
|
+
/** Memories grouped by date (key: YYYY-MM-DD, value: Memory[]) */
|
|
974
|
+
entries: Record<string, Memory[]>;
|
|
975
|
+
/** Total number of days with memories */
|
|
976
|
+
total_days: number;
|
|
977
|
+
/** Total number of memories in the range */
|
|
978
|
+
total_memories: number;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* @module services/memories
|
|
983
|
+
* @description Memory Service - Long-term memory management with semantic retrieval.
|
|
984
|
+
*
|
|
985
|
+
* Wraps the Nexus Memory API powered by Mem0. Supports CRUD operations
|
|
986
|
+
* on episodic, semantic, and procedural memories, vector similarity
|
|
987
|
+
* search, and the Memory Journal view (US-015).
|
|
988
|
+
*
|
|
989
|
+
* Based on Nexus API v2.0 - /memories endpoints
|
|
990
|
+
*/
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Parameters for listing memories with optional filtering and pagination.
|
|
994
|
+
*/
|
|
995
|
+
interface MemoryListParams {
|
|
996
|
+
/** Filter memories by user ID */
|
|
997
|
+
user_id?: string;
|
|
998
|
+
/** Filter by memory type classification */
|
|
999
|
+
memory_type?: MemoryType;
|
|
1000
|
+
/** Maximum number of results per page */
|
|
1001
|
+
limit?: number;
|
|
1002
|
+
/** Offset for pagination */
|
|
1003
|
+
offset?: number;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Parameters for the Memory Journal view (US-015).
|
|
1007
|
+
*/
|
|
1008
|
+
interface MemoryJournalParams {
|
|
1009
|
+
/** Response format: markdown for display, json for programmatic use */
|
|
1010
|
+
format?: 'markdown' | 'json';
|
|
1011
|
+
/** Start date filter (ISO 8601 date, e.g. "2026-01-01") */
|
|
1012
|
+
start_date?: string;
|
|
1013
|
+
/** End date filter (ISO 8601 date, e.g. "2026-01-31") */
|
|
1014
|
+
end_date?: string;
|
|
1015
|
+
/** Filter journal entries by user ID */
|
|
1016
|
+
user_id?: string;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Service for managing long-term memories via Mem0.
|
|
1020
|
+
*
|
|
1021
|
+
* Provides full CRUD operations, semantic search, and the chronological
|
|
1022
|
+
* Memory Journal view for reviewing memories over time.
|
|
1023
|
+
*
|
|
1024
|
+
* @example
|
|
1025
|
+
* ```typescript
|
|
1026
|
+
* const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
|
|
1027
|
+
*
|
|
1028
|
+
* // Create a memory
|
|
1029
|
+
* const memory = await nexus.memories.create({
|
|
1030
|
+
* user_id: 'user_42',
|
|
1031
|
+
* content: 'User prefers dark mode',
|
|
1032
|
+
* memory_type: 'semantic',
|
|
1033
|
+
* });
|
|
1034
|
+
*
|
|
1035
|
+
* // Semantic search
|
|
1036
|
+
* const results = await nexus.memories.search({
|
|
1037
|
+
* user_id: 'user_42',
|
|
1038
|
+
* query: 'UI preferences',
|
|
1039
|
+
* });
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1042
|
+
declare class MemoryService extends BaseService {
|
|
1043
|
+
/**
|
|
1044
|
+
* Create a new memory record.
|
|
1045
|
+
*
|
|
1046
|
+
* @param data - Memory creation payload including user_id, content, and optional type/metadata.
|
|
1047
|
+
* @returns The newly created memory with generated ID and timestamps.
|
|
1048
|
+
*/
|
|
1049
|
+
create(data: MemoryCreate, options?: RequestOptions): Promise<Memory>;
|
|
1050
|
+
/**
|
|
1051
|
+
* List memories with optional filtering and pagination.
|
|
1052
|
+
*
|
|
1053
|
+
* @param params - Optional filters for user_id, memory_type, and pagination controls.
|
|
1054
|
+
* @returns Paginated list of memory records.
|
|
1055
|
+
*/
|
|
1056
|
+
list(params?: MemoryListParams, options?: RequestOptions): Promise<MemoryList>;
|
|
1057
|
+
/**
|
|
1058
|
+
* Retrieve a single memory by its ID.
|
|
1059
|
+
*
|
|
1060
|
+
* @param memoryId - UUID of the memory to retrieve.
|
|
1061
|
+
* @returns The memory record.
|
|
1062
|
+
* @throws {ApiError} 404 if the memory does not exist.
|
|
1063
|
+
*/
|
|
1064
|
+
get(memoryId: string, options?: RequestOptions): Promise<Memory>;
|
|
1065
|
+
/**
|
|
1066
|
+
* Update an existing memory record.
|
|
1067
|
+
*
|
|
1068
|
+
* Supports partial updates -- only the provided fields are modified.
|
|
1069
|
+
*
|
|
1070
|
+
* @param memoryId - UUID of the memory to update.
|
|
1071
|
+
* @param data - Fields to update (content, memory_type, metadata).
|
|
1072
|
+
* @returns The updated memory record.
|
|
1073
|
+
* @throws {ApiError} 404 if the memory does not exist.
|
|
1074
|
+
*/
|
|
1075
|
+
update(memoryId: string, data: MemoryUpdate, options?: RequestOptions): Promise<Memory>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Delete a memory record.
|
|
1078
|
+
*
|
|
1079
|
+
* @param memoryId - UUID of the memory to delete.
|
|
1080
|
+
* @throws {ApiError} 404 if the memory does not exist.
|
|
1081
|
+
*/
|
|
1082
|
+
delete(memoryId: string, options?: RequestOptions): Promise<void>;
|
|
1083
|
+
/**
|
|
1084
|
+
* Perform semantic similarity search across memories.
|
|
1085
|
+
*
|
|
1086
|
+
* Uses Mem0's vector search to find memories relevant to the query text.
|
|
1087
|
+
* Results are ranked by similarity score and filtered by optional thresholds.
|
|
1088
|
+
*
|
|
1089
|
+
* @param request - Search parameters including user_id, query, and optional filters.
|
|
1090
|
+
* @returns Search results with scored memories and timing metadata.
|
|
1091
|
+
*/
|
|
1092
|
+
search(request: MemorySearch, options?: RequestOptions): Promise<MemorySearchResult>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Retrieve the Memory Journal view (US-015).
|
|
1095
|
+
*
|
|
1096
|
+
* Groups memories chronologically by date for review. Supports both
|
|
1097
|
+
* markdown (human-readable) and JSON (programmatic) output formats.
|
|
1098
|
+
*
|
|
1099
|
+
* @param params - Optional filters for format, date range, and user_id.
|
|
1100
|
+
* @returns Journal response with memories grouped by date.
|
|
1101
|
+
*/
|
|
1102
|
+
journal(params?: MemoryJournalParams, options?: RequestOptions): Promise<JournalResponse>;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* @nexusm/sdk - Conversation Types
|
|
1107
|
+
*
|
|
1108
|
+
* Type definitions for the Conversation Service powered by Zep OSS.
|
|
1109
|
+
* Manages conversation history, messages, and auto-generated summaries.
|
|
1110
|
+
*
|
|
1111
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
1112
|
+
*/
|
|
1113
|
+
/** Valid message roles in a conversation */
|
|
1114
|
+
type MessageRole = 'user' | 'assistant' | 'system' | 'tool';
|
|
1115
|
+
/** Conversation status */
|
|
1116
|
+
type ConversationStatus = 'active' | 'archived' | 'deleted';
|
|
1117
|
+
/**
|
|
1118
|
+
* A conversation session between a user and an AI agent.
|
|
1119
|
+
* Managed by Zep OSS for temporal graph and auto-summary.
|
|
1120
|
+
*/
|
|
1121
|
+
interface Conversation {
|
|
1122
|
+
/** Unique conversation identifier (UUID) */
|
|
1123
|
+
id: string;
|
|
1124
|
+
/** User ID that owns this conversation */
|
|
1125
|
+
user_id: string;
|
|
1126
|
+
/** Session identifier for the conversation */
|
|
1127
|
+
session_id?: string;
|
|
1128
|
+
/** Auto-generated conversation summary */
|
|
1129
|
+
summary?: string;
|
|
1130
|
+
/** Total number of messages in the conversation */
|
|
1131
|
+
message_count: number;
|
|
1132
|
+
/** Additional metadata key-value pairs */
|
|
1133
|
+
metadata?: Record<string, unknown>;
|
|
1134
|
+
/** Timestamp when the conversation was created (ISO 8601) */
|
|
1135
|
+
created_at: string;
|
|
1136
|
+
/** Timestamp when the conversation was last updated (ISO 8601) */
|
|
1137
|
+
updated_at: string;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Request payload for creating a new conversation.
|
|
1141
|
+
*
|
|
1142
|
+
* POST /conversations
|
|
1143
|
+
*/
|
|
1144
|
+
interface ConversationCreate {
|
|
1145
|
+
/** User ID to associate the conversation with */
|
|
1146
|
+
user_id: string;
|
|
1147
|
+
/** Custom session ID (auto-generated if not provided) */
|
|
1148
|
+
session_id?: string;
|
|
1149
|
+
/** Additional metadata key-value pairs */
|
|
1150
|
+
metadata?: Record<string, unknown>;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Conversation with its messages included.
|
|
1154
|
+
* Returned when include_messages=true.
|
|
1155
|
+
*/
|
|
1156
|
+
interface ConversationDetail extends Conversation {
|
|
1157
|
+
/** Messages in the conversation */
|
|
1158
|
+
messages: Message[];
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* A single message within a conversation.
|
|
1162
|
+
*/
|
|
1163
|
+
interface Message {
|
|
1164
|
+
/** Unique message identifier (UUID) */
|
|
1165
|
+
id: string;
|
|
1166
|
+
/** Message role (user, assistant, system, or tool) */
|
|
1167
|
+
role: MessageRole;
|
|
1168
|
+
/** Message content text */
|
|
1169
|
+
content: string;
|
|
1170
|
+
/** Additional metadata key-value pairs */
|
|
1171
|
+
metadata?: Record<string, unknown>;
|
|
1172
|
+
/** Message sequence number within the conversation */
|
|
1173
|
+
sequence?: number;
|
|
1174
|
+
/** Timestamp when the message was created (ISO 8601) */
|
|
1175
|
+
created_at: string;
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Request payload for adding a message to a conversation.
|
|
1179
|
+
*
|
|
1180
|
+
* POST /conversations/:conversation_id/messages
|
|
1181
|
+
*/
|
|
1182
|
+
interface MessageCreate {
|
|
1183
|
+
/** Message role */
|
|
1184
|
+
role: MessageRole;
|
|
1185
|
+
/** Message content text (1-50000 characters) */
|
|
1186
|
+
content: string;
|
|
1187
|
+
/** Additional metadata key-value pairs */
|
|
1188
|
+
metadata?: Record<string, unknown>;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Paginated list of conversations.
|
|
1192
|
+
*
|
|
1193
|
+
* GET /conversations?user_id=...
|
|
1194
|
+
*/
|
|
1195
|
+
interface ConversationList {
|
|
1196
|
+
/** Array of conversation records */
|
|
1197
|
+
data: Conversation[];
|
|
1198
|
+
/** Pagination metadata */
|
|
1199
|
+
pagination: {
|
|
1200
|
+
/** Total number of conversations */
|
|
1201
|
+
total: number;
|
|
1202
|
+
/** Current page size limit */
|
|
1203
|
+
limit: number;
|
|
1204
|
+
/** Current offset */
|
|
1205
|
+
offset: number;
|
|
1206
|
+
/** Whether more results exist */
|
|
1207
|
+
has_more: boolean;
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Paginated list of messages within a conversation.
|
|
1212
|
+
*
|
|
1213
|
+
* GET /conversations/:conversation_id/messages
|
|
1214
|
+
*/
|
|
1215
|
+
interface MessageList {
|
|
1216
|
+
/** Array of message records */
|
|
1217
|
+
data: Message[];
|
|
1218
|
+
/** Whether more messages exist before the current page */
|
|
1219
|
+
has_more: boolean;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Auto-generated summary of a conversation.
|
|
1223
|
+
* Generated by Zep OSS temporal graph analysis.
|
|
1224
|
+
*
|
|
1225
|
+
* GET /conversations/:conversation_id/summary
|
|
1226
|
+
*/
|
|
1227
|
+
interface ConversationSummary {
|
|
1228
|
+
/** Conversation identifier (UUID) */
|
|
1229
|
+
conversation_id: string;
|
|
1230
|
+
/** Generated summary text */
|
|
1231
|
+
summary?: string;
|
|
1232
|
+
/** Key points extracted from the conversation */
|
|
1233
|
+
key_points?: string[];
|
|
1234
|
+
/** Timestamp when the summary was generated (ISO 8601) */
|
|
1235
|
+
generated_at: string;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* @module services/conversations
|
|
1240
|
+
* @description Conversation Service - Conversation history and auto-summary management.
|
|
1241
|
+
*
|
|
1242
|
+
* Wraps the Nexus Conversation API powered by Zep OSS. Supports
|
|
1243
|
+
* conversation lifecycle management, message operations, and
|
|
1244
|
+
* auto-generated summaries via temporal graph analysis.
|
|
1245
|
+
*
|
|
1246
|
+
* Based on Nexus API v2.0 - /conversations endpoints
|
|
1247
|
+
*/
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* Parameters for listing conversations with optional filtering and pagination.
|
|
1251
|
+
*/
|
|
1252
|
+
interface ConversationListParams {
|
|
1253
|
+
/** Filter conversations by user ID */
|
|
1254
|
+
user_id?: string;
|
|
1255
|
+
/** Maximum number of results per page */
|
|
1256
|
+
limit?: number;
|
|
1257
|
+
/** Offset for pagination */
|
|
1258
|
+
offset?: number;
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Parameters for listing messages within a conversation.
|
|
1262
|
+
*/
|
|
1263
|
+
interface MessageListParams {
|
|
1264
|
+
/** Maximum number of messages to return */
|
|
1265
|
+
limit?: number;
|
|
1266
|
+
/** Offset for pagination */
|
|
1267
|
+
offset?: number;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Service for managing conversations and messages via Zep OSS.
|
|
1271
|
+
*
|
|
1272
|
+
* Provides conversation lifecycle management (create, list, get, delete),
|
|
1273
|
+
* message operations (add, list), and access to auto-generated summaries
|
|
1274
|
+
* produced by Zep's temporal graph analysis.
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```typescript
|
|
1278
|
+
* const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
|
|
1279
|
+
*
|
|
1280
|
+
* // Create a conversation
|
|
1281
|
+
* const conv = await nexus.conversations.create({
|
|
1282
|
+
* user_id: 'user_42',
|
|
1283
|
+
* metadata: { topic: 'project planning' },
|
|
1284
|
+
* });
|
|
1285
|
+
*
|
|
1286
|
+
* // Add a message
|
|
1287
|
+
* await nexus.conversations.addMessage(conv.id, {
|
|
1288
|
+
* role: 'user',
|
|
1289
|
+
* content: 'Let us discuss the roadmap.',
|
|
1290
|
+
* });
|
|
1291
|
+
*
|
|
1292
|
+
* // Get auto-generated summary
|
|
1293
|
+
* const summary = await nexus.conversations.getSummary(conv.id);
|
|
1294
|
+
* ```
|
|
1295
|
+
*/
|
|
1296
|
+
declare class ConversationService extends BaseService {
|
|
1297
|
+
/**
|
|
1298
|
+
* Create a new conversation session.
|
|
1299
|
+
*
|
|
1300
|
+
* @param data - Conversation creation payload including user_id and optional metadata.
|
|
1301
|
+
* @returns The newly created conversation with generated ID and timestamps.
|
|
1302
|
+
*/
|
|
1303
|
+
create(data: ConversationCreate, options?: RequestOptions): Promise<Conversation>;
|
|
1304
|
+
/**
|
|
1305
|
+
* List conversations with optional filtering and pagination.
|
|
1306
|
+
*
|
|
1307
|
+
* @param params - Optional filters for user_id and pagination controls.
|
|
1308
|
+
* @returns Paginated list of conversation records.
|
|
1309
|
+
*/
|
|
1310
|
+
list(params?: ConversationListParams, options?: RequestOptions): Promise<ConversationList>;
|
|
1311
|
+
/**
|
|
1312
|
+
* Retrieve a conversation with its messages included.
|
|
1313
|
+
*
|
|
1314
|
+
* @param conversationId - UUID of the conversation to retrieve.
|
|
1315
|
+
* @returns Conversation detail including the full message list.
|
|
1316
|
+
* @throws {ApiError} 404 if the conversation does not exist.
|
|
1317
|
+
*/
|
|
1318
|
+
get(conversationId: string, options?: RequestOptions): Promise<ConversationDetail>;
|
|
1319
|
+
/**
|
|
1320
|
+
* Add a message to an existing conversation.
|
|
1321
|
+
*
|
|
1322
|
+
* The message is appended to the conversation's message sequence.
|
|
1323
|
+
* Zep will asynchronously update the conversation summary after
|
|
1324
|
+
* new messages are added.
|
|
1325
|
+
*
|
|
1326
|
+
* @param conversationId - UUID of the target conversation.
|
|
1327
|
+
* @param message - Message payload including role and content.
|
|
1328
|
+
* @returns The newly created message with generated ID and sequence number.
|
|
1329
|
+
* @throws {ApiError} 404 if the conversation does not exist.
|
|
1330
|
+
*/
|
|
1331
|
+
addMessage(conversationId: string, message: MessageCreate, options?: RequestOptions): Promise<Message>;
|
|
1332
|
+
/**
|
|
1333
|
+
* List messages within a conversation with optional pagination.
|
|
1334
|
+
*
|
|
1335
|
+
* Messages are returned in chronological order (oldest first).
|
|
1336
|
+
*
|
|
1337
|
+
* @param conversationId - UUID of the conversation.
|
|
1338
|
+
* @param params - Optional pagination controls (limit, offset).
|
|
1339
|
+
* @returns Paginated list of messages.
|
|
1340
|
+
* @throws {ApiError} 404 if the conversation does not exist.
|
|
1341
|
+
*/
|
|
1342
|
+
getMessages(conversationId: string, params?: MessageListParams, options?: RequestOptions): Promise<MessageList>;
|
|
1343
|
+
/**
|
|
1344
|
+
* Retrieve the auto-generated summary of a conversation.
|
|
1345
|
+
*
|
|
1346
|
+
* Summaries are produced by Zep OSS temporal graph analysis and
|
|
1347
|
+
* include key points extracted from the conversation history.
|
|
1348
|
+
*
|
|
1349
|
+
* @param conversationId - UUID of the conversation.
|
|
1350
|
+
* @returns The conversation summary with key points and generation timestamp.
|
|
1351
|
+
* @throws {ApiError} 404 if the conversation does not exist.
|
|
1352
|
+
*/
|
|
1353
|
+
getSummary(conversationId: string, options?: RequestOptions): Promise<ConversationSummary>;
|
|
1354
|
+
/**
|
|
1355
|
+
* Delete a conversation and all its messages.
|
|
1356
|
+
*
|
|
1357
|
+
* This operation is irreversible. The conversation, all associated
|
|
1358
|
+
* messages, and the generated summary will be permanently removed.
|
|
1359
|
+
*
|
|
1360
|
+
* @param conversationId - UUID of the conversation to delete.
|
|
1361
|
+
* @throws {ApiError} 404 if the conversation does not exist.
|
|
1362
|
+
*/
|
|
1363
|
+
delete(conversationId: string, options?: RequestOptions): Promise<void>;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* @nexusm/sdk - Knowledge Types
|
|
1368
|
+
*
|
|
1369
|
+
* Type definitions for the Knowledge Service powered by Fast GraphRAG.
|
|
1370
|
+
* Supports entity extraction, relationship mapping, and graph traversal queries.
|
|
1371
|
+
*
|
|
1372
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
1373
|
+
*/
|
|
1374
|
+
/**
|
|
1375
|
+
* A knowledge entity in the graph.
|
|
1376
|
+
* Represents a named concept, person, organization, or other entity.
|
|
1377
|
+
*/
|
|
1378
|
+
interface KnowledgeEntity {
|
|
1379
|
+
/** Unique entity identifier */
|
|
1380
|
+
entity_id: string;
|
|
1381
|
+
/** Entity display name */
|
|
1382
|
+
name: string;
|
|
1383
|
+
/** Entity type classification (e.g., Person, Organization, Concept) */
|
|
1384
|
+
entity_type: string;
|
|
1385
|
+
/** Entity description */
|
|
1386
|
+
description?: string;
|
|
1387
|
+
/** Additional entity properties */
|
|
1388
|
+
properties?: Record<string, unknown>;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* A relationship between two knowledge entities.
|
|
1392
|
+
* Follows the Triplex format: (Subject, Relation, Object).
|
|
1393
|
+
*/
|
|
1394
|
+
interface KnowledgeRelationship {
|
|
1395
|
+
/** Source entity name (Subject) */
|
|
1396
|
+
source: string;
|
|
1397
|
+
/** Target entity name (Object) */
|
|
1398
|
+
target: string;
|
|
1399
|
+
/** Relationship type label (Relation) */
|
|
1400
|
+
relationship_type: string;
|
|
1401
|
+
/** Additional relationship properties */
|
|
1402
|
+
properties?: Record<string, unknown>;
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Request payload for extracting entities and relationships from text.
|
|
1406
|
+
*
|
|
1407
|
+
* POST /knowledge/extract
|
|
1408
|
+
*/
|
|
1409
|
+
interface ExtractionRequest {
|
|
1410
|
+
/** Text to extract entities from (1-10000 characters) */
|
|
1411
|
+
text: string;
|
|
1412
|
+
/** Agent ID for public/shared knowledge (mutually exclusive with owner_user_id) */
|
|
1413
|
+
agent_id?: string;
|
|
1414
|
+
/** User ID for private knowledge/social graph (mutually exclusive with agent_id) */
|
|
1415
|
+
owner_user_id?: string;
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Response from entity extraction operation.
|
|
1419
|
+
*/
|
|
1420
|
+
interface ExtractionResult {
|
|
1421
|
+
/** Extracted entities */
|
|
1422
|
+
entities: KnowledgeEntity[];
|
|
1423
|
+
/** Extracted relationships in Triplex format */
|
|
1424
|
+
relationships: KnowledgeRelationship[];
|
|
1425
|
+
/** Number of new entities created */
|
|
1426
|
+
entities_created: number;
|
|
1427
|
+
/** Number of new relationships created */
|
|
1428
|
+
relationships_created: number;
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Paginated list of knowledge entities.
|
|
1432
|
+
*
|
|
1433
|
+
* GET /knowledge/entities?user_id=...
|
|
1434
|
+
*/
|
|
1435
|
+
interface EntityListResponse {
|
|
1436
|
+
/** Array of entity records */
|
|
1437
|
+
entities: KnowledgeEntity[];
|
|
1438
|
+
/** Total number of entities */
|
|
1439
|
+
total_count: number;
|
|
1440
|
+
/** Current page size limit */
|
|
1441
|
+
limit: number;
|
|
1442
|
+
/** Current offset */
|
|
1443
|
+
offset: number;
|
|
1444
|
+
/** Whether more results exist */
|
|
1445
|
+
has_next: boolean;
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Request payload for querying the knowledge graph.
|
|
1449
|
+
* Uses BFS traversal from a starting entity.
|
|
1450
|
+
*
|
|
1451
|
+
* POST /knowledge/query
|
|
1452
|
+
*/
|
|
1453
|
+
interface GraphQueryRequest {
|
|
1454
|
+
/** Starting entity name for graph traversal */
|
|
1455
|
+
entity_name: string;
|
|
1456
|
+
/**
|
|
1457
|
+
* Maximum traversal depth from the starting entity.
|
|
1458
|
+
* @default 1
|
|
1459
|
+
* @minimum 1
|
|
1460
|
+
* @maximum 3
|
|
1461
|
+
*/
|
|
1462
|
+
depth?: number;
|
|
1463
|
+
/** Filter by specific relationship types (optional) */
|
|
1464
|
+
relationship_types?: string[];
|
|
1465
|
+
}
|
|
1466
|
+
/** Entity reference within a graph path */
|
|
1467
|
+
interface GraphPathEntity {
|
|
1468
|
+
/** Entity identifier */
|
|
1469
|
+
entity_id: string;
|
|
1470
|
+
/** Entity display name */
|
|
1471
|
+
name: string;
|
|
1472
|
+
/** Entity type classification */
|
|
1473
|
+
type: string;
|
|
1474
|
+
}
|
|
1475
|
+
/** Relationship reference within a graph path */
|
|
1476
|
+
interface GraphPathRelationship {
|
|
1477
|
+
/** Relationship identifier */
|
|
1478
|
+
relationship_id: string;
|
|
1479
|
+
/** Relationship type label */
|
|
1480
|
+
type: string;
|
|
1481
|
+
}
|
|
1482
|
+
/** A single traversal path in the graph query result */
|
|
1483
|
+
interface GraphPath {
|
|
1484
|
+
/** Depth of this path from the starting entity */
|
|
1485
|
+
depth: number;
|
|
1486
|
+
/** Entities along this path */
|
|
1487
|
+
entities: GraphPathEntity[];
|
|
1488
|
+
/** Relationships along this path */
|
|
1489
|
+
relationships: GraphPathRelationship[];
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Response from a graph query operation.
|
|
1493
|
+
*/
|
|
1494
|
+
interface GraphQueryResponse {
|
|
1495
|
+
/** The starting entity (null if not found) */
|
|
1496
|
+
start_entity: GraphPathEntity | null;
|
|
1497
|
+
/** Traversal paths from the starting entity */
|
|
1498
|
+
paths: GraphPath[];
|
|
1499
|
+
/** Total number of paths found */
|
|
1500
|
+
total_paths: number;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* @module services/knowledge
|
|
1505
|
+
* @description Knowledge Service - Knowledge graph construction and query.
|
|
1506
|
+
*
|
|
1507
|
+
* Wraps the Nexus Knowledge API powered by Fast GraphRAG. Supports
|
|
1508
|
+
* entity management, graph traversal queries (BFS), and automatic
|
|
1509
|
+
* entity/relationship extraction from unstructured text.
|
|
1510
|
+
*
|
|
1511
|
+
* Based on Nexus API v2.0 - /knowledge endpoints
|
|
1512
|
+
*/
|
|
1513
|
+
|
|
1514
|
+
/**
|
|
1515
|
+
* Request payload for creating a new knowledge entity.
|
|
1516
|
+
*
|
|
1517
|
+
* POST /knowledge/entities
|
|
1518
|
+
*/
|
|
1519
|
+
interface EntityCreate {
|
|
1520
|
+
/** Entity display name */
|
|
1521
|
+
name: string;
|
|
1522
|
+
/** Entity type classification (e.g., Person, Organization, Concept) */
|
|
1523
|
+
entity_type: string;
|
|
1524
|
+
/** Entity description */
|
|
1525
|
+
description?: string;
|
|
1526
|
+
/** Additional entity properties */
|
|
1527
|
+
properties?: Record<string, unknown>;
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Parameters for listing knowledge entities with optional filtering.
|
|
1531
|
+
*/
|
|
1532
|
+
interface EntityListParams {
|
|
1533
|
+
/** Filter entities by user ID (owner) */
|
|
1534
|
+
user_id?: string;
|
|
1535
|
+
/** Filter by entity type classification */
|
|
1536
|
+
entity_type?: string;
|
|
1537
|
+
/** Maximum number of results to return */
|
|
1538
|
+
limit?: number;
|
|
1539
|
+
/** Offset for pagination */
|
|
1540
|
+
offset?: number;
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Service for managing the knowledge graph via Fast GraphRAG.
|
|
1544
|
+
*
|
|
1545
|
+
* Provides entity CRUD, BFS graph traversal queries, and automatic
|
|
1546
|
+
* entity/relationship extraction from unstructured text. Supports
|
|
1547
|
+
* both public (agent-owned) and private (user-owned) knowledge.
|
|
1548
|
+
*
|
|
1549
|
+
* @example
|
|
1550
|
+
* ```typescript
|
|
1551
|
+
* const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
|
|
1552
|
+
*
|
|
1553
|
+
* // Extract entities from text
|
|
1554
|
+
* const extraction = await nexus.knowledge.extract({
|
|
1555
|
+
* text: 'Alice works at Acme Corp on the Phoenix project.',
|
|
1556
|
+
* owner_user_id: 'user_42',
|
|
1557
|
+
* });
|
|
1558
|
+
*
|
|
1559
|
+
* // Query the graph
|
|
1560
|
+
* const graph = await nexus.knowledge.query({
|
|
1561
|
+
* entity_name: 'Alice',
|
|
1562
|
+
* depth: 2,
|
|
1563
|
+
* });
|
|
1564
|
+
*
|
|
1565
|
+
* console.log(graph.paths);
|
|
1566
|
+
* ```
|
|
1567
|
+
*/
|
|
1568
|
+
declare class KnowledgeService extends BaseService {
|
|
1569
|
+
/**
|
|
1570
|
+
* Create a new knowledge entity in the graph.
|
|
1571
|
+
*
|
|
1572
|
+
* @param data - Entity creation payload including name, type, and optional description/properties.
|
|
1573
|
+
* @returns The newly created entity with generated entity_id.
|
|
1574
|
+
*/
|
|
1575
|
+
createEntity(data: EntityCreate, options?: RequestOptions): Promise<KnowledgeEntity>;
|
|
1576
|
+
/**
|
|
1577
|
+
* List knowledge entities with optional filtering.
|
|
1578
|
+
*
|
|
1579
|
+
* @param params - Optional filters for user_id, entity_type, and pagination controls.
|
|
1580
|
+
* @returns Paginated list of knowledge entities.
|
|
1581
|
+
*/
|
|
1582
|
+
listEntities(params?: EntityListParams, options?: RequestOptions): Promise<EntityListResponse>;
|
|
1583
|
+
/**
|
|
1584
|
+
* Query the knowledge graph using BFS traversal.
|
|
1585
|
+
*
|
|
1586
|
+
* Starts from a named entity and traverses outward up to the specified
|
|
1587
|
+
* depth, collecting all reachable entities and relationships along
|
|
1588
|
+
* the traversal paths.
|
|
1589
|
+
*
|
|
1590
|
+
* @param request - Graph query parameters including starting entity name, depth, and optional relationship type filters.
|
|
1591
|
+
* @returns Graph query response with the start entity, traversal paths, and total path count.
|
|
1592
|
+
*/
|
|
1593
|
+
query(request: GraphQueryRequest, options?: RequestOptions): Promise<GraphQueryResponse>;
|
|
1594
|
+
/**
|
|
1595
|
+
* Extract entities and relationships from unstructured text.
|
|
1596
|
+
*
|
|
1597
|
+
* Uses Fast GraphRAG's NLP pipeline to identify named entities and
|
|
1598
|
+
* their relationships in Triplex format (Subject, Relation, Object).
|
|
1599
|
+
* Extracted items are automatically persisted to the knowledge graph.
|
|
1600
|
+
*
|
|
1601
|
+
* @param request - Extraction request including the source text and ownership (agent_id or owner_user_id).
|
|
1602
|
+
* @returns Extraction result with lists of created entities and relationships.
|
|
1603
|
+
*/
|
|
1604
|
+
extract(request: ExtractionRequest, options?: RequestOptions): Promise<ExtractionResult>;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* @nexusm/sdk - Activity Types
|
|
1609
|
+
*
|
|
1610
|
+
* Type definitions for the Activity Service (US-013 DX Enhancement).
|
|
1611
|
+
* Supports passive activity stream ingestion from AI Agents,
|
|
1612
|
+
* which are asynchronously converted into semantic memories.
|
|
1613
|
+
*
|
|
1614
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
1615
|
+
*/
|
|
1616
|
+
/**
|
|
1617
|
+
* Supported activity action types for the activity stream.
|
|
1618
|
+
* AI Agents report these actions to build passive memory.
|
|
1619
|
+
*/
|
|
1620
|
+
type ActivityType = 'edit_file' | 'run_test' | 'api_call' | 'user_message' | 'agent_action' | 'read_file' | 'delete_file' | 'create_file' | 'commit' | 'command_run' | 'other';
|
|
1621
|
+
/**
|
|
1622
|
+
* A single activity event reported by an AI Agent.
|
|
1623
|
+
*/
|
|
1624
|
+
interface Activity {
|
|
1625
|
+
/** Activity action type */
|
|
1626
|
+
action: ActivityType;
|
|
1627
|
+
/** Timestamp when the activity occurred (ISO 8601) */
|
|
1628
|
+
timestamp?: string;
|
|
1629
|
+
/** Optional session identifier for activity grouping */
|
|
1630
|
+
session_id?: string;
|
|
1631
|
+
/** Additional activity context (file path, test name, etc.) */
|
|
1632
|
+
activity_data?: Record<string, unknown>;
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Request payload for batch activity stream ingestion.
|
|
1636
|
+
* Accepts up to 1000 activities per request.
|
|
1637
|
+
*
|
|
1638
|
+
* POST /activities/stream
|
|
1639
|
+
*/
|
|
1640
|
+
interface ActivityStreamRequest {
|
|
1641
|
+
/** Agent identifier reporting the activities */
|
|
1642
|
+
agent_id: string;
|
|
1643
|
+
/** Batch of activity events (1-1000 items) */
|
|
1644
|
+
activities: Activity[];
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Response from activity stream ingestion.
|
|
1648
|
+
*/
|
|
1649
|
+
interface ActivityStreamResponse {
|
|
1650
|
+
/** Number of activities accepted for processing */
|
|
1651
|
+
accepted: number;
|
|
1652
|
+
/** Number of activities immediately processed */
|
|
1653
|
+
processed: number;
|
|
1654
|
+
/** Number of activities queued for background processing */
|
|
1655
|
+
queued: number;
|
|
1656
|
+
/** Request ID for tracking processing status */
|
|
1657
|
+
request_id: string;
|
|
1658
|
+
}
|
|
1659
|
+
/** Processing status of a batch activity request */
|
|
1660
|
+
type ActivityProcessingStatus = 'pending' | 'processing' | 'completed' | 'failed';
|
|
1661
|
+
/**
|
|
1662
|
+
* Status of a previously submitted activity stream request.
|
|
1663
|
+
*
|
|
1664
|
+
* GET /activities/status/:request_id
|
|
1665
|
+
*/
|
|
1666
|
+
interface ActivityStatusResponse {
|
|
1667
|
+
/** Request ID from the original stream submission */
|
|
1668
|
+
request_id: string;
|
|
1669
|
+
/** Current processing status */
|
|
1670
|
+
status: ActivityProcessingStatus;
|
|
1671
|
+
/** Number of activities accepted */
|
|
1672
|
+
accepted: number;
|
|
1673
|
+
/** Number of activities processed so far */
|
|
1674
|
+
processed: number;
|
|
1675
|
+
/** Number of activities still queued */
|
|
1676
|
+
queued: number;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Activity statistics for the current tenant.
|
|
1680
|
+
*
|
|
1681
|
+
* GET /activities/stats
|
|
1682
|
+
*/
|
|
1683
|
+
interface ActivityStats {
|
|
1684
|
+
/** Tenant identifier */
|
|
1685
|
+
tenant_id: string;
|
|
1686
|
+
/** Total number of activities ingested */
|
|
1687
|
+
total_activities: number;
|
|
1688
|
+
/** Number of activities that have been processed */
|
|
1689
|
+
processed_activities: number;
|
|
1690
|
+
/** Number of activities pending processing */
|
|
1691
|
+
pending_activities: number;
|
|
1692
|
+
/** Number of activities in the last 24 hours */
|
|
1693
|
+
recent_activities_24h: number;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* @module services/activities
|
|
1698
|
+
* @description Activity stream service for passive memory ingestion.
|
|
1699
|
+
*
|
|
1700
|
+
* AI Agents report their actions (file edits, test runs, API calls, etc.)
|
|
1701
|
+
* through the activity stream. These activities are asynchronously converted
|
|
1702
|
+
* into semantic memories by the Nexus backend (Arq workers).
|
|
1703
|
+
*
|
|
1704
|
+
* @see {@link https://docs.nexus.10cg.pub/api/activities | Activity API Reference}
|
|
1705
|
+
*/
|
|
1706
|
+
|
|
1707
|
+
/**
|
|
1708
|
+
* Service for ingesting activity streams from AI Agents.
|
|
1709
|
+
*
|
|
1710
|
+
* Activities are the primary mechanism for **passive memory** collection:
|
|
1711
|
+
* agents report what they do, and Nexus converts those actions into
|
|
1712
|
+
* searchable, contextual memories in the background.
|
|
1713
|
+
*
|
|
1714
|
+
* @example
|
|
1715
|
+
* ```typescript
|
|
1716
|
+
* const nexus = new NexusClient({ apiKey: 'nx_live_...' });
|
|
1717
|
+
*
|
|
1718
|
+
* // Log a single activity
|
|
1719
|
+
* await nexus.activities.log({
|
|
1720
|
+
* action: 'edit_file',
|
|
1721
|
+
* activity_data: { path: 'src/index.ts', lines_changed: 42 },
|
|
1722
|
+
* });
|
|
1723
|
+
*
|
|
1724
|
+
* // Batch-ingest multiple activities
|
|
1725
|
+
* await nexus.activities.stream({
|
|
1726
|
+
* agent_id: 'cursor-agent',
|
|
1727
|
+
* activities: [
|
|
1728
|
+
* { action: 'read_file', activity_data: { path: 'README.md' } },
|
|
1729
|
+
* { action: 'edit_file', activity_data: { path: 'src/app.ts' } },
|
|
1730
|
+
* ],
|
|
1731
|
+
* });
|
|
1732
|
+
* ```
|
|
1733
|
+
*/
|
|
1734
|
+
declare class ActivityService extends BaseService {
|
|
1735
|
+
/**
|
|
1736
|
+
* Batch-ingest an activity stream.
|
|
1737
|
+
*
|
|
1738
|
+
* Accepts up to 1000 activities per request. Activities are queued for
|
|
1739
|
+
* asynchronous processing by Arq workers on the Nexus backend.
|
|
1740
|
+
*
|
|
1741
|
+
* @param request - The activity stream payload containing agent ID and activities.
|
|
1742
|
+
* @returns Processing summary with accepted / processed / queued counts.
|
|
1743
|
+
*/
|
|
1744
|
+
stream(request: ActivityStreamRequest, options?: RequestOptions): Promise<ActivityStreamResponse>;
|
|
1745
|
+
/**
|
|
1746
|
+
* Convenience method to log a single activity.
|
|
1747
|
+
*
|
|
1748
|
+
* Wraps {@link stream} for the common case of reporting one event at a time.
|
|
1749
|
+
*
|
|
1750
|
+
* @param activity - The activity event to record.
|
|
1751
|
+
* @param agentId - Agent identifier (defaults to `'default'`).
|
|
1752
|
+
* @returns Processing summary with accepted / processed / queued counts.
|
|
1753
|
+
*/
|
|
1754
|
+
log(activity: Activity, agentId?: string, options?: RequestOptions): Promise<ActivityStreamResponse>;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* @nexusm/sdk - Tenant Types
|
|
1759
|
+
*
|
|
1760
|
+
* Type definitions for the Tenant management service.
|
|
1761
|
+
* Supports multi-tenant isolation, API key management,
|
|
1762
|
+
* quota tracking, and usage statistics.
|
|
1763
|
+
*
|
|
1764
|
+
* Based on Nexus API v2.0 OpenAPI specification.
|
|
1765
|
+
*/
|
|
1766
|
+
/** Available tenant subscription tiers */
|
|
1767
|
+
type TenantTier = 'free' | 'starter' | 'pro' | 'enterprise';
|
|
1768
|
+
/** API Key permission scopes */
|
|
1769
|
+
type ApiKeyScope = 'read' | 'write' | 'admin';
|
|
1770
|
+
/**
|
|
1771
|
+
* Tenant quotas configuration defining resource limits.
|
|
1772
|
+
*/
|
|
1773
|
+
interface TenantQuotas {
|
|
1774
|
+
/** Maximum number of memories allowed */
|
|
1775
|
+
max_memories?: number;
|
|
1776
|
+
/** Maximum number of conversations allowed */
|
|
1777
|
+
max_conversations?: number;
|
|
1778
|
+
/** Maximum API calls per day */
|
|
1779
|
+
max_api_calls_per_day?: number;
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Current resource usage counts for a tenant.
|
|
1783
|
+
*/
|
|
1784
|
+
interface TenantUsage {
|
|
1785
|
+
/** Current number of memories stored */
|
|
1786
|
+
memories_count?: number;
|
|
1787
|
+
/** Current number of conversations */
|
|
1788
|
+
conversations_count?: number;
|
|
1789
|
+
/** API calls made today */
|
|
1790
|
+
api_calls_today?: number;
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* A tenant (organization) on the Nexus platform.
|
|
1794
|
+
* Each tenant has isolated data and configurable quotas.
|
|
1795
|
+
*
|
|
1796
|
+
* GET /tenants/me
|
|
1797
|
+
*/
|
|
1798
|
+
interface Tenant {
|
|
1799
|
+
/** Unique tenant identifier (UUID) */
|
|
1800
|
+
id: string;
|
|
1801
|
+
/** Tenant display name */
|
|
1802
|
+
name: string;
|
|
1803
|
+
/** Subscription tier */
|
|
1804
|
+
tier: TenantTier;
|
|
1805
|
+
/** Resource quotas */
|
|
1806
|
+
quotas?: TenantQuotas;
|
|
1807
|
+
/** Current resource usage */
|
|
1808
|
+
usage?: TenantUsage;
|
|
1809
|
+
/** Timestamp when the tenant was created (ISO 8601) */
|
|
1810
|
+
created_at: string;
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* An API key for authenticating with the Nexus platform.
|
|
1814
|
+
* The full key value is only returned once at creation time.
|
|
1815
|
+
*
|
|
1816
|
+
* GET /tenants/me/api-keys
|
|
1817
|
+
*/
|
|
1818
|
+
interface ApiKey {
|
|
1819
|
+
/** Unique API key identifier (UUID) */
|
|
1820
|
+
id: string;
|
|
1821
|
+
/** API key prefix for identification (e.g., "nx_live_...abc123") */
|
|
1822
|
+
key_prefix: string;
|
|
1823
|
+
/** Human-readable name for the API key */
|
|
1824
|
+
name: string;
|
|
1825
|
+
/** Permission scopes granted to this key */
|
|
1826
|
+
scopes: ApiKeyScope[];
|
|
1827
|
+
/** Expiration timestamp (null = never expires) (ISO 8601) */
|
|
1828
|
+
expires_at?: string | null;
|
|
1829
|
+
/** Last time this key was used (ISO 8601) */
|
|
1830
|
+
last_used_at?: string | null;
|
|
1831
|
+
/** Timestamp when the key was created (ISO 8601) */
|
|
1832
|
+
created_at: string;
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Request payload for creating a new API key.
|
|
1836
|
+
*
|
|
1837
|
+
* POST /tenants/me/api-keys
|
|
1838
|
+
*/
|
|
1839
|
+
interface ApiKeyCreate {
|
|
1840
|
+
/** Human-readable name for the API key (1-100 characters) */
|
|
1841
|
+
name: string;
|
|
1842
|
+
/**
|
|
1843
|
+
* Permission scopes for the key.
|
|
1844
|
+
* @default ["read", "write"]
|
|
1845
|
+
*/
|
|
1846
|
+
scopes?: ApiKeyScope[];
|
|
1847
|
+
/**
|
|
1848
|
+
* Number of days until the key expires.
|
|
1849
|
+
* Omit for a key that never expires.
|
|
1850
|
+
* @minimum 1
|
|
1851
|
+
* @maximum 365
|
|
1852
|
+
*/
|
|
1853
|
+
expires_days?: number;
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Response from creating a new API key.
|
|
1857
|
+
* Contains the full key value which is only shown once.
|
|
1858
|
+
*/
|
|
1859
|
+
interface ApiKeyCreated extends ApiKey {
|
|
1860
|
+
/**
|
|
1861
|
+
* Full API key value.
|
|
1862
|
+
* Format: nx_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
1863
|
+
* WARNING: This value is only returned once at creation time.
|
|
1864
|
+
*/
|
|
1865
|
+
key: string;
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Usage statistics for a tenant over a specific time period.
|
|
1869
|
+
*
|
|
1870
|
+
* GET /tenants/me/usage
|
|
1871
|
+
*/
|
|
1872
|
+
interface UsageStats {
|
|
1873
|
+
/** Time period for the statistics */
|
|
1874
|
+
period: 'day' | 'week' | 'month';
|
|
1875
|
+
/** Total API calls in the period */
|
|
1876
|
+
api_calls: number;
|
|
1877
|
+
/** Total tokens consumed */
|
|
1878
|
+
tokens_used?: number;
|
|
1879
|
+
/** Number of memories created in the period */
|
|
1880
|
+
memories_created?: number;
|
|
1881
|
+
/** Number of conversations created in the period */
|
|
1882
|
+
conversations_created?: number;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* @module services/tenants
|
|
1887
|
+
* @description Tenant management service for the Nexus platform.
|
|
1888
|
+
*
|
|
1889
|
+
* Provides access to the current tenant's profile, quota configuration,
|
|
1890
|
+
* and usage statistics. Tenant identity is derived from the API key
|
|
1891
|
+
* used to authenticate requests.
|
|
1892
|
+
*
|
|
1893
|
+
* @see {@link https://docs.nexus.10cg.pub/api/tenants | Tenant API Reference}
|
|
1894
|
+
*/
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* Service for managing the current tenant's profile and usage.
|
|
1898
|
+
*
|
|
1899
|
+
* The tenant is automatically identified by the API key provided
|
|
1900
|
+
* to the {@link NexusClient}. All methods operate on the
|
|
1901
|
+
* authenticated tenant's data.
|
|
1902
|
+
*
|
|
1903
|
+
* @example
|
|
1904
|
+
* ```typescript
|
|
1905
|
+
* const nexus = new NexusClient({ apiKey: 'nx_live_...' });
|
|
1906
|
+
*
|
|
1907
|
+
* // Get tenant profile
|
|
1908
|
+
* const tenant = await nexus.tenants.me();
|
|
1909
|
+
* console.log(`Tenant: ${tenant.name} (${tenant.tier})`);
|
|
1910
|
+
*
|
|
1911
|
+
* // Check resource usage
|
|
1912
|
+
* const usage = await nexus.tenants.usage();
|
|
1913
|
+
* console.log(`Memories: ${usage.memories_count}`);
|
|
1914
|
+
* ```
|
|
1915
|
+
*/
|
|
1916
|
+
declare class TenantService extends BaseService {
|
|
1917
|
+
/**
|
|
1918
|
+
* Retrieve the current tenant's profile.
|
|
1919
|
+
*
|
|
1920
|
+
* Returns the tenant record associated with the API key,
|
|
1921
|
+
* including name, tier, quotas, and current usage snapshot.
|
|
1922
|
+
*
|
|
1923
|
+
* @returns The authenticated tenant's profile.
|
|
1924
|
+
*/
|
|
1925
|
+
me(options?: RequestOptions): Promise<Tenant>;
|
|
1926
|
+
/**
|
|
1927
|
+
* Retrieve the current tenant's resource usage statistics.
|
|
1928
|
+
*
|
|
1929
|
+
* Returns counts for memories, conversations, and today's API calls.
|
|
1930
|
+
* Useful for monitoring quota consumption and building dashboards.
|
|
1931
|
+
*
|
|
1932
|
+
* @returns Current resource usage for the authenticated tenant.
|
|
1933
|
+
*/
|
|
1934
|
+
usage(options?: RequestOptions): Promise<TenantUsage>;
|
|
1935
|
+
/**
|
|
1936
|
+
* List all API keys for the current tenant.
|
|
1937
|
+
*
|
|
1938
|
+
* @returns Array of API key records (without full key values).
|
|
1939
|
+
*/
|
|
1940
|
+
listApiKeys(options?: RequestOptions): Promise<ApiKey[]>;
|
|
1941
|
+
/**
|
|
1942
|
+
* Create a new API key for the current tenant.
|
|
1943
|
+
*
|
|
1944
|
+
* @param data - API key creation parameters (name, scopes, expiry).
|
|
1945
|
+
* @returns The newly created API key, including the full key value (shown only once).
|
|
1946
|
+
*/
|
|
1947
|
+
createApiKey(data: ApiKeyCreate, options?: RequestOptions): Promise<ApiKeyCreated>;
|
|
1948
|
+
/**
|
|
1949
|
+
* Revoke (delete) an API key.
|
|
1950
|
+
*
|
|
1951
|
+
* @param id - The UUID of the API key to revoke.
|
|
1952
|
+
*/
|
|
1953
|
+
revokeApiKey(id: string, options?: RequestOptions): Promise<void>;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
/**
|
|
1957
|
+
* @module types/feedback
|
|
1958
|
+
* @description Feedback Service type definitions.
|
|
1959
|
+
*
|
|
1960
|
+
* Mirrors the Nexus API v5.0 Feedback Loop schema:
|
|
1961
|
+
* - PUT /v1/feedback/{retrieve_id} — submit rating + item-level feedback
|
|
1962
|
+
* - GET /v1/feedback — list feedback records
|
|
1963
|
+
*/
|
|
1964
|
+
/**
|
|
1965
|
+
* Per-memory-item feedback within a single feedback submission.
|
|
1966
|
+
*/
|
|
1967
|
+
interface FeedbackItemRequest {
|
|
1968
|
+
/** The memory that is being rated. */
|
|
1969
|
+
memory_id: string;
|
|
1970
|
+
/** Whether the memory item was useful in the retrieved context. */
|
|
1971
|
+
useful: boolean;
|
|
1972
|
+
/** Optional free-text explanation. */
|
|
1973
|
+
reason?: string;
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Request body for PUT /v1/feedback/{retrieve_id}.
|
|
1977
|
+
*/
|
|
1978
|
+
interface FeedbackSubmitRequest {
|
|
1979
|
+
/** Overall quality rating for the context retrieval, 1 (poor) – 5 (excellent). */
|
|
1980
|
+
rating: number;
|
|
1981
|
+
/** Optional per-item ratings for individual memories in the response. */
|
|
1982
|
+
item_feedback?: FeedbackItemRequest[];
|
|
1983
|
+
/** Free-text description of expected information that was missing. */
|
|
1984
|
+
expected_missing?: string;
|
|
1985
|
+
/** Arbitrary caller-supplied context data stored alongside the feedback. */
|
|
1986
|
+
context?: Record<string, unknown>;
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Response from PUT /v1/feedback/{retrieve_id} (HTTP 202 Accepted).
|
|
1990
|
+
*/
|
|
1991
|
+
interface FeedbackResponse {
|
|
1992
|
+
/** Unique identifier for the created feedback record. */
|
|
1993
|
+
feedback_id: string;
|
|
1994
|
+
/** The retrieve_id the feedback is associated with. */
|
|
1995
|
+
retrieve_id: string;
|
|
1996
|
+
/** Processing status — always "accepted" on success. */
|
|
1997
|
+
status: string;
|
|
1998
|
+
/** ISO 8601 timestamp of when the feedback was recorded. */
|
|
1999
|
+
created_at: string;
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* A single feedback record returned by GET /v1/feedback.
|
|
2003
|
+
*/
|
|
2004
|
+
interface FeedbackListItem {
|
|
2005
|
+
/** Unique identifier for this feedback record. */
|
|
2006
|
+
feedback_id: string;
|
|
2007
|
+
/** The retrieve_id the feedback is associated with. */
|
|
2008
|
+
retrieve_id: string;
|
|
2009
|
+
/** The user who submitted the feedback. */
|
|
2010
|
+
user_id: string;
|
|
2011
|
+
/** Overall quality rating (1–5), or null if not provided. */
|
|
2012
|
+
rating: number | null;
|
|
2013
|
+
/** Free-text description of expected missing information, if provided. */
|
|
2014
|
+
expected_missing: string | null;
|
|
2015
|
+
/** Diagnosis type assigned by the quality scoring pipeline, if any. */
|
|
2016
|
+
diagnosis_type: string | null;
|
|
2017
|
+
/** Caller-supplied context data stored with the feedback. */
|
|
2018
|
+
context_data: Record<string, unknown>;
|
|
2019
|
+
/** ISO 8601 timestamp of when the feedback was recorded. */
|
|
2020
|
+
created_at: string;
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
2023
|
+
* Response from GET /v1/feedback (HTTP 200).
|
|
2024
|
+
*/
|
|
2025
|
+
interface FeedbackListResponse {
|
|
2026
|
+
/** The feedback records for the requested page. */
|
|
2027
|
+
feedbacks: FeedbackListItem[];
|
|
2028
|
+
/** Total number of feedback records matching the query (for pagination). */
|
|
2029
|
+
total_count: number;
|
|
2030
|
+
/** Maximum number of records per page as applied by the backend. */
|
|
2031
|
+
limit: number;
|
|
2032
|
+
/** Zero-based offset of the first record in this page. */
|
|
2033
|
+
offset: number;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
/**
|
|
2037
|
+
* @module services/feedback
|
|
2038
|
+
* @description Feedback Service — submit and query context-retrieval feedback.
|
|
2039
|
+
*
|
|
2040
|
+
* Wraps the Nexus Feedback Loop API (v5.0):
|
|
2041
|
+
* - PUT /v1/feedback/{retrieve_id} — submit an explicit rating (L2 signal)
|
|
2042
|
+
* - GET /v1/feedback — list feedback records for reporting
|
|
2043
|
+
*
|
|
2044
|
+
* The `retrieve_id` in each submission links back to a prior
|
|
2045
|
+
* `/context/retrieve` response, enabling the quality scoring pipeline to
|
|
2046
|
+
* correlate explicit feedback with L0 telemetry.
|
|
2047
|
+
*
|
|
2048
|
+
* @example
|
|
2049
|
+
* ```typescript
|
|
2050
|
+
* const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
|
|
2051
|
+
*
|
|
2052
|
+
* // Submit feedback after a context retrieval
|
|
2053
|
+
* const result = await nexus.feedback.submit('retrieve-uuid', {
|
|
2054
|
+
* rating: 4,
|
|
2055
|
+
* item_feedback: [{ memory_id: 'mem-uuid', useful: true }],
|
|
2056
|
+
* });
|
|
2057
|
+
*
|
|
2058
|
+
* // List recent feedback
|
|
2059
|
+
* const list = await nexus.feedback.list({ user_id: 'user_42', limit: 20 });
|
|
2060
|
+
* ```
|
|
2061
|
+
*/
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Query parameters for listing feedback records.
|
|
2065
|
+
*/
|
|
2066
|
+
interface FeedbackListParams {
|
|
2067
|
+
/** Filter feedback records by user ID. */
|
|
2068
|
+
user_id?: string;
|
|
2069
|
+
/** Maximum number of records to return. */
|
|
2070
|
+
limit?: number;
|
|
2071
|
+
/** Zero-based offset for pagination. */
|
|
2072
|
+
offset?: number;
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Service for submitting and querying context-retrieval feedback.
|
|
2076
|
+
*
|
|
2077
|
+
* Exposes the Nexus Feedback Loop v5.0 endpoints. Feedback submissions
|
|
2078
|
+
* are processed asynchronously by the QualityScoreWorker and feed into
|
|
2079
|
+
* memory re-ranking.
|
|
2080
|
+
*/
|
|
2081
|
+
declare class FeedbackService extends BaseService {
|
|
2082
|
+
/**
|
|
2083
|
+
* Submit explicit feedback for a prior context retrieval (L2 signal).
|
|
2084
|
+
*
|
|
2085
|
+
* The backend accepts the submission immediately (HTTP 202) and processes
|
|
2086
|
+
* quality scoring asynchronously via QualityScoreWorker.
|
|
2087
|
+
*
|
|
2088
|
+
* @param retrieveId - The `retrieve_id` returned by `/context/retrieve`.
|
|
2089
|
+
* @param data - Rating and optional per-item feedback.
|
|
2090
|
+
* @param options - Optional request options (e.g. AbortSignal).
|
|
2091
|
+
* @returns The created feedback record metadata.
|
|
2092
|
+
*/
|
|
2093
|
+
submit(retrieveId: string, data: FeedbackSubmitRequest, options?: RequestOptions): Promise<FeedbackResponse>;
|
|
2094
|
+
/**
|
|
2095
|
+
* List feedback records with optional filtering and pagination.
|
|
2096
|
+
*
|
|
2097
|
+
* @param params - Optional filters: `user_id`, `limit`, `offset`.
|
|
2098
|
+
* @param options - Optional request options (e.g. AbortSignal).
|
|
2099
|
+
* @returns Paginated list of feedback records.
|
|
2100
|
+
*/
|
|
2101
|
+
list(params?: FeedbackListParams, options?: RequestOptions): Promise<FeedbackListResponse>;
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
/**
|
|
2105
|
+
* @module types/error
|
|
2106
|
+
* @description Type definitions for the Error Reporting API (US-031).
|
|
2107
|
+
*/
|
|
2108
|
+
/** Error type classification. */
|
|
2109
|
+
type ErrorType = 'api_error' | 'data_inconsistency' | 'performance' | 'other';
|
|
2110
|
+
/** Severity level of the error. */
|
|
2111
|
+
type ErrorSeverity = 'critical' | 'major' | 'minor';
|
|
2112
|
+
/** Request body for POST /v1/errors. */
|
|
2113
|
+
interface ErrorReportRequest {
|
|
2114
|
+
/** Type of error being reported. */
|
|
2115
|
+
error_type: ErrorType;
|
|
2116
|
+
/** Severity level of the error. */
|
|
2117
|
+
severity: ErrorSeverity;
|
|
2118
|
+
/** Detailed description of the error. */
|
|
2119
|
+
description: string;
|
|
2120
|
+
/** Optional: associated retrieve request ID. */
|
|
2121
|
+
retrieve_id?: string;
|
|
2122
|
+
/** SDK auto-collected request context. */
|
|
2123
|
+
request_context?: Record<string, unknown>;
|
|
2124
|
+
/** Steps to reproduce the error. */
|
|
2125
|
+
reproduction_steps?: string;
|
|
2126
|
+
/** Environment information (PII will be filtered server-side). */
|
|
2127
|
+
environment?: Record<string, unknown>;
|
|
2128
|
+
}
|
|
2129
|
+
/** Response from POST /v1/errors. */
|
|
2130
|
+
interface ErrorReportResponse {
|
|
2131
|
+
/** Error report ID. */
|
|
2132
|
+
id: string;
|
|
2133
|
+
/** Deduplication fingerprint. */
|
|
2134
|
+
fingerprint: string;
|
|
2135
|
+
/** Number of times this error has been reported. */
|
|
2136
|
+
occurrence_count: number;
|
|
2137
|
+
/** Whether this is a new error vs an existing one incremented. */
|
|
2138
|
+
is_new: boolean;
|
|
2139
|
+
/** When the error was first reported. */
|
|
2140
|
+
created_at: string;
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
/**
|
|
2144
|
+
* @module services/errors
|
|
2145
|
+
* @description Error Reporting Service — submit structured error reports.
|
|
2146
|
+
*
|
|
2147
|
+
* Wraps the Nexus Error Reporting API (US-031):
|
|
2148
|
+
* - POST /v1/errors — submit a structured error/bug report
|
|
2149
|
+
*
|
|
2150
|
+
* Errors are automatically deduplicated server-side by fingerprint
|
|
2151
|
+
* (SHA256 of error_type + endpoint + status_code).
|
|
2152
|
+
*
|
|
2153
|
+
* @example
|
|
2154
|
+
* ```typescript
|
|
2155
|
+
* const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
|
|
2156
|
+
*
|
|
2157
|
+
* // Manual error report
|
|
2158
|
+
* const report = await nexus.errors.submit({
|
|
2159
|
+
* error_type: 'api_error',
|
|
2160
|
+
* severity: 'major',
|
|
2161
|
+
* description: 'Context retrieval returned empty despite known data',
|
|
2162
|
+
* retrieve_id: 'uuid-from-retrieve-call',
|
|
2163
|
+
* });
|
|
2164
|
+
* ```
|
|
2165
|
+
*/
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* Service for submitting structured error reports.
|
|
2169
|
+
*
|
|
2170
|
+
* Reports are deduplicated server-side: repeated submissions with the
|
|
2171
|
+
* same fingerprint increment `occurrence_count` instead of creating
|
|
2172
|
+
* new records.
|
|
2173
|
+
*/
|
|
2174
|
+
declare class ErrorService extends BaseService {
|
|
2175
|
+
/**
|
|
2176
|
+
* Submit a structured error report.
|
|
2177
|
+
*
|
|
2178
|
+
* @param data - Error report payload.
|
|
2179
|
+
* @param options - Optional request options (e.g. AbortSignal).
|
|
2180
|
+
* @returns The created or updated error report metadata.
|
|
2181
|
+
*/
|
|
2182
|
+
submit(data: ErrorReportRequest, options?: RequestOptions): Promise<ErrorReportResponse>;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
/**
|
|
2186
|
+
* @module client
|
|
2187
|
+
* @description Main entry point for the Nexus SDK.
|
|
2188
|
+
*
|
|
2189
|
+
* The {@link NexusClient} class is the single object that SDK consumers
|
|
2190
|
+
* instantiate. It resolves configuration, creates a shared HTTP transport,
|
|
2191
|
+
* and exposes every domain service as a readonly property.
|
|
2192
|
+
*/
|
|
2193
|
+
|
|
2194
|
+
/**
|
|
2195
|
+
* Nexus AI Cognitive Services SDK client.
|
|
2196
|
+
*
|
|
2197
|
+
* Create a single instance and use the service properties to interact
|
|
2198
|
+
* with the Nexus platform.
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```typescript
|
|
2202
|
+
* const nexus = new NexusClient({
|
|
2203
|
+
* apiKey: process.env.NEXUS_API_KEY!,
|
|
2204
|
+
* });
|
|
2205
|
+
*
|
|
2206
|
+
* // Aggregated context retrieval (Chat main flow)
|
|
2207
|
+
* const ctx = await nexus.context.retrieve({
|
|
2208
|
+
* user_id: 'user123',
|
|
2209
|
+
* query: '用户偏好',
|
|
2210
|
+
* });
|
|
2211
|
+
*
|
|
2212
|
+
* // Memory search
|
|
2213
|
+
* const memories = await nexus.memories.search({
|
|
2214
|
+
* user_id: 'user123',
|
|
2215
|
+
* query: 'favourite colour',
|
|
2216
|
+
* });
|
|
2217
|
+
* ```
|
|
2218
|
+
*/
|
|
2219
|
+
declare class NexusClient {
|
|
2220
|
+
/** Aggregated context retrieval (Chat main flow). */
|
|
2221
|
+
readonly context: ContextService;
|
|
2222
|
+
/** Memory CRUD, search, and journal. */
|
|
2223
|
+
readonly memories: MemoryService;
|
|
2224
|
+
/** Conversation lifecycle and messages. */
|
|
2225
|
+
readonly conversations: ConversationService;
|
|
2226
|
+
/** Knowledge graph entities and queries. */
|
|
2227
|
+
readonly knowledge: KnowledgeService;
|
|
2228
|
+
/** Activity stream ingestion for passive memory. */
|
|
2229
|
+
readonly activities: ActivityService;
|
|
2230
|
+
/** Tenant profile and usage management. */
|
|
2231
|
+
readonly tenants: TenantService;
|
|
2232
|
+
/** Feedback loop — submit ratings and query feedback records (v5.0). */
|
|
2233
|
+
readonly feedback: FeedbackService;
|
|
2234
|
+
/** Error reporting — submit structured error reports (US-031). */
|
|
2235
|
+
readonly errors: ErrorService;
|
|
2236
|
+
/** @internal Shared HTTP transport. */
|
|
2237
|
+
private readonly http;
|
|
2238
|
+
/**
|
|
2239
|
+
* Create a new Nexus SDK client.
|
|
2240
|
+
*
|
|
2241
|
+
* @param config - SDK configuration. Only `apiKey` is required; all other
|
|
2242
|
+
* fields fall back to sensible defaults (see {@link resolveConfig}).
|
|
2243
|
+
*
|
|
2244
|
+
* @throws {Error} If `apiKey` is missing or empty.
|
|
2245
|
+
*/
|
|
2246
|
+
constructor(config: NexusConfig);
|
|
2247
|
+
/**
|
|
2248
|
+
* Access the offline queue instance (if offline mode is enabled).
|
|
2249
|
+
*/
|
|
2250
|
+
get queue(): OfflineQueue | undefined;
|
|
2251
|
+
/**
|
|
2252
|
+
* Set the online/offline status of the client.
|
|
2253
|
+
*
|
|
2254
|
+
* When transitioning from offline to online, queued requests are
|
|
2255
|
+
* automatically flushed.
|
|
2256
|
+
*/
|
|
2257
|
+
setOnline(online: boolean): void;
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
/**
|
|
2261
|
+
* @module errors/base
|
|
2262
|
+
* @description Base error classes for the Nexus SDK.
|
|
2263
|
+
*/
|
|
2264
|
+
/**
|
|
2265
|
+
* Base error class for all Nexus SDK errors.
|
|
2266
|
+
*
|
|
2267
|
+
* All SDK-specific errors extend this class, providing a consistent
|
|
2268
|
+
* `code` field for programmatic error handling.
|
|
2269
|
+
*
|
|
2270
|
+
* @example
|
|
2271
|
+
* ```typescript
|
|
2272
|
+
* try {
|
|
2273
|
+
* await client.context.retrieve({ ... });
|
|
2274
|
+
* } catch (err) {
|
|
2275
|
+
* if (err instanceof NexusError) {
|
|
2276
|
+
* console.error(`[${err.code}] ${err.message}`);
|
|
2277
|
+
* }
|
|
2278
|
+
* }
|
|
2279
|
+
* ```
|
|
2280
|
+
*/
|
|
2281
|
+
declare class NexusError extends Error {
|
|
2282
|
+
/** Machine-readable error code (e.g. `NEXUS_API_ERROR`). */
|
|
2283
|
+
readonly code: string;
|
|
2284
|
+
/** The original error that caused this error, if any. */
|
|
2285
|
+
readonly cause?: Error;
|
|
2286
|
+
constructor(message: string, code: string, cause?: Error);
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* Thrown when the SDK is configured with invalid options.
|
|
2290
|
+
*
|
|
2291
|
+
* @example
|
|
2292
|
+
* ```typescript
|
|
2293
|
+
* // Missing required `apiKey`
|
|
2294
|
+
* new NexusClient({}) // throws ConfigurationError
|
|
2295
|
+
* ```
|
|
2296
|
+
*/
|
|
2297
|
+
declare class ConfigurationError extends NexusError {
|
|
2298
|
+
constructor(message: string, cause?: Error);
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Thrown when a network-level failure occurs (timeout, DNS, connection refused, etc.).
|
|
2302
|
+
*/
|
|
2303
|
+
declare class NetworkError extends NexusError {
|
|
2304
|
+
constructor(message: string, cause?: Error);
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Thrown when an operation exceeds its configured timeout.
|
|
2308
|
+
*/
|
|
2309
|
+
declare class TimeoutError extends NexusError {
|
|
2310
|
+
constructor(message: string, cause?: Error);
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
/**
|
|
2314
|
+
* @module errors/api
|
|
2315
|
+
* @description API-level error classes mapped to HTTP status codes.
|
|
2316
|
+
*/
|
|
2317
|
+
|
|
2318
|
+
/**
|
|
2319
|
+
* Represents an error returned by the Nexus HTTP API.
|
|
2320
|
+
*
|
|
2321
|
+
* Use the static factory `ApiError.fromResponse()` to construct the most
|
|
2322
|
+
* specific subclass based on the HTTP status code.
|
|
2323
|
+
*
|
|
2324
|
+
* @example
|
|
2325
|
+
* ```typescript
|
|
2326
|
+
* try {
|
|
2327
|
+
* await client.memory.search({ ... });
|
|
2328
|
+
* } catch (err) {
|
|
2329
|
+
* if (err instanceof ApiError) {
|
|
2330
|
+
* console.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
2331
|
+
* }
|
|
2332
|
+
* }
|
|
2333
|
+
* ```
|
|
2334
|
+
*/
|
|
2335
|
+
declare class ApiError extends NexusError {
|
|
2336
|
+
/** HTTP status code returned by the server. */
|
|
2337
|
+
readonly statusCode: number;
|
|
2338
|
+
/** Raw response body, if available. */
|
|
2339
|
+
readonly response?: unknown;
|
|
2340
|
+
constructor(message: string, statusCode: number, response?: unknown, code?: string);
|
|
2341
|
+
/**
|
|
2342
|
+
* Create the most specific `ApiError` subclass from an Axios response.
|
|
2343
|
+
*
|
|
2344
|
+
* | Status | Error class |
|
|
2345
|
+
* |--------|------------------------|
|
|
2346
|
+
* | 400 | `ValidationError` |
|
|
2347
|
+
* | 401 | `AuthenticationError` |
|
|
2348
|
+
* | 404 | `NotFoundError` |
|
|
2349
|
+
* | 429 | `RateLimitError` |
|
|
2350
|
+
* | other | `ApiError` |
|
|
2351
|
+
*/
|
|
2352
|
+
static fromResponse(response: AxiosResponse): ApiError;
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* HTTP 401 -- the request lacks valid authentication credentials.
|
|
2356
|
+
*/
|
|
2357
|
+
declare class AuthenticationError extends ApiError {
|
|
2358
|
+
constructor(message: string, response?: unknown);
|
|
2359
|
+
}
|
|
2360
|
+
/**
|
|
2361
|
+
* HTTP 429 -- the client has sent too many requests in a given time window.
|
|
2362
|
+
*
|
|
2363
|
+
* When the server provides a `Retry-After` header, it is exposed via
|
|
2364
|
+
* {@link RateLimitError.retryAfter} (in seconds).
|
|
2365
|
+
*/
|
|
2366
|
+
declare class RateLimitError extends ApiError {
|
|
2367
|
+
/** Seconds to wait before retrying, parsed from the `Retry-After` header. */
|
|
2368
|
+
readonly retryAfter?: number;
|
|
2369
|
+
constructor(message: string, retryAfter?: number, response?: unknown);
|
|
2370
|
+
}
|
|
2371
|
+
/**
|
|
2372
|
+
* HTTP 400 -- the request body or query parameters failed validation.
|
|
2373
|
+
*
|
|
2374
|
+
* When the server returns field-level errors they are available via
|
|
2375
|
+
* {@link ValidationError.details}.
|
|
2376
|
+
*/
|
|
2377
|
+
declare class ValidationError extends ApiError {
|
|
2378
|
+
/** Per-field validation error messages, if provided by the server. */
|
|
2379
|
+
readonly details?: Record<string, string[]>;
|
|
2380
|
+
constructor(message: string, details?: Record<string, string[]>, response?: unknown);
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* HTTP 404 -- the requested resource does not exist.
|
|
2384
|
+
*/
|
|
2385
|
+
declare class NotFoundError extends ApiError {
|
|
2386
|
+
constructor(message: string, response?: unknown);
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* Thrown when client-side input validation fails (zod schema).
|
|
2391
|
+
* Distinct from the API ValidationError (HTTP 400).
|
|
2392
|
+
*/
|
|
2393
|
+
declare class InputValidationError extends NexusError {
|
|
2394
|
+
readonly fieldErrors: Record<string, string[]>;
|
|
2395
|
+
constructor(zodError: ZodError);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
declare const contextRequestSchema: z.ZodObject<{
|
|
2399
|
+
user_id: z.ZodString;
|
|
2400
|
+
query: z.ZodOptional<z.ZodString>;
|
|
2401
|
+
layers: z.ZodOptional<z.ZodArray<z.ZodEnum<["recent", "semantic", "graph"]>, "many">>;
|
|
2402
|
+
recent_hours: z.ZodOptional<z.ZodNumber>;
|
|
2403
|
+
recent_limit: z.ZodOptional<z.ZodNumber>;
|
|
2404
|
+
include_profile: z.ZodOptional<z.ZodBoolean>;
|
|
2405
|
+
profile_limit: z.ZodOptional<z.ZodNumber>;
|
|
2406
|
+
include_history: z.ZodOptional<z.ZodBoolean>;
|
|
2407
|
+
history_limit: z.ZodOptional<z.ZodNumber>;
|
|
2408
|
+
include_graph: z.ZodOptional<z.ZodBoolean>;
|
|
2409
|
+
graph_limit: z.ZodOptional<z.ZodNumber>;
|
|
2410
|
+
as_of: z.ZodOptional<z.ZodString>;
|
|
2411
|
+
}, "strip", z.ZodTypeAny, {
|
|
2412
|
+
user_id: string;
|
|
2413
|
+
include_profile?: boolean | undefined;
|
|
2414
|
+
profile_limit?: number | undefined;
|
|
2415
|
+
include_history?: boolean | undefined;
|
|
2416
|
+
include_graph?: boolean | undefined;
|
|
2417
|
+
layers?: ("recent" | "semantic" | "graph")[] | undefined;
|
|
2418
|
+
query?: string | undefined;
|
|
2419
|
+
recent_hours?: number | undefined;
|
|
2420
|
+
recent_limit?: number | undefined;
|
|
2421
|
+
history_limit?: number | undefined;
|
|
2422
|
+
graph_limit?: number | undefined;
|
|
2423
|
+
as_of?: string | undefined;
|
|
2424
|
+
}, {
|
|
2425
|
+
user_id: string;
|
|
2426
|
+
include_profile?: boolean | undefined;
|
|
2427
|
+
profile_limit?: number | undefined;
|
|
2428
|
+
include_history?: boolean | undefined;
|
|
2429
|
+
include_graph?: boolean | undefined;
|
|
2430
|
+
layers?: ("recent" | "semantic" | "graph")[] | undefined;
|
|
2431
|
+
query?: string | undefined;
|
|
2432
|
+
recent_hours?: number | undefined;
|
|
2433
|
+
recent_limit?: number | undefined;
|
|
2434
|
+
history_limit?: number | undefined;
|
|
2435
|
+
graph_limit?: number | undefined;
|
|
2436
|
+
as_of?: string | undefined;
|
|
2437
|
+
}>;
|
|
2438
|
+
|
|
2439
|
+
declare const memoryCreateSchema: z.ZodObject<{
|
|
2440
|
+
user_id: z.ZodString;
|
|
2441
|
+
content: z.ZodString;
|
|
2442
|
+
memory_type: z.ZodOptional<z.ZodEnum<["episodic", "semantic", "procedural"]>>;
|
|
2443
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2444
|
+
}, "strip", z.ZodTypeAny, {
|
|
2445
|
+
user_id: string;
|
|
2446
|
+
content: string;
|
|
2447
|
+
memory_type?: "semantic" | "episodic" | "procedural" | undefined;
|
|
2448
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2449
|
+
}, {
|
|
2450
|
+
user_id: string;
|
|
2451
|
+
content: string;
|
|
2452
|
+
memory_type?: "semantic" | "episodic" | "procedural" | undefined;
|
|
2453
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2454
|
+
}>;
|
|
2455
|
+
declare const memoryUpdateSchema: z.ZodObject<{
|
|
2456
|
+
content: z.ZodOptional<z.ZodString>;
|
|
2457
|
+
memory_type: z.ZodOptional<z.ZodEnum<["episodic", "semantic", "procedural"]>>;
|
|
2458
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2459
|
+
}, "strip", z.ZodTypeAny, {
|
|
2460
|
+
content?: string | undefined;
|
|
2461
|
+
memory_type?: "semantic" | "episodic" | "procedural" | undefined;
|
|
2462
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2463
|
+
}, {
|
|
2464
|
+
content?: string | undefined;
|
|
2465
|
+
memory_type?: "semantic" | "episodic" | "procedural" | undefined;
|
|
2466
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2467
|
+
}>;
|
|
2468
|
+
declare const memorySearchSchema: z.ZodObject<{
|
|
2469
|
+
user_id: z.ZodString;
|
|
2470
|
+
query: z.ZodString;
|
|
2471
|
+
memory_type: z.ZodOptional<z.ZodEnum<["episodic", "semantic", "procedural"]>>;
|
|
2472
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
2473
|
+
threshold: z.ZodOptional<z.ZodNumber>;
|
|
2474
|
+
}, "strip", z.ZodTypeAny, {
|
|
2475
|
+
user_id: string;
|
|
2476
|
+
query: string;
|
|
2477
|
+
memory_type?: "semantic" | "episodic" | "procedural" | undefined;
|
|
2478
|
+
limit?: number | undefined;
|
|
2479
|
+
threshold?: number | undefined;
|
|
2480
|
+
}, {
|
|
2481
|
+
user_id: string;
|
|
2482
|
+
query: string;
|
|
2483
|
+
memory_type?: "semantic" | "episodic" | "procedural" | undefined;
|
|
2484
|
+
limit?: number | undefined;
|
|
2485
|
+
threshold?: number | undefined;
|
|
2486
|
+
}>;
|
|
2487
|
+
|
|
2488
|
+
declare const conversationCreateSchema: z.ZodObject<{
|
|
2489
|
+
user_id: z.ZodString;
|
|
2490
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
2491
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2492
|
+
}, "strip", z.ZodTypeAny, {
|
|
2493
|
+
user_id: string;
|
|
2494
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2495
|
+
session_id?: string | undefined;
|
|
2496
|
+
}, {
|
|
2497
|
+
user_id: string;
|
|
2498
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2499
|
+
session_id?: string | undefined;
|
|
2500
|
+
}>;
|
|
2501
|
+
declare const messageCreateSchema: z.ZodObject<{
|
|
2502
|
+
role: z.ZodEnum<["user", "assistant", "system", "tool"]>;
|
|
2503
|
+
content: z.ZodString;
|
|
2504
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2505
|
+
}, "strip", z.ZodTypeAny, {
|
|
2506
|
+
content: string;
|
|
2507
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
2508
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2509
|
+
}, {
|
|
2510
|
+
content: string;
|
|
2511
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
2512
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2513
|
+
}>;
|
|
2514
|
+
|
|
2515
|
+
declare const entityCreateSchema: z.ZodObject<{
|
|
2516
|
+
name: z.ZodString;
|
|
2517
|
+
entity_type: z.ZodString;
|
|
2518
|
+
description: z.ZodOptional<z.ZodString>;
|
|
2519
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2520
|
+
}, "strip", z.ZodTypeAny, {
|
|
2521
|
+
name: string;
|
|
2522
|
+
entity_type: string;
|
|
2523
|
+
description?: string | undefined;
|
|
2524
|
+
properties?: Record<string, unknown> | undefined;
|
|
2525
|
+
}, {
|
|
2526
|
+
name: string;
|
|
2527
|
+
entity_type: string;
|
|
2528
|
+
description?: string | undefined;
|
|
2529
|
+
properties?: Record<string, unknown> | undefined;
|
|
2530
|
+
}>;
|
|
2531
|
+
declare const graphQueryRequestSchema: z.ZodObject<{
|
|
2532
|
+
entity_name: z.ZodString;
|
|
2533
|
+
depth: z.ZodOptional<z.ZodNumber>;
|
|
2534
|
+
relationship_types: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
2535
|
+
}, "strip", z.ZodTypeAny, {
|
|
2536
|
+
entity_name: string;
|
|
2537
|
+
depth?: number | undefined;
|
|
2538
|
+
relationship_types?: string[] | undefined;
|
|
2539
|
+
}, {
|
|
2540
|
+
entity_name: string;
|
|
2541
|
+
depth?: number | undefined;
|
|
2542
|
+
relationship_types?: string[] | undefined;
|
|
2543
|
+
}>;
|
|
2544
|
+
declare const extractionRequestSchema: z.ZodObject<{
|
|
2545
|
+
text: z.ZodString;
|
|
2546
|
+
agent_id: z.ZodOptional<z.ZodString>;
|
|
2547
|
+
owner_user_id: z.ZodOptional<z.ZodString>;
|
|
2548
|
+
}, "strip", z.ZodTypeAny, {
|
|
2549
|
+
text: string;
|
|
2550
|
+
agent_id?: string | undefined;
|
|
2551
|
+
owner_user_id?: string | undefined;
|
|
2552
|
+
}, {
|
|
2553
|
+
text: string;
|
|
2554
|
+
agent_id?: string | undefined;
|
|
2555
|
+
owner_user_id?: string | undefined;
|
|
2556
|
+
}>;
|
|
2557
|
+
|
|
2558
|
+
declare const apiKeyCreateSchema: z.ZodObject<{
|
|
2559
|
+
name: z.ZodString;
|
|
2560
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodEnum<["read", "write", "admin"]>, "many">>;
|
|
2561
|
+
expires_days: z.ZodOptional<z.ZodNumber>;
|
|
2562
|
+
}, "strip", z.ZodTypeAny, {
|
|
2563
|
+
name: string;
|
|
2564
|
+
scopes?: ("read" | "write" | "admin")[] | undefined;
|
|
2565
|
+
expires_days?: number | undefined;
|
|
2566
|
+
}, {
|
|
2567
|
+
name: string;
|
|
2568
|
+
scopes?: ("read" | "write" | "admin")[] | undefined;
|
|
2569
|
+
expires_days?: number | undefined;
|
|
2570
|
+
}>;
|
|
2571
|
+
|
|
2572
|
+
export { type Activity, type ActivityProcessingStatus, ActivityService, type ActivityStats, type ActivityStatusResponse, type ActivityStreamRequest, type ActivityStreamResponse, type ActivityType, ApiError, type ApiErrorDetail, type ApiKey, type ApiKeyCreate, type ApiKeyCreated, type ApiKeyScope, type ApiResponse, AuthenticationError, type CacheConfig, type CompoundId, ConfigurationError, type ContextDepth, type ContextDepthPreset, type ContextEntity, type ContextGraph, type ContextHistory, type ContextLayer, type ContextMemory, type ContextMessage, type ContextMeta, type ContextProfile, type ContextRelation, type ContextRequest, type ContextRetrieveResponse, ContextService, type Conversation, type ConversationCreate, type ConversationDetail, type ConversationList, type ConversationListParams, ConversationService, type ConversationStatus, type ConversationSummary, DEFAULT_CONFIG, DEPTH_PRESETS, type EntityCreate, type EntityListParams, type EntityListResponse, type ErrorReportRequest, type ErrorReportResponse, ErrorService, type ErrorSeverity, type ErrorType, type ExtractionRequest, type ExtractionResult, type FeedbackItemRequest, type FeedbackListItem, type FeedbackListParams, type FeedbackListResponse, type FeedbackResponse, FeedbackService, type FeedbackSubmitRequest, type GraphPath, type GraphPathEntity, type GraphPathRelationship, type GraphQueryRequest, type GraphQueryResponse, type HealthResponse, type HealthStatus, InputValidationError, type JournalEntry, type JournalResponse, type KnowledgeEntity, type KnowledgeRelationship, KnowledgeService, type Memory, type MemoryCreate, type MemoryJournalParams, type MemoryList, type MemoryListParams, type MemorySearch, type MemorySearchResult, MemoryService, type MemoryType, type MemoryUpdate, type Message, type MessageCreate, type MessageList, type MessageListParams, type MessageRole, NetworkError, NexusClient, type NexusConfig, NexusError, NotFoundError, type OfflineConfig, OfflineQueue, type OwnerType, type PaginatedResponse, type Pagination, type QueuedRequest, RateLimitError, type RequestOptions, type ResolvedCacheConfig, type ResolvedConfig, type ResolvedRetryConfig, type RetryConfig, type ServiceStatus, type SortOrder, type Tenant, type TenantQuotas, TenantService, type TenantTier, type TenantUsage, TimeoutError, type UsageStats, ValidationError, apiKeyCreateSchema, contextRequestSchema, conversationCreateSchema, entityCreateSchema, extractionRequestSchema, graphQueryRequestSchema, memoryCreateSchema, memorySearchSchema, memoryUpdateSchema, messageCreateSchema, resolveConfig };
|