Skip to content

Latest commit

 

History

History
115 lines (93 loc) · 2.03 KB

File metadata and controls

115 lines (93 loc) · 2.03 KB

API Reference

Endpoints

Graph Operations

GET /api/graph

Retrieves the current state of the knowledge graph.

Response

{
  nodes: Node[];
  edges: Edge[];
  metrics: {
    betweenness: Record<number, number>;
    eigenvector: Record<number, number>;
    degree: Record<number, number>;
  };
  clusters: ClusterResult[];
}

POST /api/graph/expand

Expands the graph based on a provided prompt.

Request Body

{
  prompt: string;
}

Response: Same as GET /api/graph

POST /api/graph/cluster

Recalculates semantic clusters for the current graph.

Response: Same as GET /api/graph

POST /api/graph/reconnect

Attempts to reconnect disconnected nodes.

Response: Same as GET /api/graph

WebSocket API

Connection

const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
const wsUrl = `${protocol}//${window.location.host}/ws`;
const socket = new WebSocket(wsUrl);

Message Types

  1. Graph Update

    {
      type: 'graph_update';
      data: GraphData;
    }
  2. Cluster Update

    {
      type: 'cluster_update';
      data: ClusterResult[];
    }

Error Handling

All API endpoints return standard HTTP status codes:

  • 200: Success
  • 400: Bad Request
  • 401: Unauthorized
  • 500: Server Error

Error responses include a message field:

{
  "error": "Error description"
}

Rate Limiting

  • 100 requests per minute per IP
  • WebSocket connections limited to 1 per client

Examples

Expanding the Graph

const response = await fetch('/api/graph/expand', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'Expand knowledge about artificial intelligence'
  })
});

const updatedGraph = await response.json();

WebSocket Usage

socket.onmessage = (event) => {
  const update = JSON.parse(event.data);
  if (update.type === 'graph_update') {
    updateGraphVisualization(update.data);
  }
};