@nexusm/sdk 4.0.0 → 5.1.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/dist/index.d.mts CHANGED
@@ -457,6 +457,21 @@ declare class HttpClient {
457
457
  * @returns The parsed response body.
458
458
  */
459
459
  patch<T>(path: string, data?: unknown, signal?: AbortSignal): Promise<T>;
460
+ /**
461
+ * Send a GET request and return the raw response body as a string.
462
+ *
463
+ * Intended for file-download endpoints (e.g. `GET /dashboard/export`) that
464
+ * return `text/csv` or `application/json` as a raw file stream rather than a
465
+ * JSON-parsed object. The retry and auth interceptors still apply; the
466
+ * response cache is intentionally bypassed (export payloads are not cacheable
467
+ * at the SDK layer).
468
+ *
469
+ * @param path - URL path relative to the base URL (e.g. `/dashboard/export`).
470
+ * @param params - Optional query parameters.
471
+ * @param signal - Optional {@link AbortSignal} to cancel the request.
472
+ * @returns The raw response body as a string.
473
+ */
474
+ getText(path: string, params?: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
460
475
  /**
461
476
  * Send a DELETE request.
462
477
  *
@@ -939,22 +954,25 @@ interface MemorySearchResult {
939
954
  /**
940
955
  * Paginated list of memories.
941
956
  *
942
- * GET /memories?user_id=...
957
+ * GET /memories?user_id=... — mirrors backend `MemoryListResponse` (FLAT
958
+ * container).
959
+ *
960
+ * v5.0.0 BREAKING: was nested `{data, pagination:{total, limit, offset,
961
+ * has_more}}` — that shape never existed on the wire. The backend response
962
+ * is flat `{memories, total_count, limit, offset, has_next}`; the old nested
963
+ * shape meant `result.data` was always `undefined` at runtime.
943
964
  */
944
965
  interface MemoryList {
945
966
  /** Array of memory records */
946
- data: Memory[];
947
- /** Pagination metadata */
948
- pagination: {
949
- /** Total number of memories */
950
- total: number;
951
- /** Current page size limit */
952
- limit: number;
953
- /** Current offset */
954
- offset: number;
955
- /** Whether more results exist */
956
- has_more: boolean;
957
- };
967
+ memories: Memory[];
968
+ /** Total number of memories matching the query */
969
+ total_count: number;
970
+ /** Current page size limit */
971
+ limit: number;
972
+ /** Current offset */
973
+ offset: number;
974
+ /** Whether more results exist beyond this page */
975
+ has_next: boolean;
958
976
  }
959
977
  /**
960
978
  * A single journal entry representing a memory on a specific date.
@@ -1004,8 +1022,13 @@ interface JournalResponse {
1004
1022
  * Parameters for listing memories with optional filtering and pagination.
1005
1023
  */
1006
1024
  interface MemoryListParams {
1007
- /** Filter memories by user ID */
1008
- user_id?: string;
1025
+ /**
1026
+ * User ID within the tenant whose memories to list.
1027
+ *
1028
+ * v5.0.0 BREAKING: now required — backend `GET /memories` declares
1029
+ * `user_id` as `Query(..., min_length=1)`; omitting it returns 422.
1030
+ */
1031
+ user_id: string;
1009
1032
  /** Filter by memory type classification */
1010
1033
  memory_type?: MemoryType;
1011
1034
  /** Maximum number of results per page */
@@ -1027,8 +1050,9 @@ interface MemoryJournalParams {
1027
1050
  user_id?: string;
1028
1051
  }
1029
1052
  /**
1030
- * Service for managing long-term memories via Mem0.
1053
+ * Service for managing long-term memories.
1031
1054
  *
1055
+ * Backed by the Nexus Memory Service (Native pgvector + ProfileWorker).
1032
1056
  * Provides full CRUD operations, semantic search, and the chronological
1033
1057
  * Memory Journal view for reviewing memories over time.
1034
1058
  *
@@ -1151,16 +1175,22 @@ interface Conversation {
1151
1175
  tenant_id: string;
1152
1176
  /** User ID that owns this conversation */
1153
1177
  user_id: string;
1154
- /** Originating agent (null when not agent-created) */
1155
- agent_id?: string | null;
1178
+ /**
1179
+ * Originating agent (null when not agent-created).
1180
+ *
1181
+ * v5.0.0: required-nullable convention — always emitted by the backend
1182
+ * (`ConversationResponse.agent_id: str | None`), value may be null. Was
1183
+ * `agent_id?: string | null` (optional); now `string | null` (required dict).
1184
+ */
1185
+ agent_id: string | null;
1156
1186
  /** Conversation status (e.g. active / archived) */
1157
1187
  status: string;
1158
- /** Auto-generated conversation summary */
1159
- summary?: string | null;
1188
+ /** Auto-generated conversation summary (null until first summary worker run) */
1189
+ summary: string | null;
1160
1190
  /** Total number of messages in the conversation */
1161
1191
  message_count: number;
1162
- /** Additional metadata key-value pairs */
1163
- metadata?: Record<string, unknown>;
1192
+ /** Additional metadata key-value pairs (always emitted, defaults to {}) */
1193
+ metadata: Record<string, unknown>;
1164
1194
  /** Timestamp when the conversation was created (ISO 8601) */
1165
1195
  created_at: string;
1166
1196
  /** Timestamp when the conversation was last updated (ISO 8601) */
@@ -1169,13 +1199,20 @@ interface Conversation {
1169
1199
  /**
1170
1200
  * Request payload for creating a new conversation.
1171
1201
  *
1172
- * POST /conversations
1202
+ * POST /conversations — mirrors backend `CreateConversationRequest`.
1203
+ *
1204
+ * v5.0.0 BREAKING: removed phantom `session_id` — the backend
1205
+ * (`CreateConversationRequest`) does not accept it; it was silently dropped
1206
+ * by Pydantic `extra=ignore`, and the session id is ALWAYS auto-generated
1207
+ * server-side regardless of input (the old "auto-generated if not provided"
1208
+ * doc was false). Added `agent_id` — the backend accepts it but the SDK had
1209
+ * no way to send it.
1173
1210
  */
1174
1211
  interface ConversationCreate {
1175
1212
  /** User ID to associate the conversation with */
1176
1213
  user_id: string;
1177
- /** Custom session ID (auto-generated if not provided) */
1178
- session_id?: string;
1214
+ /** Optional agent identifier to associate the conversation with */
1215
+ agent_id?: string;
1179
1216
  /** Additional metadata key-value pairs */
1180
1217
  metadata?: Record<string, unknown>;
1181
1218
  }
@@ -1295,19 +1332,26 @@ interface ConversationSummary {
1295
1332
  * @module services/conversations
1296
1333
  * @description Conversation Service - Conversation history and auto-summary management.
1297
1334
  *
1298
- * Wraps the Nexus Conversation API powered by Zep OSS. Supports
1299
- * conversation lifecycle management, message operations, and
1300
- * auto-generated summaries via temporal graph analysis.
1335
+ * Wraps the Nexus Conversation API (Native implementation: incremental
1336
+ * summaries produced by the backend SummaryWorker, NOT Zep OSS). Supports
1337
+ * conversation lifecycle management, message operations, and access to
1338
+ * auto-generated summaries.
1301
1339
  *
1302
- * Based on Nexus API v2.0 - /conversations endpoints
1340
+ * v5.0.0: corrected stale "Zep OSS"/"temporal graph"/"API v2.0" docs the
1341
+ * backend has always used a Native SummaryWorker.
1303
1342
  */
1304
1343
 
1305
1344
  /**
1306
1345
  * Parameters for listing conversations with optional filtering and pagination.
1307
1346
  */
1308
1347
  interface ConversationListParams {
1309
- /** Filter conversations by user ID */
1310
- user_id?: string;
1348
+ /**
1349
+ * User ID within the tenant whose conversations to list.
1350
+ *
1351
+ * v5.0.0 BREAKING: now required — backend `GET /conversations` declares
1352
+ * `user_id` as `Query(..., min_length=1)`; omitting it returns 422.
1353
+ */
1354
+ user_id: string;
1311
1355
  /** Maximum number of results per page */
1312
1356
  limit?: number;
1313
1357
  /** Offset for pagination */
@@ -1323,11 +1367,11 @@ interface MessageListParams {
1323
1367
  offset?: number;
1324
1368
  }
1325
1369
  /**
1326
- * Service for managing conversations and messages via Zep OSS.
1370
+ * Service for managing conversations and messages.
1327
1371
  *
1328
1372
  * Provides conversation lifecycle management (create, list, get, delete),
1329
1373
  * message operations (add, list), and access to auto-generated summaries
1330
- * produced by Zep's temporal graph analysis.
1374
+ * produced by the backend SummaryWorker (Native, incremental).
1331
1375
  *
1332
1376
  * @example
1333
1377
  * ```typescript
@@ -1379,11 +1423,11 @@ declare class ConversationService extends BaseService {
1379
1423
  /**
1380
1424
  * Add a message to an existing conversation.
1381
1425
  *
1382
- * The message is appended to the conversation's message sequence.
1383
- * Zep will asynchronously update the conversation summary after
1384
- * new messages are added.
1426
+ * The message is appended to the conversation's message sequence. The
1427
+ * backend SummaryWorker asynchronously updates the conversation summary
1428
+ * after new messages are added.
1385
1429
  *
1386
- * @param conversationId - UUID of the target conversation.
1430
+ * @param conversationId - Compound conversation ID ("tenant::user::session").
1387
1431
  * @param message - Message payload including role and content.
1388
1432
  * @returns The newly created message with generated ID and sequence number.
1389
1433
  * @throws {ApiError} 404 if the conversation does not exist.
@@ -1394,7 +1438,7 @@ declare class ConversationService extends BaseService {
1394
1438
  *
1395
1439
  * Messages are returned in chronological order (oldest first).
1396
1440
  *
1397
- * @param conversationId - UUID of the conversation.
1441
+ * @param conversationId - Compound conversation ID ("tenant::user::session").
1398
1442
  * @param params - Optional pagination controls (limit, offset).
1399
1443
  * @returns Paginated list of messages.
1400
1444
  * @throws {ApiError} 404 if the conversation does not exist.
@@ -1403,21 +1447,24 @@ declare class ConversationService extends BaseService {
1403
1447
  /**
1404
1448
  * Retrieve the auto-generated summary of a conversation.
1405
1449
  *
1406
- * Summaries are produced by Zep OSS temporal graph analysis and
1407
- * include key points extracted from the conversation history.
1450
+ * Summaries are produced incrementally by the backend SummaryWorker from
1451
+ * the conversation history.
1408
1452
  *
1409
- * @param conversationId - UUID of the conversation.
1410
- * @returns The conversation summary with key points and generation timestamp.
1453
+ * @param conversationId - Compound conversation ID ("tenant::user::session").
1454
+ * @returns The conversation summary ({@link ConversationSummary}: summary
1455
+ * text + message counts + created_at). Note: no "key points" or
1456
+ * "generated_at" fields — those were phantom (removed in v4.0.0).
1411
1457
  * @throws {ApiError} 404 if the conversation does not exist.
1412
1458
  */
1413
1459
  getSummary(conversationId: string, options?: RequestOptions): Promise<ConversationSummary>;
1414
1460
  /**
1415
- * Delete a conversation and all its messages.
1461
+ * Delete a conversation.
1416
1462
  *
1417
- * This operation is irreversible. The conversation, all associated
1418
- * messages, and the generated summary will be permanently removed.
1463
+ * Soft-delete: the backend sets `deleted_at` (the conversation stops
1464
+ * appearing in list/get) rather than physically removing the row and its
1465
+ * messages.
1419
1466
  *
1420
- * @param conversationId - UUID of the conversation to delete.
1467
+ * @param conversationId - Compound conversation ID ("tenant::user::session").
1421
1468
  * @throws {ApiError} 404 if the conversation does not exist.
1422
1469
  */
1423
1470
  delete(conversationId: string, options?: RequestOptions): Promise<void>;
@@ -1903,9 +1950,12 @@ interface ApiKeyCreate {
1903
1950
  /** Human-readable name for the API key (1-255 characters) */
1904
1951
  name: string;
1905
1952
  /**
1906
- * Permission scopes for the key (known values: read, write, admin, "*").
1907
- * @default ["*"] — the backend default grants the full wildcard; tightening
1908
- * the default is a separate backend security follow-up.
1953
+ * Permission scopes for the key (known values: read, write, admin,
1954
+ * admin:dashboard, feedback:diagnose, "*" wildcard).
1955
+ * @default ["read", "write"] least-privilege default (backend tightened
1956
+ * in security-scopes-admin-hardening, 2026-06-11). The "*" wildcard must be
1957
+ * requested explicitly; the default intentionally omits admin:dashboard /
1958
+ * feedback:diagnose.
1909
1959
  */
1910
1960
  scopes?: string[];
1911
1961
  /**
@@ -2270,6 +2320,133 @@ declare class ErrorService extends BaseService {
2270
2320
  submit(data: ErrorReportRequest, options?: RequestOptions): Promise<ErrorReportResponse>;
2271
2321
  }
2272
2322
 
2323
+ /**
2324
+ * @module types/dashboard
2325
+ * @description Dashboard Service type definitions.
2326
+ *
2327
+ * Mirrors the Nexus API dashboard export contract:
2328
+ * - GET /v1/dashboard/export — download a dataset as CSV or JSON
2329
+ *
2330
+ * The export endpoint returns raw file content (text/csv or application/json),
2331
+ * not a JSON-parsed object. The SDK therefore exposes these types only for
2332
+ * the _request_ side; the return value is `string`.
2333
+ */
2334
+ /**
2335
+ * The set of exportable dashboard datasets.
2336
+ *
2337
+ * Must stay in sync with the backend `DashboardExportDataset` Literal:
2338
+ * - `quality_distribution` — Quality score bucket distribution
2339
+ * - `feedback_trend` — Feedback rating trend over time
2340
+ * - `diagnosis_stats` — Diagnosis type statistics
2341
+ * - `feedback_health` — Overall feedback health metrics
2342
+ * - `error_heatmap` — Error frequency heatmap by endpoint / time
2343
+ * - `ab_distribution` — A/B experiment assignment distribution
2344
+ */
2345
+ type DashboardExportDataset = 'quality_distribution' | 'feedback_trend' | 'diagnosis_stats' | 'feedback_health' | 'error_heatmap' | 'ab_distribution';
2346
+ /**
2347
+ * Query parameters for `GET /v1/dashboard/export`.
2348
+ */
2349
+ interface DashboardExportParams {
2350
+ /**
2351
+ * The dataset to export. Required.
2352
+ *
2353
+ * Must be one of the six whitelisted values ({@link DashboardExportDataset}).
2354
+ * The backend returns HTTP 422 for unknown values.
2355
+ */
2356
+ dataset: DashboardExportDataset;
2357
+ /**
2358
+ * File format for the exported data.
2359
+ *
2360
+ * - `'csv'` — Comma-separated values (default when omitted).
2361
+ * - `'json'` — Raw JSON text (not parsed; returned as a string by the SDK).
2362
+ *
2363
+ * @default 'csv'
2364
+ */
2365
+ format?: 'csv' | 'json';
2366
+ /**
2367
+ * Filter results to a specific tenant.
2368
+ *
2369
+ * Only usable by API keys that carry the admin scope. The backend returns
2370
+ * HTTP 403 when this field is present but the caller lacks admin privileges,
2371
+ * and HTTP 400 when the value is not a valid UUID (it is normalized to
2372
+ * canonical form server-side).
2373
+ */
2374
+ target_tenant_id?: string;
2375
+ }
2376
+
2377
+ /**
2378
+ * @module services/dashboard
2379
+ * @description Dashboard Service — export analytics datasets.
2380
+ *
2381
+ * Wraps the Nexus Dashboard API:
2382
+ * - GET /v1/dashboard/export — download a dataset as raw CSV or JSON text
2383
+ *
2384
+ * The export endpoint is a file-download endpoint: the backend responds with
2385
+ * `Content-Disposition: attachment` and a raw file body (not a JSON envelope).
2386
+ * Accordingly, `export()` returns the raw response string rather than parsing
2387
+ * it into an object — callers receive exactly the bytes the server sent.
2388
+ *
2389
+ * ### WebSocket realtime subscriptions — deferred
2390
+ *
2391
+ * US-033b FU-3 scope is limited to the REST export method. A WebSocket
2392
+ * subscription helper (`subscribe()` / `DashboardSubscription`) was evaluated
2393
+ * for inclusion but is deferred to FU-4 (WS replay/catchup protocol decision).
2394
+ * Reasons:
2395
+ * 1. The WS message schema is not yet stabilised (FU-4 owns that contract).
2396
+ * 2. A proper WS abstraction requires a browser/Node `WebSocket` shim strategy
2397
+ * that is a non-trivial independent surface.
2398
+ * Track the WS helper in FU-4; this file should be extended there.
2399
+ *
2400
+ * @example
2401
+ * ```typescript
2402
+ * const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
2403
+ *
2404
+ * // Download quality distribution as CSV (default format)
2405
+ * const csv = await nexus.dashboard.export({ dataset: 'quality_distribution' });
2406
+ * // csv is a string like: "bucket,count\n0-1,12\n1-2,45\n..."
2407
+ *
2408
+ * // Download feedback trend as JSON
2409
+ * const json = await nexus.dashboard.export({
2410
+ * dataset: 'feedback_trend',
2411
+ * format: 'json',
2412
+ * });
2413
+ *
2414
+ * // Admin: export data scoped to a specific tenant
2415
+ * const tenantCsv = await nexus.dashboard.export({
2416
+ * dataset: 'error_heatmap',
2417
+ * format: 'csv',
2418
+ * target_tenant_id: 'tenant-abc',
2419
+ * });
2420
+ * ```
2421
+ */
2422
+
2423
+ /**
2424
+ * Service for exporting dashboard analytics datasets.
2425
+ *
2426
+ * Exposes `GET /v1/dashboard/export` as a typed method that returns the raw
2427
+ * file body (CSV or JSON text) as a string.
2428
+ */
2429
+ declare class DashboardService extends BaseService {
2430
+ /**
2431
+ * Export a dashboard dataset as raw file content.
2432
+ *
2433
+ * Sends `GET /dashboard/export` with the given query parameters and returns
2434
+ * the raw response body as a string. The string is exactly the file the
2435
+ * server would send for a browser download:
2436
+ * - `format: 'csv'` (default) → comma-separated text
2437
+ * - `format: 'json'` → JSON text (not parsed into an object)
2438
+ *
2439
+ * @param params - Dataset selection and format options.
2440
+ * @param options - Optional request options (e.g. AbortSignal).
2441
+ * @returns Raw file body string.
2442
+ *
2443
+ * @throws {ApiError} HTTP 401 — missing or invalid API key.
2444
+ * @throws {ApiError} HTTP 403 — `target_tenant_id` requires admin scope.
2445
+ * @throws {ApiError} HTTP 422 — `dataset` is not one of the six whitelisted values.
2446
+ */
2447
+ export(params: DashboardExportParams, options?: RequestOptions): Promise<string>;
2448
+ }
2449
+
2273
2450
  /**
2274
2451
  * @module client
2275
2452
  * @description Main entry point for the Nexus SDK.
@@ -2321,6 +2498,8 @@ declare class NexusClient {
2321
2498
  readonly feedback: FeedbackService;
2322
2499
  /** Error reporting — submit structured error reports (US-031). */
2323
2500
  readonly errors: ErrorService;
2501
+ /** Dashboard analytics — export datasets as CSV or JSON (US-033b FU-3). */
2502
+ readonly dashboard: DashboardService;
2324
2503
  /** @internal Shared HTTP transport. */
2325
2504
  private readonly http;
2326
2505
  /**
@@ -2575,16 +2754,16 @@ declare const memorySearchSchema: z.ZodObject<{
2575
2754
 
2576
2755
  declare const conversationCreateSchema: z.ZodObject<{
2577
2756
  user_id: z.ZodString;
2578
- session_id: z.ZodOptional<z.ZodString>;
2757
+ agent_id: z.ZodOptional<z.ZodString>;
2579
2758
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
2580
2759
  }, "strip", z.ZodTypeAny, {
2581
2760
  user_id: string;
2582
2761
  metadata?: Record<string, unknown> | undefined;
2583
- session_id?: string | undefined;
2762
+ agent_id?: string | undefined;
2584
2763
  }, {
2585
2764
  user_id: string;
2586
2765
  metadata?: Record<string, unknown> | undefined;
2587
- session_id?: string | undefined;
2766
+ agent_id?: string | undefined;
2588
2767
  }>;
2589
2768
  declare const messageCreateSchema: z.ZodObject<{
2590
2769
  role: z.ZodEnum<["user", "assistant", "system", "tool"]>;