@memorylayerai/sdk 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -414,11 +414,197 @@ var init_router = __esm({
414
414
  }
415
415
  });
416
416
 
417
+ // src/resources/graph.ts
418
+ var graph_exports = {};
419
+ __export(graph_exports, {
420
+ GraphResource: () => GraphResource
421
+ });
422
+ var GraphResource;
423
+ var init_graph = __esm({
424
+ "src/resources/graph.ts"() {
425
+ "use strict";
426
+ init_errors();
427
+ GraphResource = class {
428
+ constructor(httpClient) {
429
+ this.httpClient = httpClient;
430
+ }
431
+ /**
432
+ * Get graph data for a space/project
433
+ *
434
+ * Fetches nodes (memories, documents, entities) and edges (relationships)
435
+ * for visualization. Supports pagination and filtering.
436
+ *
437
+ * @param request - Graph data request with filters
438
+ * @returns Graph data with nodes, edges, metadata, and pagination
439
+ *
440
+ * @example
441
+ * ```typescript
442
+ * const graphData = await client.graph.getGraph({
443
+ * spaceId: 'project-123',
444
+ * limit: 100,
445
+ * nodeTypes: ['memory', 'document'],
446
+ * relationshipTypes: ['extends', 'updates']
447
+ * });
448
+ *
449
+ * console.log(`Found ${graphData.nodes.length} nodes`);
450
+ * console.log(`Found ${graphData.edges.length} edges`);
451
+ * ```
452
+ *
453
+ * Requirements: 6.1
454
+ */
455
+ async getGraph(request) {
456
+ if (!request.spaceId || request.spaceId.trim().length === 0) {
457
+ throw new ValidationError(
458
+ "Space ID is required",
459
+ [{ field: "spaceId", message: "Space ID is required" }]
460
+ );
461
+ }
462
+ const query = {};
463
+ if (request.cursor) {
464
+ query.cursor = request.cursor;
465
+ }
466
+ if (request.limit !== void 0) {
467
+ query.limit = request.limit.toString();
468
+ }
469
+ if (request.nodeTypes && request.nodeTypes.length > 0) {
470
+ query.nodeTypes = request.nodeTypes.join(",");
471
+ }
472
+ if (request.relationshipTypes && request.relationshipTypes.length > 0) {
473
+ query.relationshipTypes = request.relationshipTypes.join(",");
474
+ }
475
+ if (request.startDate) {
476
+ query.startDate = request.startDate;
477
+ }
478
+ if (request.endDate) {
479
+ query.endDate = request.endDate;
480
+ }
481
+ return this.httpClient.request({
482
+ method: "GET",
483
+ path: `/v1/graph/spaces/${request.spaceId}`,
484
+ query
485
+ });
486
+ }
487
+ /**
488
+ * Get detailed information for a specific node
489
+ *
490
+ * Fetches node data, connected edges, and neighboring nodes.
491
+ *
492
+ * @param request - Node details request
493
+ * @returns Node details with edges and connected nodes
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * const details = await client.graph.getNodeDetails({
498
+ * nodeId: 'memory-456'
499
+ * });
500
+ *
501
+ * console.log(`Node: ${details.node.label}`);
502
+ * console.log(`Connected to ${details.connectedNodes.length} nodes`);
503
+ * ```
504
+ *
505
+ * Requirements: 6.2
506
+ */
507
+ async getNodeDetails(request) {
508
+ if (!request.nodeId || request.nodeId.trim().length === 0) {
509
+ throw new ValidationError(
510
+ "Node ID is required",
511
+ [{ field: "nodeId", message: "Node ID is required" }]
512
+ );
513
+ }
514
+ return this.httpClient.request({
515
+ method: "GET",
516
+ path: `/v1/graph/nodes/${request.nodeId}`
517
+ });
518
+ }
519
+ /**
520
+ * Get edges connected to a specific node
521
+ *
522
+ * Fetches edges and connected nodes, optionally filtered by edge type.
523
+ *
524
+ * @param request - Node edges request
525
+ * @returns Edges and connected nodes
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * const edges = await client.graph.getNodeEdges({
530
+ * nodeId: 'memory-456',
531
+ * edgeTypes: ['extends', 'updates']
532
+ * });
533
+ *
534
+ * console.log(`Found ${edges.edges.length} edges`);
535
+ * ```
536
+ *
537
+ * Requirements: 6.3
538
+ */
539
+ async getNodeEdges(request) {
540
+ if (!request.nodeId || request.nodeId.trim().length === 0) {
541
+ throw new ValidationError(
542
+ "Node ID is required",
543
+ [{ field: "nodeId", message: "Node ID is required" }]
544
+ );
545
+ }
546
+ const query = {};
547
+ if (request.edgeTypes && request.edgeTypes.length > 0) {
548
+ query.edgeTypes = request.edgeTypes.join(",");
549
+ }
550
+ return this.httpClient.request({
551
+ method: "GET",
552
+ path: `/v1/graph/nodes/${request.nodeId}/edges`,
553
+ query
554
+ });
555
+ }
556
+ /**
557
+ * Get all graph pages using async iteration
558
+ *
559
+ * Automatically handles pagination to fetch all nodes and edges.
560
+ * Yields each page of results as they are fetched.
561
+ *
562
+ * @param request - Initial graph request (without cursor)
563
+ * @yields Graph data for each page
564
+ *
565
+ * @example
566
+ * ```typescript
567
+ * for await (const page of client.graph.getAllGraphPages({ spaceId: 'project-123' })) {
568
+ * console.log(`Page has ${page.nodes.length} nodes`);
569
+ * // Process nodes...
570
+ * }
571
+ * ```
572
+ *
573
+ * @example
574
+ * ```typescript
575
+ * // Collect all nodes
576
+ * const allNodes: GraphNode[] = [];
577
+ * for await (const page of client.graph.getAllGraphPages({ spaceId: 'project-123' })) {
578
+ * allNodes.push(...page.nodes);
579
+ * }
580
+ * console.log(`Total nodes: ${allNodes.length}`);
581
+ * ```
582
+ *
583
+ * Requirements: 6.4
584
+ */
585
+ async *getAllGraphPages(request) {
586
+ let cursor;
587
+ let hasMore = true;
588
+ while (hasMore) {
589
+ const page = await this.getGraph({
590
+ ...request,
591
+ cursor
592
+ });
593
+ yield page;
594
+ cursor = page.pagination.nextCursor;
595
+ hasMore = page.pagination.hasMore;
596
+ }
597
+ }
598
+ };
599
+ }
600
+ });
601
+
417
602
  // src/index.ts
