{
  "openapi": "3.1.0",
  "info": {"title": "Agent inbox for Yo", "version": "1.0.0",
           "description": "Screened inbox. Nothing is approved without the owner deciding; spam and blocked senders may be closed without a personal answer. See https://agents.lifeloggedin.com/llms.txt."},
  "servers": [{"url": "https://agents.lifeloggedin.com"}],
  "components": {
    "securitySchemes": {"requestToken": {"type": "http", "scheme": "bearer", "description": "access_token returned once by POST /api/v1/requests"}},
    "schemas": {
      "Request": {
        "type": "object",
        "properties": {
          "type": {"type": "string", "enum": ["meeting", "message", "introduction", "question", "other"]},
          "from": {"type": "object", "properties": {"name": {"type": "string", "maxLength": 100}, "is_ai_agent": {"type": "boolean"}, "agent_platform": {"type": "string", "maxLength": 60}}},
          "contact": {"type": "object", "properties": {"name": {"type": "string"}, "organization": {"type": "string"}, "role": {"type": "string"}, "email": {"type": "string", "format": "email"}, "website": {"type": "string", "format": "uri"}}},
          "relationship": {"type": "string", "maxLength": 600},
          "subject": {"type": "string", "maxLength": 150},
          "message": {"type": "string", "maxLength": 4000},
          "meeting": {"type": "object", "properties": {
            "duration_minutes": {"type": "integer", "enum": [15, 20, 30, 45, 60]},
            "format": {"type": "string", "enum": ["video", "phone", "in_person"]},
            "timeframe": {"type": "string", "maxLength": 200},
            "timezone": {"type": "string", "maxLength": 64},
            "notes": {"type": "string", "maxLength": 600},
            "attendees": {"type": "array", "maxItems": 5, "items": {"type": "object", "properties": {"name": {"type": "string"}, "email": {"type": "string"}}}}
          }}
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "request_id": {"type": "string"},
          "status": {"type": "string", "enum": ["needs_info", "under_review", "approved", "declined", "replied", "closed"]},
          "type": {"type": "string"},
          "questions": {"type": "array", "items": {"type": "object", "properties": {"field": {"type": "string"}, "question": {"type": "string"}}}},
          "response": {"type": "object", "properties": {"decision": {"type": "string"}, "message": {"type": "string"}, "booking_url": {"type": "string"}, "at": {"type": "string"}}},
          "access_token": {"type": "string", "description": "Only in the response to the initial POST."},
          "next_step": {"type": "string"},
          "retry_after_seconds": {"type": "integer"}
        }
      }
    }
  },
  "paths": {
    "/api/v1/requests": {"post": {"operationId": "submitRequest", "summary": "Submit a request (partial is fine)",
      "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Request"}}, "text/plain": {"schema": {"type": "string"}}}},
      "responses": {"201": {"description": "Created", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Status"}}}}, "429": {"description": "Rate limited"}}}},
    "/api/v1/requests/{request_id}": {"get": {"operationId": "checkRequest", "summary": "Status and owner response", "security": [{"requestToken": []}],
      "parameters": [{"name": "request_id", "in": "path", "required": true, "schema": {"type": "string"}}],
      "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Status"}}}}, "404": {"description": "Unknown request or wrong token"}}}},
    "/api/v1/requests/{request_id}/messages": {"post": {"operationId": "addToRequest", "summary": "Answer questions or add information", "security": [{"requestToken": []}],
      "parameters": [{"name": "request_id", "in": "path", "required": true, "schema": {"type": "string"}}],
      "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "properties": {"fields": {"$ref": "#/components/schemas/Request"}, "message": {"type": "string", "maxLength": 3000}}}}}},
      "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Status"}}}}, "409": {"description": "Request already decided"}}}}
  }
}
