code<spar>

Memory API

API endpoints for querying the vector store stats and resolving user identities across channels.

Memory API

CodeSpar agents maintain contextual memory via a vector store (embeddings of conversations, code, and project context) and an identity resolution system that maps users across multiple channels.

Vector Store Stats

Retrieve memory and vector store statistics for the current instance.

GET /api/memory

Request

curl http://localhost:3000/api/memory

Response

{
  "vectorStore": {
    "totalEmbeddings": 1247,
    "storageMB": 12.3,
    "lastSync": "2024-01-15T14:15:00Z",
    "dimensions": 1536,
    "backend": "file"
  },
  "conversations": {
    "totalMessages": 892,
    "uniqueUsers": 15,
    "channels": {
      "slack": 450,
      "whatsapp": 312,
      "discord": 130
    },
    "retentionDays": 30
  },
  "projectContext": {
    "filesIndexed": 45,
    "lastIndexed": "2024-01-15T13:00:00Z",
    "repo": "codespar/codespar"
  }
}

Response Schema

FieldTypeDescription
vectorStore.totalEmbeddingsnumberTotal number of stored embedding vectors
vectorStore.storageMBnumberDisk usage in megabytes
vectorStore.lastSyncstringISO 8601 timestamp of last sync
vectorStore.dimensionsnumberEmbedding vector dimensions
vectorStore.backendstringStorage backend: file, postgres, redis
conversations.totalMessagesnumberTotal conversation messages stored
conversations.uniqueUsersnumberDistinct users who have interacted
conversations.channelsobjectMessage count per channel
conversations.retentionDaysnumberHow long messages are kept
projectContext.filesIndexednumberNumber of repo files indexed
projectContext.lastIndexedstringWhen the repo was last indexed
projectContext.repostringLinked repository

User Identity Lookup

Look up a user's resolved identity by their channel-specific identifier. This is used internally for cross-channel identity resolution and can be useful for debugging identity issues.

GET /api/identity?channelType=<type>&channelUserId=<id>

Query Parameters

ParameterTypeRequiredDescription
channelTypestringYesChannel type: slack, whatsapp, discord, telegram
channelUserIdstringYesChannel-specific user ID

Request

curl "http://localhost:3000/api/identity?channelType=slack&channelUserId=U1234ABCD"

Response (registered user)

{
  "found": true,
  "identity": {
    "id": "identity-001",
    "displayName": "John Silva",
    "role": "maintainer",
    "channels": [
      {
        "type": "slack",
        "userId": "U1234ABCD",
        "username": "john",
        "linkedAt": "2024-01-15T13:28:00Z"
      },
      {
        "type": "whatsapp",
        "userId": "5511999990000",
        "username": null,
        "linkedAt": "2024-01-15T13:30:00Z"
      },
      {
        "type": "discord",
        "userId": "123456789012345678",
        "username": "john#1234",
        "linkedAt": "2024-01-16T09:00:00Z"
      }
    ],
    "registeredAt": "2024-01-15T13:28:00Z",
    "lastSeen": "2024-01-15T14:32:00Z"
  }
}

Response (unregistered user)

{
  "found": true,
  "identity": {
    "id": "identity-anon-002",
    "displayName": null,
    "role": "read-only",
    "channels": [
      {
        "type": "slack",
        "userId": "U9999ZZZZ",
        "username": "unknown-user",
        "linkedAt": "2024-01-15T14:00:00Z"
      }
    ],
    "registeredAt": null,
    "lastSeen": "2024-01-15T14:00:00Z"
  }
}

Response (not found)

{
  "found": false,
  "identity": null
}

Identity Schema

FieldTypeDescription
idstringUnique identity identifier
displayNamestring | nullRegistered display name (null if not registered)
rolestringRBAC role: owner, maintainer, operator, reviewer, read-only, emergency_admin
channelsobject[]Array of linked channel identities
channels[].typestringChannel type
channels[].userIdstringChannel-specific user ID
channels[].usernamestring | nullChannel-specific username
channels[].linkedAtstringWhen this channel was linked
registeredAtstring | nullWhen the user registered (null if auto-created)
lastSeenstringLast interaction timestamp

How Identity Resolution Works

When a user sends a message from any channel, CodeSpar resolves their identity through these steps:

  1. Channel lookup — Find the identity record matching the channelType and channelUserId
  2. Cross-channel merge — If the user has registered via @codespar register <name>, all their channel identities are merged under a single identity record
  3. Role assignment — The resolved identity carries the user's RBAC role, which determines command permissions
  4. Audit attribution — All actions are logged against the resolved identity

This allows a user to approve a deploy from WhatsApp that was requested from Slack, as long as both channels are linked to the same identity.

Next Steps

On this page