{
  "openapi": "3.1.0",
  "info": {
    "title": "SPADE Consulting Agent Intake API",
    "version": "2026-08-13",
    "description": "Machine-readable contract for authorized agents and human-agent teams to discover SPADE Consulting capabilities and email scoped requests into a private manual-review workflow. API acceptance never starts billable work or authorizes actions in customer systems."
  },
  "servers": [
    { "url": "https://api.spadeconsulting.no" }
  ],
  "paths": {
    "/api/agent/capabilities": {
      "get": {
        "operationId": "listAgentCapabilities",
        "summary": "List services that agents may request.",
        "responses": {
          "200": {
            "description": "Current capability catalog.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CapabilityCatalog" }
              }
            }
          }
        }
      }
    },
    "/api/agent/requests": {
      "post": {
        "operationId": "submitAgentRequest",
        "summary": "Submit an authorized request for private review.",
        "description": "The accountable principal must authorize the request. Do not include credentials, special-category personal data, or confidential customer material. Every logical request requires an idempotency key.",
        "parameters": [
          { "$ref": "#/components/parameters/IdempotencyKey" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AgentRequest" }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted by Resend for delivery to SPADE's private manual-review inbox.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AgentRequestResponse" } } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "Stable key for one logical request. Resend prevents duplicate delivery for identical retries within 24 hours. Reusing the key with a different payload returns HTTP 409.",
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{7,127}$"
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Request error.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorResponse" }
          }
        }
      }
    },
    "schemas": {
      "AgentRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["capability", "principal", "requester", "authorization", "summary"],
        "properties": {
          "capability": { "$ref": "#/components/schemas/CapabilityId" },
          "principal": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name", "email"],
            "properties": {
              "name": { "type": "string", "minLength": 2, "maxLength": 140 },
              "email": { "type": "string", "format": "email", "maxLength": 254 }
            }
          },
          "requester": {
            "type": "object",
            "additionalProperties": false,
            "required": ["type", "name"],
            "properties": {
              "type": { "type": "string", "enum": ["agent", "human-agent-team"] },
              "name": { "type": "string", "minLength": 2, "maxLength": 140 },
              "url": { "type": "string", "format": "uri", "pattern": "^https://", "maxLength": 500 }
            }
          },
          "authorization": {
            "type": "object",
            "additionalProperties": false,
            "required": ["confirmed", "scope"],
            "properties": {
              "confirmed": { "const": true },
              "scope": { "type": "string", "minLength": 10, "maxLength": 500 }
            }
          },
          "summary": { "type": "string", "minLength": 20, "maxLength": 4000 },
          "dataClassification": { "type": "string", "enum": ["public", "internal"], "default": "public" },
          "desiredOutcome": { "type": "string", "enum": ["proposal", "meeting", "review", "guidance", "api-access"], "default": "proposal" },
          "locale": { "type": "string", "enum": ["no", "en"], "default": "no" }
        }
      },
      "CapabilityId": {
        "type": "string",
        "enum": [
          "consulting.intake",
          "meeting.request",
          "security.risk_review",
          "privacy.dpia_triage",
          "privacy.vendor_review",
          "ai_act.classification_review",
          "ai_governance.policy_review",
          "nis2.scope_review",
          "document.compliance_review",
          "training.request"
        ]
      },
      "Capability": {
        "type": "object",
        "required": ["id", "name", "deliveryMode", "acceptedData", "typicalResponseTime", "pricingMode", "requiresHumanPrincipal"],
        "properties": {
          "id": { "$ref": "#/components/schemas/CapabilityId" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "deliveryMode": { "type": "string", "enum": ["human", "human_reviewed"] },
          "acceptedData": { "type": "array", "items": { "type": "string", "enum": ["public", "internal"] } },
          "typicalResponseTime": { "type": "string" },
          "pricingMode": { "type": "string", "enum": ["quoted", "free-intro"] },
          "requiresHumanPrincipal": { "const": true }
        }
      },
      "CapabilityCatalog": {
        "type": "object",
        "required": ["provider", "operatingModel", "capabilities"],
        "properties": {
          "provider": { "type": "string" },
          "operatingModel": { "type": "object" },
          "capabilities": { "type": "array", "items": { "$ref": "#/components/schemas/Capability" } }
        }
      },
      "AgentRequestResponse": {
        "type": "object",
        "required": ["ok", "operation", "requestId", "reviewStatus", "followUpChannel", "nextActions"],
        "properties": {
          "ok": { "const": true },
          "operation": { "const": "emailed" },
          "requestId": { "type": "string", "pattern": "^spr_[a-f0-9]{24}$" },
          "reviewStatus": { "const": "received_for_manual_review" },
          "followUpChannel": { "const": "email" },
          "nextActions": { "type": "array", "items": { "type": "string" } }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": { "error": { "type": "string" } }
      }
    }
  }
}
