{
  "openapi": "3.1.0",
  "info": {
    "title": "Metabotics Soul API",
    "version": "2.0.0",
    "description": "Persistent Soul identity, explicitly written memory, logical endpoints and traced interactions. Application API authentication is separate from a private hosting gate. Sites browser sessions also use trusted identity supplied by the hosting layer; callers must not forge those headers. Source clients are distributed with this repository. The default reference runtime uses memory_replay and all actions are simulated. V2 adds short-lived single-use pairing, endpoint-bound credentials, an installable source client, connection status/heartbeat, profile evidence labels and an official WorkBuddy configuration path."
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "Same-origin API; use the origin of an authorized running deployment."
    }
  ],
  "security": [
    {
      "ApplicationKey": []
    },
    {
      "SandboxSession": []
    }
  ],
  "paths": {
    "/souls": {
      "get": {
        "operationId": "listSouls",
        "summary": "List workspace souls",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Soul"
                  }
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      },
      "post": {
        "operationId": "createSoul",
        "summary": "Create a soul",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Soul"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SoulInput"
              }
            }
          }
        },
        "x-required-application-scope": "write"
      }
    },
    "/souls/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        }
      ],
      "get": {
        "operationId": "getSoul",
        "summary": "Read an owned soul",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Soul"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      },
      "patch": {
        "operationId": "updateSoul",
        "summary": "Update an owned soul",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Soul"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SoulPatch"
              }
            }
          }
        },
        "x-required-application-scope": "write"
      },
      "delete": {
        "operationId": "deleteSoul",
        "summary": "Delete an owned soul",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "write"
      }
    },
    "/endpoints": {
      "get": {
        "operationId": "listEndpoints",
        "summary": "List workspace endpoints",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Endpoint"
                  }
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      },
      "post": {
        "operationId": "createEndpoint",
        "summary": "Create a endpoint",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Endpoint"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointInput"
              }
            }
          }
        },
        "x-required-application-scope": "write"
      }
    },
    "/endpoints/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        }
      ],
      "get": {
        "operationId": "getEndpoint",
        "summary": "Read an owned endpoint",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Endpoint"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      },
      "patch": {
        "operationId": "updateEndpoint",
        "summary": "Update an owned endpoint",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Endpoint"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointPatch"
              }
            }
          }
        },
        "x-required-application-scope": "write"
      },
      "delete": {
        "operationId": "deleteEndpoint",
        "summary": "Delete an owned endpoint",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "write"
      }
    },
    "/memories": {
      "get": {
        "operationId": "listMemories",
        "summary": "List workspace memories",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Memory"
                  }
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      },
      "post": {
        "operationId": "createMemory",
        "summary": "Create a memory",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Memory"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemoryInput"
              }
            }
          }
        },
        "x-required-application-scope": "write",
        "description": "Workspace sessions/keys require write. Endpoint credentials require memory_write and may append only within their bound Soul, with shared or their own endpoint scope. Other memory mutations remain workspace-owner operations."
      }
    },
    "/memories/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        }
      ],
      "get": {
        "operationId": "getMemory",
        "summary": "Read an owned memory",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Memory"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      },
      "patch": {
        "operationId": "updateMemory",
        "summary": "Update an owned memory",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Memory"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemoryPatch"
              }
            }
          }
        },
        "x-required-application-scope": "write"
      },
      "delete": {
        "operationId": "deleteMemory",
        "summary": "Delete an owned memory",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "write"
      }
    },
    "/health": {
      "get": {
        "operationId": "health",
        "summary": "Check the service and D1 connection",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "storage": {
                      "type": "string"
                    },
                    "time": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "status",
                    "service",
                    "version",
                    "storage",
                    "time"
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/bootstrap": {
      "get": {
        "operationId": "bootstrap",
        "summary": "Read or initialize a workspace",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Bootstrap"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read",
        "description": "Workspace keys read their workspace; endpoint credentials receive only their bound Soul/endpoint, permitted memory and that endpoint's traces. No key or partner metadata is returned to endpoint credentials.",
        "security": [
          {
            "ApplicationKey": []
          },
          {
            "SandboxSession": []
          },
          {}
        ]
      }
    },
    "/interact": {
      "post": {
        "operationId": "interact",
        "summary": "Run a traced interaction",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InteractionResult"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InteractionInput"
              }
            }
          }
        },
        "x-required-application-scope": "interact",
        "description": "No hardware is dispatched. A successful logical action is labelled simulated; a blocked policy appears in the trace. Default responses replay stored memory without a model call."
      }
    },
    "/traces": {
      "get": {
        "operationId": "listTraces",
        "summary": "Read recent workspace traces",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Trace"
                  }
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read"
      }
    },
    "/evaluate": {
      "post": {
        "operationId": "evaluate",
        "summary": "Run deterministic D1 consistency checks",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Evaluation"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "required": []
              }
            }
          }
        },
        "x-required-application-scope": "write",
        "description": "Uses isolated temporary fixtures. This is not an LLM quality or physical-device benchmark."
      }
    },
    "/export": {
      "get": {
        "operationId": "exportWorkspace",
        "summary": "Export workspace data",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Bootstrap"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "exported_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "format": {
                          "type": "string",
                          "const": "metabotics-workspace-v1"
                        }
                      },
                      "required": [
                        "exported_at",
                        "format"
                      ]
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-required-application-scope": "read",
        "description": "Endpoint credentials are forbidden. Existing exported files are not affected by later record deletion."
      }
    },
    "/keys": {
      "post": {
        "operationId": "createKey",
        "summary": "Create a scoped application key",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KeyCreated"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KeyInput"
              }
            }
          }
        },
        "description": "Requires a trusted hosting user session or an existing sandbox session. Application API keys cannot create keys. Sandbox-created keys expire with their session.",
        "security": [
          {
            "SandboxSession": []
          }
        ]
      }
    },
    "/keys/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        }
      ],
      "delete": {
        "operationId": "revokeKey",
        "summary": "Revoke an application key",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Requires a trusted hosting session or sandbox session, not an API key.",
        "security": [
          {
            "SandboxSession": []
          }
        ]
      }
    },
    "/partners": {
      "post": {
        "operationId": "createPartnerApplication",
        "summary": "Save a hardware-partner application",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerApplication"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PartnerInput"
              }
            }
          }
        },
        "x-required-application-scope": "write",
        "description": "Saves a record in the submitting workspace. Does not send external email or create a CRM entry. May establish a sandbox when no session exists.",
        "security": [
          {
            "ApplicationKey": []
          },
          {
            "SandboxSession": []
          },
          {}
        ]
      }
    },
    "/mcp": {
      "post": {
        "operationId": "mcp",
        "summary": "Stateless MCP JSON-RPC endpoint",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/McpResponse"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "202": {
            "description": "Initialized notification accepted; no response body."
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/McpRequest"
              }
            }
          }
        },
        "description": "Supports initialize (2025-03-26), notifications/initialized, ping, tools/list and tools/call. Discover schemas via tools/list. Tools enforce read/write/interact scopes. Tool errors may appear in a 200 response with result.isError=true; initialization notification returns 202 without content."
      }
    },
    "/auth/register": {
      "post": {
        "operationId": "registerAccount",
        "summary": "Create an account and start a session",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "account": {
                      "$ref": "#/components/schemas/Account"
                    }
                  },
                  "required": [
                    "account"
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountCredentials"
              }
            }
          }
        },
        "description": "Creates an account in this deployment's own D1 database and sets an HttpOnly mb_account cookie. No email verification is performed; password recovery is manual.",
        "security": []
      }
    },
    "/auth/login": {
      "post": {
        "operationId": "loginAccount",
        "summary": "Sign in to an account",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "account": {
                      "$ref": "#/components/schemas/Account"
                    }
                  },
                  "required": [
                    "account"
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountCredentials"
              }
            }
          }
        },
        "description": "Rate limited per network identity. Returns a generic error for unknown emails or wrong passwords.",
        "security": []
      }
    },
    "/auth/logout": {
      "post": {
        "operationId": "logoutAccount",
        "summary": "Revoke the current account session",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "required": []
              }
            }
          }
        },
        "description": "Deletes the server-side session record and clears the mb_account cookie.",
        "security": [
          {
            "AccountSession": []
          }
        ]
      }
    },
    "/auth/me": {
      "get": {
        "operationId": "accountStatus",
        "summary": "Read the current account session",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountStatus"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Returns account: null when the request is not signed in. This route never creates a sandbox or account.",
        "security": []
      }
    },
    "/connect/profiles": {
      "get": {
        "operationId": "connectionProfiles",
        "summary": "Discover supported connection profiles",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profiles": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConnectionProfile"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/connect/manifest": {
      "get": {
        "operationId": "connectionManifest",
        "summary": "Read the agent-installable connection contract",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectManifest"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [],
        "parameters": [
          {
            "name": "profile",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "python-sdk"
            }
          }
        ]
      }
    },
    "/connect/preflight": {
      "get": {
        "operationId": "connectionPreflight",
        "summary": "Check actual API/storage readiness and integration requirements",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectPreflight"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/connect/sessions": {
      "get": {
        "operationId": "listConnections",
        "summary": "List connections in the owning browser workspace",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConnectSession"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SandboxSession": []
          }
        ]
      },
      "post": {
        "operationId": "createConnection",
        "summary": "Create a one-time pairing grant for one endpoint",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectCreated"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConnectInput"
              }
            }
          }
        },
        "security": [
          {
            "SandboxSession": []
          }
        ],
        "description": "Requires the owning browser session, including trusted Sites identity. Workspace API keys and endpoint credentials cannot create grants."
      }
    },
    "/connect/sessions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "connectionStatus",
        "summary": "Read a connection state and non-secret credential metadata",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectSession"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "revokeConnection",
        "summary": "Revoke the grant and credential and pause its endpoint",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SandboxSession": []
          }
        ]
      }
    },
    "/connect/redeem": {
      "post": {
        "operationId": "redeemConnection",
        "summary": "Atomically exchange a one-time grant for a bound credential",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedeemResult"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RedeemInput"
              }
            }
          }
        },
        "security": [],
        "description": "No workspace API key is used. The grant is accepted once, through the JSON request body. A private hosting gate remains separate."
      }
    },
    "/connect/heartbeat": {
      "post": {
        "operationId": "connectionHeartbeat",
        "summary": "Record an authenticated software endpoint heartbeat",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HeartbeatResult"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {}
              }
            }
          }
        },
        "security": [
          {
            "EndpointKey": []
          }
        ],
        "description": "A software heartbeat is not physical hardware verification. Workspace API keys cannot call this operation."
      }
    },
    "/connect/workbuddy-launch": {
      "post": {
        "operationId": "workBuddyLaunch",
        "summary": "Prepare an official WorkBuddy launch URL or manual fallback",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkBuddyLaunch"
                }
              }
            }
          },
          "default": {
            "description": "Application error; inspect error.code. A hosting access gate can return HTML or a redirect before this API is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WorkBuddyLaunchInput"
              }
            }
          }
        },
        "security": [
          {
            "SandboxSession": []
          }
        ],
        "description": "Signed mode requires registered app settings and explicit enablement. Returns a URL; does not claim the app opened or installation completed."
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApplicationKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Metabotics-Key",
        "description": "Workspace mb_ key or endpoint-scoped mbe_ credential. Endpoint credentials are limited to one Soul/endpoint, permitted context, memory append, interaction and heartbeat. They cannot export or administer a workspace. Hosting access is separate."
      },
      "SandboxSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "mb_sandbox",
        "description": "HttpOnly 24-hour demo session established by the application; do not synthesize it. Persistent browser identity on Sites is provided separately by the trusted hosting layer."
      },
      "AccountSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "mb_account",
        "description": "HttpOnly 30-day session created by /auth/register or /auth/login. Workspace owner is the account's acct_ identifier; data survives beyond sandbox expiry."
      },
      "EndpointKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Metabotics-Key",
        "description": "Single-endpoint mbe_ credential returned once by /connect/redeem."
      }
    },
    "schemas": {
      "Soul": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "name": {
            "type": "string"
          },
          "personality": {
            "type": "string"
          },
          "system_prompt": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "personality",
          "system_prompt",
          "version",
          "created_at",
          "updated_at"
        ]
      },
      "Endpoint": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "soul_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "web",
              "robot",
              "mobile",
              "glasses",
              "api"
            ]
          },
          "capabilities": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.-]{0,39}$"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "connected",
              "paused"
            ]
          },
          "simulated": {
            "type": "boolean",
            "const": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_seen_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "soul_id",
          "name",
          "type",
          "capabilities",
          "status",
          "simulated",
          "created_at",
          "last_seen_at"
        ]
      },
      "Memory": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "soul_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "content": {
            "type": "string"
          },
          "scope": {
            "type": "string",
            "enum": [
              "shared",
              "endpoint"
            ]
          },
          "endpoint_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "soul_id",
          "content",
          "scope",
          "endpoint_id",
          "created_at",
          "updated_at"
        ]
      },
      "TraceStep": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "passed",
              "blocked",
              "skipped"
            ]
          },
          "detail": {
            "type": "string"
          },
          "duration_ms": {
            "type": "integer"
          }
        },
        "required": [
          "name",
          "status",
          "detail",
          "duration_ms"
        ]
      },
      "Trace": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "soul_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "endpoint_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "message": {
            "type": "string"
          },
          "response": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "memory_replay",
              "llm"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "completed",
              "blocked",
              "failed"
            ]
          },
          "latency_ms": {
            "type": "integer"
          },
          "memory_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TraceStep"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "soul_id",
          "endpoint_id",
          "message",
          "response",
          "mode",
          "status",
          "latency_ms",
          "memory_ids",
          "steps",
          "created_at"
        ]
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "name": {
            "type": "string"
          },
          "prefix": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "read",
                "write",
                "interact"
              ]
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "prefix",
          "scopes",
          "created_at",
          "last_used_at",
          "revoked_at"
        ]
      },
      "PartnerApplication": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "company": {
            "type": "string"
          },
          "device": {
            "type": "string"
          },
          "stage": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "received",
              "reviewing",
              "accepted"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "email",
          "company",
          "device",
          "stage",
          "message",
          "status",
          "created_at"
        ]
      },
      "EvaluationCase": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "passed": {
            "type": "boolean"
          },
          "detail": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "passed",
          "detail"
        ]
      },
      "Evaluation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "suite": {
            "type": "string"
          },
          "passed": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "cases": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EvaluationCase"
            }
          },
          "duration_ms": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "scope": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "suite",
          "passed",
          "total",
          "cases",
          "duration_ms",
          "created_at",
          "scope"
        ]
      },
      "Runtime": {
        "type": "object",
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "memory_replay",
              "llm"
            ]
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_configured": {
            "type": "boolean"
          },
          "storage": {
            "type": "string",
            "const": "d1"
          },
          "api_version": {
            "type": "string",
            "const": "v1"
          },
          "demo_mode": {
            "type": "boolean"
          }
        },
        "required": [
          "mode",
          "model",
          "provider_configured",
          "storage",
          "api_version",
          "demo_mode"
        ]
      },
      "Bootstrap": {
        "type": "object",
        "properties": {
          "user": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              },
              "name": {
                "type": "string"
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "demo": {
                "type": "boolean"
              },
              "expires_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            },
            "required": [
              "id",
              "name",
              "email",
              "demo",
              "expires_at"
            ]
          },
          "souls": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Soul"
            }
          },
          "endpoints": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Endpoint"
            }
          },
          "memories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Memory"
            }
          },
          "traces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Trace"
            }
          },
          "keys": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiKey"
            }
          },
          "applications": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PartnerApplication"
            }
          },
          "evaluations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Evaluation"
            }
          },
          "stats": {
            "type": "object",
            "properties": {
              "souls": {
                "type": "integer"
              },
              "endpoints": {
                "type": "integer"
              },
              "memories": {
                "type": "integer"
              },
              "requests": {
                "type": "integer"
              },
              "blocked_requests": {
                "type": "integer"
              },
              "avg_latency_ms": {
                "type": "integer"
              }
            },
            "required": [
              "souls",
              "endpoints",
              "memories",
              "requests",
              "blocked_requests",
              "avg_latency_ms"
            ]
          },
          "runtime": {
            "$ref": "#/components/schemas/Runtime"
          }
        },
        "required": [
          "user",
          "souls",
          "endpoints",
          "memories",
          "traces",
          "keys",
          "applications",
          "evaluations",
          "stats",
          "runtime"
        ]
      },
      "Action": {
        "type": "object",
        "properties": {
          "capability": {
            "type": "string",
            "minLength": 1
          },
          "input": {
            "type": "object"
          }
        },
        "required": [
          "capability"
        ]
      },
      "InteractionInput": {
        "type": "object",
        "properties": {
          "soul_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "endpoint_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "maxLength": 6000
          },
          "action": {
            "$ref": "#/components/schemas/Action"
          }
        },
        "required": [
          "soul_id",
          "endpoint_id",
          "message"
        ]
      },
      "ActionReceipt": {
        "type": "object",
        "properties": {
          "capability": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "simulated",
              "blocked"
            ]
          },
          "receipt": {
            "type": "string"
          }
        },
        "required": [
          "capability",
          "status",
          "receipt"
        ]
      },
      "InteractionResult": {
        "type": "object",
        "properties": {
          "response": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "memory_replay",
              "llm"
            ]
          },
          "soul": {
            "$ref": "#/components/schemas/Soul"
          },
          "endpoint": {
            "$ref": "#/components/schemas/Endpoint"
          },
          "memories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Memory"
            }
          },
          "trace": {
            "$ref": "#/components/schemas/Trace"
          },
          "action": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ActionReceipt"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "response",
          "mode",
          "soul",
          "endpoint",
          "memories",
          "trace",
          "action"
        ]
      },
      "SoulInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "personality": {
            "type": "string",
            "maxLength": 2000
          },
          "system_prompt": {
            "type": "string",
            "maxLength": 6000
          }
        },
        "required": [
          "name"
        ]
      },
      "SoulPatch": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "personality": {
            "type": "string",
            "maxLength": 2000
          },
          "system_prompt": {
            "type": "string",
            "maxLength": 6000
          }
        },
        "required": []
      },
      "EndpointInput": {
        "type": "object",
        "properties": {
          "soul_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "type": {
            "type": "string",
            "enum": [
              "web",
              "robot",
              "mobile",
              "glasses",
              "api"
            ]
          },
          "capabilities": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.-]{0,39}$"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "connected",
              "paused"
            ]
          }
        },
        "required": [
          "soul_id",
          "name"
        ]
      },
      "EndpointPatch": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "capabilities": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.-]{0,39}$"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "connected",
              "paused"
            ]
          }
        },
        "required": []
      },
      "MemoryInput": {
        "type": "object",
        "properties": {
          "soul_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "content": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          },
          "scope": {
            "type": "string",
            "enum": [
              "shared",
              "endpoint"
            ]
          },
          "endpoint_id": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "soul_id",
          "content"
        ]
      },
      "MemoryPatch": {
        "type": "object",
        "properties": {
          "content": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          }
        },
        "required": [
          "content"
        ]
      },
      "KeyInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "scopes": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "read",
                "write",
                "interact"
              ]
            }
          }
        },
        "required": [
          "name"
        ]
      },
      "KeyCreated": {
        "type": "object",
        "properties": {
          "key": {
            "$ref": "#/components/schemas/ApiKey"
          },
          "token": {
            "type": "string",
            "writeOnly": false,
            "description": "Shown once; retain securely. Never present in later list responses."
          }
        },
        "required": [
          "key",
          "token"
        ]
      },
      "PartnerInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "company": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "device": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "stage": {
            "type": "string",
            "maxLength": 80
          },
          "message": {
            "type": "string",
            "maxLength": 4000
          }
        },
        "required": [
          "name",
          "email",
          "company",
          "device"
        ]
      },
      "Ok": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          }
        },
        "required": [
          "ok"
        ]
      },
      "Account": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "email",
          "name"
        ]
      },
      "AccountSession": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "email",
          "name",
          "expires_at"
        ]
      },
      "AccountCredentials": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "password": {
            "type": "string",
            "minLength": 10,
            "maxLength": 200
          },
          "name": {
            "type": "string",
            "maxLength": 80
          }
        },
        "required": [
          "email",
          "password"
        ]
      },
      "AccountStatus": {
        "type": "object",
        "properties": {
          "account": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AccountSession"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "account"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "McpRequest": {
        "type": "object",
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "number",
              "null"
            ]
          },
          "method": {
            "type": "string"
          },
          "params": {
            "type": "object"
          }
        },
        "required": [
          "jsonrpc",
          "method"
        ]
      },
      "McpResponse": {
        "type": "object",
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "number",
              "null"
            ]
          },
          "result": {
            "type": "object"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "jsonrpc",
          "id"
        ]
      },
      "ConnectionProfile": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "evidence": {
            "type": "string"
          },
          "category": {
            "enum": [
              "developer",
              "assistant",
              "robot"
            ]
          },
          "endpoint_type": {
            "enum": [
              "web",
              "robot",
              "mobile",
              "glasses",
              "api"
            ]
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "support_status": {
            "enum": [
              "software-tested",
              "provider-config",
              "adapter-required",
              "verified"
            ]
          },
          "requirements": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "docs_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "transport": {
            "enum": [
              "https",
              "mcp",
              "local-adapter"
            ]
          },
          "hardware_verified": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "name",
          "support_status",
          "hardware_verified"
        ]
      },
      "ConnectSession": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "profile_id": {
            "type": "string"
          },
          "soul_id": {
            "type": "string"
          },
          "endpoint_id": {
            "type": "string"
          },
          "endpoint_name": {
            "type": "string"
          },
          "status": {
            "enum": [
              "awaiting_pair",
              "paired",
              "active",
              "expired",
              "revoked"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "paired_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_seen_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "credential_expires_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "credential_prefix": {
            "type": [
              "string",
              "null"
            ]
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "hardware_verified": {
            "const": false
          }
        },
        "required": [
          "id",
          "profile_id",
          "soul_id",
          "endpoint_id",
          "status",
          "expires_at"
        ]
      },
      "ConnectManifest": {
        "type": "object",
        "properties": {
          "version": {
            "const": "1.0"
          },
          "profile": {
            "$ref": "#/components/schemas/ConnectionProfile"
          },
          "api_base_url": {
            "type": "string"
          },
          "api_prefix": {
            "type": "string"
          },
          "mcp_url": {
            "type": "string"
          },
          "install_script_url": {
            "type": "string"
          },
          "connection_bundle_url": {
            "type": "string"
          },
          "contract_url": {
            "type": "string"
          },
          "grant_exchange_url": {
            "type": "string"
          },
          "hosting_access": {
            "type": "string"
          },
          "auth": {
            "type": "object",
            "properties": {
              "header": {
                "const": "X-Metabotics-Key"
              },
              "credential_kind": {
                "const": "endpoint"
              },
              "pairing_ttl_seconds": {
                "type": "integer"
              },
              "credential_ttl_seconds": {
                "type": "integer"
              }
            }
          },
          "preflight": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ConnectInput": {
        "type": "object",
        "properties": {
          "soul_id": {
            "type": "string"
          },
          "profile_id": {
            "type": "string"
          },
          "endpoint_name": {
            "type": "string",
            "maxLength": 80
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "soul_id",
          "profile_id",
          "endpoint_name"
        ]
      },
      "ConnectCreated": {
        "type": "object",
        "properties": {
          "session": {
            "$ref": "#/components/schemas/ConnectSession"
          },
          "pairing_code": {
            "type": "string",
            "description": "15-minute single-use grant; returned only on creation. Never use it as an API key."
          },
          "install_prompt": {
            "type": "string"
          },
          "manifest": {
            "$ref": "#/components/schemas/ConnectManifest"
          }
        },
        "required": [
          "session",
          "pairing_code",
          "install_prompt",
          "manifest"
        ]
      },
      "RedeemInput": {
        "type": "object",
        "properties": {
          "pairing_code": {
            "type": "string",
            "pattern": "^mbp_[a-f0-9]{64}$",
            "writeOnly": true
          },
          "client_name": {
            "type": "string",
            "maxLength": 100
          }
        },
        "required": [
          "pairing_code"
        ]
      },
      "RedeemResult": {
        "type": "object",
        "properties": {
          "credential": {
            "type": "string",
            "description": "Endpoint-scoped mbe_ credential, returned once. Store privately; at most 7 days or earlier sandbox expiry."
          },
          "session": {
            "$ref": "#/components/schemas/ConnectSession"
          },
          "manifest": {
            "$ref": "#/components/schemas/ConnectManifest"
          },
          "config": {
            "type": "object",
            "properties": {
              "base_url": {
                "type": "string"
              },
              "soul_id": {
                "type": "string"
              },
              "endpoint_id": {
                "type": "string"
              },
              "profile_id": {
                "type": "string"
              },
              "api_key_header": {
                "type": "string"
              },
              "mcp_url": {
                "type": "string"
              },
              "credential_expires_at": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "credential",
          "session",
          "config"
        ]
      },
      "ConnectPreflight": {
        "type": "object",
        "properties": {
          "status": {
            "enum": [
              "ready",
              "attention"
            ]
          },
          "api_base_url": {
            "type": "string"
          },
          "model_mode": {
            "enum": [
              "memory_replay",
              "llm"
            ]
          },
          "hosting_access_required": {
            "type": "boolean"
          },
          "workbuddy_launcher_configured": {
            "type": "boolean"
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "status": {
                  "enum": [
                    "passed",
                    "attention"
                  ]
                },
                "label": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "HeartbeatResult": {
        "type": "object",
        "properties": {
          "session": {
            "$ref": "#/components/schemas/ConnectSession"
          },
          "endpoint": {
            "$ref": "#/components/schemas/Endpoint"
          },
          "observed": {
            "type": "object",
            "properties": {
              "credential": {
                "const": "accepted"
              },
              "transport": {
                "const": "http"
              },
              "hardware_verified": {
                "const": false
              }
            }
          }
        }
      },
      "WorkBuddyLaunchInput": {
        "type": "object",
        "properties": {
          "session_id": {
            "type": "string"
          },
          "prompt": {
            "type": "string",
            "maxLength": 8000,
            "description": "Original installation prompt for this session, including its still-valid short-lived grant."
          }
        },
        "required": [
          "session_id",
          "prompt"
        ]
      },
      "WorkBuddyLaunch": {
        "type": "object",
        "properties": {
          "mode": {
            "enum": [
              "manual",
              "signed"
            ]
          },
          "url": {
            "type": "string"
          },
          "app_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "Direct deep link to the visitor's own WorkBuddy app, used with a copied install prompt when no registered-app signing credentials are configured."
          },
          "reason": {
            "type": "string"
          },
          "verification": {
            "const": "provider-config"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  }
}