418
603
  var index_exports = {};
419
604
  __export(index_exports, {
420
605
  APIError: () => APIError,
421
606
  AuthenticationError: () => AuthenticationError,
607
+ GraphResource: () => GraphResource,
422
608
  IngestResource: () => IngestResource,
423
609
  MemoriesResource: () => MemoriesResource,
424
610
  MemoryLayerClient: () => MemoryLayerClient,
@@ -704,6 +890,16 @@ var MemoryLayerClient = class {
704
890
  }
705
891
  return this._router;
706
892
  }
893
+ /**
894
+ * Access graph visualization operations
895
+ */
896
+ get graph() {
897
+ if (!this._graph) {
898
+ const { GraphResource: GraphResource2 } = (init_graph(), __toCommonJS(graph_exports));
899
+ this._graph = new GraphResource2(this.httpClient);
900
+ }
901
+ return this._graph;
902
+ }
707
903
  };
708
904
 
709
905
  // src/index.ts
@@ -712,10 +908,12 @@ init_memories();
712
908
  init_search();
713
909
  init_ingest();
714
910
  init_router();
911
+ init_graph();
715
912
  // Annotate the CommonJS export names for ESM import in node:
716
913
  0 && (module.exports = {
717
914
  APIError,
718
915
  AuthenticationError,
916
+ GraphResource,
719
917
  IngestResource,
720
918
  MemoriesResource,
721
919
  MemoryLayerClient,
package/dist/index.d.cts CHANGED
@@ -31,6 +31,7 @@ declare class MemoryLayerClient {
31
31
  private _search?;
32
32
  private _ingest?;
33
33
  private _router?;
34
+ private _graph?;
34
35
  constructor(config?: ClientConfig$1);
35
36
  /**
36
37
  * Access memory operations
@@ -48,6 +49,10 @@ declare class MemoryLayerClient {
48
49
  * Access router operations
49
50
  */
50
51
  get router(): any;
52
+ /**
53
+ * Access graph visualization operations
54
+ */
55
+ get graph(): any;
51
56
  }
52
57
 
53
58
  /**
@@ -308,6 +313,171 @@ interface StreamChunk {
308
313
  /** Array of streaming choices */
309
314
  choices: StreamChoice[];
310
315
  }
316
+ /**
317
+ * Memory status for visualization
318
+ */
319
+ type MemoryStatus = 'latest' | 'older' | 'forgotten' | 'expiring' | 'new';
320
+ /**
321
+ * Node types in the graph
322
+ */
323
+ type NodeType = 'memory' | 'document' | 'entity';
324
+ /**
325
+ * Edge types in the graph
326
+ */
327
+ type EdgeType = 'updates' | 'extends' | 'derives' | 'similarity';
328
+ /**
329
+ * Node in the graph (memory, document, or entity)
330
+ */
331
+ interface GraphNode {
332
+ /** Unique identifier for the node */
333
+ id: string;
334
+ /** Type of node */
335
+ type: NodeType;
336
+ /** Display label (truncated content or title) */
337
+ label: string;
338
+ /** Node data */
339
+ data: {
340
+ /** Full content (for memory nodes) */
341
+ content?: string;
342
+ /** Title (for document nodes) */
343
+ title?: string;
344
+ /** Memory status */
345
+ status?: MemoryStatus;
346
+ /** Creation timestamp (ISO 8601) */
347
+ createdAt: string;
348
+ /** Expiration timestamp (ISO 8601) */
349
+ expiresAt?: string;
350
+ /** Source reference */
351
+ source?: string;
352
+ /** Additional metadata */
353
+ metadata?: Record<string, any>;
354
+ };
355
+ /** Optional position hints for layout */
356
+ position?: {
357
+ x: number;
358
+ y: number;
359
+ };
360
+ }
361
+ /**
362
+ * Edge in the graph (relationship or similarity)
363
+ */
364
+ interface GraphEdge {
365
+ /** Unique identifier for the edge */
366
+ id: string;
367
+ /** Source node ID */
368
+ source: string;
369
+ /** Target node ID */
370
+ target: string;
371
+ /** Type of edge */
372
+ type: EdgeType;
373
+ /** Display label for the edge */
374
+ label?: string;
375
+ /** Edge data */
376
+ data: {
377
+ /** Strength of the relationship (0.0 to 1.0) */
378
+ strength: number;
379
+ /** Additional metadata */
380
+ metadata?: Record<string, any>;
381
+ };
382
+ }
383
+ /**
384
+ * Graph metadata and statistics
385
+ */
386
+ interface GraphMetadata {
387
+ /** Total number of nodes */
388
+ totalNodes: number;
389
+ /** Number of memory nodes */
390
+ memoryCount: number;
391
+ /** Number of document nodes */
392
+ documentCount: number;
393
+ /** Number of entity nodes */
394
+ entityCount: number;
395
+ /** Total number of edges */
396
+ totalEdges: number;
397
+ /** Number of relationship edges */
398
+ relationshipCount: number;
399
+ /** Number of similarity edges */
400
+ similarityCount: number;
401
+ }
402
+ /**
403
+ * Pagination information
404
+ */
405
+ interface PaginationInfo {
406
+ /** Whether there are more results */
407
+ hasMore: boolean;
408
+ /** Cursor for the next page */
409
+ nextCursor?: string;
410
+ /** Total count (optional, may be expensive to compute) */
411
+ totalCount?: number;
412
+ }
413
+ /**
414
+ * Complete graph data structure
415
+ */
416
+ interface GraphData {
417
+ /** Array of nodes */
418
+ nodes: GraphNode[];
419
+ /** Array of edges */
420
+ edges: GraphEdge[];
421
+ /** Graph metadata and statistics */
422
+ metadata: GraphMetadata;
423
+ /** Pagination information */
424
+ pagination: PaginationInfo;
425
+ }
426
+ /**
427
+ * Request to get graph data
428
+ */
429
+ interface GetGraphRequest {
430
+ /** Space/project ID to fetch graph for */
431
+ spaceId: string;
432
+ /** Pagination cursor (optional) */
433
+ cursor?: string;
434
+ /** Maximum number of nodes to return (default: 500, max: 2000) */
435
+ limit?: number;
436
+ /** Filter by node types */
437
+ nodeTypes?: NodeType[];
438
+ /** Filter by relationship types */
439
+ relationshipTypes?: EdgeType[];
440
+ /** Filter by start date (ISO 8601) */
441
+ startDate?: string;
442
+ /** Filter by end date (ISO 8601) */
443
+ endDate?: string;
444
+ }
445
+ /**
446
+ * Node details response
447
+ */
448
+ interface NodeDetails {
449
+ /** The node */
450
+ node: GraphNode;
451
+ /** Edges connected to this node */
452
+ edges: GraphEdge[];
453
+ /** Neighboring nodes */
454
+ connectedNodes: GraphNode[];
455
+ }
456
+ /**
457
+ * Request to get node details
458
+ */
459
+ interface GetNodeDetailsRequest {
460
+ /** Node ID */
461
+ nodeId: string;
462
+ }
463
+ /**
464
+ * Request to get node edges
465
+ */
466
+ interface GetNodeEdgesRequest {
467
+ /** Node ID */
468
+ nodeId: string;
469
+ /** Filter by edge types (optional) */
470
+ edgeTypes?: EdgeType[];
471
+ }
472
+ /**
473
+ * Response for get node edges
474
+ */
475
+ interface GetNodeEdgesResponse {
476
+ /** Edges connected to the node */
477
+ edges: GraphEdge[];
478
+ /** Nodes connected via these edges */
479
+ connectedNodes: GraphNode[];
480
+ }
311
481
 
312
482
  /**
313
483
  * Configuration for the HTTP client
@@ -489,4 +659,113 @@ declare class RouterResource {
489
659
  stream(request: RouterRequest): AsyncIterable<StreamChunk>;
490
660
  }
491
661
 
492
- export { APIError, AuthenticationError, type Choice, type ClientConfig$1 as ClientConfig, type CreateMemoryRequest, type IngestFileRequest, IngestResource, type IngestResponse, type IngestTextRequest, type ListMemoriesRequest, MemoriesResource, type Memory, MemoryLayerClient, MemoryLayerError, type Message, NetworkError, RateLimitError, type RouterRequest, RouterResource, type RouterResponse, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type StreamChoice, type StreamChunk, type StreamDelta, type UpdateMemoryRequest, type Usage, ValidationError, type ValidationErrorDetail };
662
+ /**
663
+ * Resource for graph visualization operations
664
+ *
665
+ * Provides methods to fetch graph data (nodes and edges) for visualization.
666
+ *
667
+ * Requirements: 6.1, 6.2, 6.3, 6.4
668
+ */
669
+ declare class GraphResource {
670
+ private httpClient;
671
+ constructor(httpClient: HTTPClient);
672
+ /**
673
+ * Get graph data for a space/project
674
+ *
675
+ * Fetches nodes (memories, documents, entities) and edges (relationships)
676
+ * for visualization. Supports pagination and filtering.
677
+ *
678
+ * @param request - Graph data request with filters
679
+ * @returns Graph data with nodes, edges, metadata, and pagination
680
+ *
681
+ * @example
682
+ * ```typescript
683
+ * const graphData = await client.graph.getGraph({
684
+ * spaceId: 'project-123',
685
+ * limit: 100,
686
+ * nodeTypes: ['memory', 'document'],
687
+ * relationshipTypes: ['extends', 'updates']
688
+ * });
689
+ *
690
+ * console.log(`Found ${graphData.nodes.length} nodes`);
691
+ * console.log(`Found ${graphData.edges.length} edges`);
692
+ * ```
693
+ *
694
+ * Requirements: 6.1
695
+ */
696
+ getGraph(request: GetGraphRequest): Promise<GraphData>;
697
+ /**
698
+ * Get detailed information for a specific node
699
+ *
700
+ * Fetches node data, connected edges, and neighboring nodes.
701
+ *
702
+ * @param request - Node details request
703
+ * @returns Node details with edges and connected nodes
704
+ *
705
+ * @example
706
+ * ```typescript
707
+ * const details = await client.graph.getNodeDetails({
708
+ * nodeId: 'memory-456'
709
+ * });
710
+ *
711
+ * console.log(`Node: ${details.node.label}`);
712
+ * console.log(`Connected to ${details.connectedNodes.length} nodes`);
713
+ * ```
714
+ *
715
+ * Requirements: 6.2
716
+ */
717
+ getNodeDetails(request: GetNodeDetailsRequest): Promise<NodeDetails>;
718
+ /**
719
+ * Get edges connected to a specific node
720
+ *
721
+ * Fetches edges and connected nodes, optionally filtered by edge type.
722
+ *
723
+ * @param request - Node edges request
724
+ * @returns Edges and connected nodes
725
+ *
726
+ * @example
727
+ * ```typescript
728
+ * const edges = await client.graph.getNodeEdges({
729
+ * nodeId: 'memory-456',
730
+ * edgeTypes: ['extends', 'updates']
731
+ * });
732
+ *
733
+ * console.log(`Found ${edges.edges.length} edges`);
734
+ * ```
735
+ *
736
+ * Requirements: 6.3
737
+ */
738
+ getNodeEdges(request: GetNodeEdgesRequest): Promise<GetNodeEdgesResponse>;
739
+ /**
740
+ * Get all graph pages using async iteration
741
+ *
742
+ * Automatically handles pagination to fetch all nodes and edges.
743
+ * Yields each page of results as they are fetched.
744
+ *
745
+ * @param request - Initial graph request (without cursor)
746
+ * @yields Graph data for each page
747
+ *
748
+ * @example
749
+ * ```typescript
750
+ * for await (const page of client.graph.getAllGraphPages({ spaceId: 'project-123' })) {
751
+ * console.log(`Page has ${page.nodes.length} nodes`);
752
+ * // Process nodes...
753
+ * }
754
+ * ```
755
+ *
756
+ * @example
757
+ * ```typescript
758
+ * // Collect all nodes
759
+ * const allNodes: GraphNode[] = [];
760
+ * for await (const page of client.graph.getAllGraphPages({ spaceId: 'project-123' })) {
761
+ * allNodes.push(...page.nodes);
762
+ * }
763
+ * console.log(`Total nodes: ${allNodes.length}`);
764
+ * ```
765
+ *
766
+ * Requirements: 6.4
767
+ */
768
+ getAllGraphPages(request: Omit<GetGraphRequest, 'cursor'>): AsyncGenerator<GraphData, void, undefined>;
769
+ }
770
+
771
+ export { APIError, AuthenticationError, type Choice, type ClientConfig$1 as ClientConfig, type CreateMemoryRequest, type EdgeType, type GetGraphRequest, type GetNodeDetailsRequest, type GetNodeEdgesRequest, type GetNodeEdgesResponse, type GraphData, type GraphEdge, type GraphMetadata, type GraphNode, GraphResource, type IngestFileRequest, IngestResource, type IngestResponse, type IngestTextRequest, type ListMemoriesRequest, MemoriesResource, type Memory, MemoryLayerClient, MemoryLayerError, type MemoryStatus, type Message, NetworkError, type NodeDetails, type NodeType, type PaginationInfo, RateLimitError, type RouterRequest, RouterResource, type RouterResponse, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type StreamChoice, type StreamChunk, type StreamDelta, type UpdateMemoryRequest, type Usage, ValidationError, type ValidationErrorDetail };